cancel
Showing results for 
Search instead for 
Did you mean: 

Making STM32L47 boot into DFU mode without toggling BOOT0 pin.

YBCH_.1
Associate II

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:

  1. Run main() as usual until CB_BootLoaderCheck()
  2. CB_BootLoaderCheck() checks for a dedicated magic word in flash and decides if to jump or not.
  3. If magic word does not exist, the application code runs normally.
  4. Via CLI I'm running DFU mode command which writes the magic word in flash and execute reset NVIC_SystemReset().
  5. After the reset, the magic word does exist and CB_JumpToBootLoader() is called and supposed to send the Stackpointer to the desire address (0x1FFF0000)

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?

2 REPLIES 2

>>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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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?