This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Type struct pointer issue

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.....

Parents
  • __attribute__((packed))   and  __packed are very similar, but not the same.
    
    struct S2E_Packet
    {
       uint8_t module_type[3];
       uint8_t fw_ver[3];
       uint32_t uint1;   // &se2_Packet.uint1 gives you a (uint32_t *)
    } __attribute__((packed)) S2E_Packet;
    
    __packed struct S2E_Packet
    {
        uint8_t module_type[3];
        uint8_t fw_ver[3];
        uint32_t uint1;  // &se2_Packet.uint1 gives you a (__packed uint32_t *)
    } S2E_Packet;
    
    
    If you use the following cast, it works with aligned or un-aligned data. No Hard Fault.
    uint32_t test = *(__packed uint32_t*)AddressSrc;
    
    
    
    
    Google "Cortex-M0 data alignment" and you will get good information
    
    
    

Reply
  • __attribute__((packed))   and  __packed are very similar, but not the same.
    
    struct S2E_Packet
    {
       uint8_t module_type[3];
       uint8_t fw_ver[3];
       uint32_t uint1;   // &se2_Packet.uint1 gives you a (uint32_t *)
    } __attribute__((packed)) S2E_Packet;
    
    __packed struct S2E_Packet
    {
        uint8_t module_type[3];
        uint8_t fw_ver[3];
        uint32_t uint1;  // &se2_Packet.uint1 gives you a (__packed uint32_t *)
    } S2E_Packet;
    
    
    If you use the following cast, it works with aligned or un-aligned data. No Hard Fault.
    uint32_t test = *(__packed uint32_t*)AddressSrc;
    
    
    
    
    Google "Cortex-M0 data alignment" and you will get good information
    
    
    

Children