Setting up TI TivaC Cortex M4 EK-TM4C123GXL

For this guide I followed instructions from https://engineering.purdue.edu/ece477/Archive/2014/Spring/S14-Grp3/tivac.html to be able to flash software on the dev kit and https://scompoprojects.wordpress.com/2012/11/07/debugging-a-program-on-the-stellaris-launchpad-board/ along with http://processors.wiki.ti.com/index.php/Stellaris_Launchpad_with_OpenOCD_and_Linux to set up debugging. You can follow these links and get the exact (and possibly more) information, I just want to have it in one place for me.

To start I got this running on both Ubuntu 14.04 and Debian Wheezy successfully, and you’ll need to install a bunch of packages. You may or may not need them all, I was too lazy to verify.

sudo apt-get install apt-src \
gawk \
git \
gzip \
perl \
autoconf \
m4 \
automake \
libtool \
libncurses5-dev \
libusb-1.0-0-dev \
gettext \
gperf \
dejagnu \
expect \
tcl \
autogen \
guile-2.0 \
flex \
flip \
bison \
tofrodos \
texinfo \
g++ \
gcc-multilib \
mingw32 \
mingw32-binutils \
mingw32-runtime \
libgmp3-dev \
libmpfr-dev \
debhelper \
texlive \
texlive-extra-utils

Next comes the gcc-arm-embedded tool chain, found https://launchpad.net/gcc-arm-embedded. No need to compile from source for this guy, just extract and set the PATH variable to point at the binaries. I use bash but feel free to change the .bashrc to .profile or whatever config you’d like

tar xjf gcc-arm-none-eabi-<version>-linux.tar.bz2
echo 'export PATH=$PATH:/path/to/folder/gcc-arm-none-eabi-<version>/bin' >> ~/.bashrc

A piece of software called lm4flash is used to write software to the microcontroller, it is part of lm4tools and must be compiled from source and, just like above, added to the PATH variable.

git clone https://github.com/utzig/lm4tools.git
cd lm4tools/lm4flash
make
echo 'export PATH=$PATH:/path/to/folder/lm4tools/lm4flash/' >> ~/.bashrc

Now, depending on how $PATH is set up, adding the lm4flash binary may be useless since sudo is needed to write to the USB ports. To make this path available to sudo you can add :/path/to/folder/lm4tools/lm4flash/ to the secure_path in /etc/sudoers by using the visudo command.

The last thing needed to write code for this micro controller is the TivaWare library. Found http://www.ti.com/tool/sw-tm4c, download TivaWare for C Series Software (Complete) and select SW-TM4C-<version>.exe. Yes it says .exe but it’s actually a zip file, I have no idea why. Extract and build with

A piece of software called lm4flash is used to write software to the microcontroller, it is part of lm4tools and must be compiled from source and, just like above, added to the PATH variable.

unzip SW-TM4C-<version>.exe
make

Once everything has built, it’s finally time to flash a program to the micro. First we will build blinky.c. A simple program that flashes the LED on the dev board.

cd /path/to/tivaware/examples/boards/ek-tm4c123gxl/blinky/
arm-none-eabi-gcc blinky.c startup_gcc.c \
-g \
-mthumb \
-mcpu=cortex-m4 \
-mfpu=fpv4-sp-d16 \
-mfloat-abi=hard \
-Os \
-ffunction-sections \
-fdata-sections \
-MD \
-std=c99 \
-Wall \
-pedantic \
-DPART_TM4C123GH6PM \
-c \
-I/path/to/folder/tivaware/ \
-DTARGET_IS_BLIZZARD_RA1

Next we must link the source files

arm-none-eabi-ld -T blinky.ld --entry ResetISR -o a.out startup_gcc.o blinky.o --gc-sections

Create the binary image

arm-none-eabi-objcopy -O binary a.out blinky.bin

And finally flash the binary

sudo lm4flash blinky.bin

If the LED is flashing green at a steady pace, it worked!

Now for debugging. This is done with OpenOCD and the same gcc-arm toolchain that comes with gdb. Go ahead and grab the source for OpenOCD and start building.

git clone http://git.code.sf.net/p/openocd/code openocd
./bootstrap
./configure --enable-maintainer-mode --enable-ti-icdi
make
sudo make install

Start openOCD with

sudo openocd --file /usr/local/share/openocd/scripts/board/ek-lm4f120xl.cfg

OpenOCD must be running at all times to debug, so feel free to screen it or just open another terminal window.

arm-none-eabi-gdb
(gdb) target extended-remote :3333
(gdb) monitor reset halt
(gdb) load
(gdb) monitor reset init

You can now debug your microcontroller with the typical gdb commands.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s