AnsweredAssumed Answered

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

Question asked by Dmitry Kuklin on Aug 4, 2018
Latest reply on Aug 9, 2018 by Dmitry Kuklin


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", (

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?