cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G030 BOOT0 Pin not working

JLee1
Associate II

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?

9 REPLIES 9
KnarfB
Principal III

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

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

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.

That's why I configured the PA14 pin as GPIO Input and set it to no pull. I also attached code that I used. However, debug was not able after that, but the BOOT0 pin still didn't work.

I founded for discussion that you told.

https://community.st.com/s/question/0D50X0000ARQLq2/has-anyone-gotten-the-boot0-pin-to-work-on-an-stm32g071-solved

Is the discussion you mentioned this one?

It seems that the discussion above also solved it by changing nBOOT_SEL. But I haven't been able to solve it this way, is there any other point that seems to be a problem?

Yes, thats that discussion. Sorry that it doesn't help you. Have you checked that BOOT_LOCK bit in FLASH_SECR register (Flash security) is 0? Can you measure voltage at BOOT0 pin, is it really high or maybe pull-up too weak? No more ideas :(

Thank you. I'll test the things you told me.

Hi, I tried to debug with ST Link and found something strange. First, FLASH_SECR register not exist. I think stm32g0x0 series don't have it. And another strange point is this.

0693W000002lgoFQAQ.png

After I executed code that changing option byte, option bytes in the information block (address 0x1FFF7800) was 0xDEFFE1AA (nBOOT_SEL = 0), but FLASH_OPTR (address 0x40022020) was 0xDFFFE1AA (nBOOT_SEL = 1). Is it correct that the option bytes changes have been applied properly?

ne562
Associate II

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);
	}
}