STM32L151C6, Jump to System Memory (Bootloader)
Background:
If I used the Boot0 button, reset, and the demo-flasher, everything works as it should.
Problem:
My application needs to jump to system memory. I've read many post on this which should be fairly straight forward but after jumping to System-Memory, the demo-flasher is not able to communicate with the mcu. Here is the code I'm using:
/**
* Function to perform jump to system memory boot from user application
*
* Call function when you want to jump to system memory
*/
void JumpToBootloader(void) {
void (*SysMemBootJump)(void);
/**
* Step: Set system memory address.
*
* For STM32L151, system memory is on 0x1FF0 0000
* For other families, check AN2606 document table 121 with descriptions of memory addresses
*/
volatile uint32_t addr = 0x1FF00000;
HAL_UART_MspDeInit(&huart1);
HAL_UART_MspDeInit(&huart2);
HAL_I2C_MspDeInit(&hi2c1);
/**
* Step: Disable RCC, set it to default (after reset) settings
* Internal clock, no PLL, etc.
*/
HAL_RCC_DeInit();
/**
* Step: Disable systick timer and reset it to default values
*/
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
/**
* Step: Disable all interrupts
*/
__disable_irq();
/**
* Step: Remap system memory to address 0x0000 0000 in address space
*/
/* ARM Cortex-M Programming Guide to Memory Barrier Instructions.*/
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
/**
* Step: Set jump memory location for system memory
* Use address with 4 bytes offset which specifies jump location where program starts
*/
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
/**
* Step: Set main stack pointer.
* This step must be done last otherwise local variables in this function
* don't have proper value since stack pointer is located on different position
*
* Set direct address location which specifies stack pointer in SRAM location
*/
__set_MSP(*(__IO uint32_t*) 0x1FF00000);
/**
* Step: Actually call our function to jump to set location
* This will start system memory execution
*/
SysMemBootJump();
/**
* Step: Connect USB<->UART converter to dedicated USART pins and test
* and test with bootloader works with STM32 Flash Loader Demonstrator software
*/
}
