I am working on a boot loader for a STM32F103 (Cortex M3) and I cannot get the jump code to work properly. I am fairly new to ARM and I have exhausted my knowledge in trying to fix this. This is what I have:
#define USER_FLASH_START ( 0x8000000 + ( 16 * 1024 ) ) /* Flash start address 16K */ #define USER_FLASH_END ( 0x8000000 + ( 0x10000 ) ) #define USER_FLASH_SIZE ( USER_FLASH_END - USER_FLASH_START )
void GoToUserApp(void) {
u32 appJumpAddress;
void (*GoToApp)(void);
appJumpAddress = *((volatile u32*)(USER_FLASH_START + 4));
GoToApp = (void (*)(void))appJumpAddress;
SCB->VTOR = USER_FLASH_START;
__set_MSP(*((volatile u32*) USER_FLASH_START)); //stack pointer (to RAM) for USER app
GoToApp();
}
The above code just keeps causing the controller to reset. If I debug, I am getting these values:
- USER_FLASH_START: 0x8004000 - appJumpAddress: 0x8000101 - GoToApp: 0x8000101 - __set_MSP: 0x8000156
These values do not make sense to me so I am hoping someone here can help me out. Thanks.
If you have linked the application for address 0x8000000 but stores it in address 0x8000000 + ( 16 * 1024 ) then you will pick up a reset vector that does not point into the code but instead points into your boot loader.
And if you created your application and specified the wrong address range for your RAM, then you might also pick up a very strange stack pointer.
Thanks! That was the problem. I didn't change the boot loader but I recompiled my test code and changed the R/O Base to 0x08004000 in the Linker tab. That fixed it.