Procedures for developing an STM32 bootloader + app
Hello there,
I am trying to develop an STM32L4 proof of concept bootloader application. I am basing on this source: https://github.com/akospasztor/stm32-bootloader and Atollic's "Working with bootloaders on Cortex-M devices".
I am trying to do a simple thing: My bootloader should start and jump to a fixed address in flash, under which the regular application lies. The procedure I have done is as follows:
I have programmed the bootloader app to the flash memory (using ST-LINK), ld file contains following flash description:
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 220KThe total flash memory is 512K.
Then I flashed the application code to the memory (with ST-LINK). Its ld file flash parameter looks as follows:
FLASH (rx) : ORIGIN = 0x8037000, LENGTH = 292K220 * 1024 = 0x37000, so my starting address for the app is 0x08037000.
220K + 292K = 512K, so the memory sizes look fine.
My jump function looks as follows:
typedef void (*pFunction)(void);
/**
* @brief Jumps the program counter to the memory location set by \p address.
* Before the jump is performed vector tables are set.
*/
void boot_jump2Address(const uint32_t address)
{
uint32_t appStack;
pFunction appEntry;
// get the application stack pointer (1st entry in the app vector table)
appStack = (uint32_t)*((__IO uint32_t*)address);
// Get the app entry point (2nd entry in the app vector table
appEntry = (pFunction)*(__IO uint32_t*)(address + 4);
boot_basicClockConfig();
HAL_RCC_DeInit();
HAL_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
// Reconfigure vector table offset to match the app location
#if (SET_VECTOR_TABLE)
SCB->VTOR = address;
#endif
__set_MSP(appStack); // Set app stack pointer
appEntry(); // Start the app
while (1); // never reached
}I then start to debug the application (not bootloader code). The bootloader starts and it jump to the app code, then my debugger catches the PC and I can debug my application. The problem is that the application crashes. When debugging it, one can see that the line at which it crashes is in the HAL_RCC_OscConfig function generated by CubeMx:
assert_param(IS_RCC_PLLR_VALUE(RCC_OscInitStruct->PLL.PLLR));This assert is not passed, because the PLLR is visible as 1, instead of 2. 2 is the value set in the code. For some reason its changing itself. But only if I run directly to the breakpoint set at this line- if I go trhough the code line by line until this point, I can see in the debugger view that its 2 correctly. That doesnt matter, because the code crashes later on on similar stages.
My question is- Is there any additional setting I need to modify for my base application in order to place it under different flash address than 0x08000000? I have only changed the linker script (FLASH parameter). But is there anything else?
I would really appreciate all help, as I am out of ideas on how to fix this.
