2025-02-22 01:37 PM
While working on a FLASH writing routing I got stumped with a bunch of flags being set in the SR register. It starts with CFGBSY. reading through the forums someone said they encountered this while accessing an uninitialized pointer. I found that I was doing the same. So my question is this, is there some type of exception or error that is being detected by this uninitialized access that I can see that would lead me faster to know I was using an uninitialized pointer?
Thanks
2025-02-22 02:45 PM
As far as the chip is concerned, there is no difference between a regular access and an "uninitialized" access. If the pointer points to a valid memory space, it'll return what's there. If not, you'll get a hard fault. Note that 0x0 is a valid memory address.
If you don't want 0x0 to be a valid memory address, you can set the MPU to hard fault when it's accessed.
assert(ptr != null) type statements can be helpful. But there's no silver bullet for preventing uninitialized pointer bugs. Have to get the code right.