ISP or IAP

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

ISP or IAP

3,995 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ppx on Fri Jan 18 10:27:50 MST 2013
I have a board with LPC1124 (will be replaced by LPC811) on a live main supply. It is communicating serially with an LPC1764 via 2 optocouplers. I have software update on Ethernet working in the M3 and I would like to store the software for the M0 inside the M3 so I can update also the M0 software remotely.

I see 3 ways.
1. Create some clever hardware, perhaps just R and C to create the right ISP/reset sequence from togling an output on the M0.
2. Somehow trigger ISP mode from the M0 software. Is it possible?
3. Use IAP but it looks messy. Do I have to do download/handshake/flashing in my own software? The user guide says it will change to Thumb mode when you invoke IAP. How is that handled by the C compiler?

Also after download I probably want to do some kind of reset. Does it sound correct to make a watchdog reset rotine, place that routine at a fixed address and "go" from that address? I don't want to add more optocouplers.

Are there perhaps any better ways?
0 Kudos
Reply
17 Replies

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Miendar on Fri Jan 17 03:27:14 MST 2014
Hi,

To exit to ISP bootloader, I'm using advice from Ex-Zero by using Application Interrupt and Reset Control Register (AIRCR).
In my project, I use a soft under VB to communicate with the LPC11C14. I use following messages to write instructions in RAM at 0x1000 0300 (RAM aera used by FlashMagic to write temporary instructions) and to execute it (GO command):

        Dim write_unlock() As Byte = {&H2B, &H0, &H50, &H0, &H5A, &H5A, &HDE, &H4}
        Dim write_address() As Byte = {&H23, &H15, &H50, &H0, &H0, &H3, &H0, &H10}
        Dim write_prg_data() As Byte = {&H21, &H50, &H1F, &H1, &H0, &H4, &H0, &H0}
        Dim write_code_1() As Byte = {&H0, &H1, &H4A, &H2, &H4B, &HDA, &H60, &HC0}
        Dim write_code_2() As Byte = {&H10, &H46, &H4, &H0, &HFA, &H5, &H0, &HED}
        Dim write_code_3() As Byte = {&H0, &H0, &HE0, &H0, &H0, &H0, &H0, &H0}
        Dim go() As Byte = {&H23, &H70, &H50, &H1, &H0, &H3, &H0, &H10}
        Dim start() As Byte = {&H2F, &H51, &H1F, &H1, &H1, &HFE, &HDE, &H4}

For information (from Ex-zero post):

void Own_Reset(void)
{
      SCB->AIRCR  = ((0x5FA << SCB_AIRCR_VECTKEY_Pos)      |
300:    4a01          ldr    r2, [pc, #4]    ; (308 )
302:    4b02          ldr    r3, [pc, #8]    ; (30c )
304:    60da          str    r2, [r3, #12]
                         SCB_AIRCR_SYSRESETREQ_Msk);
}
306:    4770          bx    lr
308:    05fa0004     .word    0x05fa0004
30c:    e000ed00     .word    0xe000ed00

the compiled code is:
const char system_reset[]={0x01,0x4a,0x02,0x4b,0xda,0x60,0xc0,0x46,0x04,0x00,0xfa,0x05,0x00,0xed,0x00,0xe0};

I hope it can help someone someday !

0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ppx on Thu Jan 24 02:40:59 MST 2013
There are two main reasons for my ideas. I want the watchdog to run in the normal application and since I can not not turn it off when it is on, I want to set maximum timeout so watchdog does not interfere with ISP.
Secondly I don't want to to use the ISP and the reset pins because it will force me to add more optocouplers. The M0 is on the mains supply. It is clear that the routine for incorrect watchdog feed can be anywhere as long as I know where. If I write it to RAM just before using it I am sure where it is.
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Jan 24 02:12:16 MST 2013

Quote: ArneB
Maybe its too early in the morning and I am not fully awake, but why do make it so complicated ?



Because that's not reliable, it's far better to reset before and after ISP :eek:
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArneB on Thu Jan 24 02:02:12 MST 2013
Maybe its too early in the morning and I am not fully awake, but why do make it so complicated ?

Send a command from your host controller to the target controller to switch into the ISP mode.
Download the new firmware into the taget controller via ISP commands.
Start the new firmware with the ISP "GO" command.

No need for watchdogs, RAM functions etc....
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Wed Jan 23 10:25:44 MST 2013
[FONT=Tahoma][SIZE=2]I would modify your scheme slightly:

Leave watchdog disabled until after the download (and download image verification),
Then start watchdog with max timer **
Call code in ram (with interrupts disabled) to do the IAP stuff
Then send a deliberate mis-feed to cause the watchdog reset.

** The watchdog setup/miss-feed need not be in ram, normal flash is ok.
The setup sequence should be (assume not already enabled)

1) write 3 (enable+cause reset) to mode reg
2) set timeout value to max
3) correct feed AA/55 -- this actualy sets the watchdog going

Regards, Mike

PS: You might want to set a flag for normal power on or update success/fail
and put this in one of the RTC NV general purpose regsiters.
Then on reset after the watchdog event, you can check the flag
to see if (a) an upload was attempted and (b) if it worked or not.
NB: clear the flag after read  ready for next boot/upload.




[/SIZE][/FONT]
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ppx on Wed Jan 23 10:10:09 MST 2013
On LPC800 and internal clock I think it is around 111 seconds. So my idea is to have a user command coming in on the uart that does the following:

Feed watchdog, set max watchdog time out, feed watchdog again, turn off interrupt, call IAP to start ISP, download new program, download simple program in RAM that generates an incorrect watchdog feed. Jump to that program with an ISP command and it should reset and start immediately.

If clock has been modified in the previous user code we should either set clock back to default before IAP call or we must read clock and set baudrate in the beginning of ISP.
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Wed Jan 23 09:51:15 MST 2013
[FONT=Tahoma][SIZE=2]
Quote:
I'm thinking about setting a long watchdog timeout

The maximum watchdog timeout is ~2 minutes.
(At least on my LPC1778).

Mike
[/SIZE][/FONT]
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ppx on Wed Jan 23 07:30:49 MST 2013
Found another simple method I can write in C. Just feed the watchdog an invalid feed sequence. Immediate reset!
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Jan 23 06:28:36 MST 2013
Just use NVIC_SystemReset() :eek:

Write it's code to RAM, execute it and voila: Reset :D

See #37 of http://knowledgebase.nxp.com/showthread.php?t=2460
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ppx on Wed Jan 23 02:42:10 MST 2013
Hi Zero,

I understand your idea but how do I leave ISP mode when the new software is flashed? I don't want to implement a reset line because it would need one more optocoupler.
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Jan 22 11:21:12 MST 2013
Another (working) option

#1 Before switching to ISP, store an ISP flag in noinit region of RAM

__attribute__ ((section(".keep"))) volatile uint16_t isp_memo;//isp memory flag
#2 Reset :eek:

NVIC_SystemReset();            //and Reset
#3 Read ISP flag, don't start watchdog and switch to ISP via IAP 57
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ppx on Tue Jan 22 10:24:08 MST 2013
I think I understand how to invoke ISP via IAP and download new code. However, starting the new program without reset pin and in my case also optocoupler etc., is not 100% clear.

I know I cant disable the watchdog once it is enabled but I think I can reprogram the timeout. I'm thinking about setting a long watchdog timeout so I have time to do ISP and download. Than let the watchdog do a reset to start the new program. Does this look right?
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Mon Jan 21 12:11:01 MST 2013
[FONT=Tahoma][SIZE=2]
Quote: ArneB
Here is another link for the application note, as long as San Jose is still sleeping... ;)



It seems that they have woken up again :) with no explanation as to the snooze time.

[/SIZE][/FONT]
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArneB on Mon Jan 21 05:42:26 MST 2013
I can confirm, that there is indeed an IAP command to reinvoke the ISP mode again. It works like charm in my application... :)
As long as you don't issue a flash write/erase IAP command, you don't have to reserve the last 32 bytes in memory. I haven't expected any ISP/IAP related hard-faults yet.

Here is another link for the application note, as long as San Jose is still sleeping... ;)
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Mon Jan 21 05:22:58 MST 2013
[FONT=Tahoma][SIZE=2]Don't know about 800 specifically, but 1700's have an IAP command to re-invoke ISP (IAP = called from your code to BootRom).

There are several gotcha's (aka hard fault) so read you docs very carefully!

Mike

Sorry -- this point seems to have been made already.

You can get the appnote from NXP site:
[/SIZE][/FONT][FONT=Tahoma][SIZE=2]http://www.nxp.com/documents/application_note/AN11229.pdf

[/SIZE][/FONT]
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ppx on Mon Jan 21 04:44:35 MST 2013
I was supprised to see that the W command in ISP on LPC111X wanted UUencoded data and on an LPC800, binary data.

I don't understand exactly how to invoke ISP from software. One way would perhaps to invalidate the exception vectors and issue a watchdog reset. The MCU should than not be able to find any user code and should start the auto-baud. Any better ways? I would probably need a reset after downloding th new M0 code but I can not find a reset among the ISP commands. Is my proposed solution in my previous post OK or is it enough with a G to 0 (or somewhere else).

Last thing, the lpcware.com has been done for quite some time. Could anyone post the application note that Arne mentioned?
0 Kudos
Reply

3,826 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArneB on Fri Jan 18 12:33:05 MST 2013
I have a very similar configuration in my project and this is my solution:
HW: I have connected the UART lines with my host controller.
SW: After board assembly, the M0 flash is empty and it starts automatically in its bootloader mode after power-up. The host controller can use ISP to flash it for the first time. In the M0 software there is a trigger, which is able to reinvoke the ISP mode again. For field updates the host controller send this trigger command to the M0 and afterwards it sends the updated firmware to the M0.
There is only one drawback: If the flash procedure fails, then you need to have access to the SWD pins to revive your system...

The ISP procedure is explained in the M0 user manual and there is nice application note covering the necessary UUENCODE procedure.
0 Kudos
Reply