An4767 Application Note ST Com
An4767 Application Note ST Com
An4767 Application Note ST Com
Application note
Optimized usage of the dual bank structure of Flash memory in
STM32 microcontrollers - Software expansion for STM32Cube
Introduction
Dual bank functionality is a feature common to several STM32 microcontrollers. The goal of
this document is to describe how to take advantage of this feature in customer applications.
The main topic treated in this application note is the Field Upgrade, covered also by the
provided code example (X-CUBE-DBFU).
Although only Cat.5 devices from STM32L0 Series and access line and USB OTG devices
from the STM32L4 Series are directly addressed in this document, other STM32 MCUs with
two semi-independent banks of memory may share some of the described properties and
be used in a similar way.
The following documents, all available on www.st.com, are considered as reference:
• Reference manual RM0367: “Ultra-low-power STM32L0x3 advanced ARM®-based 32-bit
MCUs”
• Reference manual RM0376: “Ultra-low-power STM32L0x2 advanced ARM®-based 32-bit
MCUs”
• Reference manual RM0377: “Ultra-low-power STM32L0x1 advanced ARM®-based 32-bit
MCUs”
• Application note AN2606: “STM32 microcontroller system memory boot mode”
• Application note AN4024: “STM32 secure firmware upgrade (SFU)”
• Application note AN4657: “STM32L0 in-application programming using UART”
Contents
1 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4 Example project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.1 HW setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
4.2 Encryption option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
4.2.1 Encrypting the binary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2.2 Configuring for decryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.2.3 Limits of the simple solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.2.4 Other cryptography options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.3 Example operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
6 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
List of tables
List of figures
1 Definitions
When designing an application that uses a dual bank device, there are several choices to
make on how to utilize the second half of the program memory.
With dual bank, all the manipulation with the other bank is just another task of the main
program. Thanks to internal remapping of the code address range, binaries in both banks
can remain identical during normal operation.
The typical scenario to perform the field upgrade is shown in Figure 1.
)LHOGXSJUDGHVWDUW
<HV 1R &RS\FRGHIURP
(UDVH%DQN 7U\DJDLQ"
%DQNWR%DQN
5HWULHYHDQG
1R
SURJUDPWKH 2."
QHZILUPZDUH
<HV
6HW%)%ELWLQ2%
6:UHVHW VZLWFKWR%DQN
5XQQLQJ (UDVH%DQN
IURP%DQN
5XQQLQJ &RS\FRGH
IURP%DQN IURP%DQNWR%DQN
5HVHW%)%ELWLQ2% (QG
069
It is important to keep BFB2 flag set when there is no code in Bank1, thus being safe in case
of unexpected power cut. Then, after reset, the firmware has several ways to detect that the
code in the Bank1 must be replaced, and the process is running from Bank2. It is important
to implement this decision, i.e. there is only one binary code, and the code is executed on
each boot.
The NVM in the STM32L0 and STM32L4 Series is split in several areas:
• User code memory (Program Flash)
• System code memory
• Option bytes
• User data memory (Data EEPROM), only for the STM32L0 Series
The memories to which the dual bank feature is applicable (i.e. those that are found in two
instances on Dual bank capable devices) are User code memory and User data memory.
&38
%XVPDWUL[
0,)
0HPRU\LQWHUIDFH
069
The memory interface is capable of reading both banks in parallel, or can read one bank
while writing the other. No such parallelism is possible within one bank, hence it is more
efficient for application to store the data in the opposite bank.
The most efficient EEPROM storage solution (for STM32L0) is when the code in Bank1
uses data EEPROM from Bank2 and code from Bank2 uses data EEPROM from Bank1
(same is true when program memory of the other bank is written).
Disabling interrupts during field upgrade is another option, however it unfortunately negates
some of the big advantages of the dual bank system, such as the lack of any “limited mode”.
4 Example project
An example code is described in the following, demonstrating firmware upgrade use case. It
is closely related to an IAP application, with only one difference, there is only one firmware,
identical for both banks, serving as both the loader and the application.
4.1 HW setup
Connect USART2 port to a PC using a RS-232 serial cable. Use a terminal application that
supports YMODEM protocol. Tera Term is offering a solid, cost free alternative to Windows
HyperTerminal. Example functionality has been tested with Tera Term version 4.84.
Configure communication speed of 115200 Bd, 8 data bits, no parity, 1 stop bit and then
power the board.
The cryptest.exe will generate an .aes file that will be used on devices with AES peripheral
(STM32L083/STM32L486).
5 Conclusion
The dual bank feature, when used properly, holds number of advantages for a broad range
of applications.
The user can exploit these advantages by selecting devices featuring a double bank
memory, this may require use of products with higher cost and larger package.
6 Revision history
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgement.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of Purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.