Hello, I'm stuck with hardfault handler.
When I try to execute read value from pointer address:
struct S2E_Packet { uint8_t module_type[3]; uint8_t fw_ver[3]; } __attribute__((packed)) S2E_Packet;
struct S2E_Packet s2e_packet;
AddressSrc=(uint32_t)&s2e_packet; uint32_t test = *(uint32_t*)AddressSrc; HAL_FLASH_Unlock(); HAL_FLASH_Program(TYPEPROGRAM_WORD, AddressDes, test);
program goes to hardfault handler. No errors or warnings during compilation.
I have no idea.....
What processor is being used? Can you be more specific about what instruction is faulting, and the register/process state at that point? Can you step with a debugger? Can you use a Hard Fault Handler that provides details of the fault? Compilers check for syntax errors not functional ones.
Processor is STM32F072RB. Fault is connected with instruction: uint32_t test = *(uint32_t*)AddressSrc;
It is strange but it works when I switch to char: AddressSrc=(uint32_t)&s2e_packet; char test = *(uint32_t*)AddressSrc; Now I can read first byte of struct variable.
But I need 4 byte for flash write function.;(
Why I cannot read uint32_t type from pointer? What else can I check?
Note that you are playing with packed data.
Then you type-cast into a pointer that does not know anything about the data being packet. So if AddressSrc isn't a 32-bit-aligned value then you will get into troubles when reading/writing using your pointer.
Be very, very careful when playing with type casts. Especially that you don't strip some volatile, packed or other important attribute.
View all questions in Keil forum