Peripheral init broken at any optimization above zero.

Share code examples or discuss embedded software, including device drivers, interrupt handlers, middleware and application code.
Posts: 13
Joined: Thu Nov 10, 2016 8:58 am

Peripheral init broken at any optimization above zero.

Postby Otatiaro » Thu Dec 22, 2016 8:52 pm


I have a weird issue with optimization. I'm writing drivers, so far one for an USART, and one for an SPI.
Final app will require high performance, so I'm regularly checking that everything works fine on O3.
Target MCU is STM32F401CC, I do not use the hal nor the standard peripheral library, only the registers definition and their flags. The code is c++ only.

The USART driver went fine, I can init, receive and transmit (using DMAs) without any problem on O0, O3, Os, etc.

But the SPI driver triggers an IBUSERR as soon as optimization is set above O0 (even on Og !). I did check the compiled code and the disassembly seems fine, loading registers with values and modifying them with BIC.w and stuff. If I reorder some lines of code, then the hard fault error triggers on a different line (but always in the SPI init function, or just after returning from it). Isn't IBUSERR precise ? It seems there can be a few instructions before it triggers.

I'll post the code tomorrow, but does anybody already faced this kind of issue ?
I already did check the classical errors like uninitialized variables, etc.


Mattias Norlander
Posts: 78
Joined: Fri Apr 29, 2016 10:01 am

Re: Peripheral init broken at any optimization above zero.

Postby Mattias Norlander » Wed Jan 11, 2017 4:38 pm

Could you post the code?

Return to “Embedded target code development discussions”

Who is online

Users browsing this forum: No registered users and 1 guest