Skip to main content
Visitor II
March 17, 2020
Question

Dual Flash Memory Bank Swap

  • March 17, 2020
  • 5 replies
  • 3615 views

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

    This topic has been closed for replies.

    5 replies

    Super User
    March 18, 2020

    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.

    DCtechAuthor
    Visitor II
    March 18, 2020

    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 ?

    Super User
    March 18, 2020
    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)
    DCtechAuthor
    Visitor II
    March 18, 2020

    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 ?

    DCtechAuthor
    Visitor II
    March 18, 2020

    How Can I solve this problem ?

    Visitor II
    September 19, 2020

    Hi ,

    I am running in to the issue where I flashed the image to 0x81000000 while booted with 0x80000000.

    I made sure, I follow the every steps mentioned in the reference manual. However, I can't seem to get this 100 percent working.

    On 1st boot it switches and boots the image located at 0x81000000 but successive upgrade always boots the image located at 0x810000. It should switch to the image located at 0x8000000.

    To confirm that above behavior is consistent, ​

    1. I flashed one image at 0x80000000 and then flashed a second image at 0x81000000 (tweaked linker script).

    2. I wrote a function where ​on every few seconds I call bankSwitchandBoot function.

    In this function I d the following

    1.Unlock flash

    2.Unlock option byte

    3.Set OPTIONBYTE_BOOTCONFIG

    4.Set ​bootconfig=OB_DUAL_BOOT_ENABLE

    5.Sett DB1M Bit in OPTCR_BYTE2_ADDRESS

    6.Get the current active bank

    If current active bank is bank 1.

    Enable bank swapping.

    else

    Disable bankswapping

    7. Program option byte and check for errors (no errors are reported)

    8. Lock Option byte

    9. Lock flash

    Could some one please confirm if the above sequence is correct or send a code snippet to have successful memory bank swapping? ​

    ​I would appreciate your quick response as such I am stuck on this issue for the last couple of days.

    Visitor II
    January 10, 2024

    I'm also working the STM32F429VE,  which is the 512K byte flash part.
    Does it support dual bank?   Or is only for 1M byte parts.

     

    Graduate II
    January 10, 2024

    It probably doesn't but surely it's pretty easy to dump the entire memory space, or probe it, and flip the bits for banks, etc.

    Most of these parts use the same die, and then sub-portions of the memory are tested to reduce time and costs.

    You'd be looking at the 0x08000000 and 0x08080000 memory addresses. If it doesn't Hard Fault then the 1MB is present.