AnsweredAssumed Answered

LPC4337 IAP erase flash hang

Question asked by Mike Cruse on Aug 27, 2016
Latest reply on Mar 12, 2018 by Stjepan Cajic

Hi there, I am having a problem with IAP rom code hanging on the LPC4337.


I have a bootloader in flash bank A and application code in flash bank B.

I can erase bank B, read the app code from the SD card and program the flash just fine under the debugger. However if I run the board without debugging it hangs. When I attach to the running code I find that the MCU stuck in a loop reading the FMSTAT register at 0x4000dfe0. I appears the loop is waiting for the SIG_DONE bit to be set and this never happens. See assembly code below.


After checking for the obvious things like interrupts being enabled etc. I reverted to the LPC4337 LPCOpen example code, periph_flashiap, just to remove any variables that may be introduced by my own code.


I get the same result. I appears to be during the sector erase IAP call. The sector(s) are prepared for write/erase but the erase call never returns unless I run the code under the debugger.


The LPCOpen example uses the last sector in bank A whereas I am using bank B so the FMSTAT for bank A is being checked.


Here is the relevant bit of assembly code:


r0 = 0x4000d000 or 0x4000c000 depending in flash bank being used

r5 = 0x00000fe0 offset to FMSTAT register


r1 contains 0x00000008 after reading the FMSTAT register.


104019da:   b.n     0x104019c8
104019dc:   adds    r1, r5, #1
104019de:   beq.n   0x104019d6
104019e0:   ldr     r1, [r0, r5]      <-- Looping here
104019e2:   lsls    r1, r1, #29
104019e4:   beq.n   0x104019e0
104019e6:   pop     {r4, r5, pc}
104019e8:   push    {r0, r1, r2, r3, r4, r5, r6, r7, lr}
104019ea:   sub     sp, #12


A further problem that I have noticed with the example code is that the Chip_FMC_ComputeSignatureBlocks() call generates a hard fault. Specifically, the fault happens when writing to the FMSTATCLR register in fmc_18xx_43xx.h, although it is flagged as imprecise to I can't be too sure.


STATIC INLINE void Chip_FMC_ComputeSignature(uint8_t bank, uint32_t start, uint32_t stop)
    LPC_FMC[bank]->FMSSTART = (start >> 4);
    LPC_FMC[bank]->FMSTATCLR = FMC_FLASHSIG_STAT;     <-- Hard fault here
    LPC_FMC[bank]->FMSSTOP = (stop >> 4) | FMC_FLASHSIG_BUSY;


I am not using this feature yet but this is unmodified example code and I figure it should work.

As soon as I hit this hard fault lpcxpresso completely freezes and has to be killed externally.


I am using version 8.2.0 of lpcxpresso with the latest GDB as I know there are problems with the version supplied with 8.2.0.

Any help on these issue would be greatly appreciated.