memcmp crashes when accessing data stored in flash
STM32H745zi
I am storing some configuration data in flash memory at address 0x080E0000.
If I call HAL_FLASHEx_Erase and then do a memcmp of 24 bytes at this address vs a buffer where I have prepared data I want to write there everything is fine although of course the data does not match.
However if i dont erase it and I just call memcmp of the new data with the data at this address I get this crash in the memcmp function:
CM7: r0 = 0x080e0000
CM7: r1 = 0x20000cf0
CM7: r2 = 0x00000018
CM7: r3 = 0x00000000
CM7: r12 = 0x2001fef3
CM7: lr = 0x08001c11
CM7: return_address = 0x08008778
CM7: xpsr = 0x21000200
CM7: SCB->HFSR = 0x40000000
CM7: Forced Hard Fault
CM7: SCB->CFSR = 0x00008200
CM7: SCB->BFSR = 0x82
CM7: BFARVALID - bfar address was the cause
CM7: SCB->BFAR = 0x080e0000
CM7: PRECISERR - instruction triggered the problem
R0-2 are the parameters I passed to memcmp
The assembly dump at 0x08008778 is
memcmp:
0800876c: push {r4, r5, lr}
0800876e: movs r4, #0
08008770: cmp r2, r4
08008772: bne.n 0x8008778 <memcmp+12>
08008774: movs r0, #0
08008776: b.n 0x8008788 <memcmp+28>
08008778: ldrb r3, [r0, r4]
so basically it is crashing on the loading of the byte at 0x080E0000 ... is doing a memcmp illegal for the STM32H7xx not a legal operation?
