Skip to main content
SDalv.1
Associate II
April 2, 2021
Question

Misaligned memory write causes hard fault.

  • April 2, 2021
  • 1 reply
  • 951 views

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

This topic has been closed for replies.

1 reply

Tesla DeLorean
Guru
April 2, 2021

The CortexM0 does not tolerate misaligned word access.​

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