I am using STM32F072 mcu and IAR as compiler.
When I run the code below, it goes into hardfault handler. I couldn't figure out why is that.
uint8_t *ptr1;
uint32_t *ptr2;
uint32_t temp;
typedef struct{
uint8_t Data[10];
} example_struct;
example_struct sensor;
sensor.Data[0] = 0xAA;
ptr1 = &sensor.Data[0]; // here ptr1 is pointing 0xAA with no problem
ptr2 = (uint32_t*) ptr1; // here *ptr2 is 0x000000AA, so there is no problem.
temp = *ptr2; // here mcu goes in to hardfault handler
Do you have any idea why I am having this issue?
Thanks
User contributions licensed under CC BY-SA 3.0