Configuring projects to span multiple flash devices

表示  限定  | 次の代わりに検索 

Configuring projects to span multiple flash devices

Senior Contributor I


Historically, LPCXpresso IDE could only associate a single flash driver with a particular project. This meant that if the target system had more than one type of flash (typically an LPC18xx / LPC43xx with internal flash and external SPIFI flash). then there was no way to directly configure the project so that the generated image could be directly programmed into both flash devices.


The typical use case for this is a project which stores its main code and data in internal flash, but additional rodata (for example graphics data for displaying on an LCD) in the external SPIFI flash.


LPCXpresso IDE v8.0.0 and later now provide extended support for the creation and programming of projects that span multiple flash devices. Previously only a single (default) flash driver could be specified for a project, now it is possible to specify a flash driver for each region of flash memory.


[Note : This single flash driver restriction does not apply to the dual bank internal flash of the LPC18xx / LPC43xx parts - as they are treated as a single device and the same flash driver is used to program both banks.


The rest of this FAQ considers some specific issues involved in the use of projects using multiple flash devices.

However for further general information, you should read the LPCXpresso IDE v8.x User Guide chapter : "Memory Editor and User Loadable Flash Driver mechanism".


Controlling the placement of code/rodata

By default, LPCXpresso IDE will place code and rodata into the first Flash region, as displayed in the Memory Configuration Editor.


If you have a second flash device that you wish to place certain functions or rodata items into, then the simplest way to do this is to decorate the definitions of these items using the macros from cr_section_macros.h header file. This is described in:



For small numbers of items, this mechanism works well. However if you have large numbers of source files, with many functions or rodata items in them, where you want all of these items to end up in the second flash device, then this can quickly become a source maintenance problem.


A better approach is to make use of the LPCXpresso IDE's Freemarker Linker Script Templates to place the contents of specific files into the second flash device. One very simple way to do this is to place such source files into a separate source folder within your project. You can then supply linker script templates to place the code and rodata from these files into the appropriate flash.


For example, for a project using the LPC4337 with two internal flash banks, plus external SPIFI flash, if the source folder used for this purpose were called 'spifidata', then placing the following files into a 'linkscripts' directory within your project would have the desired affect:



<#global skipCompare=true>

<#if memory.alias=="Flash3">



  *(.text_${memory.alias}*) /* for compatibility with previous releases */

  *(.text_${}*) /* for compatibility with previous releases */




<#global skipCompare=true>

<#if memory.alias=="Flash3">






Note: the check of the memory.alias being Flash3 is to prevent the code/rodata items from ending up in the BankB flash bank (which is Flash2 by default).


Device specific vs Default Flash Drivers

When a project is configured to use additional flash devices via the Memory Configuration Editor, the flash driver to be used for programming that flash device has to be specified in the Driver column. Typically for a SPIFI device, this should be LPC18_43_SPIFI_GENERIC.cfx (for LPC18/LPC43 family MCUs) or LPC40xx_SPIFI_GENERIC.cfx (for LPC407x/8x MCUs, LPCXpresso IDE v8.2 onwards only) .


Default flash drivers and region specific drivers must not be mixed. Once a region driver is specified, the default driver will be ignored. Therefore care must be taken to set the correct driver for each defined flash region. For example - as below.



Example project

The attached ZIP file contains a very simple example for LPC4337 connected to a 1MB SPIFI flash device (as per the LPCXpresso4337 board) which has been configured to place some code and rodata into the SPIFI device, and with the main code/data located in the internal flash.


When LPCXpresso IDE debugs and executes this project, it should display output similar to the following in the console view via semihosting - showing that the function and rodata have been placed into SPIFI flash (at address 0x14000000):


const_data_table at address : 0x14000014

0xdeadbeef 0xbaddcafe 0xfacefeed 0x000ff1ce

Calling spifi_func

spifi_func at address : 0x14000001


For more information

Original Attachment has been moved to:

0 返答(返信)