I’m giving some consideration to trying to write a USB flash loader program for the LPC-series ARM chips (LPC214x). What I’m thinking about doing is having some sort of handler function that gets called when the user wants to reprogram the chip. This will be triggered when the USB section of the chip receives some special programming sequence from the PC. However, I want this function (and only this function) to run from RAM so that the entire flash of the chip can be programmed.
One of my requirements for this is that it can happen at any time, even when the device has been running for a while. Also, under normal circumstances, the code will be running from flash, which makes it even more interesting to try to load just the handler function into RAM. Any ideas will be much appreciated.
Keep it simple to start with. Use something like xmodem with CRC to download a packet which you convert to binary and put it in RAM where the packet says it should go. Then jump to it. You don’t have to have all of the flash loader program in the first packet, just enough code so it can get the rest if needed. You don’t even need to use xmodem, but it is very simple and there is a lot of documentation on it.
Compile your loader for ram, convert the binary image to an ASCII text file. Base64 is the most popular way to encode binary into ASCII strings because its bandwidth efficient. In this case that is not a major concern so you can just convert every binary byte to two hex ASCII characters corresponding to their upper and lower nibble. That’s also easy to convert back to binary in the target.
BTW, in the bad old days, computers had toggle switches on the front panel to allow keying into ram a few instructions. Those instructions were just enough to read a short paper tape, `loader’ from the teletype machine. At the end of that short tape, enough program was in place to read the real program into memory.
In other words, the loader method hasn’t changed, just the hardware being used to load a few instructions, which load more, etc.
That’s a really good idea to download the loader through USB. That would allow me to not have to worry at all about keeping it on-chip. Thanks, smead - I’d have probably never thought of doing that.
I know there is a DFU (device firmware update) USB class.
Or perhaps you could use serial emulation and do something like SILL does, just copy/pasting the hex file to the serial port.
Or will you use a custom interface? In that case you could use libusb for easy interfacing on the host side (same source code should work both under windows and linux)
Here’s some source code for an existing bootloader over USB for the LPC214x, based on my lpcusb library:
More than likely I’ll be using a custom device with your LPCUSB. I’ll check out this source and see if I can get it working. The question with it is, what do I use on the PC side of things to load the program? Does it work with the Philips Flash Loader or did they write a custom PC application?