Skip to main content
JLee1
Associate
August 27, 2020
Question

STM32G030 BOOT0 Pin not working

  • August 27, 2020
  • 9 replies
  • 3666 views

I'm currently developing with STM32G030K8T6 (Rev 1.1). I want to use PA14 as BOOT0 pin. So, I set option byte nBOOT_SEL as 0 using STM32CubeProgrammer (nBOOT0, nBOOT1 both option byte are set to 1). But BOOT0 pin not worked. So, I also set PA14 GPIO mode as floating input by HAL using this code

GPIO_InitTypeDef GPIO_InitStruct = {0};
 __HAL_RCC_GPIOA_CLK_ENABLE();
 GPIO_InitStruct.Pin = GPIO_PIN_14;
 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

But BOOT0 pin didn't worked too. I tried to change nBOOT_SEL by HAL using this code

 FLASH_OBProgramInitTypeDef OBInit;
 OBInit.USERType = OB_USER_nBOOT_SEL;
 OBInit.USERConfig = OB_BOOT0_FROM_PIN;
 OBInit.OptionType = OPTIONBYTE_USER;
if(HAL_FLASH_Unlock() == HAL_OK) {
 if(HAL_FLASH_OB_Unlock() == HAL_OK) {
 HAL_FLASHEx_OBProgram(&OBInit);
 if(HAL_FLASH_OB_Lock() == HAL_OK) {
 HAL_FLASH_Lock();
 HAL_FLASHEx_OBGetConfig(&OBInit);
 if((OBInit.USERConfig & OB_BOOT0_FROM_OB) == OB_BOOT0_FROM_PIN)
 {
 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);
 }
 }
 }
 }

and when I executed this code, LED connected on PB3 turned on. But still BOOT0 pin didn't worked. Does anyone know how can I use BOOT0 pin in STM32G030K8T6?

This topic has been closed for replies.

9 replies

KnarfB
Super User
August 27, 2020

What do you mean exactly by "BOOT0 pin didn't worked"?

JLee1
JLee1Author
Associate
August 27, 2020

Yes. I mean, chip didn't get into bootloader when I connected VCC(+3.3V) and BOOT0 Pin(PA14).

KnarfB
Super User
August 27, 2020

There is a footnote in the data sheet "Upon reset, these pins are configured as SW debug alternate functions, and the internal pull-up on PA13 pin and the internal pull-down on PA14 pin are activated." and there was a discussion here in the forum which I don't recall right now.

ne562
Associate III
November 19, 2022

Here is the code I'm using to fix nBOOT bit:

// check/fix nBOOT bit in Option area
inline void flash_nboot_fix(){
	// check if nBOOT_SEL bit is set
	if(FLASH->OPTR & FLASH_OPTR_nBOOT_SEL){
		// unlock flash/option
		FLASH->KEYR = 0x45670123;
		FLASH->KEYR = 0xCDEF89AB;
		FLASH->OPTKEYR = 0x08192A3B;
		FLASH->OPTKEYR = 0x4C5D6E7F;
 
		while(FLASH->SR & FLASH_SR_BSY1);
 
		// clear nBOOT_SEL bit
		FLASH->OPTR &= ~FLASH_OPTR_nBOOT_SEL;
 
		// write
		FLASH->CR |= FLASH_CR_OPTSTRT;
		while(FLASH->SR & FLASH_SR_BSY1);
	}
}