cancel
Showing results for 
Search instead for 
Did you mean: 

Using pre-programmed bootloader on STM32G0B0RE

Tiboww
Associate II

hello

I am developping on a STM32G0B0RE, I've learned after finishing my board and everything that boot pin can be used by default.

It is not a problem since I have ST-Link for production but I would like to be able to do firmware update through bootloader.

 

The issue is, since nBOOT_SEL is set to '1' by default I need to change it to 0 so I go in bootloader if my pin PA14-BOOT0 is tied up at startup. I find how to change it in STM32CubeProgrammer but I would like to do it in my firmware so the flashing process is not too complicated in factory.

 

I've tried this but it does not have any effect : 

Tiboww_0-1729088556950.png

Best Regards

Thibaud HABRAND

16 REPLIES 16
SofLit
ST Employee

Hello @Tiboww and welcome to the community,

Using user option byte:

SofLit_0-1729094824462.png

Refer to the RM0444 / 2.5 Boot configuration

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hello

I know this table, as I said I've been able de modify "nBOOT_SEL" bit in the STM32CubeProgrammer but I would like to implement it in my firmware. So they only need to flash a firmware in factory. 

I am developping on STM32CubeIDE v1.16.0, I tried to use the function "HAL_FLASHEx_OBGetConfig". Can you tell me if I am using this function wrong or I have to do an other way ? 

Best Regards

Thibaud HABRAND

Hello 

 

@SofLit Do you have any update on my case ?

 

Best Regards

Thibaud HABRAND

Shirley.Ye
ST Employee

ShirleyYe_0-1729583993151.png

D you mean you cannot change your "nBOOT_SEL" bit from 1 to 0 by the function HAL_FLASHEx_OBProgram?

please note:

New option bytes configuration will be taken into account in two cases:
* - after an option bytes launch through the call of @ref HAL_FLASH_OB_Launch()
* - after a power reset (BOR reset or exit from Standby/Shutdown modes) 

Hi Thibaud,

I have implemented this on a STM32G0B1CC, should be the same on your MCU (in main.c after:

  /* USER CODE BEGIN Init */
  // check if we have to switch the nBoot_SEL bit
  FLASH_OBProgramInitTypeDef OBData;
  HAL_FLASHEx_OBGetConfig(&OBData);
  if(OBData.USERConfig & OB_USER_nBOOT_SEL)
  {
	  HAL_FLASH_Unlock();
	  HAL_FLASH_OB_Unlock();
	  OBData.OptionType = OPTIONBYTE_USER;
	  OBData.USERType = OB_USER_nBOOT_SEL;
	  OBData.USERConfig = OB_BOOT0_FROM_PIN;
	  if ( HAL_FLASHEx_OBProgram(&OBData) != HAL_OK )
	  {
		  HAL_FLASH_OB_Lock();
		  HAL_FLASH_Lock();
		  Error_Handler();
	  }
	  HAL_FLASH_OB_Launch();
	  /* We should not make it past the Launch, so lock
	   * flash memory and return an error from function
	   */
	  HAL_FLASH_OB_Lock();
	  HAL_FLASH_Lock();
	  Error_Handler();
  }
  /* USER CODE END Init */

Martin

Hello

I've tried to add HAL_FLASH_OB_Launch() : 

Tiboww_2-1729606178517.png Tiboww_1-1729606143898.png

Tiboww_3-1729606242296.png Tiboww_4-1729606264366.png

Tiboww_5-1729606297463.png Tiboww_6-1729606314161.png

 

 

I didi'nt tried power reset because when I do programm then get it seems like the modification didn't do anything in the register and it changed only my local structure.

BR 

Thibaud

 

 

 

 

Hello 
Thank you, I will try it but you're going in Error_handler every time you use this function? If yes you add a reset in this error_handler()?

Thibaud

Hi
Thank you I've been able to change it with your function but seems HAL_FLASH_OB_Launch(); is blocking the mcu did you add like a timer to reset it ?

Thibaud

 

Hi Thibaud,
No I don't enter there Error_Hander (the Error_Handler is a simple endless loop!), but the function HAL_FLASH_OB_Launch() will generate a reset! You can call this function only when you have to program the nBOOT_SEL bit, that’s why I check if the bit is already programmed before trying to program it.

Martin