When using ARM GCC g++ compiler with optimization level -O2 (and up) this code:
HAL_R32
(REG_AON_STACK
);//
=> r0
= (*
(volatile uint32_t*
)(0x00000000
))
200008a8: 2300 movs r3,
200008aa: 681b ldr r3,
[r3,
200008ac: deff udf
And this gives me hardfault at undefined instruction @0x200008ac. Also, if there is more code after that, it is not compiled into final binary.
You can disable this by using -fno-delete-null-pointer-checks
The pointer you are passing has a value which matches the null pointer, and the compiler can see that from static analysis, so it faults (because that is the defined behaviour).