Trouble trying to implement SPIFI library

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

Trouble trying to implement SPIFI library

825 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alaric on Wed Feb 03 23:40:51 MST 2016
Hi,
I'm trying to use the latest "spifilib_m3" V1.03 library on our lpc1830, with a S25FL128S dataflash, using the latest lpcxpresso V8.
We want to use the dataflash for code execution (XIP) and data storage. The board that I am working on currently works perfectly with our Keil project using one of the first spifi libraries implementations.

I've followed the app note on how to relocate a library to RAM using the linkerscripts (https://www.lpcware.com/content/faq/lpcxpresso/relocating-code-flash-ram) but I still get a Hardfault condition when i run/debug the code.

I've looked at the map file and it shows that there are some "static const" like ".rodata.spifiCmdOp" and ".rodata.pData" which still reside in .text region which is address 0x1400 xxxx which I think is causing the problem.

I've included my test projects and would appreciate any help or suggestions.

Thanks,
Alaric

Original Attachment has been moved to: workspace.zip

0 Kudos
8 Replies

574 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alaric on Fri Feb 05 04:45:19 MST 2016
Hi,
I see that your example project in "lpcopen_2_12_lpcxpresso_keil_mcb_1857_SPIFI_v1.0.zip" does exactly what I mentioned with "setup_spifi()" function being located in RAM and also at the end of the function it goes back to memory mode by calling "spifiDevSetMemMode()".

However it would be far better if the library handled all this instead of the application having to have wrapper functions (relocated to RAM) when ever it wants to use the library functions.

I'm currently looking at modifying the library code to try and achieve this, may not be pretty but will be neater for my application code.
Thanks for all your help, hope that these changes can be added to the library in the future.
0 Kudos

574 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alaric on Thu Feb 04 23:38:42 MST 2016
Hi,
I have found a workaround which is to call "spifiDevSetMemMode" to put the controller back into memory mode before returning and this seems to work. It does point to the library not restoring back to memory mode after a call to the library.
0 Kudos

574 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alaric on Thu Feb 04 23:05:10 MST 2016
Hi,
I don't have any interrupts enabled, however did try disabling interrupts with "__disable_irq()" which made no difference.
I tried wrapping the spifi functions in "spifi_test()" function which I then located in RAM using "__RAMFUNC(RAM)".
Now each of the spifi calls returns correcting and the returned handle pReturnVal looks correct but as soon as it returns to main() the hardfault occurs.

The simple function called "test()" also located in RAM returns correctly, it looks like the spifi library doesn't restore spifi back to normal memory access that why it Hardfaults after returning to main which is located in Flash 0x1400xxxx.

Any suggestions?
0 Kudos

574 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Thu Feb 04 07:24:56 MST 2016
Interrupts maybe? Have you disabled them before trying to access the SPIFI memory - otherwise you will probably end up executing back from SPIFI if one goes off.

You might find this helpful too:

https://www.lpcware.com/content/faq/lpcxpresso/debugging-hard-fault

Regards,
LPCXpresso Support
0 Kudos

574 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alaric on Thu Feb 04 07:05:32 MST 2016
Hi,
The map file looks right now, thanks, but I am getting a Hardfault condition after returning from the "spifiGetHandleMemSize" call.
I've attached some snapshots of the instruction stepping as it is returning from the function.

Thanks,
Alaric
0 Kudos

574 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Alaric on Thu Feb 04 06:35:50 MST 2016
Thanks,
will try your suggestions and report the outcome.
0 Kudos

574 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Thu Feb 04 06:16:53 MST 2016
And an even simpler fix is to remove the " -fdata-sections" options from the library's build options (MCU C Compiler -> Miscellaneous).

Regards,
LPCXpresso Support
0 Kudos

574 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Thu Feb 04 06:04:00 MST 2016
The "static" keyword on the definitions of all the spifiCmdOp and pData definitions within spifilib_fam_standard_cmd.c do appears to be what's causing the trouble here.

We need to look into this in more detail, but in the short term if you remove the use of "static" on all these definitions, then everything will then link and be placed in RAM as expected. And although I haven't tested it I can't see why this would stop the SPIFIlib code from working correctly.

Regards,
LPCXpresso Support
0 Kudos