Getting started with External memory Manager and External memory loader

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.

3.png
The image below shows the STM32H7Rx/H7Sx application architecture based on the use of two middleware; External Memory Manager and External Memory Loader.
bldiag.png

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

mx1.png

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.
FS1.png

2. As project manager, make sure you name the project and verify that all three subprojects are selected.
subproject1.png

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.

clk1.png


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.

mpu.png


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).

xspi22.png

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.

xspi33.png


3.Set the XSPI2 clock to 200 Mhz and lock it to 200 Mhz.

clk4.png


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.
emm1.png

5.Configure the Boot use case to execute In Place (XIP)
emm6.png

6. Configure the memory data lines interface to 8 lines for octal mode
emm5.png


STEP5: Enable IO HSLV.

ml2.png

Info white.png Information
Enabling the SBS IO HSLV has no effect if the option bytes are not correctly set.

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.
  • Initialize the memory
    • peripheral associated with the memories.
    • used the EXTMEM_MANAGER middleware to initialize the memory.


STEP1: Configure the External Memory loader.
1. Select the External Memory loader middleware.
2. Activate the External Memory loader middleware.
ml.png


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.

Info white.png Information
The scatter file of the application depends on the memories present in the system, STM32CubeMX embeds an algorithm which selects the file according to the EXTMEM_MANAGER configuration done in the Boot subproject. This file is provided as template and can be modified by the application.

In this application, we use the PO1, PO5 LEDs to prepare a simple application and load it into the external NOR-SFDP memory.
app.png

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.

app1.png

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.
st1.png
STEP2: Change the linker file
st2.png
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
Info white.png Information
The user is required to run the IDE in administrator mode.

1.The postbuild.sh shell script is responsible for automating all the steps that were previously done manually.
pathbuild.png
2. Include the postbuild.sh script in your project's build settings.
postbuild.png
4.Launch the STM32CubeProgrammer.
5.Connect the board.
6.Select the new added loader in the STM32CubeProgrammer.
prg.png
STEP4: Check Application using the new added loader.
st4.png

2.3. References