Cory Heuschkel

(IAR) Using Flash Data Blocks with SPIFI while Running XIP Code on the Same Part

Discussion created by Cory Heuschkel on Sep 2, 2016

There's not a whole lot of guidance on how to do this from the spifilib documentation, so I decided I would release what I've done to create usable data blocks with SPIFI while executing code on the same external Flash part.  I, too, saw the following lines in lpclibspifi_1.03_68.pdf, with no actual link on how to relocate the spifilib to RAM:

If you are using a SPIFI FLASH device as a execute-in-place memory for your LPC device, you can’t use the SPIFI
library if it’s located in SPIFI FLASH. To use the library in this case, the library needs to be relocated to another
memory (like IRAM) and the functions executed from there. The page below describes how to setup and use the
library in this type of system. 

Copyright (C) 2014 NXP Semiconductors. All rights reserved. <- Link to nothing

NXP - will you please address this? There's no documentation for anything besides those using LPCXpresso IDE.


Relocating spifilib to RAM (IAR)

I pretty much just had to brute force this.  I added __ramfunc to relocate all the functions.  I also removed all the const modifiers from all the variables used so that they would be placed in RAM.  I attached a .zip containing my modified spifilib to place everything needed to run spifilib in RAM.

Note: I only updated the structs used for my part only, so you will need to update spifilib_fam_standard_cmd.c for your part.


Creating Data Blocks (IAR ILINK and Winbond W25Q80BV)

I created two different data sections for the NVM data I wished to store in NVM in my IAR ILINK .icf file.  I also created some HAL files to handle setting up spifilib and created the nvmData module to create seperate mock data structures to be placed in seperate data subblocks.  The data partition replaces the last data block on the W25Q80BV and uses subblocks.

Vector Table

I did not relocate my vector table to RAM since all these operations are polled.  Because my application does not demand any other peripherals to be running while accessing Flash, I simply disabled interrupts for all SPIFI data operations.


Feel free to critique the code or add your own suggestions.  Note that you may have some compiling/running problems as I had to just scrape the code from my project.  If you find any problems, please update the files and repost.


See the original root of the reason I posted this solution here:
Erasing SPIFI data block causes hard fault after reset (can't run to main) 

Original Attachment has been moved to:

Original Attachment has been moved to:

Original Attachment has been moved to:

Original Attachment has been moved to:

Original Attachment has been moved to:

Original Attachment has been moved to: