-
Notifications
You must be signed in to change notification settings - Fork 143
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
Add fastcode attribute to delay_ns #498
Conversation
This will only work on devices with a single-cycle access instruction cache, like the F3 (ICCM), F7 (I-Cache) and H7 I-Cache). |
Since I had a STM32G431 board handy, I decided to do a quick test on that. Here, the delay_ns function works roughly as expected, both with and without the modm_fastcode attribute enabled. But I think I found another issue with the delay_ns function. In my test code, I happened to also use a delay_us as well:
With a delay_us value of 10, I got a delay of 180us. With any other value I tried, I got the expected delay. Debugger showed the argument was in fact passed as 180, when I tried to pass 10. Inspecting disassembly, I found that when I used 10, the compiler passed the value of register r6 as first argument ( From https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#InputOperands:
I'm about to push a change that fixes it, by adding an output to the asm block. |
a2789fd
to
94044aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent catch!
GCC requires any input register that is modified be tied to an output, or optimizations may fail.
94044aa
to
19a00e2
Compare
Will merge next after CI passes. (Rebased on develop and reworded the commit messages slightly) |
See issue #495.
I found the delay_ns to be off by scale factor of 2 on stm32f303. Putting the code into fast code section fixes this, at least for this part.