In this step we will enable an external quad or octo SPI flash in memory mapped mode. An external flash is recommended for most project as it allows the application to use many and large images. The internal flash will quickly be full even for modest applications.
When data is to be placed in external flash it is important that the external flash can be read by the MCU. The external flash should run at desired (typically maximum) speed to get the best performance.
The goal for this section is to enable the external flash, change it to memory mapped mode, and read data from it. As the read speed of the external flash is very important to graphics, you should also test the reading speed.
Here are the verification points for this section:
|External flash is readable||External flash can be used for image storage|
|External flash performance||Graphics performance depends a lot of the performance of the image memory|
The following are the prerequisites for this step:
- Information about the flash, typically a datasheet
- Information about the connections between the MCU and the external flash
The QSPI controller is configured in CubeMX under Connectivity -> QUADSPI:
In the mode section you can configure the flash to single/dual/quad data lines. Quad lines are the fastest. Similar to the external RAM, you also here need to select and configure the GPIOs used for the data lines, chip select and clock signal.
After enabling the flash, we can test it by reading data from it. The Cube Firmware package contains examples for that.
After enabling the flash and testing it in block mode, it is necessary to change it to memory mapped mode. This will allow the CPU to fetch data directly from the flash.
The STM32 Cube HAL contains functions to change to memory mapped mode. An example is given here. It is necessary to consult the datasheet for the configuration data. The Cube Firmware package for your MCU contains more examples.
If you are using the same flash as one of the STM32 evaluation kits, then the BSP packages for these boards (also in the Cube Firmware) contains valuable examples that can be modified for your hardware.
When the flash is in memory mapped mode, you can test it with code similar to what we used for external RAM (find the address in your MCU datasheet):
Reuse the memory performance tests you did in earlier steps to also test the performance of the external flash.