2024-10-16 07:25 AM
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 :
Best Regards
Thibaud HABRAND
2024-10-16 09:08 AM
2024-10-17 12:24 AM
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
2024-10-22 12:07 AM
2024-10-22 01:05 AM
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)
2024-10-22 02:40 AM
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
2024-10-22 07:14 AM
Hello
I've tried to add HAL_FLASH_OB_Launch() :
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
2024-10-22 07:18 AM
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
2024-10-22 07:25 AM
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
2024-10-22 07:29 AM
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