Target description
The first part of the article :
This article introduces the External Memory Manager and External Memory Loader middleware features in a bootflash application for the STM32H7R/H7S product in order to:
- Provide an API that allows access to all types of memory.
- Launch an application that is stored in an external memory .
- Generate an External memory loader file.
The second part of the article :
The article presents a detailed tutorial on the implementation of the External Memory Manager and External Memory Loader middleware functionalities. The article also features a configuration sample utilizing STM32CubeMX, which can be used as a reference to apply these functionalities to:
- Configure the External Memory Manager.
- Configure the External Memory Loader.
- Build a BootFlash application.
Hardware
- STM32H7R/H7S
Software
- An IDE (IAR, KEIL, STM32CubeIDE).
- Software tool for STM32 products programming.
Literature
- Getting started with Octo-SPI and Hexadeca-SPI Interface on STM32microcontroller[1]
1. What is a BootFlash product
1.1. Definition
A BootFlash product is a product with a small embedded Flash for an initial boot step and with an application located in an external memory.
1.2. What is a BootFlash application?
The STM32CubeMx tool provides the ability to create a BootFlash application, which uses the external memory manager and external memory loading middleware, to create a boot system that is capable of launching an application stored on external memory.
The project structure of a BootFlash application is divided into three different contexts:
- Boot: Boot code to run from Internal Flash.
- Appli: Application code to run from External Flash.
- ExtMemLoader: code dedicated to generate the External Loader.
The image below shows the STM32H7Rx/H7Sx application architecture based on the use of two middleware; External Memory Manager and External Memory Loader.
1.3. How to create a BootFlash project with the STM32 ecosystem
1.3.1. STM32CubeMX Ecosystem Tool
STM32CubeMX is a graphical tool that allows a very easy configuration of STM32 microcontrollers and microprocessors, as well as the generation of the corresponding initialization C code for the Arm® Cortex®-M core or a partial Linux® Device Tree for Arm® Cortex®-A core, through a step-by-step process.
Additionally, the STM32CubeMX offers integration with the following middleware:
- External Memory Manager
- External Memory Loader
1.3.2. External Memory Manager
The External Memory Manager module has been implemented to assist in the development of BootFlash applications on STM32H7R/H7S, but it can be used on other platforms. This STM32 middleware provides two services:
- A unique API to access all types of memory.
- A Boot system to launch an application stored on an external memory.
You can access an overview of the STM32 External Memory Manager by clicking on the link below.
External memory Manager
1.3.3. External Memory Loader
The External Memory Loader is a middleware for STM32 that assists in developing various target loader entry points. It includes three target entry point definitions for building a loader compatible with different IDEs:
- EWARM : contains the target entry points definition to build a loader compatible with the IAR Embedded Workbench IDE
- MDK-ARM : contains the target entry points definition to build a loader compatible with KEIL µVision 5 IDE.
- STM32Cube : contains the target entry points definition to build a loader compatible with the STM32Cube tools : STM32CubeProgrammer and STM32CubeIDE.
The External Memory Loader relies on the ExtMem_Manager services to interface with the memory and IDEs entry points to perform standard operations like initialization, reading, writing, erasing, mass erasing and memory mapping.
For an overview of the STM32 External Memory Loader, click on the link below.
External memory Loader
2. STM32CubeMX BootFlash Application Configuration
To get started on the project, use the STM32H7S7L8H6H board.
1. Select this board by referring to the Board Selector that is displayed in the figure below.
2. As project manager, make sure you name the project and verify that all three subprojects are selected.
2.1. Boot subproject Configuration
The BootFlash Boot subproject is mainly built using the External Memory Manager middleware and this project is responsible for three operations:
- System initialization.
- Initialization of external memory(ies).
- Application start (XIP (eXecute In Place) or LRUN (Load & Run)).
STEP1: Clock configuration.
1.To reach the highest performance, set the clock to max frequency for both Boot and ExtMemLoader subprojects :
Select the system clock at 600 Mhz:
- Select HSI from PLL1 Source Mux.
- Select PLLCLK from System Clock Mux.
- Set HCLK to 600 MHz.
STEP2: Configure the arm® Cortex®-M7 MPU to define :
- A background region to set default attributes for all regions and prevent speculative accesses on Normal memory type.
- A region of RAM to store non cacheable buffer.
1. Enable ICACHE.
2. Enable DCACHE.
3. Enable MPU.
STEP3: To configure the external memory peripheral, select the peripheral connected to the external memory and select the Boot context.
1. In this example, XSPI2 instance corresponds to the interface to the serial NOR SFDP memory on H7RS Discovery board (MB1736-HS7S78-DK).
2.The user must configure the XSPI2 depending on the used external memory
- Select Octo SPI mode .
- Select the Port and the Chip Select.
- Set the parameters of XSPI2 instance as shown below to connect NOR SFDP memory.
3.Set the XSPI2 clock to 200 Mhz and lock it to 200 Mhz.
STEP4: To simplify the use of the External memory manager, select and configure the EXTMEM_MANAGER middleware.
1. Select the EXTMEM_MANAGER middleware .
2. Activate the EXTMEM_MANAGER middleware.
3. Select XSPI interface.
4. Select the driver of NOR SFDP memory.
5.Configure the Boot use case to execute In Place (XIP)
6. Configure the memory data lines interface to 8 lines for octal mode
STEP5: Enable IO HSLV.
2.2. ExtMemLoader subproject Configuration
ExtMemLoader is a subproject used to generate a binary library capable of downloading an application to external memory. This binary is called a "Loader" and can be used by the IDE or the STM32CubeProgrammer.
This system initialization function performs the following operations:
- Initialize the system:
- Irq disabling (a loader does not use any irq).
- Enable the cache for performance purpose.
- Initialize the HAL context.
- Disable any ongoing MPU configuration.
- Clock configuration with maximum speed.
- Irq disabling (a loader does not use any irq).
- Initialize the memory
- peripheral associated with the memories.
- used the EXTMEM_MANAGER middleware to initialize the memory.
- peripheral associated with the memories.
STEP1: Configure the External Memory loader.
1. Select the External Memory loader middleware.
2. Activate the External Memory loader middleware.
2.3. Application subproject Configuration
The Application context (Appli) is the end user application stored in the external memory and its execution is initiated by the Boot context. This process causes the application to inherit from the configurations made by the Boot context.
In this application, we use the PO1, PO5 LEDs to prepare a simple application and load it into the external NOR-SFDP memory.
2.1. Compile and flash
- To view the base address of XSPI2 where the user application is loaded, open the memory view and observe the memory address 0x70000000.
2.2. STM32CubeProgrammer loader file Generation
To generate STM32CubeProgrammer loader file from the IAR ExtMemLoader project, you must follow the 4 steps below :
STEP1: Change Defined Symbols C/C++/Assembler preprocessors.
STEP2: Change the linker file
STEP3: Set the generated loader in the STM32CubeProgrammer
There are two methods available to configure the generated loader in the STM32CubeProgrammer:
- A Manual method to configure the generated loader in the STM32CubeProgrammer :
1.Rebuild the ExtMemLoader Project.
2.Rename the *.out project to *.stldr.
3.Copy the *.stldr into binary path of the STM32CubeProgrammer below :
C:\ProgramFiles\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\ExternalLoader\
- An automated method to configure the generated loader in the STM32CubeProgrammer
1.The postbuild.sh shell script is responsible for automating all the steps that were previously done manually.
2. Include the postbuild.sh script in your project's build settings.
4.Launch the STM32CubeProgrammer.
5.Connect the board.
6.Select the new added loader in the STM32CubeProgrammer.
STEP4: Check Application using the new added loader.
2.3. References