简体   繁体   中英

How to swap two memory regions from different banks in FLASH Memory for STM32L475?

I am working on B-L475E-IOT01A2 which is a STM32L475 series Discovery IoT kit and has an ARM M4 cortex. It has two banks of FLASH Memory of size 512 KB each. I am implementing two applications along with a bootloader and all of them are stored in the FLASH. Since there is very little space, the bootloader, the 1st application and some part of the 2nd application is stored in the 1st bank whereas the 2nd bank contains the remaining part of the 2nd application. So at a point in the bootloader program, I need to swap both the applications.

The problem is that only some part of both the applications is getting swapped because the 2nd Application is stored partly in both the banks. Only one page (2 KB) of memory can be written at once in the FLASH . Both the applications have a size of 384 KB and after calculation it turns out to be 192 pages. But after running the swapping program only 72 pages were swapped.

Here are the addresses of the applications and the bootloader.

BOOTLOADER_ADDRESS 0x08000000,  (Size = 48K )

APPLICATION1_ADDRESS 0x0800F000 (Size = 384 KB)

APPLICATION2_ADDRESS 0x0806F800 (Size = 384 KB)

So what should I do to ensure proper swapping? Should I enable dual bank mode or store the 2nd Application in the 2nd bank or do something else?

Your help will be highly appreciated.

Thanks,

Shetu

One possible workaround/different approach is to integrate the bootloader functionality into both application 1 and application 2, and having each application in its own flash bank (1 and 2). Using dual bank mode makes switching back and forth between applications much easier. I have used this approach with an STM32F7 device.

When the device boots it is configured to boot from flash bank 1 or 2 depending on several device option bytes/settings. If your code in the bootloader/application decides to boot into the other application, it can do this by modifying some option bytes and then performing a soft reset. Also, while running bootloader/application from one flash bank, the other flash bank can be updated.

If using this approach to do firmware updates, you must be especially careful that new firmware versions do not break the firmware update functionality of the bootloader.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM