Pages

Monday, 23 September 2013

Hello World Blinky for ezSBC2 LPC1347 in Assembler

Doing things the hard way sometimes is the best way to learn. I've been meaning to learn some embedded ARM-fu for years, and just never got around to it since AVRs are just so darn easy (or familiar, in my case).

I like using a simple text editor and command-line toolchain but since most ARM vendors have wrapped up all the details of their chip startup in wizards within their huge IDEs, it's a pain to figure out just what's happening and what is required to bootstrap a given chip.

For my experiment, I chose the LPC1347 microcontroller from NXP, on a simple board called the ezSBC2. This chip has a neat built-in ROM that makes the chip virtually unbrickable -- pull a certain pin on power-up and the chip appears as a USB flash drive, and you just paste in a new 'firmware.bin' file with your code, reset and it's reprogrammed. Couldn't be simpler.

However, it took me two full nights' worth of searching online to find any kind of 'Hello World' reset startup code for the LPC134x chips. The best I could find was some for the related LPC1766, which was close enough for me to eventually figure it out. See below for download. I had to modify the startup.S, main.S and linker script to fit the LPC1347 memory map and peripheral registers.

One thing that isn't spelled out anywhere is that the Cortex-M chips are very different from traditional ARM chips in a lot of ways; for instance, the vector table isn't composed of branch instructions -- it's just a list of absolute addresses, like the old 68000 (and at vector 0x0, just like the 68000, is the initial system stack pointer value). They also don't have nearly as many contexts as traditional ARM (IRQ, FIQ, etc.). I'm still reading up on all the differences but it makes bootstrap code for 'standard' ARM totally inapplicable.

As for NXP-specific differences: not mentioned explicitly on ezSBC's website, but buried in the lpc1347 user manual, is the fact that one must put a 32-bit checksum in the first reserved vector 0x1C to validate the code. Otherwise the USB programmer won't accept the firmware.bin file. I've included a quick and dirty C program in the ZIP file below to patch up the binary after linking.

Hello World Blinky in Assembler for ARM Cortex-M3 NXP lpc1347

ezSBC2 ARM board

NXP lpc13xx User Manual

No comments:

Post a Comment