LPC802 boot loader: howto? - Page 1
Forum section: electronics / general

author: MatthiasU
author_rank: Newbie
timestamp: March 03, 2023, 09:58:05 am
content: 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.

author: darkspr1te
author_rank: Frequent Contributor
timestamp: March 06, 2023, 01:09:26 pm
content: will this helphttps://www.yorku.ca/professor/drsmith/wp-content/uploads/sites/444/2019/03/LPC802_UserManual_UM11045.pdfdarkspr1te

author: Chat GPT
author_rank: Contributor
timestamp: March 08, 2023, 10:41:20 am
content: 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.

author: JimmyJimJames
author_rank: Newbie
timestamp: May 25, 2023, 07:27:44 pm
content: 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 theUM11045 document)Table 35. Reinvoke ISPCommand CompareInput Command code: 57 (decimal)Param0(mode): ISP interface selection1 - USART ISPStatus code ERR_ISP_REINVOKE_ISP_CONFIGResult 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:__disable_irq();IAP.cmd = IAP_REINVOKE_ISP;IAP_Call(&IAP.cmd, &IAP.stat); // Make the IAP call to reinvoke ISPBut 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."?

author: JimmyJimJames
author_rank: Newbie
timestamp: May 31, 2023, 08:47:01 pm
content: On the NXP forum, they told me to use the SDK call instead of implementing it myself, so I'm trying this:Code:__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 aJ<CR><LF>in an attempt to read the Part ID, but no luck.

author: nctnico
author_rank: Super Contributor
timestamp: May 31, 2023, 11:36:14 pm
content: "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.

author: JimmyJimJames
author_rank: Newbie
timestamp: June 05, 2023, 03:25:02 pm
content: Quote from: JimmyJimJames on May 31, 2023, 08:47:01 pmTo 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 callingIAP_ReinvokeISP(), and additionally, in the NXP library's fsl_iap.ciap_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, theIAP_ReinvokeISP()function now works, and I can enter ISP mode.

author: cv007
author_rank: Frequent Contributor
timestamp: June 05, 2023, 08:09:04 pm
content: QuoteThe 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.