Execute code from SPIFI

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

Execute code from SPIFI

6,444 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by schisanoa on Mon Sep 08 05:30:09 MST 2014
Hi,

I need to use the SPIFI as flash program memory in order to expand the flash capacity of my device. The microcontroller is a LPC4088, these are my question:

Where I should start?
Do I need to change something in LPCXpresso setting?
LPCXpresso is able to program directly the SPIFI flash as per the internal flash?
How to place code in SPIFI?
is there a working example code with this implementation?
or have someone already implemented this and want to share some parts of code?

Thanks in advance
Alessio
Labels (1)
0 Kudos
18 Replies

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by schisanoa on Fri Feb 26 03:05:31 MST 2016

Quote: schisanoa
With the latest version og LPCXpresso is possible to work with 2 different flash at the same time as per previous post in this thread?



I'll answer myself to be useful for other user ;-) :

Yes it is possible
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by schisanoa on Fri Feb 12 10:53:57 MST 2016
With the latest version og LPCXpresso is possible to work with 2 different flash at the same time as per previous post in this thread?

0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by abels on Wed Jan 28 06:09:56 MST 2015
Thanks for the information.

While the new release arrive I will try to program using LPCOpen lpcspifilib.

Regards,

Abel
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Wed Jan 28 05:59:42 MST 2015
LPCXpresso up to, and including, v7.5.0 does not include Flash Drivers for this part. We will be releasing a new version very shortly, which should support this part.

Alternatively, you can write you own flash driver, by modifying one of the existing drivers. Follow this FAQ:
http://www.lpcware.com/content/faq/lpcxpresso/lpc18-lpc43-external-flash-drivers

And look in  Examples/NXP/FlashDrivers for the source.
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by abels on Wed Jan 28 05:32:53 MST 2015
Sorry for the missing information:

LPC4088 QSB has the W25Q64FVSSIG 64Mbit QSPI flash memory.

LPCXpresso compiles the project without any warning or error and I tried two ways with "Program Flash using MBED CMSIS-DAP":

1- Flash Driver "LPC407x_8x_S25FL032P.cfx", file "LPC40XX_EXT_FLASH.axf", and base Address 0 (log below)
2- Flash Driver "LPC18_43_SPIFI_4MB_4KB.cfx", file "LPC40XX_EXT_FLASH.axf", and base Address 0 (log below)

LPCXpresso gives the errors show below:

log on window for option 1:

Ni: LPCXpresso RedlinkMulti Driver v7.3 (Jul  1 2014 11:18:44 - crt_emu_cm_redlink.exe build 130)
Pc: (  0) Reading remote configuration
Nc: Found chip XML file in C:/Users/AbelS/Documents/LPCXpresso_7.3.0_186/LP40088_QSPI_Test/LPC40XX_EXT_FLASH/Debug/LPC4088.xml

Pc: (  5) Remote configuration complete
Pc: ( 30) Emulator Connected
Xs:
Xc:
Pc: ( 40) Debug Halt
Pc: ( 50) CPU ID
Nc: Emu(0): Conn&Reset. DpID: 2BA01477. CpuID: 410FC240. Info: (null)
Nc: Debug protocol: SWD. RTCK: Disabled. Vector catch: Disabled.
Nc: Loaded LPC407x_8x_S25FL032P.cfx: LPC407x_8x S25FL032P 4MB(64KB) SPIFI @0x28000000 (Sep  9 2014 14:08:24)  External Flash Device on SPI

Pc: ( 65) Chip Setup Complete
Nt: Connected: was_reset=true. was_stopped=false
Cr:v LPCXpresso Free License - Download limit is 256K
Pc: ( 70) License Check Complete
Nt: Loading ELF file 'LPC40XX_EXT_FLASH.axf' at location 28000000
Ec: Flash driver "Init" return code: 0x2
Pb: (100) Writing Flash ended with an error.
Ed:05: File 'LPC40XX_EXT_FLASH.axf' load failure: Ef(38). Flash operation has returned an error (see log).
Pc: (100) Target Connection Failed

log on window for option 2:

Ni: LPCXpresso RedlinkMulti Driver v7.3 (Jul  1 2014 11:18:44 - crt_emu_cm_redlink.exe build 130)
Pc: (  0) Reading remote configuration
Nc: Found chip XML file in C:/Users/AbelS/Documents/LPCXpresso_7.3.0_186/LP40088_QSPI_Test/LPC40XX_EXT_FLASH/Debug/LPC4088.xml

Pc: (  5) Remote configuration complete
Pc: ( 30) Emulator Connected
Xs:
Xc:
Pc: ( 40) Debug Halt
Pc: ( 50) CPU ID
Nc: Emu(0): Conn&Reset. DpID: 2BA01477. CpuID: 410FC240. Info: (null)
Nc: Debug protocol: SWD. RTCK: Disabled. Vector catch: Disabled.
Nc: Loaded LPC18_43_SPIFI_4MB_4KB.cfx: LPC18/43 4MB(4KB) SPIFI @0x14000000 (Jul  1 2014 11:51:54)  External Flash Device on SPI

Pc: ( 65) Chip Setup Complete
Nt: Connected: was_reset=true. was_stopped=false
Cr:v LPCXpresso Free License - Download limit is 256K
Pc: ( 70) License Check Complete
Nt: Loading ELF file 'LPC40XX_EXT_FLASH.axf' at location 28000000
Pb: (100) Writing Flash ended with an error.
Ed:05: File 'LPC40XX_EXT_FLASH.axf' load failure: Nn(05). ACK Fault
Pc: (100) Target Connection Failed


I apologise again if I missed some data. I am still learning how to post for help and any help or correction will be welcome.

Regards,

Abel
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Wed Jan 28 04:38:36 MST 2015
It would help if you told us what the problem is... "lpcxpresso gives a problem" is not sufficient for us to be able to help you. Also, you need to tell us what the QSPI Chip actually is.
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by abels on Wed Jan 28 04:18:50 MST 2015
Hello everyone,

I am trying to flash and run the example give by mc previously but the LPC40088 QSB board of Embedded Artist has a different QSPI and lpcxpresso gives a problem.

Do you know how to adapt the .cfx file or another possible error?

Board -> LPC4088QuickStartBoard Rev B
IDE -> LPCXpresso v7.3.0
Used Code -> SplitCodeExamplewith FlashDriverV1_10Sep2014.zip posted by mc the 2012-05-21

Thanks in advance (If I need to open a new post, tell me please)

Regards
Abel
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee

Content originally posted in LPCWare by lpcxpresso-support on Wed Sep 17 03:28:37 MST 2014
The attached example project demonstrates how you can use a single project to create the images to load into both the internal and external SPIFI flashes on LPC4088. It has been created in a workspace containing the projects previously posted above, and is basically a quick port of that previous example into a single project.

The project has been modified in a number of ways from how created using the LPCOpen C project new project wizard.

Firstly, the memory configuration editor (documented in the LPCXpresso User Guide) has been used to add a second flash bank (the SPIFI device). You should locate this as the second flash in the list, as displayed in the editor.

Secondly, the function in dummy.c has been prefixed with the __TEXT(Flash2) macro, to place the function into the second flash bank

Finally, the post build step has been modified to generated a binary containing the code to be placed in the SPIFI flash bank

[list]
  [*]http://www.lpcware.com/content/faq/lpcxpresso/post-processing-linked-application
[/list]

The commands being used in this case are:

arm-none-eabi-size "${BuildArtifactFileName}"
cp "${BuildArtifactFileName}"  "${BuildArtifactFileBaseName}_ORIGINAL.axf"
arm-none-eabi-objcopy --only-section .text_Flash2 --rename-section .text_Flash2=.text -O elf32-littlearm "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}_EXTFLASH.axf"
arm-none-eabi-objcopy -O binary "${BuildArtifactFileBaseName}_EXTFLASH.axf" "${BuildArtifactFileBaseName}_EXTFLASH.bin"
arm-none-eabi-objcopy --remove-section .text_Flash2 -O elf32-littlearm "${BuildArtifactFileName}" "${BuildArtifactFileName}"
arm-none-eabi-size "${BuildArtifactFileName}"
arm-none-eabi-size "${BuildArtifactFileBaseName}_EXTFLASH.axf"

What these do are:
[list=1]
  [*]Generate size information for the whole project
  [*]Take a copy the generated whole project AXF for future reference (optional), as we are going to modify the AXF
  [*]Generate an AXF from the whole project AXF containing only the code being placed into the SPIFI flash.
  [*]Generate a binary of the SPIFI flash AXF. This could be combined into the previous step, but it can be useful to have access to the AXF as well as the binary.
  [*]Generate a binary containing only the code/data being placed into the internal flash. This overwrites the original whole project AXF and will be used when we start a debug session.
  [*]Display size information of the two AXFs that match the two flash types.
[/list]

To use this project, first of all build as normal.

Then select the LPC4088_Combined_EXTFLASH.bin file in the Project Explorer view, and click on the GUI flash programmer tool on the main icon bar

[list=1]
  [*]http://www.lpcware.com/content/faq/lpcxpresso/gui-flash-programming-tool
[/list]

Select the LPC407x_8x_S25FL032P.cfx flash driver you have previously placed into the LPCXpresso bin directory, and enter 0x28000000 in the base address field. Then hit OK. You should then see a log confirming the LPC4088_Combined_EXTFLASH.bin has been programmed.

Having done this, you can then launch a debug session as normal, and the main code will be downloaded into the internal flash and you can then debug/run this as normal.

If you prefer, then once you have everything working as per above, you could change from using the GUI flash programming tool for downloading to the SPIFI flash to using the command line programmer - either from a command line prompt, or by adding it as a "Pre launch command" entry for the debugger in your launch configuration. For more details, please see:

[list]
  [*]http://www.lpcware.com/content/faq/lpcxpresso/command-line-flash-programming
  [*]http://www.lpcware.com/content/faq/lpcxpresso/launch-configuration-menu
[/list]

Regards,
LPCXpresso Support

0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by schisanoa on Tue Sep 16 08:31:07 MST 2014
Thanks,


Quote:
The issue here is that LPCXpresso cannot currently use two different flash drivers when launching a debug session. The solution previously provided by my colleagues avoids this issue by using a separate project for each flash device (the internal flash and the SPIFI flash).

This is not strictly necessary though. It is possible to create a single project, but you then need to do some post-processing to split the image into two and program one part (the binary to go into the SPIFI) as pre-debug-launch job using one flash driver. Then you program the other flash using the other flash driver as normal when you start the debug session.

I will look at providing an example that shows how this can be done over the next day or so.



Ok, it would be perfect if you can provide the example of how this can be done in the next day. Thanks in advance for this, because it is very useful for us.


Quote:
Note that generally, in particular because of the issues with debugging code in the external SPIFI flash on LPC407x_8x parts, I would recommend avoiding putting code into this flash. Instead I would recommend that you look at putting rodata there instead.



Yes, this is what I will do. My idea is to place only DATA in the SPIFI, like image, logo, or other data, but I in case of necessity(hope never happen) I will add code in the SPIFI.

Thanks again
alessio

0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Tue Sep 16 06:43:01 MST 2014
The issue here is that LPCXpresso cannot currently use two different flash drivers when launching a debug session. The solution previously provided by my colleagues avoids this issue by using a separate project for each flash device (the internal flash and the SPIFI flash).

This is not strictly necessary though. It is possible to create a single project, but you then need to do some post-processing to split the image into two and program one part (the binary to go into the SPIFI) as pre-debug-launch job using one flash driver. Then you program the other flash using the other flash driver as normal when you start the debug session.

I will look at providing an example that shows how this can be done over the next day or so.

Note that generally, in particular because of the issues with debugging code in the external SPIFI flash on LPC407x_8x parts, I would recommend avoiding putting code into this flash. Instead I would recommend that you look at putting rodata there instead. The simplest way to do this is use the macros documented in the below FAQ:

[list]
  [*]http://www.lpcware.com/content/faq/lpcxpresso/coderodata-different-flash-blocks
[/list]

Regards,
LPCXpresso Support
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by schisanoa on Tue Sep 16 05:34:56 MST 2014
Is this a LPCXpresso limitation? Moving project to IAR or Keil make possible to merge the project and place code and data on multiple physical memories?

If I understand your suggestion is to place the code and data that I need to place on external flash, in the external flash, with a function pointer table, that allow the access through a function pointer, right?

0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Fri Sep 12 11:50:24 MST 2014

No, you can't merge the projects at this time since the respective code/data spans multiple physical memories. There are future plans to accommodate this in the debugger. For now, you'll need to flash these projects in separate steps.

If your secondary bootloader is intended to program SPIFI flash, you'll need to incorporate the SPIFI driver into the bootloader and initiate the calls from there. You can't use IAP for this.

As far as locating code at specific memory locations, the most straightforward way is to assign the code to a unique section, and locate these sections with a custom linker script. LPCXpresso assigns data to specific RAM memories in this way.  See the macros in cr_section_macros.h, and review the managed linker scripts. It's the same idea for code sections. Locating individual calls in this way can become unmanageable when you create separate output files for code/data in internal flash vs. external flash. Some user's create and locate a function pointer table in external flash, then access the individual calls through a function pointer (like the example). The benefit of this approach is you only need to explicitly locate the function pointer table. There's other variations on this theme but require a bit more effort.

Regards,
LPCXpresso Support
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by schisanoa on Fri Sep 12 05:59:06 MST 2014
Ok, your example is working on my board(I have the same SPIFI).

Now, can I merge both the project?

For example, Can I take the LPC40XX_CALL_TEST, put into its memory configuration the flash driver for the SPIFI, and put a function into the SPIFI memory(like the dummy function of the second project), while keeping the other parts of the firmware in the flash memory?
If it is possible how I can say to the compiler to put a function or a constant data at a particular address?

And if I want to program the SPIFI from my bootloaer, can I use the IAP function or I should use the SPIFI Write,Read etc function from the driver?

Thanks
Alessio
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by schisanoa on Wed Sep 10 15:12:16 MST 2014
Thank you. I will try your example tomorrow morning( I'm in italy) and I will inform you about the test.

Thank you again
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mc on Wed Sep 10 12:07:00 MST 2014
Hi schisanoa,
Please find attached  an example code. I prepared it just to help you to show how to split code between internal and external QSPI flash. There may be other ways, but I think this is one of the way to do it. Please let me know your feedback.
This example works on EA LPC4088 board which contains S25FL032P QSPI flash device. This workspace has below 6 projects.

lib_lpcspifilib  : SPIFI library project
lpc_board_ea_devkit_4088 : EA LPC4088 board library
lpc_chip_40xx : LPC407x_8x Chip Library
LPC40XX_CALL_TEST : Code executes from internal flash and calls code from QSPI flash
LPC40XX_EXT_FLASH : Contains a dummy function which returns value 50 from external flash
LPC40xx_SPIFIdriver : You can generate flash driver and can use it to program QSPI flash using LPC4088_EXT_Flash project

--------------------------------
Please follow below steps.
1)Build all the projects
2)     Connect the debug hardware.
3)In the builds folder of the “LPC40xx_SPIFIdriver” project you will find the LPC407x_8x_S25FL032P.cfx flash driver file. Copy it to C:\nxp\LPCXpresso_7.x.x_xxx\lpcxpresso\bin\Flash folder
4)Open the LPC40XX_EXT_FLASH project and navigate to Properties->C/C++Build->MCU Settings. Make certain the LPC407x_8x_S25FL032P.cfx flash driver file is configured as the flash driver for this project. Note the SPIFI_4MB flash region at 0x28000000. Your device may not be identical to this example. Use the Memory Configuration editor to correct the size information.
5)Program the device using the Flash Dialog. Browse for the LPC40XX_EXT_FLASH.axf file in the project. It contains only 2 instructions, so don't be alarmed by the size.
6)Finally, debug the LPC40XX_CALL_TEST project and see the value of ret (line number 110) in LPC40XX_CALL_TEST.c file it will show you 50 indicating the value returned from the call resident in external flash.
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Tue Sep 09 12:29:35 MST 2014

A SPIFI flash driver project and source is supplied in the Examples folder in the LPCXpresso installation, but LPCXpresso does not provide a prebuilt SPIFI flash driver for the LPC40xx. The LPC40xx SPIFI flash interface is identical to the LPC43xx, except the SPIFI register block is in a different location.

An LPC40xx version of the flash driver would need to be built from the supplied project. Expect changes to the processor pinmux, clock setup, SPIFI register block location, and flash device memory location.

Please note that, although it's possible to use an external flash memory on the LPC40xx part for code or data, you're not going to be able to debug code in this address space. ARM debug does not support hardware breakpoints at or above address 0x20000000. It's suitable for data or code, provided you can debug your code from another memory prior to deployment.

Regards,
LPCXpresso Support
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by schisanoa on Tue Sep 09 05:41:46 MST 2014
Ok, I've already read, but it refers only about "LPC18_43_SPIFI" flash driver, and also looking in the driver folder I don't see anything about LPC40XX SPIFI driver. Are the same drivers?
0 Kudos

1,540 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LessThanZero on Mon Sep 08 13:02:58 MST 2014

This is all covered in the LPCXpresso User Guide provided in your installation folder. Read the chapter on the Memory Editor and User Loadable Flash Driver.

LessThanZero.
0 Kudos