page:  1   2   3  »    

Part I: LPC2148 USB Bootloader Overview

The USB Bootloader for the LPC2148 is a cool trick that SparkFun created for some of our ARM7 based projects. Because the ARM architecture allows for such large flash space (over 1MB on some chips!) loading code onto the LPC2148 ARM7 over the serial port was painfully slow. Over time, we discovered how to connect the LPC2148 to an SD card for datalogging, and a LPC2148 to USB running the mass storage profile. The bootloader brings all these techniques together to create an easy to use and very fast development system without any need for expensive hardware or software (all free!).
http://www.sparkfun.com/images/tutorials/USB_Bootloader/Pic1_0
MP3 Development Platform

Don't be mistaken, a bootloader is not a new idea; in fact the idea of bootloading, or bootstrapping, has been around since the 1950's. The implementation we use is somewhat different than that used by personal computers, but the idea is generally the same. In this tutorial we will cover what a bootloader is, why it's a good idea, and how to use it. In the last part of the tutorial we'll even get into exactly what the bootloader is doing at the code level. If you're new to the LPC2148, or you've just received a SparkFun product with the USB bootloader, or if you just want to learn a little bit about our LPC2148 USB Bootloader, then this tutorial is for you!

What is a Bootloader?

A bootloader is a small piece of code that runs before the operating system starts running. In our case the bootloader is the code that runs before the device firmware starts up. Typically a bootloader is used because the system memory is too small to contain the entire program, and so the bootloader uses a set of routines to call the program from a different part of memory.

The SparkFun LPC2148 USB bootloader performs three steps:

  • First, 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.
  • The next thing the bootloader does is look for a firmware file. For SparkFun projects, the bootloader looks for 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. Cool!
  • 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.

Why would you use the LPC2148 USB Bootloader?

You certainly don't have to use a bootloader on SparkFun products or any other ARM based project. However the bootloader provides several distinct advantages. First, if you have a board that has been preloaded with the bootloader then you don't even need a programmer to load code onto the board! This is great because most every tinkerer has a spare USB cable lying around, so you don't need any special equipment to start creating your own embedded systems.

Another reason the LPC2148 USB bootloader is great is because it is smokin' fast at loading code! When using a serial programmer to load code onto an ARM, it can take several minutes to get your code up and running(around 45 seconds for a 200kB file at programmed at 38400 baud) This can be a major setback when you're writing very large programs, and you start debugging. If you're only changing one or two lines of code, and it takes several minutes to load your changes onto the board, it's easy to get frustrated. Using the LPC2148 USB bootloader allows you to load code in seconds, literally!

How do you use the Bootloader?

First you have to program the bootloader onto the LPC2148. We use the LPC serial port programmer to load this code once over the serial port. Once the bootloader is on the LPC2148 , using it is simple! Several SparkFun products come with the bootloader already loaded: the UberBoard, the MP3 Development Board, KinetaMap and the Package Tracker are all ARM boards with the bootloader installed before being sent out the door. If you are creating your own ARM project based on the LPC2148 with a USB interface and a FAT16 storage system, then you will have to program the bootloader code on first (we'll go over that in part 3 of this tutorial).

For now lets assume that you have an UberBoard, and you've written some neat code to use the on-board accelerometer. That's great, but how do you get the code from your computer onto the UberBoard? It's easy: plug a USB cable in, turn the power to the board on, and when the USB Mass Storage Device opens on your desktop just drag and drop the FW.SFE file onto the device. When you unplug the USB cable the UberBoard will automatically reset; the bootloader will look for the file named FW.SFE and if the file is found the bootloader will program the new code onto the microprocessor. Presto! You're new code will now be up and (hopefully) running.

That seems easy enough, but how do I get this FW.SFE file? Good question! In order to get the FW.SFE file, first we have to compile the code. In order to compile the code you need a...compiler! At SparkFun we use the WinARM suite and the GNU-GCC compiler. We'll go over how to set this up in a bit. After you set up your compiler, the Makefile has to be created/edited to properly create the FW.SFE file. A makefile is used to tell the compiler how you want your code to be interpreted by the ARM. I say the makefile has to be “created/edited” because generally we don't create makefiles from scratch (in fact, I've never created one from scratch). We take a makefile that's known to be good, and play around with it until it does what we want it to do. Makefiles are usually included in examples that come with WinARM. In a later part of this tutorial we'll cover what needs to be changed in a makefile in order to create the FW.SFE firmware file.

Setting Up Your Programming Environment (WinARM)

If you're new to programming, or even if you have some programming experience but you're new to embedded systems, then you may be wondering how exactly you get the code you need to put onto the bootloader. To do this you'll need what is generally referred to as a programming environment. A programming environment consists of a text editor (for writing the code), a compiler (for creating the “machine” code), and a programmer (for loading the code onto your device). Some environments will come with other tools as well, such as debuggers and microprocessor simulators; you'll learn how to use those later though (and probably from someone else...). There are several programming environments out there; OpenOCD and Keil are two very prominent ones that I know of. However, the only one I've used is called WinARM. It's free, it works great, and it has everything you need. In this section of the tutorial we'll cover the steps you'll need to take to get the WinARM programming environment set up on you computer. Since I use Windows, though, the instructions will only be for Windows; hopefully if you use another operating system you'll be able to draw enough information from these steps to figure it out yourself.

  1. The first thing you need to do is download the WinARM zip file. You'll have to scroll down a little ways until you find the download for the “WinARM 20060606 zip Archive.” Click the link to download the zip file. It's a pretty big file(95 Mb), so don't be surprised if it takes a while to download.
  2. Once you've downloaded the WinARM 20060606 zip file, you need to extract the contents into the C:\ of your PC. That is, once extracted the directory C:\WinARM should exist, and inside this folder should be nine other folders along with a Readme file.
  3. The next part is perhaps the most confusing. You'll need to extend your system-search path. This is an environment variable in windows. Follow these steps to extend your system search path:
1. Right click on “My Computer” and select “Properties.”
2. Click on the “Advanced” tab.
The image “http://www.sparkfun.com/images/tutorials/USB_Bootloader/Pic1_1” cannot be displayed, because it contains errors.
Advanced System Properties Window

3. Click on the “Environment Variables” button near the bottom of the window.In the Environment Variables window, scroll down the System Variables list until you see the Variable named “Path.”
4. Select the “Path” Variable and press the “Edit” button.
The image “http://www.sparkfun.com/images/tutorials/USB_Bootloader/Pic1_2” cannot be displayed, because it contains errors.
Environment Variables Settings Window

5. With the Edit System Variable window open, scroll to the end of the Variable Value text box and paste this string: ";C:\WinARM\utils\bin;C:\WinARM\bin" at the end of the text that is already in the text box. WARNING: Do not delete any of the text that already resides in this text box as these values are used by Windows to run other programs.
http://www.sparkfun.com/images/tutorials/USB_Bootloader/Pic1_3
Editing the Path System Variable

6. Press “OK” to close out all of the System Properties windows that are now open(there should be three).

Once you've completed all of these steps WinARM should be properly installed on your system. You now have the tools available to write and compile code, and using the ARM bootloader you will be able to easily get that code onto your embedded system. In the next section we'll go over some simple code to load onto an UberBoard, and what you need to do to your Makefile in order to create the firmware file needed to load onto the SD card for the bootloader.

Back to Tutorials

 

Comments

6 comments


Log in to post comments.

by
tapenot's rank:
+1
|   September 11, 2008 at 1:45 AM
Comment rating:
0
I've tried this led-on application and it works great. But I've tried a more complicated one, with interrupts enabled. And those interrupts are not serviced. I guess that the IVT (interrupt table) is not redirected to the position 0x10000, where the application code starts.
The question is...how can I use interrupts in the application?
|   September 11, 2008 at 9:11 AM
Download the firmware for the KinetaMap. In the bootup() function of the main code there are a couple of interrupts initialized. This should give you an idea of how to assign the interrupt locations.
by
tapenot's rank:
+1
|   September 22, 2008 at 2:17 AM
Comment rating:
0
I checked up the KinetaMap and I could check it was not an interrupt problem. I'm using the EFSL library and when I run my project from address 0 (without this bootloader), the filesystem works. When using the bootloader and the application starts at address 10000, when we run the initialization of the sd card (send 100 times a reset command),there is no response from the card.I guess that it has to be related to that the filesystem initialization has already been done by the booloader.
GregCapo's rank:
+3.6
|   October 21, 2008 at 6:58 PM
Comment rating:
0
I am trying to work through using the USB bootloader with the logomatic V2. Windows will not recognise it as a USB device. The mini SD has been formatted and the config files are present. I can't find any mention of USB drivers in the literature. Please help.
LVicente's rank:
+1.7
|   June 19, 2009 at 3:43 PM
Comment rating:
0
Anyone knows a way to compile the MP3 source code in Mac OS X using the arm toolchain. The source code has references to -D__WinARM__. After compiling and installing the new firmware, nothing happens in the LCD but you can hear the music. Think that's because the compiling flags are different if you don't use winarm.
blazzing's rank:
+3.5
|   July  2, 2009 at 10:21 PM
Comment rating:
0
This bootloader rocks! Thanks SparkFun!

If anyone's interested in using the bootloader on the imagecraft C compiler for the ARM, I posted a ported version on my blog: blazzing.wordpress.com

Feedback

What's on your mind?

Please include your email address if you'd like us to respond to a specific question.

submit


If you would like to tell us more, you can fill out our form if you need some psycho-suggestive questions. Go to the form.