This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

HardFault when writing/erasing flash unless RTT debugger active

Hi,

I found one older question (7 months ago) with the same problem but that had no answer.

Situation:

- SDK 15.3, s132 v6.1.1
- The softdevice has been enabled and ble stack initialized
- Code needs to erase and write a flash page (settings) unless already initialized

As soon as the flash erase (or write) is performed, the app crashes unless the RTT debugger (RTT viewer or Ozone) is attached. If the debug-connection is active everything works.

My code stores the hardfault information into noinit memory and prints it to RTT on next reboot, so when I attach a RTT connection to continuously rebooting MCU, I get:


00:00:00 *CPU FAULT*
00:00:00 - HFSR = 40000000
00:00:00 - CFSR = 400
00:00:00 - MMFAR = e000ed34
00:00:00 - BFAR = e000ed38
00:00:00 - R0 = 2000587c
00:00:00 - R1 = 1
00:00:00 - R2 = 76b6f
00:00:00 - R3 = 4001e400
00:00:00 - R12 = 0
00:00:00 - LR = 200058ac
00:00:00 - PC = 77141
00:00:00 - PSR = 0

PC is in the bootloader memory though the application code is clearly being run (seen from power curve).


Same thing happens with both Debug & Release builds and I'm running out of ideas...

Parents Reply Children
  • That was it! Very big THANK YOU! (A simple debug print of BPROT config registers confirmed this)

    It looks like the default DFU bootloader marks all but the 0x7F000 page above bootloader start protected. We used to have a bootloader starting from 75000 so that debug version would fit. Unfortunately the DFU cannot change the bootloader start address when updating SD + BL, so now were stuck with it and had to use the 7D for our settings page. 

    So all I have to do is to modify our bootloader code to not mark the needed pages protected and we're good to go.

    Thank you for a swift solution!

Related