Back to all threads

CodeBase and LPCXpresso, command line

Post reply

Mark  S
(16 posts)

Posted: 25 Mar 2012, 12:03

While LPCXpresso was created around a graphical IDE, it's possible to set it up with a command line based toolchain. I tested the following on Ubuntu Linux. If you are running Mac OSX or Microsoft Windows you can easily install a virtual machine on your computer, e.g. VirtualBox plus Ubuntu Linux as 'guest OS'.

First a short introduction how embedded software is created in general. Software will be compiled and linked on a computer, the result is a binary file, which can be uploaded/flashed to the target hardware in at least four different ways:
 
a) via the 'LPC-Link' of the LPCXpresso board, the left part is a JTAG/SWD interface 
b) via any other JTAG/SWD interface, must be bought separately and connected
c) via on-chip USB boot loader, requires to solder a connector (plus a few parts)
d) via on-chip UART boot loader, requires to solder a connector (plus a few parts)

The last two are a bit tricky with the LPCXpresso board, because you need to solder connections to specific pins, create a binary file with correct checksum and transfer the file in a specific way to the hardware (using dd, mtools or lpc21isp). Any of these ways can be used. Just for now and to keep things simple, I'll describe the first way in more detail.

The following explains how to create software for the LPCXpresso LPC1343 board from the command line.

Step 1: Install the GCC development environment for ARM. You can follow any tutorial, but if you plan to use the LPC-Link to flash the LPCXpresso board, you also need some tools from Code-Red, which conveniently install the GCC toolchain for you: http://lpcxpresso.code-red-tech.com/LPCXpresso/

Now add the GCC compiler to your path. There are many ways to do this on Linux, I suggest the following from a console window:
sudo ln -s /usr/local/lpcxpresso_4.2.0_224/lpcxpresso /usr/local/lpcxpresso
gedit ~/.bashrc

Add this line to the end of the file:
export PATH=$PATH:/usr/local/lpcxpresso/bin/:/usr/local/lpcxpresso/tools/bin/

Restart the console window and check that the installation was successful. The following command should display the compiler version:
arm-none-eabi-gcc --version

Step 2: Install the MicroBuilder CodeBase for LPC1343. If you already have installed the tools from Code-Red then this is done pretty straight forward with the graphical user interface. Download CodeBase as zip-file from GitHub, open up the LPCXpresso IDE (search for it in the Ubuntu dash), create a new workspace called workspace2, click on "Import projects" in the Quickstart panel and select the downloaded zip-file. https://github.com/microbuilder/LPC1343CodeBase/downloads

Of course you can do this from a command line in your console window, unpack the CodeBase zip-file into a directory in your home folder:
mkdir workspace2
unzip Downloads/microbuilder-LPC1343CodeBase-YOURVERSION.zip -d workspace2

Alternatively use the git repository:
mkdir workspace2; cd workspace2
sudo apt-get install git-core
git clone git://github.com/microbuilder/LPC1343CodeBase.git

Step 3: Build the example software. Type the following commands in your console window: 
cd workspace2/microbuilder-LPC1343CodeBase-YOURVERSION
make

It gives the following error after compiling and linking:

./lpcrc firmware.bin
make: ./lpcrc: Command not found
make: *** [firmware] Error 127

Which can be ignored for now, because we will use the 'firmware.elf' together with the LPC-Link. It will actually build three different binaries, but we are only using one of them.

Step 4: Upload software to your hardware via LPC-Link. Add the following lines to the end of the Makefile:
# Settings for LPCXPresso LPC-Link (experimental)
CRTINIT=dfu-util
CRTINIT_FLAGS=-d 0x471:0xdf55 -c 0 -t 2048 -R -D /usr/local/lpcxpresso/bin/LPCXpressoWIN.enc
CRT=crt_emu_lpc11_13_nxp
CRT_FLAGS=-pLPC1343 -wire=winUSB
flashboot:
$(CRTINIT) $(CRTINIT_FLAGS)
flash:
$(CRT) $(CRT_FLAGS) --flash-load-exec=$(OUTFILE).bin

When you copy/paste this into the Makefile, make sure there is a tab character in front of the lines beginning with $(CRTINIT) and $(CRT), not a space character. It's a problem of this forum software.

Prepare the boot loader. This has to be done ONCE after board is connected to the USB port, the boot loader is stored in RAM. A new USB device is detected as 'Code Red Technologies LPC-Link Probe', after you typed in the following command:
make flashboot

Now flash the binary onto the target hardware. The following command will upload and start execution:
make flash

Step 5: Test software on your hardware. If everything works fine you will see a blinking LED on the LPCXpresso board, which is wired to GPIO port 0 pin 7. The example software will not do this out-of-the-box. What you have to do is simply define CFG_BRD_LPC1343_LPCXPRESSO in file 'projectconfig.h' (don't forget to comment out CFG_BRD_LPC1343_REFDESIGN), then do 'make clean; make; make flash'.

Step 6: Enjoy. Time to write software in your favorite text editor.

Notes: Debugging should be possible as well, it definitely works in the LPCXpresso Code-Red IDE on Linux, but I haven't had time to test command line debugging yet. To reduce the size of the created binary you can disable debug mode all together, in the Makefile change DEBUGBUILD to FALSE and then do a complete rebuild. At the time of writing, the Makefile didn't detect file dependencies properly and you might have to trigger a complete rebuild with "make clean; make". Once the command line tool chain is up and running, you can adjust it for a different target hardware than the LPCXpresso board.

Hope this helps.

Reply

Mark  S
(16 posts)

Posted: 25 Mar 2012, 13:03

Here is how the command line output should look like in step 4, using the LPC-Link:

make flashboot
...
Starting download: [##################################################] finished!
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present
Done!
can't detach: error sending control message: Broken pipe
Resetting USB to switch back to runtime mode

make flash
...
Nt: Loading binary file 'firmware.bin' at location 00000000
Nc: nSRST assert (if available)
Nc: Executing in user flash.
Nc: nSRST assert (if available)
Nc: Executing in user flash.

Reply

Post reply