Author Topic: LPC802 boot loader: howto?  (Read 1132 times)

0 Members and 1 Guest are viewing this topic.

Offline MatthiasUTopic starter

  • Newbie
  • Posts: 1
  • Country: de
LPC802 boot loader: howto?
« on: March 03, 2023, 09:58:05 am »
Hi,

is the boot loader protocol for the LPC802 documented anywhere? Which (Linux) tool can be used?

I don't want to use SWD because in my current project I have a serial connection to the LPC802 anyway, thus I'd like to simply use that to re-flash if necessary.
 

Offline darkspr1te

  • Frequent Contributor
  • **
  • Posts: 290
  • Country: zm
 

Offline Chat GPT

  • Contributor
  • !
  • Posts: 17
  • Country: us
Re: LPC802 boot loader: howto?
« Reply #2 on: March 08, 2023, 10:41:20 am »
Yes, the boot loader protocol for the LPC802 is documented in the "LPC80x Bootloader User Manual" which can be found on NXP's website. The manual provides a detailed description of the boot loader protocol, including the commands and responses that are used to communicate with the boot loader.

To use the serial connection to re-flash the LPC802, you can use the "LPCScrypt" tool provided by NXP. LPCScrypt is a cross-platform command-line tool that can be used to program the flash memory of LPC devices using a serial connection.

To use LPCScrypt to re-flash the LPC802, you will need to:

1. Connect the LPC802 to your computer using a serial connection.
2. Enter the boot loader mode on the LPC802 by holding down the ISP button while resetting the device.
3. Start LPCScrypt and specify the serial port and baud rate used to communicate with the LPC802.
4. Specify the binary file containing the firmware you want to flash to the device.
5. Start the programming process.

LPCScrypt can be downloaded from the NXP website and is available for Linux, Windows, and macOS.
 

Offline JimmyJimJames

  • Newbie
  • Posts: 5
  • Country: us
Re: LPC802 boot loader: howto?
« Reply #3 on: May 25, 2023, 07:27:44 pm »
I'm looking for a similar solution, but without the use of the ISP/RESET pins.

I have an active serial connection to the LPC802 from another board which I want to use to send new software updates to the LPC802, but I do not have access to the ISP/RESET pins on the LPC802.

It appears that I can use IAP commands to put the device into ISP mode using the "Reinvoke ISP" command.  (Section 4.6.8 in the UM11045 document)


Table 35. Reinvoke ISP
Command    Compare
Input           Command code: 57 (decimal)
                   Param0(mode): ISP interface selection
                   1 - USART ISP
Status code  ERR_ISP_REINVOKE_ISP_CONFIG
Result          None.
Description   This command is used to invoke the ISP. If the ISP is invoked, then the CPU clock is switched to FRO.
                   This command is used to invoke the boot loader in ISP mode. It maps boot vectors and configures the peripherals for ISP.
                   This command may be used when a valid user program is present in the internal flash memory and the ISP entry pin are not accessible to force the ISP mode.
                   If using USART ISP mode, enable the clocks to the default before calling this command.

I have a simple glob of code which just does:
Code: [Select]
__disable_irq();
IAP.cmd = IAP_REINVOKE_ISP;
IAP_Call(&IAP.cmd, &IAP.stat);  // Make the IAP call to reinvoke ISP

But it doesn't seem to properly enter ISP mode.
I can make similar IAP calls to successfully read the UID, Boot Code version number and the Part Identification number, so the IAP calls do work.
But, I don't seem to be able to enter ISP mode.

Using a Windows computer, I can use Flash Magic to successfully connect to my device when I press and hold the ISP button, press and release the RESET button and then release the ISP button.  But, when I command the device into ISP mode via a serial message which invokes the code above (and then quickly close PuTTY and start a query from Flash Magic) I cannot connect/synchronize.

Any ideas?  Does it have something to do with the line which says:  "If using USART ISP mode, enable the clocks to the default before calling this command."?
 

Offline JimmyJimJames

  • Newbie
  • Posts: 5
  • Country: us
Re: LPC802 boot loader: howto?
« Reply #4 on: May 31, 2023, 08:47:01 pm »
On the NXP forum, they told me to use the SDK call instead of implementing it myself, so I'm trying this:

Code: [Select]
__disable_irq();
uint8_t isp_type = 1;
uint32_t status;
IAP_ReinvokeISP(isp_type, &status);

But I still can't see to get it to work.

The UM11045 user manual for the LPC802 seems to say to use the isp_type value of 1, but I've also tried a value of 0 and FlashMagic won't connect and do the Read Signature.

Again, if I press and hold ISP, then press and release RESET, then release ISP, FlashMagic will connect and return valid data when I do a Read Signature.

Any ideas?

Do I have a misunderstanding on how ReinvokeISP() works?  When I utilize that function, will FlashMagic not work because it maybe doesn't to the ?, Auto-Baud, OK, Connected handshake?  Does ReinvokeISP() put the system into ISP mode without any of that handshaking process?

I've tried just using a serial terminal and after initiating the call to ReinvokeISP() I sent a J<CR><LF> in an attempt to read the Part ID, but no luck.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26906
  • Country: nl
    • NCT Developments
Re: LPC802 boot loader: howto?
« Reply #5 on: May 31, 2023, 11:36:14 pm »
"If using USART ISP mode, enable the clocks to the default before calling this command."?

This says you need to bring the clocks back to how they are set after a reset. I'd start with trying a simple program that doesn't change any of the clock configuration (so running from the 12MHz internal clock) and go from there.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline JimmyJimJames

  • Newbie
  • Posts: 5
  • Country: us
Re: LPC802 boot loader: howto?
« Reply #6 on: June 05, 2023, 03:25:02 pm »
On the NXP forum, they told me to use the SDK call instead of implementing it myself, so I'm trying this:

Code: [Select]
__disable_irq();
uint8_t isp_type = 1;
uint32_t status;
IAP_ReinvokeISP(isp_type, &status);

But I still can't see to get it to work.


To update this, I sent a sample project to someone at NXP via their support forum and after a few days I received a solution.

I have to NOT call __disable_irq(); in my code before calling IAP_ReinvokeISP(), and additionally, in the NXP library's fsl_iap.c iap_entry() function, you also need to remove the call to __disable_irq();

It spooks me a bit that I have to modify NXP's library to get this to work, but after removing the __disable_irq(); calls, the IAP_ReinvokeISP() function now works, and I can enter ISP mode.

« Last Edit: June 05, 2023, 03:30:12 pm by JimmyJimJames »
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 825
Re: LPC802 boot loader: howto?
« Reply #7 on: June 05, 2023, 08:09:04 pm »
Quote
It spooks me a bit that I have to modify NXP's library to get this to work,
The rom bootloader code probably assumes since the only way (they thought at the time) to get to the bootloader is via a reset, there is no need to make sure primask is clear. They probably use the uart irq to handle uart duties, but with primask set there is no uart irq so cannot communicate.

I think it would be a little unsettling to have an app running, with unknown (but known) irq's firing while the reinvokeISP takes place, which then switches the vector table to its own code. Maybe not a problem and they have that sorted out, but if something else slipped through the cracks then probably not so great that reinvoking isp results in 95% success and you have to wonder why 5% of the time something seems to goes wrong.

Whether a problem or not, an alternative would be to use some signal to your own code (like via ram) that a reinvokeISP is wanted- disable irq's, setup the 'signal', do a software reset, then somewhere in early code before the mcu is configured you check the 'signal' and reinvokeISP if requested (system reset status can also be used to help- ignore 'signal' unless sysrst flag set). The rom bootloader now gets an mcu in a state closer to the reset state it normally gets.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf