2021-12-14 09:57:38 +01:00
..
2021-12-14 09:57:38 +01:00
2021-12-14 09:57:38 +01:00
2021-12-14 09:57:38 +01:00
2021-12-14 09:57:38 +01:00
2021-12-14 09:57:38 +01:00
2021-12-14 09:57:38 +01:00

/**
  @page ExtMem_CodeExecution Boot application for External memory execution Readme file

  @verbatim
  ******************************************************************************
  * @file    ExtMem_CodeExecution/ExtMem_Boot/readme.txt
  * @author  MCD Application Team
  * @brief   Description of External memory boot
  *          with reduced internal flash (ExtMem_CodeExecution on STM32F7xx devices) AN5188.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2016 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  @endverbatim

@par Application Description

This directory contains a set of sources files and pre-configured projects that
describes how to build an application for execution from external memory using
the ExtMem_Boot firmware.

@note You must not touch any part of the system that been initialized by the
      ExtMem_Boot firmware to avoid system failure, more details in the AN5188.

The STM32F730xx and STM32F750xx value line come with only 64KB internal flash.
These value line are intended for code execution from external memories.
This application shows how to boot from internal flash, configure external memories
then jump to user application located on external memory.

On the STM32756G_EVAL, user can select QSPI flash , FMC-NOR flash, external SDRAM
or external SRAM for code execution.
In case of code execution from external SRAM/SDRAM, the application binary can be stored
on the micro-SD card or on the QSPI flash.
The Boot application will then copy the application binary to the target execution memory.
User can select internal RAM, external SRAM or external SDRAM for application data memory

Define "CODE_AREA" , "DATA_AREA" and "BINARY_AREA" in file memory.h are used respectively
to select the Code execution area, the application data area and the binary storage area.
The ExtMem_Boot program is located at 0x08000000 (Internal flash).

Please Refer to the bellow "Table 1. IAP implementation on STM32756G_Eval" for different configurations and corresponding settings.

@par Keywords

External Memory Boot, Loader, Boot

@Note<74>If the user code size exceeds the DTCM-RAM size or starts from internal cacheable memories (SRAM1 and SRAM2),that is shared between several processors,
      then it is highly recommended to enable the CPU cache and maintain its coherence at application level.
      In case of constraints it is possible to configure the MPU as "Write through/not shareable" to guarantee the cache coherence at write access but the user
      has to ensure the cache maintenance at read access though.
      The address and the size of cacheable buffers (shared between CPU and other masters)  must be properly updated to be aligned to cache line size (32 bytes).

@Note It is recommended to enable the cache and maintain its coherence, but depending on the use case
      It is also possible to configure the MPU as "Write through", to guarantee the write access coherence.
      In that case, the MPU must be configured as Cacheable/Bufferable/Not Shareable.
      Even though the user must manage the cache coherence for read accesses.
      Please refer to the AN4838 (Managing memory protection unit (MPU) in STM32 MCUs)
      Please refer to the AN4839 (Level 1 cache on STM32F7 Series)

@par Directory contents

 - "ExtMem_Boot/Inc": contains the ExtMem_Boot firmware header files
    - ExtMem_Boot/Inc/main.h                 The main include file of the project.
    - ExtMem_Boot/Inc/memory.h               This file provides all the headers for all external memory
                                             control function along with configuration defines
    - ExtMem_Boot/Inc/memory_msp.h           Header for msp function needed for external memory initialization.
    - ExtMem_Boot/Inc/stm32f7xx_hal_conf.h   Library Configuration file
    - ExtMem_Boot/Inc/stm32f7xx_it.h         Header for stm32f7xx_it.c

 - "ExtMem_Boot/Src": contains the ExtMem_Boot firmware source files
    - ExtMem_Boot/Src/main.c                 Main program
    - ExtMem_Boot/Src/stm32f7xx_it.c         Interrupt handlers
    - ExtMem_Boot/Src/stm32f7xx_hal_msp.c    Microcontroller specific packages initialization file.
    - ExtMem_Boot/Src/system_stm32f7xx.c     STM32F7xx system source file
    - ExtMem_Boot/Src/memory_msp.c           This file contains external memory control function along
                                                       with configuration defines
    - ExtMem_Boot/Src/qspi.c                 This file contains configuration required to initialize QSPI
                                                       and configure in memory mapped mode.
    - ExtMem_Boot/Src/fmc.c                  This file contains configuration for all kind of memory
                                                       controlled by the FMC
    - ExtMem_Boot/Src/sdcard.c               This file contains configuration for <20>SD memory

@par Hardware and Software environment

  - This application runs on STM32F750xx devices.

  - This application has been tested with STM32756G_Eval and can be
    easily tailored to any other supported device and development board.

Table 1. IAP implementation on STM32756G_Eval
/****************|***** Configuration ********* |************* Implementation **************************|
|                |                              | QSPI Flash is used for code execution                 |
|                | DATA_AREA: USE_INTERNAL_SRAM | The user application image is linked and stored       |
|                |            USE_EXTERNAL_SDRAM| on the QSPI flash located at 0x90000000.              |
|                |            USE_EXTERNAL_SRAM |                                                       |
|                | CODE_AREA: USE_QSPI          |                                                       |
|                |----------------------------- |-------------------------------------------------------|
|    XIP         |                              | FMC-NOR Flash is used for code execution              |
|                | DATA_AREA: USE_INTERNAL_SRAM | The user application image is linked and stored       |
|                |            USE_EXTERNAL_SDRAM| on the FMC-NOR flash located at 0x60000000.           |
|                |            USE_EXTERNAL_SRAM |                                                       |
|                | CODE_AREA: USE_NOR           |                                                       |
|----------------|----------------------------- |-------------------------------------------------------|
|                | BINARY_AREA: USE_SPI_NOR     | Code execution from external SDRAM                    |
|                |              USE_SDCARD      | The user application is linked to the SDRAM 0xC0000000|
|                | DATA_AREA: USE_INTERNAL_SRAM | the binary image stored on storage memory             |
|                | CODE_AREA: USE_EXTERNAL_SDRAM| either SDCard or SPI_Nor memory and will be copied    |
|                |                              | into SDRAM at boot                                    |
|    BootROM     |----------------------------- |-------------------------------------------------------|
|                | BINARY_AREA: USE_SPI_NOR     | Code execution from external SRAM                     |
|                |              USE_SDCARD      | The user application is linked to the SRAM 0x68000000 |
|                | DATA_AREA: USE_INTERNAL_SRAM | the binary image stored on storage memory             |
|                | CODE_AREA: USE_EXTERNAL_SRAM | either SDCard or SPI_Nor memory and will be copied    |
|                |                              | into SRAM at boot                                     |
|----------------|----------------------------- |-------------------------------------------------------|

(1) User application location address is defined in the memory.h file as:
      -QSPI:    #define APPLICATION_ADDRESS           ((uint32_t)0x90000000)
      -NOR :    #define APPLICATION_ADDRESS           ((uint32_t)0x60000000)
      -SDRAM:   #define APPLICATION_ADDRESS           ((uint32_t)0xC0000000)
      -SRAM:    #define APPLICATION_ADDRESS           ((uint32_t)0x68000000)
To modify it, change the default value to the desired one. Note that the application must be linked
relatively to the new address too, for this application icf file shall be updated and APPLICATION_ADDRESS
in preprocessor defines shall be update as well.

Following configuration are supported by the firmware, Please refer to fmc.c and qspi.c for exact part number:
  - XiP (Execute In Place):
      External Flash is configured and set to memory mapped mode.
      Set the MSP and then jump to application start.
        - QSPI : @ 0x90000000
            CODE_AREA   USE_QSPI
        - NOR  : @ 0x60000000
            CODE_AREA   USE_NOR
        - SDRAM : @ 0xC0000000
            CODE_AREA   USE_EXTERNAL_SDRAM
        - SRAM  : @ 0x68000000
            CODE_AREA   USE_EXTERNAL_SRAM

  - Volatile Memory :
      Memory Configuration (memory mapped mode)
        - Internal SRAM  : @ 0x20000000
             DATA_AREA    USE_INTERNAL_SRAM
        - External SDRAM : @ 0xC0000000
             DATA_AREA    USE_EXTERNAL_SDRAM
        - External SRAM  : @ 0x68000000
             DATA_AREA    USE_EXTERNAL_SRAM

Supported configuration by STM32756G_Eval:
    - XiP From QSPI, Data on Internal SRAM
    - XiP From QSPI, Data on External SRAM
    - XiP From QSPI, Data on External SDRAM
    - XiP From NOR, Data on Internal SRAM
    - XiP From NOR, Data on External SRAM
    - XiP From NOR, Data on External SDRAM
    - BootROM : Execution From External SDRAM , Data on Internal SRAM
    - BootROM : Execution From External SRAM , Data on Internal SRAM


@Note Configuration used in ExtMem_Boot and ExtMem_Application must be inline otherwise required resources
      will not be initialized as required.


@par How to use it?

In order to make the program work, you must do the following:

  1. Select required configuration in memory.h.
  2. Program the internal Flash with the ExtMem_Boot (see below).
  3. Use corresponding project configuration for ExtMem_CodeExecution/ExtMem_Application/..
  4. Program the external memory with "ExtMem_CodeExecution/ExtMem_Applicaiton/.." (see below).
  5. Start debugging user application as usual or reset for free running.

In order to load the ExtMem_Boot code :
   - Open your preferred toolchain :
      - Open the Project
      - Rebuild all files
      - Load project image

In order to load the ExtMem_Application/... to th external memory:
   - Open your preferred toolchain
      - Open the Project
      - Use project matching ExtMem_Boot selected configuration
      - Rebuild all files:
      - Run & debug the program:
      - For an XiP configuration (eXecute in Place from QSPI, FMC-NOR):
          - Using EWARM or MDK-ARM : Load project image from the IDE: Project->Debug
          - Using SW4STM32 :
            - Open the STM32CubeProgrammer tool
            - Select the QSPI external flash loader "MT25QL512A_STM32756G-EVAL" in case of XiP from QSPI
            - Select the FMC-NOR external flash loader "M29W128GL_STM32F756G-EVAL" in case of XiP from FMC-NOR
            - From Erasing & Programming menu, browse and open the output hex file relative to the ExtMem_Application\... configuration
            - Load the hex file into the external QSPI flash using "Start Programming"

      - For a BootROM configuration (BootROM externalSRAM/external SDRAM):
        - if BINARY_AREA is USE_SPI_NOR then use the STM32CubeProgarmmer tool, select QSPI external flash loader "MT25QL512A_STM32756G-EVAL"
          and load the project.bin (application binary output file) to the QSPI memory at the address 0x90000000
        - if BINARY_AREA is USE_SDCARD then copy the project.bin to a micro-SD to be plugged on CN16 and reset the board.
        - In order to debug the  ExtMem_Application/.., user shall attach the debugger, and perform a reset


 */