I am using a TM4C1294NCPDT and am currently porting a bootloader that was developed for the LM3S9D90. The problem that has me stuck is that after a call to ROM_FlashErase, subsequent code will cause a hard fault. I have used two methods to track down this hard fault: printing to UART2 and toggling an LED. For example, line 10 will cause a hard fault when the UART2 interrupt is enabled. Line 9 will likewise cause a fault when GPIOPinWrite is called (the GPIOPinRead part of that macro seems to work?). If both lines 9 and 10 are removed from the loop, the loop will complete, then I will get a hard fault in line 12 (if in) or line 13 (if 12 is removed). If both line 12 and 13 are removed, I will get a hard fault later. The NVIC_VTABLE is always 0.
Here is the code fragment.
- PRINTF("About to start flash erase.\n"); //This prints OK
- MID_LED_TGL; //This works
- //Note: MID_LED_TGL is GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_1, (GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_1) ^ GPIO_PIN_1))
- // Enter a loop to erase all the requested flash pages beginning at the
- // application start address (above the USB stick updater).
- for (ulIdx = APP_START_ADDRESS; ulIdx < ulFlashEnd; ulIdx += FLASH_PAGE_SIZE) {
- ROM_FlashErase (ulIdx);
- //MID_LED_TGL; //this will cause a hard fault if used
- //PRINTF("Erased a page.\n"); //this will cause a hard fault if used (when the UART interrupt is enabled)
- }
- MID_LED_OFF; //if just ROM_FlashErase is in previous loop, then this will cause a hard fault
- PRINTF("Finished flash erase.\n"); //This will fault when interrupt is enabled
This may or may not be related, but it might be a clue: when I get this fault, I cannot restart the code in the debugger. If the code is stopped and I do a System Reset and/or Core Reset and press the Restart button (which is what I normally do to re-start code) code starts immediately (without me pressing the "Play" button) and the uC will be in the hard fault handler. Forcing a reload of the uC is the only why I've found to re-run the code.