2023-05-24 08:09 AM
Hi,
I need help!!!
I'm working with STM32L47 and I'm trying to add the option to update the FW via DFU without toggling BOOT0.
I tried to make the Stackpointer jump to the same address the BOOT0 as it's sent by the BOOT0 press (0x1FFF0000) but the only thing I get is a fast close on open of the USB port (as seen by Device manger of Windows) and then the Stackpointer is going back to address 0x08000000 and the application code is being executed.
My sequence is as follows:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
CB_BootLoaderCheck();
void CB_JumpToBootLoader(void)
{
volatile uint32_t SYSTEM_MEMORY = 0x1FFF0000;
typedef void (*pFunction)(void);
pFunction JumpToApplication;
// uint32_t JumpAddress;
HAL_RCC_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
/* Step: Disable all interrupts */
//__disable_irq();/* ARM Cortex-M Programming Guide to Memory Barrier Instructions.*/
__DSB();
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();/* Remap is bot visible at once. Execute some
unrelated command! */
__DSB();
__ISB();
JumpToApplication = (void (*)(void))(*((uint32_t*)(SYSTEM_MEMORY
+ 4)));/* Initialize user application's
Stack Pointer */
__set_MSP(*(__IO uint32_t*)SYSTEM_MEMORY);
JumpToApplication();
}
void CB_BootLoaderCheck(void)
{
if((*(__IO long *) (BK_SRAM_BASE + 0)) == SRAM_FLAG_SET_VAL)
{
(*(__IO long *) (BK_SRAM_BASE + 0)) = SRAM_FLAG_CLEAR_VAL; // Reset memory, if desired.
CB_JumpToBootLoader();
}
}
case DFU_MODE:
printf("Logger__r: insert MCU into bootloader mode\r\n");
CB_SetDFU_FlagSRAM();
Logger_ResetMCU();
break;
The problem is that it's not working. The Stackpointer keeps returning to the application code.
What am I doing wrong?
2023-05-24 09:07 AM
>>The Stackpointer keeps returning to the application code. What am I doing wrong?
Stop doing it in C, and having a local stack frame in the subroutine, might be a start..
>>STM32L47
??
Figure if the loader is kicking back to you. Determine if you have the best entry point or if you need to patch the loader.
2023-05-29 12:51 AM
Hi,
I didn't understand any of your answers...
You recommendation is of doing it in Assembly?
>>Figure if the loader is kicking back to you. Determine if you have the best entry point or if you need to patch the loader.
Can you elaborate?