This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GH6PGE hard fault on memory read

Hi,

I ran into a very weird error where the processor goes into a Hard Fault when I run a simple line like this:

uint8_t report_buffer [8];
int16_t motor_rpm, motor_torque;

motor_rpm = my_func1();
motor_torque = my_func2();

((float*)report_buffer) [0] = (float)motor_rpm;
((float*)report_buffer) [1] = (float)motor_torque;

The error appears in the line one before last.

My code size is big, but not that big. I am using a USB HID stack as a vendor specific HID device reporting 8 bytes every 16 msecs and a motor driver that is using the PWM0 module. Also using the FPU but not in Lazy Stacking mode.

The same code work fine before I declared the new variable int16_t motor_torque;

Please also help with how I can make a readable memory profile to find out if its a memory overrun or access violation or something using CCSv6.

  • After some fault analysis, I realize its an unaligned access fault.

    So in reality the code is more like this

    float a, b, c; //etc....
    int16_t motor_rpm, motor_torque;
    uint8_t report_buffer [8];

    motor_rpm = my_func1();
    motor_torque = my_func2();

    ((float*)report_buffer) [0] = (float)motor_rpm;
    ((float*)report_buffer) [1] = (float)motor_torque;


    So resolving the char pointer as a float cause the fault as the report_buffer is not 4-byte aligned (as per ARM specification).

    A simple solution is to move the declaration above the floats so that the compiler automatically aligns the buffer. The other would be to use some alignment mechanism like alignas keyword but I am not sure that if the TI compiler has that built in or not. another option would be to use std:allign.
  • Hello Safiullah,

    You may want to bring this to the attention of TI C/C== Compiler forum. There are already issues like use of cpp and its handling by the TI compiler, that this may also be addressed.

    Regards
    Amit