USB Bootloader for lpc1754 module

Being able to program the lpc1754 without the need of any external hardware was one of my first requests. Not only does this allow any user who is not willing to invest more money than needed to start using this board but this also is a great feature for in circuit programming of devices that are out there in the field.

NXP provided us with an example of a USB bootloader (look for AN10866 on the lpc1754 support page).
Code Red created a version for the LPCXpresso tools using LPCUSB, an open source USB stack for the lpc series microcontrollers.

The lpc1754 USB bootloader is based upon Code Red's work, making programming the lpc1754 target an easy job.
All you need to do is to ty the P1.31 pin to Gnd and plug a USB cable into the board's USB connector. In Windows you'll now see a new storage device called LPC1754. Programming the device is as easy as dragging your own prepared binary onto this storage device and you're done.

The project archive presented here contains both the USB bootloader (usb_bootloader) program and a test program (usb_test). The test program contains a number of tests to test the board, results of the tests can be shown using a terminal program to connect to the virtual COM port that is created by the application.
The tests in this program will test the I2C EEPROM, the micro-SD interface (you need to mount a formatted micro-SD with some files for this to work) and the RTC (to show the availability of the RTC's crystal)

Notes on the USB Bootloader

This boot loader is a slightly modified version of the USB bootloader created by Code Red. Which in turn is based on the original bootloader that was presented in the Application Note "AN10866 LPC1700 secondary USB bootloader" by NXP.

The original Application Note can befound on this page at NXP's site, the version created by Code Red is installed in the Examples/NXP/LPC1000/LPC17xx/ project archive that is installed with the LPCXpresso tools (also downloadable from this page at CodeRed's site).

I made some changes to the code and reverted some fixes that Code Red made to make the bootloader work with the lower (4kB sized) flash blocks. This seems to work well as long as you keep a few basic rules in mind:

  • Always delete an existing image from the device (by deleting the FIRMWARE.BIN file) before writing a new one.
  • Never attempt to write more than one file to the flash
  • Wait for windows to complete the copy operation before removing the USB cable from the device.
  • Always power cycle (or reset) the device in between flash writes, do not copy/delete/copy in one session. This is not supported and may result in incorrect flash programming.

If programming fails, you can always re-program the device. If for some strange reason the USB bootloader gets corrupted, you can always download a new copy of the USB bootloader using the ISP protocol (e.g. using Flashmagic) or using an LPC-Link or another JTAG/SWD debugger pod.

Notes on the test program

Whenever started, the test program will create a virtual COM port on the PC it is connected to. As part of the project the file usbser.inf is delivered - you will need this file to configure windows to detect this COM port.

Use your favorite terminal program to open the port, then press the <enter> key on your keyboard to awake the application. This will show a menu with 3 possible tests:

  • I2C (EEPROM) test
    This test tests the 24LC08 EEPROM by writing/reading a sequence of bytes.
    To prevent multiple write/read sequences this test first checks if the test pattern is already available in the EEPROM - if it is, the test passes.
  • RTC test
    Verify it the RTC is correctly running by setting the time and checking twice in a 5 s interval if the time is still running. There is also a check if the clock stops when power is removed. If the clock keeps running with power removed the backup battery is OK.
  • micro SD test
    Reads the root directory from the micro SD card to show a working SD card interface.

FatFS test

ChaN's FatFS seems to be the better choice when looking for a FAT filesystem. It is still actively being maintained by the author, as of today the latest updates are from November 14, 2011, and there is a lot of information on the author's website ( A FatFS port to the lpc17xx is availble from NXP Semiconductor's website (AN10916 FAT library EFSL and FatFs port on NXP LPC1700).

My board uses the other SSP, all I had to change are the references to the correct I/O pins and the SSP interface.
An easy job (unless you oversee one or two lines of code ...), even replacing the real uart output for the USB virtual one was not that hard.

I was a bit concerned about memory size; it can do more than EFSL and it looks to be a bigger piece of code. A quick comparison shows that this could be true: EFSL uses 12180 bytes of flash whereas FatFS uses 19336. But then, my test application does not use all functions from EFSL and FatFS can be optimized by removing a number of functions.
Using the release configuration drops the flash footprint to 8980 bytes or even 6564 when using FS_MINIMIZE = 3. EFSL uses 5456 so still a bit smaller in case you need to squeeze the last bytes out of your code.

Speed also looks OK, but don't spent too much time looking at the figures calculated by the test application. The logic analyzer shows a throughput of 1 byte per 900 ns so that is a bit more than 1 MByte per second  not bad at all.


These files are project archives created by the LPCXpresso export function.
Store the files on your computer and use the "import archived projects" function to import them into LPCXpresso.