cancel
Showing results for 
Search instead for 
Did you mean: 

Software reset is occurring on its own again and again

PMeht.1
Associate II

I am using NUCLEO STM32L4R5ZI. 

I tried to access the boot mode using the following command

  HAL_FLASH_Unlock();
  while(FLASH->SR & FLASH_SR_BSY)
		  ;
  HAL_FLASH_OB_Unlock();
  while(FLASH->SR & FLASH_SR_BSY)
		  ;  
  FLASH->OPTR &= ~(FLASH_OPTR_nSWBOOT0 | FLASH_OPTR_nBOOT0);
  FLASH->OPTR |= FLASH_OPTR_nBOOT1;
 
  FLASH->CR |= FLASH_CR_OPTSTRT;
  FLASH->CR |= FLASH_CR_OBL_LAUNCH;  
  
  while(FLASH->SR & FLASH_SR_BSY)
		  ;
  HAL_FLASH_OB_Lock();
  while(FLASH->SR & FLASH_SR_BSY)
		  ;
  HAL_FLASH_Lock();
  while(FLASH->SR & FLASH_SR_BSY)
		  ;
  HAL_NVIC_SystemReset();

Now I removed these commands still my system resets on its own again and again.

Thank you.

2 REPLIES 2

The processor is only going to run code you have loaded into it.

Pull BOOT0 HIGH and mass erase the part.

In the future perhaps gate execution of code like this on the state of a GPIO pin you can change, or some user interaction.

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

Thank you got the problem solved, but not able to operate uart in boot mode

while (1)
  {
	  if(HAL_GPIO_ReadPin(USER_BUTTON_GPIO_Port, USER_BUTTON_Pin))
	  {
		 Bootloader_JumpToSysMem();
 
	  }
  }
void Bootloader_JumpToSysMem(void)
{
	void (*SysMemBootJump)(void);
	volatile uint32_t BootAddr = 0x1FFF0000;
 
	/* Set up the jump to booloader address + 4 */
	SysMemBootJump = (void (*)(void)) (*((uint32_t*) ((BootAddr + 4))));
 
    HAL_RCC_DeInit();
    HAL_DeInit();
 
    SysTick->CTRL = 0;
    SysTick->LOAD = 0;
    SysTick->VAL  = 0;
 
    __HAL_RCC_SYSCFG_CLK_ENABLE();
    __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
 
    __set_MSP(*(uint32_t*) BootAddr);
    SysMemBootJump();
 
    while(1)
        ;
}