2018-03-07 05:38 AM
Hello,
I'm currently designing a custom bootloader and get stuck during the 'Jump to App' function. I was recognizing, that there are a lot of community entries concerning that topic. I was reading and trying various topics, but unfortunately nothing really worked for me. Maybe anyone of you can give me the golden hint?
I'm using System Workbench for STM32 and want to implement my code on the STM32L431 device.
In the *.ld file of the bootloader I added regions FLASH2 and MAGIC:
/* Specify the memory areas */
/* Attention: Different sizes for different types of the controller (flash size!) */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 26K
FLASH2 (rx) : ORIGIN = 0x8006800, LENGTH = 254K - 26K -2K
MAGIC (rx) : ORIGIN = 0x803F800, LENGTH = 2K
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
FLASH2 will hold the app, MAGIC holds some bootloader specific data.
After readingAN3965 (esp. page 11), I changed the *.ld file of the app:
/* Specify the memory areas */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8006800, LENGTH = 256K - 28K
MAGIC (rx) : ORIGIN = 0x803F800, LENGTH = 2K
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?
Point 1 of AN3965 should be ok. Now Point 2:
/************************* Miscellaneous Configuration ************************/
/*!< Uncomment the following line if you need to relocate your vector Table in
Internal SRAM. */
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET 0x6800 /*!< Vector Table base offset field.
This value must be a multiple of 0x */�?�?�?�?�?�?�?�?�?�?�?�?
I compiled both the bootloader and the app and started the bootloader. I checked memory for correct download of the app.bin with ST-LINK Utility by comparing memory beginning from 0x8006800 with the binary: Everything's ok.
The first to entries in the binary file are:0x20010000 0x08006d0d
Now I want to start the the application:
__disable_irq();
volatile uint32_t StartAddress = (uint32_t) &_appStart; //label in linker file
/* Jump to user application */
JumpAddress = *(__IO uint32_t*)(&StartAddress + 4);
Jump_To_Application = (pFunction) JumpAddress;
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
__set_MSP(*(__IO uint32_t*) &StartAddress);
Jump_To_Application();�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
Set a breakpoint at line 12 and checked the MSP register: It holds the value 0x8006800.But going one step further and halt the cpu, I end up at address 0x8000d
The output of the openocd debugger:
Info : halted: PC: 0x08000d02
Info : The target is not running when halt was requested, stopping GDB.If I restart the controller, I end up in HardFault_Hanlder().
Info : halted: PC: 0x08001566
Error: address + size wrapped(0xffffffff, 0x00000004) Error: address + size wrapped(0xffffffff, 0x00000002) Error: address + size wrapped(0xffffffff, 0x00000004) Error: address + size wrapped(0xffffffff, 0x00000002)Has anyone of you an idea, why that's the case?
Solved! Go to Solution.
2018-03-07 06:24 AM
Pretty sure the system is not interested in the address of StartAddress, but rather the content
JumpAddress = *(__IO uint32_t*)(&StartAddress + 4);
__set_MSP(*(__IO uint32_t*) &StartAddress);
If StartAddress = 0x08006800, then
JumpAddress = *((__IO uint32_t*)(StartAddress + 4));
__set_MSP(*((__IO uint32_t*) StartAddress));
2018-03-07 06:24 AM
Pretty sure the system is not interested in the address of StartAddress, but rather the content
JumpAddress = *(__IO uint32_t*)(&StartAddress + 4);
__set_MSP(*(__IO uint32_t*) &StartAddress);
If StartAddress = 0x08006800, then
JumpAddress = *((__IO uint32_t*)(StartAddress + 4));
__set_MSP(*((__IO uint32_t*) StartAddress));
2018-03-07 07:44 AM
OMG! Didn't see the tree in the forest...
:(
Thanks Clive One for finding my needle in the haystack