Close

2. LPC2148 USB Bootloader

A project log for USB MicroSD card reader

Reads the data from MicroSD card interfaced to LPC2148 and sends via USB.

rutwik-narendra-jainRutwik Narendra Jain 11/26/2018 at 10:030 Comments

The two main references that helped tremendously in implementing USB bootloader were

[1] SparkFun LPC2148 Bootloader Tutorial https://www.sparkfun.com/tutorials/94

[2] AN10711 USB secondary ISP bootloader: Application Note, Rev. 02, 15 July 2008.

While both references assume different FAT size, different programs and code, a combination of files drawn from both sources proved to be fruitful for this project. 

The LPC2148 USB bootloader performs three steps:

1. The bootloader checks to see if a USB cable has been plugged in. If the LPC2148 detects the
presence of a USB cable then it initiates a USB Mass Storage system. This will cause the
target board to appear on any computer platform as a removable flash drive. The user can
then seamlessly transfer files to the flash drive. In the background, the LPC2148 moves the
user’s files onto the SD card using the FAT16 file system.

2. The next thing the bootloader does is look for a firmware file (a file named FW.SFE). This
file contains the desired operating firmware (in a binary file format) for the LPC2148 microprocessor. If the bootloader finds this file on the FAT16 system then it programs the
contents of this file to the flash memory of the LPC2148. In this way, the bootloader acts as
a "programmer" for the LPC2148; and we can upgrade the firmware on the LPC2148 simply
by loading a new file onto the micro SD card.

3. After performing the first two checks, the bootloader calls the main firmware. The main code
should not even know that the bootloader was used and will run normally.

The USB device class used is MSCD (Mass Storage Class Device). The MSCD presents easy
integration with PC’s operating systems. This class allows the embedded system’s flash memory
space be represented as a folder in Windows/Linux, and the user can update the flash with the
binary image using drag and drop (eg, using Windows Explorer).

To make the LPC214x appear like a folder (or disk drive), we need a FAT (File Allocation table).
The LPC2000 on chip Code Flash will appear as one single entity (file name: firmware.bin).
In order to run this program, the WinARM programming environment is used. The version used
is WinARM 20060606. It’s an open source IDE, similar to Keil. Given that it was a text editor,
programmer and compiler before more advanced IDEs like Keil came along, WinARM was later
found to be incompatible with Windows 10 OS. All MakeFiles to generate main.hex were executed
on a laptop running Windows7.

LPC2148 USB Bootloader Source Code (from [1]) contains a whole bunch of source code, including
two subdirectories: LCPUSB and System, along with the startup assembly code (crt.S) and the
linker file (lpc2138.cmd).

A combination of programs/libraries from the USBMem demo of AN10711 and the SparkFun tutorial (drawn from Bertik Sikken), successfully works. Figures below show the LPC
recognized as a Mass Storage device in an Explorer window

firmware.bin in LPC2148 Flash recognized as mass storage device
CRP DISABLD USB Mass Storage

Discussions