-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clock issues for STM32F103RE custom board #32382
Comments
I think the timer is still off, I tried counting using the Mbed OS blinky example: int main()
{
// Initialise the digital pin LED1 as an output
DigitalOut led(LED1);
int a = 0;
while (true) {
led = !led;
printf("%d\n", a++);
ThisThread::sleep_for(BLINKING_RATE);
}
} And the timing matches stopwatch perfectly, so there must be something wrong with my setup. |
Thanks for reporting. We need to resinstantiate it. |
This reverts commit "drivers/clock_control: Remove useless CLOCK_STM32_PLL_XTPRE config" 9be1f7e. Fixes zephyrproject-rtos#32382 Signed-off-by: Erwan Gouriou <[email protected]>
@erwango Hi, I've added the commit manually in PlatformIO's Zephyr package and it seems to be working? With the same ~2s slower than Windows 10 stopwatch after 10mins. I'm not sure if this is normal? |
Can you clarify the question ? What are you measuring ? What is the clock source ? |
Hi @ycsin, I was also working on this bug and I think I have pretty much the same HW setup as you. 16MHz external clock and running the sytem at 72MHz on an STM32F103C8T6. The pull-request fixed it for me and the clock configuration looks correct now. I tried to reproduce the clock drift issue with your code snipped (I picked SLEEP_TIME_MS = 1000) but for me it tracks the system time of my PC well. After about 2500 seconds I have no visible drift in the seconds range (granted that this is a fairly crude measruement). Can you check the content of your RCC_CFGR register and see if it matches the configuration you expect? Especially if the HSE clock is really selected? |
Hey @erwango, I was counting up a variable every second like so in the while (1) {
printk("%d\n", a++);
k_msleep(1000);
} and compared the value with a stopwatch to determine the timer precision. But the value was 1 second slower than a stopwatch after every 5 minutes. (slower clock) I've tried to compile a similar program using Mbed OS that I mentioned earlier, but the Mbed OS example doesn't have the "slower clock" issue. Therefore I wondered if this is an expected outcome. The clock source that I'm using for the RTC is a 32.768kHz LSE. I've tried to setup the defconfig to use LSE for the RTC:
And also these flags to enable the RTC counter.
After further digging I guess this issue is likely due to this #32431 |
Hey @narodo, I'll check it asap, do you mind sharing me your I've added LSE and COUNTER/RTC related flags but they are disabled as they are not working.
|
@narodo This is my RCC register's content: This is the result of my comparison: |
Hi @ycsin, I let my board run for a lot longer and I can also see some drift now. But it took me about ~5000 seconds to get to the 2s(ish). So a factor of 10 slower than your test. In my opinion the clock tree is configured correctly now. I don't think this patch is related to this behaviour. I don't see how it could introduce this drifting behaviour if the clocks are setup correctly (which they seem to be according to the RCC_CFGR register). I think the problem is that the printk time execution time has to be added to the loop time (plus any other overhead), and that's why this test if off by so much as this error accumulates. |
This reverts commit "drivers/clock_control: Remove useless CLOCK_STM32_PLL_XTPRE config" 9be1f7e. Fixes #32382 Signed-off-by: Erwan Gouriou <[email protected]>
This reverts commit "drivers/clock_control: Remove useless CLOCK_STM32_PLL_XTPRE config" 9be1f7e. Fixes #32382 Signed-off-by: Erwan Gouriou <[email protected]>
This reverts commit "drivers/clock_control: Remove useless CLOCK_STM32_PLL_XTPRE config" 9be1f7e. Fixes #32382 Signed-off-by: Erwan Gouriou <[email protected]>
CONFIG_CLOCK_STM32_PLL_PREDIV1
inCUSTOM_BOARD_defconfig
for my custom board based on STM32F103RET6 doesn't seem to be working.My board is using a 16 MHz HSE. To support my custom board, I copied the
nucleo_f103rb
board and made necessary changes to the board files. However, thenucleo_f103rb
does not use HSE but the 8MHz clock from the STLINK, therefore for my case I will have to divide the HSE output by 2 before inputting into the PLL Source Mux, which will be X9 at its output to obtain 72 Mhz atSYSCLK
.I've met two issues when I try to configure this:
CONFIG_CLOCK_STM32_PLL_MULTIPLIER
to 9, settingCONFIG_CLOCK_STM32_PLL_MULTIPLIER
to a value lower than 9 works, but thek_msleep(SLEEP_TIME_MS)
in Blinky example doesn't match the specified time.CONFIG_CLOCK_STM32_PLL_PREDIV1
has no effect to the program.After checking
drivers\clock_control\clock_stm32f1.c
'sconfig_pll_init(LL_UTILS_PLLInitTypeDef *pllinit)
andRCC_PLLConfig(u32 RCC_PLLSource, u32 RCC_PLLMul)
of STM32HAL'sstm32f10x_rcc.h
, I guess theconfig_pll_init(LL_UTILS_PLLInitTypeDef *pllinit)
is missing something for thepllinit->Prediv
.I've then edited
config_pll_init(LL_UTILS_PLLInitTypeDef *pllinit)
to the following:My def_config file:
And now the program is able to work, and counting up like so:
Seems to match my stopwatch pretty well, with ~2 seconds off after ~10 minutes. But I'm not sure if I'm doing it correctly.
Environment:
Additional context
Highlighted in green is my
CONFIG_CLOCK_STM32_PLL_PREDIV1
, and can only choose from/1
or/2
according to STM32CubeMX.The text was updated successfully, but these errors were encountered: