Getting started with External memory Manager and External memory loader

Revision as of 16:11, 30 January 2024 by Registered User

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 on an external memory .
  • Generate a loader file.

The second part of the article :

Additionally, this article provides a step-by-step guide on how to utilize the External Memory Manager and External Memory Loader middleware features. It also includes a configuration example using STM32CUBEMX. By following this example, you will be able to apply these features to:

  • Configure the External Memory manager.
  • Configure the External Memory Loader.
  • Build a BootFlash application.

Hardware

  • STM32H7R/H7S

Software

  • An IDE (IAR, KEIL, CubeIDE).
  • A loader program (CubeProgrammer).

Literature

  • Getting started with Octo-SPI and Hexadeca-SPI Interface onSTM32microcontroller[1]

1. What is a BootFlash/Bootflash-like products

1.1. Definition

A BootFlash STM32H7R/H7S series is a product with no embedded Flash and the application is located in an external memory.
A BootFlash -like product corresponds to a product configuration with small embedded Flash for an initial boot step and the application is located in an external memory.

1.2. How to built a BootFlash/Bootflash-like projects

The purpose of this example is to build a BootFlash Application with CubeMx, which employs the external memory manager and external memory loader middlewares, to create a BOOT system that can launch an application stored on an external memory.
The image below shows STM32H7R/H7S Application Architecture.
bldiag.png

1.3. How STM32 ecosystem will help you to build such a project

2. External Memory Manager

2.1. Introduction

The External Memory Manager module has been implemented to assist in the development of ROMLess applications, but of course it can also be used on other platforms. It is an STM32 middleware providing two services:

  • A unique API to access all types of memory.
  • A BOOT system to launch an application stored on an external memory.


External memory Manager
An overview STM32 External memory Manager

3. External Memory Loader

3.1. Introduction

External Memory Loader is an STM32 middleware helping to develop different target of loader entry points:

  • 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 laoder compatible with KEIL uVision 5 IDE.
  • STM32Cube  : contains the target entry points definition to build a loader compatible with the STM32Cube tools : STM32CubeProgrammer and STM32CubeIDE

3.2. What is a loader ?

A "loader" is a set of functions grouped together in a binary that are individually called by a tool to perform actions on dedicated memory. The loader is loaded by the tools inside a RAM space and its execution is managed by the tool, the loader specifity are :

  • binary  : loader is a binary using a continuos RAM area to store code and data.
  • loader file  : the loader file is an ELF file (contains symbol information)
  • interrupt : they are disabled this is a recommandation for the tool to keep control over the execution flow.
  • Stack Pointer  : the loader doesn't allocate memory space to the stack.
  • RAM Buffer  : there is no space allocated to store the data to be written.
  • Map mode  : this is the preferred mode for checking written data.


External memory Loader
An overview STM32 External memory loader

3.3. Architecture of External Memory Loader

The External Memory Loader is a middleware for STM32 that consists of a core component and target entry points for the loader.
The core contains two components:

  • memory_wrapper : an abstraction layer poviding basic memory services based on the usage of the middleware external memory manager.
  • systick : a systick wrapper to make systick managament functionnal without interrupt, the main reason for this module is to keep functionnal HAL management of timing.

File:Ext loader.png

3.4. Loader Mechanism in IDEs

To run a loader, you need three essential components: a tool such as an IDE (IAR, KEIL, CubeIDE) or a loader program (CubeProgrammer), a binary format loader containing code and symbol information, and an STM32 board with embedded external Flash memory.

The loader tool operates in the following steps:

  • Read the loader file to retrieve function and memory information.
  • Load the code into the internal RAM of the STM32.
  • Allocate space in RAM for RAM buffer and Stack.
  • Use loader functions to load firmware into external memory.

File:External Loader process.jpg Main loader operations

The main loader operations are :

  • Initialize the external memory.
  • Erase memory by sector or by masserase.
  • Write buffer into external memory.
  • Verify external memory downloaded content.


3.4.1. EWARM (IAR IDE)

MDK-ARM loader configuration file:

The generated *.FLM file needs to be added to the Pack with Device Support, so that it is available to the tool user for programming his device. Usually, a directory Flash is created and the algorithm is saved in this directory. The algorithm is specified within the the /package/devices/family level:

File:EW loader.png

  • The argument start specifies the base address for the Flash programming algorithm.
  • The argument size specifies the size covered by the Flash programming algorithm. End address = start + size - 1.
  • The argument default specifies whether a Flash programming algorithm is set as the default algorithm in a project (when true).

3.4.2. STM32CUBE

STM32CUBE loader configuration file  ::

No configuration needed, the ExtMemLoader will be copied automatically under STM32CubeProgrammer using post build.
cube.png

3.4.3. MDK-ARM (keil IDE)

MDK-ARM loader configuration file ::

No configuration needed, the ExtMemLoader will be copied automatically under STM32CubeProgrammer using post build;
File:keil.png

4. Getting started with Building ROM-Less Application with CubeMX

4.1. BootFlash Project Structure

The project deployment strategy is composed of three subprojects :

  • BOOT/FSBL (First Boot Loader)  : it manages the startup of the application subproject.
  • EXTMEMLOADER  : Tool to download the application binary to external memory
  • APPLICATION  : it is the main application stored on an external memory.

5. STM32CubeMX BootFlash Application Configuration

To get started on the project, it is necessary to utilize the STM32H7S7L8H6H board.
1. Select this board by referring to the Board Selector that is displayed in the figure below.
FS1.png

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

5.1. Boot subproject Configuration

The BootFlash BOOT subproject is mainly built using the middleware External Memory Manager and project will mainly perform three operations:

  • System initialization.
  • Initialization of external memories.
  • Application start (LRUN or XIP).

STEP1. Clock configuration.
1.To reach the highest performance, set the clock to max frequency for both BOOT/FSBL 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

2.Set the XSPI2 clock to 200 Mhz and Lock it to 200 Mhz.

clk4.png

STEP2 Configure the MPU to define :

  • A backroung region to set default attributes for all region.
  • A region of RAM to store non cacheable buffer.

1. Enable ICACHE .
2. Enable DCACHE .
3. Enable MPU .

mpu.png


STEP2. To Configure the external memory peripheral, select on 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. Once the XSPI2 the clock configuration have been done, 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 like below to connect NOR SFDP memory.

xspi33.png

STEP4. To simplify the use of external memory manager ,select and configure the EXTMEM_MANAGER middleware.

1. Select the EXTMEMMANAGER middleware .
2. Activate the EXTMEMMANAGER middleware.
3. Select XSPI interface.
4. Select the DRiver of NOR SFDP memory.
emm1.png

5.Configure the boot usecase. (XIP)
emm6.png

6. Configure the memory (8 Lines).
emm5.png

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

5.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" which can be used by the IDE or CubeProgrammer.
This system initialization function performs the following operations:

  • Initialize the system:
    • Irq disabling (a loader doesn't use any irq).
    • Enable the cache for performance purpose.
    • Initialize the HAL context.
    • Disbale any ongoing MPU configuration.
    • Clock configuration with maximun speed.
  • Initalize the memrory
    • peripheral associated with the memories.
    • used the EXTMEM Manager middleware to initialize the memory.

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


5.3. Application subproject Configuration

The APPLICATION context 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 syteme, CubeMX embbeds an algorithm which selects the file according to the EXTMEM_Manager configuration done in the BOOT subproject. This file is provides 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

5.1. Compile and flash

  • To view the address base of XSPI2 where the user application is loaded, open the memory view and observe the memory address 0x70000000.

app1.png

5.2. STM32CubeProgrammer loader file Generation

To Generate STM32CubeProgrammer loader file from the IAR ExtMemLoader project, You should 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 STM32CubeProg

1.Rebuil the ExtMemLaoder Project.
2.Rename the *.out project to *.stldr.
3.Copy the *.stldr into binary path of the STM32Cube Programmer below :

  C:\ProgramFiles\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\ExternalLoader\

5.Launch the STM32CubeProgrammer.
6.Connect the board.
7.Select the new added loader in the STM32CubeProgrammer.
prg.png

  • STEP3: Check Application using the new added loader.

st4.png