2013-01-21 11:33 AM
Chip: STM32F4
Toolchain: AtollicI have a custom bootloader at 0x08000000, and regular code at 0x0800C000. On boot, the bootloader checks for a valid image and then jumps to regular code: typedef void (*pFunction)(void); pFunction JumpToApplication; uint32_t jumpAddress; // Initialize the user application Stack Pointer __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS); // Jump to the user application // The stack pointer lives at APPLICATION_ADDRESS // The reset vector is at APPLICATION_ADDRESS + 4 jumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4); JumpToApplication = (pFunction) jumpAddress; JumpToApplication();This works as expected. However, I need to jump back to the bootloader from the main application. This is where I'm running into trouble. I'm trying to jump to mainFromUserSpace(). Here is part of my map file: .text.NVIC_SystemReset 0x080004c4 0x30 src\main.o .text.mainFromUserSpace 0x080004f4 0xc8 src\main.o .text.SendUartByte 0x080005bc 0x14 src\main.oThe function I'd like to jump to is mainFromUserSpace, so it looks like I want 0x080004f4 as my address, but this results in a hard fault: typedef void (*pFunction)(void); pFunction JumpToBootloader; uint32_t jumpAddress; // Initialize the bootloader Stack Pointer __set_MSP(*(__IO uint32_t*) 0x08000000); // Jump to the bootloader jumpAddress = *(__IO uint32_t*) (0x080004f4); JumpToBootloader = (pFunction) jumpAddress; JumpToBootloader();I only see one difference between the two jumps. The bootloader jumps to the reset vector for the user code while the user code jumps to an individual function in bootloader space. Am I setting this up properly? #stm32f4-bootloader2013-01-21 11:47 AM
Am I setting this up properly?
No. You're loading the address indirectly, and the address of 16-bit Thumb code is always ODD, the Cortex-M3 can't execute ARM code at EVEN addresses, and will Hard Fault. Personally to get back to the boot loader I'd probably just reset the processor, as there is less potential to get it in a screwed up state. Figure clocks, interrupts, vectors, etc.
// Jump to the bootloader
jumpAddress = (uint32_t) 0x080004f5; // 0x4f4 + 1
JumpToBootloader = (pFunction) jumpAddress;
JumpToBootloader();
2013-01-21 05:28 PM
Ah, the ''odd'' address has solved the problem. Thanks for the help.
2013-01-22 02:58 AM