NOTICE: This website will be shut down in the near future. Product content has moved to nxp.com. Forum content and FAQs have been moved to community.nxp.com. We encourage you to create a user account on nxp.com to use the new community forums and access NXP microcontroller content. We greatly appreciate your contributions and look forward to seeing you at our new web location.

 

Configuring projects to span multiple flash devices

lpcxpresso-support's picture

Background


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 Template mechanism 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:

text.ldt

<#global skipCompare=true> 
<#if memory.alias=="Flash3">
        *spifidata/*(.text*)
</#if>
    	*(.text_${memory.alias}*) /* for compatibility with previous releases */
    	*(.text_${memory.name}*) /* for compatibility with previous releases */
    	*(.text.$${memory.alias}*)
    	*(.text.$${memory.name}*)

rodata.ldt

<#global skipCompare=true> 
<#if memory.alias=="Flash3">
        *spifidata/*(.rodata*)
</#if>
    	*(rodata.$${memory.alias}*)
    	*(rodata.$${memory.name}*)

Note that 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 .

However if such a device specific driver is specified, then you should also explicitly specify the driver to be used for programming the other Flash regions (typically the internal Banks A and B) in the driver column too - as shown in the below screenshot - rather than relying on the default flash driver specified about the memory region definitions. If this is not done, then you may encounter issues when starting debug sessions.

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


 

PreviewAttachmentSize
LPC4337_multiple_flash.zip12.9 KB
0
Your rating: None
feedback