Skip to main content
Visitor II
November 5, 2024
Question

STM32G0B0 BRICKING AFTER OPTION BYTES CHANGE

  • November 5, 2024
  • 2 replies
  • 944 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. 

    This topic has been closed for replies.

    2 replies

    Graduate II
    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?

    EmbedDevAuthor
    Visitor II
    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
    }

    .
     

    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.

    EmbedDevAuthor
    Visitor II
    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