Tool/software: Starterware
Hello.I have tried and studied the bootloader examples that are provided in the examples folder for the TM4C1294Xl launchpad. In my example, i'm trying to flash the firmware bytes (bytes that are generated in the bin file after successful builds) using the API " ROM_FlashProgram((uint32_t *)&FirmwareData, ui32ProgAddr, 4); ". which was explained in the usb_stick_update example.
Serially fetching the bytes on the UART3 on the TIVAC and then successfully writing them on the desired memory blocks as intended.
The code which performs all this operation is stored from memory location 0x000 and the serial data received is stored from location 0x00011F40.
In my example i'm trying to flash the bin file which is generated after changing the APP START ADDR of the default blinky code to 0x00011F40.
Now, after flashing the bytes i also verified the contents of the memory via the "Verify flash contents " option in the LM flash programmer.
Everything is perfect up till now.
Here is the code
CODE1
uint_fast32_t ui32ProgAddr = 0x00011F40; void CallApplication(uint_fast32_t ui32StartAddr) { HWREG(NVIC_VTABLE) = ui32StartAddr; __asm(" ldr r1, [r0]\n" " mov sp, r1\n"); __asm(" ldr r0, [r0, #4]\n" " bx r0\n"); } int main(void) { g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN |SYSCTL_USE_PLL |SYSCTL_CFG_VCO_480), 120000000); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); // ************************************************************************************** // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_6); GPIOPinWrite (GPIO_PORTA_BASE, GPIO_PIN_6, GPIO_PIN_6); GPIOPinConfigure(GPIO_PA4_U3RX); GPIOPinConfigure(GPIO_PA5_U3TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5); UARTConfigSetExpClk(UART3_BASE, g_ui32SysClock, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // ************************************************************************************** // // ************************************************************************************** // while(1) { if (APPflag == SET) CallApplication(APP_START_ADDRESS); while(UARTCharsAvail(UART3_BASE)) { i++; rdata[i] = UARTCharGetNonBlocking(UART3_BASE); Updatefirmware(i); // This function will write to the memory and set APPflag when all the bytes will be written } } }
The problem comes here in the CallApplication function that is getting called after successful flashing.
HWREG(NVIC_VTABLE) = 0x00011F40; __asm(" ldr r1, [r0]\n" " mov sp, r1\n"); __asm(" ldr r0, [r0, #4]\n" " bx r0\n");
Now the observed result is that the LED is blinking very fast. Now this is the abnormal behavior which i was talking about.
I selected the Flash necessary pages option in the CCS debug and flashed this following code into TIVAC.
CODE2
#define APP_START_ADDRESS 0x00011F40 int main(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); ROM_GPIODirModeSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)) { } GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1); while(1) { if(ROM_GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_0) == 0) { CallApplication(APP_START_ADDRESS); } } } void CallApplication(uint_fast32_t ui32StartAddr) { HWREG(NVIC_VTABLE) = ui32StartAddr; __asm(" ldr r1, [r0]\n" " mov sp, r1\n"); __asm(" ldr r0, [r0, #4]\n" " bx r0\n"); }
Note: At this point of time i have the above code(CODE2) starting from 0x000 and the flashed bin file contents of the previous code(CODE1) from 0x00011F40 (Since i selected erase necessary pages only in CCS Debug)
After running CODE2 the execution goes perfectly to the APP_START_ADDR which is 0x00011F40 in my case and the blinky is executed perfectly.
This experiment verifies that the program which i'm using to write on the flash memory(CODE1) is working perfectly. But when i try to call CallApplication() in CODE1 it shows abnormal execution of the program which works perfectly when i try to call CallApplication() from CODE2. I'm not sure how to debug this problem sort of problem.
Regards,
Nishit.