erwinp
Posts: 2
Joined: Thu Sep 14, 2023 6:41 pm

Wrong core-clock from mailbox-property-interface with new bootloader images

Thu Sep 14, 2023 6:52 pm

Hello,
I have a Pi4B and I write a baremetal software. The Pi boots with arm-clock 600MHz and core-clock 200MHz. I use the mailbox property interface to change the clock to a higher value. I set the arm-clock to the maximum of 1500MHz and I see that the core-clock changes to 500MHz.

I updated the bootloader images start4cd.elf and fixup4cd.elf to the newest versions (https://github.com/raspberrypi/firmware ... 1.20230405). After the update I see that the core-clock remains at 200MHz when I set arm-clock to 1500MHz. This has the effect that the calculation of the baudrate-reg for the mini-uart is wrong and the mini-uart does not work. When I calculate the baudrate-reg based on a fixed core-clock value of 500MHz then the mini-uart works.

For me it seems that that core-clock is 500MHz, but the mailbox reports a wrong value of 200MHz.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6948
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Wrong core-clock from mailbox-property-interface with new bootloader images

Fri Sep 15, 2023 6:38 pm

The rules are that GET_CLOCK_RATE will return the last value set by the arm (or initial value if unset).

That is required due to how linux works. When setting a clock, it does a GET_CLOCK_RATE and then skips the call if the value is as desired.

Returning a value that firmware has set (e.g. due to throttling, automatic boosting when entering turbo mode, or, say when required by a display, or video decoder) can unfortunately sometimes match what the arm wants, which means we lose the fact a higher clock was desired.

Then, when the firmware's reason for the clock boost has gone, the arm no longer has it's desired boost.

It may be best if you also request the boosted core clock.

Or you can use GET_CLOCK_MEASURED which will give the real value (although that is slightly slower to respond).

erwinp
Posts: 2
Joined: Thu Sep 14, 2023 6:41 pm

Re: Wrong core-clock from mailbox-property-interface with new bootloader images

Sat Sep 16, 2023 12:30 pm

I did not really understand everything of your explanation, so I have a few more questions:

This is what I want to achieve:
a) set the processor to its maximum speed
b) get the clock value that is used to calculate the baudrate-reg of the mini-uart

---
For a) I do this (is this correct?):
max_arm_clock = GET_MAX_CLOCK_RATE (CLOCK_ID_ARM)
SET_CLOCK_RATE(CLOCK_ID_ARM, max_arm_clock)

---
For b) do you mean that I have to set the core clock also to a new value?
new_core_clock = ???
SET_CLOCK_RATE(CLOCK_ID_CORE, new_core_clock)

But what is the new value for the core clock?
As soon as I know the value for new_core_clock, calling SET_CLOCK_RATE(CLOCK_ID_CORE, new_core_clock)
is useless for me because I can work with this value to calculate the mini-uarts baudrate-reg.

For me it seems that changing the arm clock, the core clock changes by the same ratio. Is this correct?
Are there other clocks that depend on the arm clock?

---
Is this an alternative procedure for a) ?
max_core_clock = GET_MAX_CLOCK_RATE (CLOCK_ID_CORE)
SET_CLOCK_RATE(CLOCK_ID_CORE, max_core_clock)

Thanks

Return to “Bare metal, Assembly language”