cancel
Showing results for 
Search instead for 
Did you mean: 

Dual Flash Memory Bank Swap

DCtech
Associate II

I want to try dual-bank project in my STM32F429 Board. So I am using Stm32Cube : IAP-LWIP Example for the this project. I am using 

0x08000000

 address for the BANK1 and also I am using 0x08100000 address for the BANK2.

  • When I start the BANK1, than I receive firmware update request from TFTP Client and find which bank active then, I cleaned non-active bank and writing code in BANK2 successfully.

*Then I reset the system and system starting BANK2, when I request again for the update code. BANK1 cleaned successfully . But I can not write code successfully. I have this error: 

FLASHIF_WRITINGCTRL_ERROR

12 REPLIES 12
TDK
Guru

I know you said you checked it, but I would put a check to verify the memory is 0xFFFFFFFF right before the HAL_FLASH_Program call. And when the values don't match, print out the address and the values to help debug.

I would also put a check to verify that (destination + i * 4) is still within flash.

If you feel a post has answered your question, please click "Accept as Solution".
DCtech
Associate II

Yes you are right,

I found the problem, *(__IO uint32_t *)(destination + (i * 4)) return BANK2 values but destination address is BANK1 why this happened I dont understand.

 READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_UFB_MODE) return BANK2 value .But in the below line compare with BANK2 values although destination=0x0800000 (BANK1). How can I solve this problem ?

if (*(__IO uint32_t *)(destination + (i * 4)) != *(uint32_t *)(p_source + i))

 Why the *(__IO uint32_t *)(destination + (i * 4)) value return from BANK2 although destination is 0x0800000 (BANK1) address ?

DCtech
Associate II

How Can I solve this problem ?

If SYSCFG_MEMRMP_UFB_MODE is set, then 0x08000000 is BANK2, not BANK1, so if destination = 0x08000000, then it points to BANK2, not BANK1.
Bit 8 FB_MODE: Flash Bank mode selection
Set and cleared by software. This bit controls the Flash Bank 1/2 mapping.
0: Flash Bank 1 is mapped at 0x0800 0000 (and aliased at 0x0000 0000) and
Flash Bank 2 is mapped at 0x0810 0000 (and aliased at 0x0010 0000)
1: Flash Bank 2 is mapped at 0x0800 0000 (and aliased at 0x0000 0000) and
Flash Bank 1 is mapped at 0x0810 0000 (and aliased at 0x0010 0000)
If you feel a post has answered your question, please click "Accept as Solution".
DCtech
Associate II

Thank you so much TDK

checkBank=READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_UFB_MODE)

if(checkBank==0){

     serialMessage(" Program Running in Bank 1 \n");

}else{

     serialMessage(" Program Running in Bank 2 \n");

}

I see Program Running from Bank2 so, this meaning BANK2 mapped 0x08000000 address, so I have to use 0x0810000 value for the BANK1. Is that true ?

That’s what the manual says.
If you feel a post has answered your question, please click "Accept as Solution".
DCtech
Associate II

But there is a problem, If I have "Program Running in Bank 2" output this if-else than I try to erase 0x08100 0000 but there is problem here because I am in 0x0810 000 area I can not erase.

If you’re running from bank2, then bank2 is 0x08000000 and bank1 is 0x08100000. In this scenario, why can’t you erase bank1? I dont see a problem.
If you feel a post has answered your question, please click "Accept as Solution".
DCtech
Associate II

Okey I found the problem, after you said I change flash write address to 0x810000 but I cant change BFB2 bit so I switch every time reset so problem solved thank you.