‎2020-08-26 09:55 PM
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?
‎2020-08-27 08:44 AM
What do you mean exactly by "BOOT0 pin didn't worked"?
‎2020-08-27 08:47 AM
Yes. I mean, chip didn't get into bootloader when I connected VCC(+3.3V) and BOOT0 Pin(PA14).
‎2020-08-27 09:36 AM
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.
‎2020-08-27 09:41 AM
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.
​
‎2020-08-28 01:57 AM
I founded for discussion that you told.
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?
​
‎2020-08-28 02:33 AM
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 :(
‎2020-08-28 02:36 AM
Thank you. I'll test the things you told me.
‎2020-08-28 10:35 AM
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.
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?
‎2022-11-19 04:30 AM
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);
}
}