I am working with an LM4F232 using CCS 5.1. I previously posted this under the compiler area and they sent me to Stellaris.
I have a custom bootloader in the first 12KB of memory and use it to load an application into FLASH starting at 0x3000.
I am now trying to figure out how to jump to the application and start running.
I have the application loading and running in CSS at 0x3000. I have the bootloader loading and running in CSS at 0x0000.
For the application, I have in startup_css.c:
#pragma DATA_SECTION(g_pfnVectors, ".intvecs")
void (* const g_pfnVectors[])(void) =
{
(void (*)(void))((unsigned long)&__STACK_TOP),
// The initial stack pointer
ResetISR, // The reset handler
NmiSR, // The NMI handler
FaultISR, // The hard fault handler
MPU_fault_ISR, // The MPU fault handler
Bus_fault_ISR, // The bus fault handler
Usage_fault_ISR, // The usage fault handler
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
...
In memory for both the application running out of CCS and after using the bootloader to download the app to 0x3000:
Hex 32 Bit - TI Style g_pfnVectors 20001050 00008631 00007F5F 00007537 00008479 000082F1 000085B1 00000000 00000000 00000000 00000000 000084F9 00008309 00000000 000084B9 00008229 00008339 00008341
The first word is the top of the stack. The second word is the address of the ResetISR. Am I correct? Why are all the addresses seem to be
the address of the function + 1? They are all odd. I would expect something modulo 4. If I look at the disassmbly at 0x8630, I see I am at the
ResetISR.
So I am trying to jump to this code while running the bootloader in CSS and after downloading the application to flash:
void (*funcptr)( void ); // Set up function pointer to application
//
unsigned long funcptrAddress = *((unsigned long *)0x3004);
funcptrAddress--; // TODO: explain, why is entry into table an odd number and not modulo 4?
funcptr = (void (*)())funcptrAddress;
funcptr();
But I end up jumping into the weeds and end up in the FaultISR.
The Disassembly at 0x8630 is (and I do not understand it, is the code branching to the address in R14, if so where was R14 loaded?):
ResetISR:
00008630: F7FFB918 B.W _c_int00
372 }
00008634: 4770 BX R14
SysCtlDelay:
It is when I execute 0x8630 that I jump to FaultISR.
When I debug the application, execution starts at main(), so the initialization code is already run and
I am not able to set a breakpoint in ResetISR to see how this operates.
So what is wrong with this approach?