Skip to main content
Associate
November 5, 2024
Question

STM32G0B0 BRICKING AFTER OPTION BYTES CHANGE

  • November 5, 2024
  • 2 replies
  • 945 views

We are having an issue of the MCU bricking when we change the n_SWAP_Bank bit of the User Option bytes. What could be the issue? The issue occurs when we are clearing this bit. Once we clear it the chip bricks. 

2 replies

Tesla DeLorean
Guru
November 5, 2024

Bricks how? No code runs? No SWD connectivity?

What exactly is getting written in to the Option Bytes, and HOW?

Can you put functional code instance at beginning of both banks?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
EmbedDevAuthor
Associate
November 6, 2024

No SWD Connectivity. Here is a snippet of the code

void OTAFlashInt_SwapBanks(){
 HAL_FLASHEx_OBGetConfig(&OpBytesRW);
 if(OpBytesRW.USERConfig & FLASH_OPTR_nSWAP_BANK){
 OpBytesRW.USERConfig &= ~FLASH_OPTR_nSWAP_BANK; //set bit high to make next active bank1
 }else{
 OpBytesRW.USERConfig |= FLASH_OPTR_nSWAP_BANK; //set bit low to make next active bank 2
 }
 HAL_FLASH_Unlock();
 HAL_FLASH_OB_Unlock();
 if(HAL_FLASHEx_OBProgram(&OpBytesRW)== HAL_OK){
 HAL_FLASH_OB_Launch();
 }
 HAL_FLASH_OB_Lock();
 HAL_FLASH_Lock();
 #ifndef TEST
 NVIC_SystemReset();
 #endif
}

.
 

mƎALLEm
ST Technical Moderator
November 5, 2024

Hello @EmbedDev and welcome to the community,

How you did handle Option bytes? using STM32CubeProgrammer or in your code?

If in the code you need to share it and please use </> button.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
EmbedDevAuthor
Associate
November 6, 2024

Hello @mƎALLEm ,
This happened when handling Option bytes using STM32Programmer as well as in code.

void OTAFlashInt_SwapBanks(){
 HAL_FLASHEx_OBGetConfig(&OpBytesRW);
 if(OpBytesRW.USERConfig & FLASH_OPTR_nSWAP_BANK){
 OpBytesRW.USERConfig &= ~FLASH_OPTR_nSWAP_BANK; //set bit high to make next active bank1
 }else{
 OpBytesRW.USERConfig |= FLASH_OPTR_nSWAP_BANK; //set bit low to make next active bank 2
 }
 HAL_FLASH_Unlock();
 HAL_FLASH_OB_Unlock();
 if(HAL_FLASHEx_OBProgram(&OpBytesRW)== HAL_OK){
 HAL_FLASH_OB_Launch();
 }
 HAL_FLASH_OB_Lock();
 HAL_FLASH_Lock();
 #ifndef TEST
 NVIC_SystemReset();
 #endif
}


That is  a snippet of the code