2021-06-15 03:20 PM
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
*/
}
2021-06-15 04:10 PM
Don't disable interrupts. Or if you do, reenable them before the jump.
Follow this guide and adapt for your chip:
https://community.st.com/s/article/STM32H7-bootloader-jump-from-application
2021-06-15 04:25 PM
Disable All Interrupts is a requirement for you to turn off all the sources of interrupts you have running, not turn off the processors ability to interrupt. Who re-enables that?
C compiler implementations might also get in the way of cleanly changing stack mid-subroutine, recommend doing this in Assembler
SYSCFG clock needs to be running to change SYSCFG registers
Step the code, check the registers, confirm you get into the ROM successfully. Make sure the ROM code isn't checking the BOOTx pin states, or if the FLASH has a valid image.
2024-05-24 05:23 AM
hello, did you solve the problem now?