lpcware

IAP on LPC1778 -- Erase returns 'busy' but erase is complete

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by MikeSimmonds on Mon Apr 15 05:32:49 MST 2013
[FONT=Tahoma][SIZE=2]I am on an LPC1778 (running at 120MHz)

"Flash programming hardware interface is busy" IAP return code 11.

[I]What does that actually mean? Why is it busy? What is it doing?
What status is it waiting for?[/I]

My code uses IAP commands to erase flash sectors 16 and 17 (each 32KB)
I 'prepare' the sectors (status is 0) then erase. The code 11 is returned,
[I]but[/I] the sectors [I]are[/I] erased.

An immediately following 'prepare/copy ram to flash' loop for the 64KB in
4KB chunks works OK (and returns a status code of zero).

So the "Flash programming hardware interface" wasn't busy after all.
So why does the code in the boot rom lie to me like that.

I suspect that NXP will have to answer this one.

I don't really want to ignore the return value for erase because it might
really fail one day.

Regards, Mike

For the nit pickers:

;-----------------------------------------------------------------------!
; Constants and Equates                            !
;-----------------------------------------------------------------------!

IAP    = 0x1FFF1FF1            ; ROM Boot IAP dispatch address

clkKHz    =     120000            ; system clock in KHz

cmdSz    =         32            ;
codeSz    =       4096            ;

;-----------------------------------------------------------------------!
; Private Data                                !
;-----------------------------------------------------------------------!
.section .sbss, "aw", %nobits        ; private sram bss area
.align 2,0

.type cmdBuff, %object
.size cmdBuff, cmdSz

cmdBuff:    .space cmdSz

.type codeBuff, %object
.size codeBuff, codeSz

codeBuff:    .space codeSz

;-----------------------------------------------------------------------!
; Erase Flash                                !
;-----------------------------------------------------------------------!

; r0 = start sector, r1 = sector count

fn FLZap

    push    {r7,lr}            ;
    ldr    r7, =cmdBuff        ;
    str    r0, [r7, 1*4]        ; stash first sector
    adds    r0, r1            ; calc last sector
    subs    r0, 1            ; first+count-1
    str    r0, [r7, 2*4]        ; stash last sector
    ldr    r0, =clkKHz        ; get   clock speed
    str    r0, [r7, 3*4]        ; stash clock speed

;---------------------------------------;
    movs    r0, 53            ; blank check
    str    r0, [r7]        ;
    movs    r0, r7            ; 'in'  parameters
    adds    r1, r7,  5*4        ; 'out' parameters
    bl    GoIAP            ;
    ldr    r0, [r7, 5*4]        ; get status code
    cbz    r0, 9f            ; skip erase if blank

;---------------------------------------;
    movs    r0, 50            ; prepare
    str    r0, [r7]        ;
    movs    r0, r7            ; 'in'  parameters
    adds    r1, r7,  5*4        ; 'out' parameters
    bl    GoIAP            ;
    ldr    r0, [r7, 5*4]        ; get status code
    cbnz    r0, 9f            ; OOPS -- IAP failed

    movs    r0, 52            ; erase
    str    r0, [r7]        ;
    movs    r0, r7            ; 'in'  parameters
    adds    r1, r7,  5*4        ; 'out' parameters
    bl    GoIAP            ;
    ldr    r0, [r7, 5*4]        ; get status code
    ;cbnz    r0, 9f            ; OOPS -- IAP failed

;---------------------------------------;
9:    pop    {r7,pc}            ; return (zero == success)

fe FLZap

;-----------------------------------------------------------------------!
; IAP Invoke Wrapper                            !
;-----------------------------------------------------------------------!

fn GoIAP

    push    {lr}            ;
    ldr    r12, =IAP        ; get abs entry point
    blx    r12            ; go IAP
    pop    {pc}            ; return

fe GoIAP
[/SIZE][/FONT]

Outcomes