void spifi_cmdmode(void) { __disable_irq(); // Disable IRQs SCnSCB->ACTLR &= ~2; // disable Cortex write buffer to avoid exceptions when switching back to SPIFI for execution if (LPC_SPIFI->STAT & 0x01) { // In memory mode? LPC_SPIFI->STAT = 0x10; // Go to command mode while(LPC_SPIFI->STAT & 0x10); // wait for reset to complete } } void spifi_memmode(void) { LPC_SPIFI->MEMCMD = (0xebul << 24) | // opcode 0xeb Quad IO High Performance Read for Spansion (0x6 << 21) | // frame form indicating no opcode and 3 address bytes (0x2 << 19) | // field form indicating serial opcode and dual/quad other fields (0x3 << 16); // 3 intermediate data bytes SCnSCB->ACTLR |= 2; // Enable Cortex write buffer __enable_irq(); } |
Hi Greg,
I can't speak much about the source code for the SPIFI Driver, but here's an example I wrote for the LPC4350 eval board from Hitex with the Spansion S25FL129P. The SPIFI registers are pretty easy to use once you get the hang of it. Hopefully this will help.
This is an imperfect example as this board uses an SPI Flash part that is not very suitable to execute in place. The reason is explained below. But the example code might be useful. It is an example that directly uses the registers of the SPIFI.
XIP (Execute in Place) Example
The biggest issue you will have is that the Spansion part that Hitex put on this board uses uniform 256 KB sectors. This means that attempting to write data will require a 256 KB scratch area, which I would imagine is too big a scratch area for these chips. I would recommend getting the same general SPI FLASH part but with the uniform 64 KB sectors which also has 4 KB parameter sectors. (The 256 KB part doesn’t support the 4 KB parameter sectors). Here is an example project to write to one word in SPIFI and continue execution. It is not using the spifi library. It uses the register interface directly.
*** The project uses the 256 KB erase command, but pretends that it only needs to store 4 KB. That of course is not correct for a standard application. Please make sure to get the appropriate 64 KB uniform sector part with the 4 KB parameter sectors in order to use this example code in a real application.
Note the disabling and re-enabling of the Cortex Write Buffer (SCnSCB->ACTLR bit 2). Without disabling the write buffer, the Cortex will prefetch from the SPIFI memory area before the SPIFI memory area is turned on, and that will cause an exception.
Note the usage of 0xd8 instead of 0x20 to perform the erase, see line 115 in spifi_functions.c.
***Note that the whole spifi_functions.c is put in IRAM. Please set the volatile go bit (from a watch window) to run the example.
Noah
ESD1148ZRY is Rev A:
http://www.lpcware.com/content/forum/errata-situation-can-lpc4350-revision-esd1148zry#comment-2189