Using the SPIFI library with the LPC4370.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using the SPIFI library with the LPC4370.

Using the SPIFI library with the LPC4370.

In this document, I will explain how to create a project to use the SPIFI library version 1.03 with the LPC4370. For this we will need the following tools:

  1. MCUXpresso IDE 10.2. Link
  2. LPC-LINK2 to use it as an evaluation board for the LPC4370. Link
  3. External debugger. In my case, I used another LPC-LINK2 board.
  4. LPCOpen v2_12 for the LPC4370, this version comes with the installation of MCUXpresso IDE.
  5. SPIFI library v1.3. Link
  6. Code Example lpcopen_2_12_lpcxpresso_ngx_xplorer_1830_SPIFI_v1.0. Link

First, download and install all the tools needed.

In your workspace of MCUXpresso we will import (1) three projects of the LPCOpen v2_12 for the LPC4370: periph_blinky, lpc_board_nxp_lpclink2_4370 and lpc_chip_43xx.  The LPCOpen zip file is in the next path of your PC: C:\nxp\MCUXpressoIDE_10.2.1_795\ide\Examples\LPCOpen (2)

pastedImage_3.jpg

pastedImage_5.jpg

Extract the files of the zip named lpclibspifi_lpcxpresso_1.03_68 that we downloaded before. The folder that we need is spifilib_m4f. Drag and drop this folder into the Project Explorer on your workspace of the LPC4370, after choosing copy and you should see the spifilib_m4f in your Project Explorer.

pastedImage_8.jpg

Once you imported correctly the SPIFI library, select the library (1) on the project explorer window and build it (2). Once you do this you should see that a new folder called Debug appear (3).

pastedImage_11.jpg

Now we need to edit the properties of the periph_blinky example to add the library spifilib_m4f to the project. To do this, right click on the project and click properties.

pastedImage_13.jpg

Once in the properties window click on C/C++ Build (1) > Settings (2) > Includes (under the section MCU C Compiler) (3).

pastedImage_15.jpg

In the includes window click Add… (1) > Workspace (2) > spifilib_m4f (3) > inc (4) > click OK (5) on the window Folder Selection > click OK (6) on the window Add directory path.

pastedImage_17.jpg

You should see the following on the include paths.

pastedImage_19.jpg

Now, go to the libraries (1) option under the section MCU Linker, on the section Libraries (-I) click Add… (2) finally write the name of the library (spifilib_m4f) (3) and click OK (4).

pastedImage_21.jpg

Under the section Library search path (-L) click Add… (1) > Workspace (2) > spifilib_m4f (3) > Debug (4) > OK (5).

pastedImage_23.jpg

If you see the same as shown in the below image you are good to go so click Apply and close.

pastedImage_25.jpg

To check if you did the below steps correct let’s do the following. On the project periph_blinky in the file systick.c include the file spifilib_api.h and compile the project. If the project compiles without problems it means that you imported correctly the spifi library. If you found problems please stop and repeat all the steps mentioned before.

Now that we added successfully the library we can start to migrate the example for the LPC1830 that we download before. First, unzip the file lpcopen_2_12_lpcxpresso_ngx_xplorer_1830_SPIFI_v1.0. Once you unzipped the file go to the following path: spifilib_blinky > example > src. Open the file named Blinky.c and copy all the content of the file. Now go to the file systick.c on your workspace of MCUXpresso within the project periph_blinky, delete all the content of this file and paste what you copied before. Do not compile at this point or you will receive multiple errors!

pastedImage_27.jpg

Go back to the path spifilib_blinky > example > src on your PC. Drag and drop the file called spifi_setup.c into the folder src of your project periph_blinky on your Workspace.

pastedImage_29.jpg

Open the file that we just copy into our workspace and go to line 46 of the code. Here we are creating a buffer of 64KB that we will use later to write in the SPIFI. The __BSS(RAM3) is to save this buffer in the RAM block three of memory. The problem here is that the block of RAM3 in the LPC4370 is not big enough to store the buffer of 64KB (see below image), so let’s change this for either RAM or RAM2 that are big enough to store the buffer.

pastedImage_31.jpg

Now that we added the spifi_setup file let’s go back to the systick.c file and add the external declaration for the function spifiSetUp. At this point, if we compile the project we shouldn’t see any problems, only some warnings because of the functions and variables that we are not using.

pastedImage_33.jpg

We are almost done, we are missing the most important thing. With this demo you will be writing, deleting and reading the SPIFI memory, this means that you cannot be executing form the SPIFI flash memory. You need to move to the RAM memory all the functions that are going to make this. This is the reason why in the file systick.c we don’t have any function that interacts directly with the SPIFI, this will make much easier the work of moving all the functions that interact with the SPIFI memory to RAM. The function spifiSetUp is the one that will make all the tests on the SPIFI and it is in the spifi_setup file, so we will need to move this entire file to RAM along with the SPIFI library.

We will use three different scripts to move the library and the file spifi_setup to RAM. You can learn more about this in the following community post: https://community.nxp.com/thread/389110. First, right click on the folder of the project > new > folder, the name of the folder must be linkscripts.

pastedImage_35.jpg

According to the sections Relocating particular objects into RAM and Relocating particular libraries into RAM of the community post mentioned before we need to create three files in this new folder: main_text.ldt, main_rodata.ldt and main_data.ldt. To do this, right click on the folder linkscripts > new > file.

pastedImage_37.jpg

Here is the content that you should have on the three files that we just created. Do not include on the files the text that is in bold, that's just for reference!

File main_data.ldt

*libspifilib_m4f.a:(.text*)

*libspifilib_m4f.a:(.rodata .rodata.* .constdata .constdata.*)

*spifi_setup.o(.text*)

*spifi_setup.o(.rodata .rodata.* .constdata .constdata.*)

. = ALIGN(${text_align});

*(.data*)

File main_rodata.ldt

*(EXCLUDE_FILE(*libspifilib_m4f.a: *spifi_setup.o) .rodata)

*(EXCLUDE_FILE(*libspifilib_m4f.a: *spifi_setup.o) .rodata.*)

*(EXCLUDE_FILE(*libspifilib_m4f.a: *spifi_setup.o) .constdata)

*(EXCLUDE_FILE(*libspifilib_m4f.a: *spifi_setup.o) .constdata.*)

. = ALIGN(${text_align});

File main_text.ldt

*(EXCLUDE_FILE(*libspifilib_m4f.a: *spifi_setup.o) .text*)

After finishing with the three files you are done with the demo! It’s important to mention that if you want to go inside the function spifiSetUp while debugging you need to set a breakpoint inside the function.

While debugging we can see that before calling the function spifiSetUp we are running from the SPIFI flash memory and once we enter to the function we are running from RAM memory.

pastedImage_38.png

pastedImage_40.png

Once we run the demo successfully we should see the following in a terminal and the LED1 will be blinking.

pastedImage_45.jpg

Hope this guide is helpful!

Best Regards,
Victor.

Labels (2)
No ratings
Version history
Last update:
‎11-15-2018 07:16 AM
Updated by: