Programming Flash from which the program was booted, LPC43xx (LPC-Link2)

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

Programming Flash from which the program was booted, LPC43xx (LPC-Link2)

1,714 Views
kuklindima
Contributor II

Hi,

I want to program Flash memory from the running program (the Flash is 1MB W25Q80BV on LPC-Link2, LPC4370 chip). I'm using SPIFI example from LPCOpen 3.02 for LPCXpresso. This example is currently located in directory "misc_spifi_tst", (https://www.nxp.com/downloads/en/libraries/lpcopen_3_02_lpcxpresso_link2_4370.zip).

After some tweaking with placing functions in RAM (to program the flash from which the program was booted), I successfully wrote data to Flash (that part of the Flash which was not occupied by the code). However, I have problems when switching back to execution code from the Flash.

Here is the approximate sequence:

1. Entering command mode;

2. Writing data to Flash;

3. Entering memory mode;

4. Executing code, located in Flash. The problem starts here. It seems that it can't read the code. Looks like the chip doesn't recognize the Flash (for code execution). So calling any function located in Flash drives microcontroller crazy. Maybe it didn't enter memory mode properly. So, maybe I need to do something else to enter the memory mode and the chip could see the code in Flash (as it was before switching to command mode)? Core reset helps to go back to execution code from Flash but it is not very convenient (resetting after each Flash programming).

Maybe it is the same problem as this one SPIFI Command Mode to Memory Mode? Seems like in the LPCOpen SPIFI example a similar approach is used to that in the link (and in the example, they also mention Spansion memory; in the link - Spansion S25FL256S is used). But in my case, it is different Flash memory and I need a different code/settings to switch correctly to memory mode?

Edit: I got it working. What I did is simply read all the needed registers before entering command mode (CTRL, CMD, IDATA, and MCMD) and loaded them to enter memory mode. Btw, the chip uses very inefficient serial mode! While LPCOpen SPIFI example tries to use fast read quad I/O with "continuous read mode" (see W25Q80BV manual), which is much faster. But it doesn't work in my case. So maybe someone could successfully use the fast mode?

Labels (5)
4 Replies

1,250 Views
miguel_mendoza
NXP Employee
NXP Employee

Hi Dmitry Kuklin,

I do not understand the following statement

While LPCOpen SPIFI example tries to use fast read quad I/O with "continuous read mode" (see W25Q80BV manual), which is much faster. But it doesn't work in my case.

Could you give me more information about "does not work my case" mean, Did you edit the example? or how do you know that does not work?

regards,
Miguel Mendoza

0 Kudos

1,250 Views
kuklindima
Contributor II

First, I placed critical functions in RAM. And then I tried to change spifi_memory_mode() function, as the original one didn't switch to memory mode correctly.

The microcontroller doesn't "see" code, located in the flash: it cannot read data if it is located in flash (if I try to access some array, for example) and it hangs when it tries to call some function in flash.

When I enter memory mode correctly, everything works fine. But I only could switch to memory mode using serial mode. Currently, the spifi_memory_mode() looks like this (I simply loaded the values of the registers that I read before entering command mode):

__RAMFUNC(RAM) void spifi_memory_mode(void) {
#ifdef CORE_M4
    SCnSCB->ACTLR &= ~2;
#endif
    LPC_SPIFI->CTRL = 0x6009ffff;
    LPC_SPIFI->DATINTM = 0xffffffff;
    LPC_SPIFI->CMD = 0x3800000;
    while(LPC_SPIFI->STAT & 2);
    LPC_SPIFI->MEMCMD = 0x3800000;
#ifdef CORE_M4
    SCnSCB->ACTLR |= 2;
#endif
}

It works but this is serial mode. It would be better to use one of the fast modes.

It is also interesting to know when the values of the registers were set initially (i.e. at which stage of boot/initialization process this memory mode was chosen and set); can it be altered right there, or the only way to change memory mode is reinitialization.

0 Kudos

1,250 Views
miguel_mendoza
NXP Employee
NXP Employee

HI Dmitry Kuklin

We share you via email an example for LPC4370, made by the team, that uses the SPIFI library that we provide. I think that can cover that you need. the example has some functions to entry to memory mode (also in fast mode) in a simple way.

Hopes it helps! and if you have any questions or problems let me know through this thread

best regards,
Miguel Mendoza

1,250 Views
kuklindima
Contributor II

Thanks, Miguel! I'll dig into it.

0 Kudos