cancel
Showing results for 
Search instead for 
Did you mean: 

Misaligned memory write causes hard fault.

SDalv.1
Associate II

Hi,

I checked with the test code below, and it sets the hard fault for the G0 controller. It looks like an alignment issue. But the same code runs fine with L4 and F4 microcontrollers and does not set any fault for misaligned assignments. Project settings for all the 3 controllers was default generated by the ST Cube IDE. So is this an issue with the microcontroller G0 where I am facing this issue currently ?

This test code fails for G0 but passes for L4 and F4 controllers

 UI_8 Buffer[16] = {0};

*(UI_16*)(Buffer+1)=*(UI_16*)(Buffer+1); // Code goes to hard fault at this line.

// Buffer + 1 is not a 4 byte aligned address.

Thanks,

Nilesh

1 REPLY 1

The CortexM0 does not tolerate misaligned word access.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..