cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0B0 BRICKING AFTER OPTION BYTES CHANGE

EmbedDev
Associate II

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. 

4 REPLIES 4

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
Up vote any posts that you find helpful, it shows what's working..
SofLit
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.

Hello @SofLit ,
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

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
}

.