When assigning a pointer to structure pointer, mcu goes in to Hardfault Handler

1

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

pointers
structure
stm32
asked on Stack Overflow Mar 25, 2020 by Frkn • edited Mar 26, 2020 by veeman

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0