-
Notifications
You must be signed in to change notification settings - Fork 292
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
Sleep time is too long in STM32F4 #674
Comments
Looks like it could be related to zephyrproject-rtos/zephyr#21762 |
We had a similar issue in STM32G0. In our case, it was because of PWM frequency was too low and not using the CPU frequency as expected. |
Hmm ok I am not doing anything involving PWM as far as I know. I tried playing with |
Take a look if it is not related to the PWM either way, because in our case it was affecting the timers, so changing the frequency over there fixed the issue for us. |
Would you mind giving me some more info on how to do this? I am new to this sort of thing :) |
Run your emulation, and execute command
At the top of the list should be 'sysTick' row. Check at what frequency is it set, and compare to the one you use in your example. To change systick frequency run for eg.
Or I think in "stm32f4.repl' you should see something like this:
|
Interesting. I saw that the frequency is set in the stm32f4.repl to 72MHz, and setting It seems like the time is much more precisely 2.0 seconds between state changes rather than ~2.3. I am not quite sure how this stuff plays with each other yet but will keep digging. Thanks :) |
In our specific case we had to change the repl file and adjust that to use the proper frequency as specified in the microcontroller datasheet. See:
|
Thanks I will try it. Weirdly I am struggling to find that value in the data sheet. That is probably a me-problem though! Edit: I think it is 100MHz. Setting the value there brought the time interval down to ~1.4s |
Look at zephyr examples and tests Maybe try with the official image:
|
Thanks for your help, I had not seen that online tool yet :) Setting it to 168MHz fixed the problem:
I am struggling to find out why this number was chosen though. I cannot see it in the datasheet. The only thing I have found at 168MHz is the AHB bus on one variant of the stm32f4 core. Edit: I was looking at the wrong datasheet, it looks like this board assumes the core is a STM32F415xx or STM32F417xx where TIM1 has a "Max timer clock" of 168MHz |
Quick search on stm site:
STM32F4-Discovery-kit uses STM32F407 and in DOCS it state:
So we can easily assume they used maximum frequency at which this mcu can operate. My question will be, why your code doesn't work when you set |
Yes, I had mistakenly been using the STM32F411xC/STM32F411xE data sheet. I just found this:
In So this could be what is causing a discrepancy https://docs.zephyrproject.org/latest/build/dts/api/bindings/clock/st,stm32-rcc.html
So perhaps my setting for |
Description
I am running the Zephyr "Blinky" example on the STM32F4_Discovery-Kit board. Blinky should change the state of the LED every 1 second. However, when running the software I see it takes roughly 2.33 seconds.
The main loop is
Where
SLEEP_TIME_MS
is 1000Expected behaviour
Roughly 1 second intervals in virtual time between LED state changes. Instead I see ~2 second intervals between state changes.
How to reproduce?
zephyr build cmd
test.resc
Environment
Please, provide the following information:
Additional information
I also tried removing the printf to see the effect on the latency but it was negligible. Removing the sleep entirely also lets the code spin freely, so it seems like it is the sleep that is taking too long and not something else introducing latency.
Do you plan to address this issue and file a PR?
Happy to try and fix once I know the problem. For now I do not know where to start.
The text was updated successfully, but these errors were encountered: