Jul 24, 2014


Hello everyone, i have been busy with my college and other projects, but i want to share a complete tutorial for develop firmware on the TIVA launchpad from texas. It has been a while since texas instruments change your arm family name, now with the TIVA series, some problems may occur when you use this tutorial for the old name[STELLARIS] that i did in a few months ago. In this post you will see that some tools are the same as we have been using in the stellaris family, in fact, the lm4f120 microcontroller has almost the same architecture that tm4c123g and you can flash the same code, but when you use some specific peripherals the instantiated libraries can change and this can be a big problem. This tutorial is based on Doragasu tutorial. We will install all the necessary tools and after, configure the ECLIPSE-CDT to develop our codes with one of the best IDEs to the linux. Alright, lets install all the tools in the "~/tools" folder in your linux distribution.

[DISCLAIMER] - This tutorial is based on debian linux distributions.

ARM toolchain
First we need the toolchain for arm and then add the repository to your ppa directories and install the tool, to simplify our lives:
sudo add-apt-repository ppa:terry.guo/gcc-arm-embedded -y
sudo apt-get update -y &>> /dev/null
sudo apt-get install gcc-arm-none-eabi -y

In the place of StellarisWare, we have now the TivaWare library, to download go to TI website and download the TIVAWARE library (SW-TM4C-, after unzip into a folder, lets call “tools” folder in your home directory:
mkdir -p ~/tools/tivaware
sudo apt-get install -y unzip &>> /dev/null
unzip -u ~/Downloads/SW-TM4C- -d ~/tools/tivaware
cd ~/tools/tivaware

Lm4flash is the programmer for arm and other architectures, you can use OpenOCD to program and load to the microcontroller, but lets use this. Install the dependencies:

sudo apt-get install libusb-1.0-0-dev -y
sudo apt-get install libtool libusb-dev -y
Install git control version:
sudo apt-get install git -y
cd ~/tools
git clone https://github.com/utzig/lm4tools.git
cd lm4tools/lm4flash
Add lm4flash programmer to your PATH and udev rules for usb device:
sudo echo "export PATH=$PATH:$HOME/tools/lm4tools/lm4flash" &>> ~/.profile
echo 'ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="00fd", GROUP="users", MODE="0660"' | sudo tee /etc/udev/rules.d/99-stellaris-launchpad.rules
sudo usermod -aG users $USER 

Let's build OpenOCD (Open On-Chip Debugger) with ICDI (in-circuit debug interface) support to debug the Tiva-LaunchPad:
cd ~/tools
git clone http://git.code.sf.net/p/openocd/code openocd
sudo apt-get install autoconf automake texinfo 
sudo apt-get -o Dpkg::Options::="--force-overwrite" install gdb-arm-none-eabi
./configure --enable-maintainer-mode --enable-ti-icdi
sudo make install

Installing Eclipse
First install eclipse with:
sudo apt-get install eclipse-cdt -y
And then, open eclipse:
Configuring the project template:
The first screen that you will see is the workspace:

1 - Select "ok" and create your workspace projects into home folder. After goto menu: File > New > Project and select the C project

2 - Go next and select this Executable > Empty Project and Toolchains: Cross GCC, the name you can select anyone, but lets call "template"

3 - After select, click on next and now click on Advanced Settings... 

4 - Now select C/C++ tab, Build>Settings. Change the Configuration: box to [All Configurations], after write in the Prefix box arm-none-eabi-

Remember to select [All Configurations], in the next configurations boxes. 
5 - Click on Cross GCC Compiler>Symbols, and add the symbols PART_TM4C123GH6PM, TARGET_IS_BLIZZARD_RB1, ARM_MATH_CM4, the apply: 

6 - Go to Cross GCC Compiler>Include, and add the way of tivaware (/home/your_user/tools/tivaware)

7 - Select the Cross GCC Compiler>Miscellaneous, and add in the Other flags tab this flags "-c -fmessage-length=0 -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections": 

8 - Next, click on Cross GCC Linker>Libraries and add this path "/home/your_user/tools/tivaware/driverlib/gcc", in the Libraries add "driver"

9 - Select the Cross GCC Linker>Miscellaneous and add the flags "-Wl,--static,--gc-sections,-T../ldStart.ld -mthumb -mcpu=cortex-m4"

10 - Go to Build Steps, and add the command "arm-none-eabi-objcopy -O binary ${ProjName}.elf ${ProjName}.bin" and if you want, change the description "Generate binary file from elf file"

11 - Go to Build Artifact tab and add the ".elf" to the Artifact Name box, this instance the output from the compiler: 

12 - After this step, click on "Apply","ok" and "Finish"

13 - In the "Cross compiler prefix:" box, type "arm-none-eabi-" and "Finish" again:

Now we need to add some files to conclude our workspace, like the loader script to the target and the vector of interrupts. Just get this files from:

cd ~/workspace/template
wget --no-check-certificate https://github.com/aignaciors/tiva_arm_template/blob/master/template/ldStart.ld && wget --no-check-certificate https://github.com/aignaciors/tiva_arm_template/blob/master/template/startup_gcc.c && wget --no-check-certificate https://github.com/aignaciors/tiva_arm_template/blob/master/template/main.c

These files are copied into your workspace/template, if you create a new template, remember to copy them into the new. Before we continue, click in Refresh in the template project: 

LM4FLASH on eclipse
1 - Now we need to configure the flasher for your ambiance, lets use lm4tools instead OpenOCD, this can be a little easier for a new template. Alright, in eclipse, just click on "Run>External Tools>External Tools Configuration". Now right click on Program tab and "New"

2 - Now, change the Name to lm4flash, location to "/home/your_user/tools/lm4tools/lm4flash/lm4flash" and Working Directory: to "${workspace_loc:/template/Debug}", in the Arguments: add the binary file, "template.bin"

3 - Now click on "Apply" and then in "Close", if you did Al right now we can program the Tiva Launchpad. First, let's compile our code, click on "Build" to compile the blink green example, and after go to the external tools symbol(see picture below), then click on lm4flash, now you need to connect your board to computer. 

If all it's right, your board will flash the green led. 

OpenOCD on eclipse
Okay, maybe you are sweating at this time, i know that's is very extensive tutorial, but i guarantee that when you finish you will be happy to develop to this target platform. One of the basic tools when you work with microcontrollers is the debug tool, the [OpenOCD] is the right tool when you need to this for our target. Let's configure this tool on eclipse to debug our programs.
1 - Go to Run>External tools and right click on Program>New, as you did for lm4flash. Create with name "openocd". In Location paste "/home/your_user/tools/openocd/src/openocd", Working Directory paste "${workspace_loc:/template/Debug}" and in the Arguments, just paste the script that you will use to debug "-f /home/your_user/tools/openocd/tcl/board/ek-tm4c123gxl.cfg" and then apply: 

2 - Go to Help>Install New Software on the Work With tab, add "CDT - http://download.eclipse.org/tools/cdt/releases/helios" and search for C/C++ GDB Hardware Debugging and install the plugin: 

3 - After go to Run>Debug Configurations, right click on GDB Hardware Debugging and select New, then change the name to gdb, then go to C/C++ Application: and paste "Debug/template_tiva.elf". Modify the Project box to "template" then apply the settings: 

4 - Now go to Debugger tab and uncheck the "Use remote target", paste as GDB command "arm-none-eabi-gdb", and remember to select "Standard GDB Hardware Debugging Launcher" then apply>close

5 - Now go to Startup tab and, uncheck "Reset and Delay(seconds)" and "Halt", paste the gdb commands to initialize "target extended-remote :3333 monitor reset halt" on Run Commands box, just paste "monitor reset init" and then apply: 

6 - Then select Launch Group menu, and create a launch with name Debug, after add in this sequence,Program::Openocd and GDB Hardware Debugging::gdb with Add... then apply: 

7 - Now close and go to debug button, then click on "1 Debug" and if no errors appeared, you probably finished configuring all.

If you reached this step without any problems, then congratulations, you have a perfect environment to develop firmware for the ARM platform. Thanks mainly to the blogger Doragasu. We meet in the next tutorial.