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.

TM4C123GH6PM: Increasing string array size above 20 elements causes program to hang and after pausing the debugger creates hard fault

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: EK-TM4C123GXL

platform : EK-TM4C123GXL

IAR Embedded Workbench 32kb limit version, v.9.20.4.47112

IAR Embedded Workbench shared components v.9.0.11.9006

Used timers example from (TivaWare_C_Series-2.2.0.295) as a foundation for the program, added I2C for LCD display, removed timers and LED, wrote routine to scan 8x10 keys array (see below)

void InitKBScanner()
{
UARTprintf("\033[2JKBScannerf initializing...\n");


// Initializing pin groups
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

// Configuring scanning pins
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 |GPIO_PIN_3);//MATC0,1,2 and 3
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7);//MATC4,5,6 and 7

//Configuting scanner reading pins
MAP_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3| GPIO_PIN_4| GPIO_PIN_5);//MATL0-5
MAP_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7);//MATL6-9

// Turning all scanning pins LOW
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 |GPIO_PIN_2 |GPIO_PIN_3, 0);
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7, 0);
}

Code compiles and works well if the char* KB_MAP[] contains no more than 20 elements, biggest element is 9 char string.

I have split array in 8 separate arrays x10 elements each and implemented data display (see below)

char* KB_MAP_MATC0[10]=
{
"1", "2", "3", "K", "L", "M", "N", "O", "blank", "CLR"
};
char* KB_MAP_MATC1[10]=
{
"4", "5", "6", "P", "Q", "R", "S", "T", "BRT", "LEFT"
};
char* KB_MAP_MATC2[10]=
{
"7", "8", "9", "U", "V", "W", "X", "Y", "DIM", "RIGHT"
}; etc

//data display:

void displayLabel(char* LBL)
{
UARTprintf(LBL);
SetCursorPos(11, 3);
WriteString(LBL);

}

//example of scanning one column of the matrix with data display

GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 1);
keyCode=KeyDetectf();
if(keyCode)
{
displayLabel(KB_MAP_MATC0[(keyCode-1)]);
keyCode=0;
SysCtlDelay(50000);

}

GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0);

//keyDetecf detects high input and returns line number for activated key

uint8_t KeyDetectf()
{
uint8_t matL=0; //returning active MATLx line value
//UARTprintf(" KeyDetectf called...\n");
// SysCtlDelay(5000000);
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0))
matL=1;
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1))
matL=2;
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2))
matL=3;
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3))
matL=4;
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_4))
matL=5;
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_5))
matL=6;
if(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_4))
matL=7;
if(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_5))
matL=8;
if(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_6))
matL=9;
if(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_7))
matL=10;
return matL;
}

Code executes perfectly well, only when any two out of eight column scans use "displayLabel(KB_MAP_MATCx[(keyCode-1)]);"

Adding third arbitrary column call "displayLabel(KB_MAP_MATCx[(keyCode-1)]);" compiles without errors or warnings, but debugging and execution hangs and upon stopping debugger results in hard fault:

"Fri May 20, 2022 14:31:31: HardFault exception.
Fri May 20, 2022 14:31:31: The processor has escalated a configurable-priority exception to HardFault.
Fri May 20, 2022 14:31:31:
Fri May 20, 2022 14:31:31: A precise data access error has occurred (CFSR.PRECISERR, BFAR)
Fri May 20, 2022 14:31:31: At data address 0x1ffffff0.
Fri May 20, 2022 14:31:31:
Fri May 20, 2022 14:31:31: A derived bus fault has occurred on exception entry (CFSR.STKERR, BFAR)
Fri May 20, 2022 14:31:31: At data address 0x1ffffff0.
Fri May 20, 2022 14:31:31:
Fri May 20, 2022 14:31:31: Could not determine the location where the exception occurred.
Fri May 20, 2022 14:31:31:
Fri May 20, 2022 14:31:31: See the call stack for more information."

Call stack displays:

" FaultISR()

   <Exception frame> "

Any and all help will be greatly appreciated. 

  • Hello Andrei,

    What is the stack size you've set? My first instinctual hunch here is stack overflow. Have you tested to see that is not the root cause?

    Best Regards,

    Ralph Jacobi

  • Ralph, 

    Thank you very much for prompt response.

    The stack size was set by the example source code and I have not touched it.

    $PROJ_DIR$\timers.icf:

    "

    //
    // Define a memory region that covers the entire 4 GB addressible space of the
    // processor.
    //
    define memory mem with size = 4G;

    //
    // Define a region for the on-chip flash.
    //
    define region FLASH = mem:[from 0x00000000 to 0x0003ffff];

    //
    // Define a region for the on-chip SRAM.
    //
    define region SRAM = mem:[from 0x20000000 to 0x20007fff];

    //
    // Define a block for the heap. The size should be set to something other
    // than zero if things in the C library that require the heap are used.
    //
    define block HEAP with alignment = 8, size = 0x00000000 { };

    "

    Please advise

  • Hello Andrei,

    I'm not overly familiar with the IAR setup for this, but from what I can see you can edit the stack size in the start_ewarm.c file. Look for a line like this:

    //*****************************************************************************
    //
    // Reserve space for the system stack.
    //
    //*****************************************************************************
    static uint32_t pui32Stack[64] @ ".noinit";

    I would recommend trying 512 bytes as an initial stack size.

    Best Regards,

    Ralph Jacobi

  • That did it. I am a greenhorn in this scary IAR jungles and really appreciate your expertise and guidance.

    Thank you sir.

  • Hi Andrei,

    Glad that worked out! Though I only have fractionally more experience than you do on IAR.

    If you have the option, you may want to consider Code Composer Studio for an IDE instead. It's license-free and our TM4C team would be much more capable to help you with questions as well (plus we have a whole CCS support team).

    Best Regards,

    Ralph Jacobi