2024-11-05 04:57 AM
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.
2024-11-05 08:15 AM
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?
2024-11-05 08:57 AM
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.
2024-11-06 12:08 AM
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
2024-11-06 12:10 AM
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
}
.