Forums

New to LPC2129 (coming from PIC) - Attempting to enter ISP mode from user code

Started by tc_lawabider March 22, 2012
Hi,

I've recently inherited a project running an LPC2129 and FreeRTOS 6.1.1, and I've not got much background with this type of chip.

I'm trying to enter ISP mode from user code, using AN10356 and the help of one website which suggested I use a watchdog timer to ensure I can exit after the code upgrade has been performed.

My code, unfortunately, does not seem to enter bootloader mode. If I run FlashMagic, it says failed to autobaud and won't take any code.

My code is as follows:
/******************************************/
void StartISP(unsigned long wdticks)
{
void (*bootloader_entry)(void)=0;

// reset PINSEL (set all pins to GPIO)
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;

//disable stuff
U0IER=0x00; U0LCR=0x80; U0DLL=0x01; U0DLM=0x00;
U0LCR=0x00; U0FCR=0x06;

// reset GPIO, but drive P0.14 low (output)
GPIO_IODIR = 0x00004000; // P0.14 = output, others are input
GPIO_IOCLR = 0x00004000;

// clear vector
VICINTENCLR=0x0;

// power up all peripherals
PCONP = 0x000003be; // If having trouble, check that this is the correct setting for LPC2129. Currently set for LPC2104, which has 0x0000 1FBE as reset

// disconnect PLL
PLLCON = 0x00;
PLLFEED = 0xAA;
PLLFEED = 0x55;

//reset timer 1
TIMER1_PR=0x0;
TIMER1_MCR=0x0;
TIMER1_CCR=0x0;
VPBDIV = 0x00; // set peripheral bus to 1/4th of the system clock
MEMMAP = 0x0; // map bootloader vectors

//Timer to exit and relaunch program
if (wdticks != 0) {
WDTC = wdticks; //this is the constant reload value
WDMOD = 0x03; //this is the mode
WDFEED = 0xAA; WDFEED = 0x55; //this starts the timer
}
bootloader_entry(); // jump to the bootloader address
}
/******************************************/

And I'm calling it with:

StartISP(400000000);
Could anyone please provide some insight as to what I might be doing/setting/calling wrong?

Additionally, the reason for calling this code from within user code is to facilitate OTA updating over Bluetooth, on a module running Python. I only have access to the basic Python functions and serial port calls. Other than pyLPC, is there a good resource for explaining a quick-and-dirty way to program a .hex file to the micro? I have the manual here on pages 262-283, but would love any insight you have that might save unnecessary processing time.

Here's what I understand:
- Host sends '?' as a synchronization character at 8/N/1 at it's baud rate
- The LPC sends 'Synchronized\r\n'
- The host confirms receipt with 'Synchronized\r\n'
- The LPC sends 'OK\r\n' to host to confirm
- The host then sends '12000\r\n' to the LPC to set the crystal speed (12MHz)
- The LPC replies 'OK\r\n', or this process starts from the '?' again
- The host unlocks the LPC for write, erase, and go using 'U 23130\r\n'

I'm a bit lost as to where to go from here. I need to transfer my .hex to program space, but I don't know how to split/send/UU-encode the data, and so on. Any help would be sincerely appreciated.

Thank you!
-Josh

An Engineer's Guide to the LPC2100 Series

Hello,

Please note that if you activate the watchdog it will reset the chip after a timeout. The ISP bootloader will not kick the watchdog, which means that you must have completed reprogramming the device before that time. Have you tried it without the watchdog?
It is also possible to make your own secondary bootloader, that way you can use any type of communication you want. However it will cost you some extra code flash space.

--
Kevin
--- In l..., "tc_lawabider" wrote:
>
> Hi,
>
> I've recently inherited a project running an LPC2129 and FreeRTOS 6.1.1, and I've not got much background with this type of chip.
>
> I'm trying to enter ISP mode from user code, using AN10356 and the help of one website which suggested I use a watchdog timer to ensure I can exit after the code upgrade has been performed.
>
> My code, unfortunately, does not seem to enter bootloader mode. If I run FlashMagic, it says failed to autobaud and won't take any code.
>
> My code is as follows:
> /******************************************/
> void StartISP(unsigned long wdticks)
> {
> void (*bootloader_entry)(void)=0;
>
> // reset PINSEL (set all pins to GPIO)
> PINSEL0 = 0x00000000;
> PINSEL1 = 0x00000000;
>
> //disable stuff
> U0IER=0x00; U0LCR=0x80; U0DLL=0x01; U0DLM=0x00;
> U0LCR=0x00; U0FCR=0x06;
>
> // reset GPIO, but drive P0.14 low (output)
> GPIO_IODIR = 0x00004000; // P0.14 = output, others are input
> GPIO_IOCLR = 0x00004000;
>
> // clear vector
> VICINTENCLR=0x0;
>
> // power up all peripherals
> PCONP = 0x000003be; // If having trouble, check that this is the correct setting for LPC2129. Currently set for LPC2104, which has 0x0000 1FBE as reset
>
> // disconnect PLL
> PLLCON = 0x00;
> PLLFEED = 0xAA;
> PLLFEED = 0x55;
>
> //reset timer 1
> TIMER1_PR=0x0;
> TIMER1_MCR=0x0;
> TIMER1_CCR=0x0;
> VPBDIV = 0x00; // set peripheral bus to 1/4th of the system clock
> MEMMAP = 0x0; // map bootloader vectors
>
> //Timer to exit and relaunch program
> if (wdticks != 0) {
> WDTC = wdticks; //this is the constant reload value
> WDMOD = 0x03; //this is the mode
> WDFEED = 0xAA; WDFEED = 0x55; //this starts the timer
> }
> bootloader_entry(); // jump to the bootloader address
> }
> /******************************************/
>
> And I'm calling it with:
>
> StartISP(400000000);
> Could anyone please provide some insight as to what I might be doing/setting/calling wrong?
>
> Additionally, the reason for calling this code from within user code is to facilitate OTA updating over Bluetooth, on a module running Python. I only have access to the basic Python functions and serial port calls. Other than pyLPC, is there a good resource for explaining a quick-and-dirty way to program a .hex file to the micro? I have the manual here on pages 262-283, but would love any insight you have that might save unnecessary processing time.
>
> Here's what I understand:
> - Host sends '?' as a synchronization character at 8/N/1 at it's baud rate
> - The LPC sends 'Synchronized\r\n'
> - The host confirms receipt with 'Synchronized\r\n'
> - The LPC sends 'OK\r\n' to host to confirm
> - The host then sends '12000\r\n' to the LPC to set the crystal speed (12MHz)
> - The LPC replies 'OK\r\n', or this process starts from the '?' again
> - The host unlocks the LPC for write, erase, and go using 'U 23130\r\n'
>
> I'm a bit lost as to where to go from here. I need to transfer my .hex to program space, but I don't know how to split/send/UU-encode the data, and so on. Any help would be sincerely appreciated.
>
> Thank you!
> -Josh
>

Kevin,

Thank you for the reply. I understand that the watchdog timer will kick out from ISP mode; this is how I will auto-restart the board. I believe the timeout is sufficiently long to allow reprogramming. I have tried without the watchdog timer and I still appear to be unable to enter ISP mode.

I may look into writing my own bootloader if I can't get the default one to work. I would rather avoid it if possible not so much because of code space, but because I am a mechanical engineer and wish to get the software written quickly!

-Josh

--- In l..., "Kevin" wrote:
>
> Hello,
>
> Please note that if you activate the watchdog it will reset the chip after a timeout. The ISP bootloader will not kick the watchdog, which means that you must have completed reprogramming the device before that time. Have you tried it without the watchdog?
> It is also possible to make your own secondary bootloader, that way you can use any type of communication you want. However it will cost you some extra code flash space.
>
> --
> Kevin
> --- In l..., "tc_lawabider" wrote:
> >
> > Hi,
> >
> > I've recently inherited a project running an LPC2129 and FreeRTOS 6.1.1, and I've not got much background with this type of chip.
> >
> > I'm trying to enter ISP mode from user code, using AN10356 and the help of one website which suggested I use a watchdog timer to ensure I can exit after the code upgrade has been performed.
> >
> > My code, unfortunately, does not seem to enter bootloader mode. If I run FlashMagic, it says failed to autobaud and won't take any code.
> >
> > My code is as follows:
> > /******************************************/
> > void StartISP(unsigned long wdticks)
> > {
> > void (*bootloader_entry)(void)=0;
> >
> > // reset PINSEL (set all pins to GPIO)
> > PINSEL0 = 0x00000000;
> > PINSEL1 = 0x00000000;
> >
> > //disable stuff
> > U0IER=0x00; U0LCR=0x80; U0DLL=0x01; U0DLM=0x00;
> > U0LCR=0x00; U0FCR=0x06;
> >
> > // reset GPIO, but drive P0.14 low (output)
> > GPIO_IODIR = 0x00004000; // P0.14 = output, others are input
> > GPIO_IOCLR = 0x00004000;
> >
> > // clear vector
> > VICINTENCLR=0x0;
> >
> > // power up all peripherals
> > PCONP = 0x000003be; // If having trouble, check that this is the correct setting for LPC2129. Currently set for LPC2104, which has 0x0000 1FBE as reset
> >
> > // disconnect PLL
> > PLLCON = 0x00;
> > PLLFEED = 0xAA;
> > PLLFEED = 0x55;
> >
> > //reset timer 1
> > TIMER1_PR=0x0;
> > TIMER1_MCR=0x0;
> > TIMER1_CCR=0x0;
> >
> >
> > VPBDIV = 0x00; // set peripheral bus to 1/4th of the system clock
> > MEMMAP = 0x0; // map bootloader vectors
> >
> > //Timer to exit and relaunch program
> > if (wdticks != 0) {
> > WDTC = wdticks; //this is the constant reload value
> > WDMOD = 0x03; //this is the mode
> > WDFEED = 0xAA; WDFEED = 0x55; //this starts the timer
> > }
> > bootloader_entry(); // jump to the bootloader address
> > }
> > /******************************************/
> >
> > And I'm calling it with:
> >
> > StartISP(400000000);
> >
> >
> > Could anyone please provide some insight as to what I might be doing/setting/calling wrong?
> >
> > Additionally, the reason for calling this code from within user code is to facilitate OTA updating over Bluetooth, on a module running Python. I only have access to the basic Python functions and serial port calls. Other than pyLPC, is there a good resource for explaining a quick-and-dirty way to program a .hex file to the micro? I have the manual here on pages 262-283, but would love any insight you have that might save unnecessary processing time.
> >
> > Here's what I understand:
> > - Host sends '?' as a synchronization character at 8/N/1 at it's baud rate
> > - The LPC sends 'Synchronized\r\n'
> > - The host confirms receipt with 'Synchronized\r\n'
> > - The LPC sends 'OK\r\n' to host to confirm
> > - The host then sends '12000\r\n' to the LPC to set the crystal speed (12MHz)
> > - The LPC replies 'OK\r\n', or this process starts from the '?' again
> > - The host unlocks the LPC for write, erase, and go using 'U 23130\r\n'
> >
> > I'm a bit lost as to where to go from here. I need to transfer my .hex to program space, but I don't know how to split/send/UU-encode the data, and so on. Any help would be sincerely appreciated.
> >
> > Thank you!
> > -Josh
>

Try adding the following line just before you call the boot loader entry point ( bootloader_entry(); )

bootloader_entry = (void (*)(void))(0x0);

(This is in addition to the definition of bootloader_entry you have at the beginning of this function)
...~Steve>



Thank you Steve. I'm not with the board at the moment, but I'll try that and report back!

--- In l..., Steve McCarter wrote:
>
> Try adding the following line just before you call the boot loader entry point ( bootloader_entry(); )
>
> bootloader_entry = (void (*)(void))(0x0);
>
> (This is in addition to the definition of bootloader_entry you have at the beginning of this function)
> ...~Steve>
>

Still no luck, unfortunately. I don't get any response when I send '?' to the LPC.

--- In l..., "tc_lawabider" wrote:
>
> Thank you Steve. I'm not with the board at the moment, but I'll try that and report back!
>
> --- In l..., Steve McCarter wrote:
> >
> > Try adding the following line just before you call the boot loader entry point ( bootloader_entry(); )
> >
> > bootloader_entry = (void (*)(void))(0x0);
> >
> > (This is in addition to the definition of bootloader_entry you have at the beginning of this function)
> >
> >
> > ...~Steve>
> >
> >
>

--- In l..., "tc_lawabider" wrote:
>

> I'm a bit lost as to where to go from here. I need to transfer my .hex to program space, but I don't know how to split/send/UU-encode the data, and so on. Any help would be sincerely appreciated.
>
> Thank you!
> -Josh
>
I don't quite follow why you want to get to ISP to load code from within your program. Whatever...

All you need is to have P0.14 at ground potential when the CPU comes out of reset and you will be in ISP mode. Not withstanding what happens if the watchdog has tripped. At your earliest opportunity, get rid of the watchdog until you are certain your code is finalized.

I don't know if repeatedly hitting reset will eventually get you to a state where the wathdog hasn't tripped...

Read section 20 of the User Manual and, in particular, this paragraph:

QUOTE

DESCRIPTION

The flash boot loader code is executed every time the part is powered on or reset. The loader can execute the ISP command
handler or the user application code. A LOW level after reset at the P0.14 pin is considered as the external hardware request to
start the ISP command handler. This pin is sampled in software. Asuming that proper signal is present on X1 pin when the rising
edge on RST pin is generated, it may take up to 3 ms before P0.14 is sampled and the decision on wether to continue with user
code or ISP handler is made. If P0.14 is sampled low and the watchdog overflow flag is set, the external hardware request to
start the ISP command handler is ignored. If there is no request for the ISP command handler execution (P0.14 is sampled HIGH
after reset), a search is made for a valid user program. If a valid user program is found then the execution control is transferred
to it. If a valid user program is not found, the auto-baud routine is invoked.

END QUOTE.

Flash Magic will take care of everything else as long as you have UART0 implemented.

Notice this sentence in the above quote:

QUOTE

If P0.14 is sampled low and the watchdog overflow flag is set, the external hardware request to start the ISP command handler is ignored.

END QUOTE

This concerns me greatly... You might not be able to ever get into ISP mode. As I have never used the watchdog, I have no idea how to recover from this. Perhaps JTAG?

Richard

Well, the reason I want to enter via software is because this is for an over-the-air update of existing hardware. Sure, I could pull the pin low - but I don't have it tied to any configurable hardware other than a physical jumper, and I don't trust the end user to use FlashMagic.

Again, the watchdog is just to reboot the device once the update has performed. I understand that it won't trigger the hardware entry into the bootloader, but that is not the intent. It will be set for several minutes, so the box can come back online without having to ask the user to restart it. For testing, I have disabled it - but it will be needed for production.
--- In l..., "rtstofer" wrote:
>
> --- In l..., "tc_lawabider" wrote:
> > > I'm a bit lost as to where to go from here. I need to transfer my .hex to program space, but I don't know how to split/send/UU-encode the data, and so on. Any help would be sincerely appreciated.
> >
> > Thank you!
> > -Josh
> >
> I don't quite follow why you want to get to ISP to load code from within your program. Whatever...
>
> All you need is to have P0.14 at ground potential when the CPU comes out of reset and you will be in ISP mode. Not withstanding what happens if the watchdog has tripped. At your earliest opportunity, get rid of the watchdog until you are certain your code is finalized.
>
> I don't know if repeatedly hitting reset will eventually get you to a state where the wathdog hasn't tripped...
>
> Read section 20 of the User Manual and, in particular, this paragraph:
>
> QUOTE
>
> DESCRIPTION
>
> The flash boot loader code is executed every time the part is powered on or reset. The loader can execute the ISP command
> handler or the user application code. A LOW level after reset at the P0.14 pin is considered as the external hardware request to
> start the ISP command handler. This pin is sampled in software. Asuming that proper signal is present on X1 pin when the rising
> edge on RST pin is generated, it may take up to 3 ms before P0.14 is sampled and the decision on wether to continue with user
> code or ISP handler is made. If P0.14 is sampled low and the watchdog overflow flag is set, the external hardware request to
> start the ISP command handler is ignored. If there is no request for the ISP command handler execution (P0.14 is sampled HIGH
> after reset), a search is made for a valid user program. If a valid user program is found then the execution control is transferred
> to it. If a valid user program is not found, the auto-baud routine is invoked.
>
> END QUOTE.
>
> Flash Magic will take care of everything else as long as you have UART0 implemented.
>
> Notice this sentence in the above quote:
>
> QUOTE
>
> If P0.14 is sampled low and the watchdog overflow flag is set, the external hardware request to start the ISP command handler is ignored.
>
> END QUOTE
>
> This concerns me greatly... You might not be able to ever get into ISP mode. As I have never used the watchdog, I have no idea how to recover from this. Perhaps JTAG?
>
> Richard
>

Hi,

If you don't trust user and you don't have access to the pin, you should write your own bootloader, which has to do:
- start after reset,
- check own checksum
- check application checksum
- check flag to forced bootloading from application in RAM
- receive HEX accordingly to your protocol and program it
- start application

WBR
Vlad
----- Original Message -----
From: tc_lawabider
To: l...
Sent: Sunday, March 25, 2012 5:01 AM
Subject: [lpc2000] Re: New to LPC2129 (coming from PIC) - Attempting to enter ISP mode from user code

Well, the reason I want to enter via software is because this is for an over-the-air update of existing hardware. Sure, I could pull the pin low - but I don't have it tied to any configurable hardware other than a physical jumper, and I don't trust the end user to use FlashMagic.

Again, the watchdog is just to reboot the device once the update has performed. I understand that it won't trigger the hardware entry into the bootloader, but that is not the intent. It will be set for several minutes, so the box can come back online without having to ask the user to restart it. For testing, I have disabled it - but it will be needed for production.

--- In l..., "rtstofer" wrote:
>
>
>
> --- In l..., "tc_lawabider" wrote:
> >
>
> > I'm a bit lost as to where to go from here. I need to transfer my .hex to program space, but I don't know how to split/send/UU-encode the data, and so on. Any help would be sincerely appreciated.
> >
> > Thank you!
> > -Josh
> >
>
>
> I don't quite follow why you want to get to ISP to load code from within your program. Whatever...
>
> All you need is to have P0.14 at ground potential when the CPU comes out of reset and you will be in ISP mode. Not withstanding what happens if the watchdog has tripped. At your earliest opportunity, get rid of the watchdog until you are certain your code is finalized.
>
> I don't know if repeatedly hitting reset will eventually get you to a state where the wathdog hasn't tripped...
>
> Read section 20 of the User Manual and, in particular, this paragraph:
>
> QUOTE
>
> DESCRIPTION
>
> The flash boot loader code is executed every time the part is powered on or reset. The loader can execute the ISP command
> handler or the user application code. A LOW level after reset at the P0.14 pin is considered as the external hardware request to
> start the ISP command handler. This pin is sampled in software. Asuming that proper signal is present on X1 pin when the rising
> edge on RST pin is generated, it may take up to 3 ms before P0.14 is sampled and the decision on wether to continue with user
> code or ISP handler is made. If P0.14 is sampled low and the watchdog overflow flag is set, the external hardware request to
> start the ISP command handler is ignored. If there is no request for the ISP command handler execution (P0.14 is sampled HIGH
> after reset), a search is made for a valid user program. If a valid user program is found then the execution control is transferred
> to it. If a valid user program is not found, the auto-baud routine is invoked.
>
> END QUOTE.
>
> Flash Magic will take care of everything else as long as you have UART0 implemented.
>
> Notice this sentence in the above quote:
>
> QUOTE
>
> If P0.14 is sampled low and the watchdog overflow flag is set, the external hardware request to start the ISP command handler is ignored.
>
> END QUOTE
>
> This concerns me greatly... You might not be able to ever get into ISP mode. As I have never used the watchdog, I have no idea how to recover from this. Perhaps JTAG?
>
> Richard
>



Hi,

I agree a custom bootloader will indeed be better, because if you use the isp bootloader and the power fails during programming (never trust a user) you might not get back into the isp bootloader.
Your own bootloader is able to detect a broken firmware and wait for a new one.

--
Kevin

--- In l..., "Vladimir Ljaschko" wrote:
>
> Hi,
>
> If you don't trust user and you don't have access to the pin, you should write your own bootloader, which has to do:
> - start after reset,
> - check own checksum
> - check application checksum
> - check flag to forced bootloading from application in RAM
> - receive HEX accordingly to your protocol and program it
> - start application
>
> WBR
> Vlad
> ----- Original Message -----
> From: tc_lawabider
> To: l...
> Sent: Sunday, March 25, 2012 5:01 AM
> Subject: [lpc2000] Re: New to LPC2129 (coming from PIC) - Attempting to enter ISP mode from user code
>
> Well, the reason I want to enter via software is because this is for an over-the-air update of existing hardware. Sure, I could pull the pin low - but I don't have it tied to any configurable hardware other than a physical jumper, and I don't trust the end user to use FlashMagic.
>
> Again, the watchdog is just to reboot the device once the update has performed. I understand that it won't trigger the hardware entry into the bootloader, but that is not the intent. It will be set for several minutes, so the box can come back online without having to ask the user to restart it. For testing, I have disabled it - but it will be needed for production.
>
> --- In l..., "rtstofer" wrote:
> >
> >
> >
> > --- In l..., "tc_lawabider" wrote:
> > >
> >
> > > I'm a bit lost as to where to go from here. I need to transfer my .hex to program space, but I don't know how to split/send/UU-encode the data, and so on. Any help would be sincerely appreciated.
> > >
> > > Thank you!
> > > -Josh
> > >
> >
> >
> > I don't quite follow why you want to get to ISP to load code from within your program. Whatever...
> >
> > All you need is to have P0.14 at ground potential when the CPU comes out of reset and you will be in ISP mode. Not withstanding what happens if the watchdog has tripped. At your earliest opportunity, get rid of the watchdog until you are certain your code is finalized.
> >
> > I don't know if repeatedly hitting reset will eventually get you to a state where the wathdog hasn't tripped...
> >
> > Read section 20 of the User Manual and, in particular, this paragraph:
> >
> > QUOTE
> >
> > DESCRIPTION
> >
> > The flash boot loader code is executed every time the part is powered on or reset. The loader can execute the ISP command
> > handler or the user application code. A LOW level after reset at the P0.14 pin is considered as the external hardware request to
> > start the ISP command handler. This pin is sampled in software. Asuming that proper signal is present on X1 pin when the rising
> > edge on RST pin is generated, it may take up to 3 ms before P0.14 is sampled and the decision on wether to continue with user
> > code or ISP handler is made. If P0.14 is sampled low and the watchdog overflow flag is set, the external hardware request to
> > start the ISP command handler is ignored. If there is no request for the ISP command handler execution (P0.14 is sampled HIGH
> > after reset), a search is made for a valid user program. If a valid user program is found then the execution control is transferred
> > to it. If a valid user program is not found, the auto-baud routine is invoked.
> >
> > END QUOTE.
> >
> > Flash Magic will take care of everything else as long as you have UART0 implemented.
> >
> > Notice this sentence in the above quote:
> >
> > QUOTE
> >
> > If P0.14 is sampled low and the watchdog overflow flag is set, the external hardware request to start the ISP command handler is ignored.
> >
> > END QUOTE
> >
> > This concerns me greatly... You might not be able to ever get into ISP mode. As I have never used the watchdog, I have no idea how to recover from this. Perhaps JTAG?
> >
> > Richard
> >
>
>
>