Hi,
I'm using Freertos on a LPC4370 and, in order to optimize power consumption, I'm trying to change the core clock frequency depending on what section of code the core is running.
However, for the rtos to keep working as expected the tickrate must be kept constant. Since the core's Systick timer is being used to generate the OS's tick and it uses the same clock base as the core, when the core clock frequency changes, I'm also changing the Systick config registers. So far, I've been having trouble with keeping the freertos time ticking at the correct rate, seemingly indicating that the Systick isn't interrupting at the correct rate.
The procedure I'm following is:
The clock settings for the peripherals remain unchanged as they are fed from other base clocks, unrelated to the core clock.
So far I've found that everything seems to work when the core clock changes are made between frequencies on lower ranges, e.g. from 12MHz to 90MHz. If I request the time since boot from the OS, I can verify that the internal time is being correctly kept, that is, the systick is generating interrupts at the correct frequency after the core clock change.
However, if I try to move into higher frequency ranges, e.g. changing the core clock from 12MHz to 204MHz, I can verify that the time since boot variable isn't being updated at the correct frequency since every real second the internal clock advances ~30s. This seems to indicate that the systick isn't generating interrupts at the correct frequency.
While trying to debug this problem I've done the following tests:
Note that having the internal timekeeping run 30x faster in the second test is the same behavior as when the Systick registers were being updated on the first try, when both clock and systick configurations where being changed, which is not expected. From the first test I know that without changing clock frequency, updating the systick configuration registers produces the expected behavior. It is unclear why changing clock frequency affects that.
Furthermore, I've found the information present at the user manual to be confusing. While looking for details on the operation of changing core clocks, I've found subsection "13.2.1 Configuring the BASE_M4_CLK for high operating frequencies", from chapter "13 LPC43xx/LPC43Sxx Clock Generation Unit (CGU)", and the procedures it describes. Since every procedure listed explicitly includes the step "enable the crystal oscillator", I find it is implied that in order to run the core at more than 110MHz one needs to use an external crystal oscillator. However from the information specified in the rest of chapter 13, it seems that there should be no trouble to run the clock at 204MHz with the Internal RC as clock source, as it falls within the specified capabilities of the CGU and PLL1. This seems to be aligned with the results from the third test that show that running the clock at 204MHz from the start works as expected and internal time is correctly kept. Additionally, I've found that the datasheet also seems to imply that an external high-frequency oscillator isn't needed to operate at maximum frequency: "Three PLLs allow CPU operation up to the maximum CPU rate without the need for a high-frequency crystal. "
I'm out of ideas on how to try to solve this problem and any help or hints would be greatly appreciated.
Hi,
As you know that the systick module uses the same clock as Cortex-M4, which is driven by BASE_M4_CLK for LPC4370, pls output the BASE_M4_CLK to CLKOUT pin and use a scope to measure it's clock frequency and check if it is expected.
BR
XiangJun Rong