0

I am trying to implement a bank swap mechanism for STM32L471RET6. my Code Doesn't seem to have errors for setting and resetting Option bytes but Nothing Happens when Calling the bank Swap Functions. after I checked the option bytes using STM32CubeProgrammer, I realized that the option bytes didn't changed. Here is my bank swap function.

HAL_StatusTypeDef SwapBank(void)
{
 FLASH_OBProgramInitTypeDef OB;
 HAL_FLASHEx_OBGetConfig(&OB);
if (OB.USERConfig & OB_DUALBANK_DUAL)
{
 if (OB.USERConfig & OB_BFB2_ENABLE)
 {
 HAL_FLASH_Unlock();
 HAL_FLASH_OB_Unlock();
 OB.OptionType = OPTIONBYTE_USER;
 OB.USERType = OB_USER_BFB2;
 OB.USERConfig = OB_BFB2_DISABLE;
 }
 else
 {
 OB.OptionType = OPTIONBYTE_USER;
 OB.USERType = OB_USER_BFB2;
 OB.USERConfig = OB_BFB2_ENABLE;
 }
 if (HAL_FLASHEx_OBProgram(&OB) != HAL_OK)
 {
 HAL_FLASH_OB_Lock();
 HAL_FLASH_Lock();
 return HAL_ERROR;
 }
 HAL_FLASH_OB_Launch();
 HAL_FLASH_OB_Lock();
 HAL_FLASH_Lock(); 
 NVIC_SystemReset();
 return HAL_OK;
 }
 return HAL_ERROR;
}

I checked The STM32L4xx reference manual for programming Option bytes. I searched for it and asked for help from AI tools But I failed. I had written this program and mechanism for STM32L0 successfully and it is working but I don't Know what's wrong with STM32L471RET6.

asked Dec 1, 2024 at 11:32

1 Answer 1

0

Fixed...

HAL_StatusTypeDef SwapBank(void)
{
 FLASH_OBProgramInitTypeDef OB;
 HAL_FLASHEx_OBGetConfig(&OB);
if (OB.USERConfig & OB_DUALBANK_DUAL)
{
 HAL_FLASH_Unlock();
 HAL_FLASH_OB_Unlock();
 if (OB.USERConfig & OB_BFB2_ENABLE)
 {
 OB.OptionType = OPTIONBYTE_USER;
 OB.USERType = OB_USER_BFB2;
 OB.USERConfig = OB_BFB2_DISABLE;
 }
 else
 {
 OB.OptionType = OPTIONBYTE_USER;
 OB.USERType = OB_USER_BFB2;
 OB.USERConfig = OB_BFB2_ENABLE;
 }
 if (HAL_FLASHEx_OBProgram(&OB) != HAL_OK)
 {
 HAL_FLASH_OB_Lock();
 HAL_FLASH_Lock();
 return HAL_ERROR;
 }
 
 HAL_FLASH_OB_Launch();
 HAL_FLASH_OB_Lock();
 HAL_FLASH_Lock(); 
 NVIC_SystemReset();
 return HAL_OK;
 }
 return HAL_ERROR;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.