Debugging EK-TM4C123GXL with Visual Studio Code on Linux

If you have TM4C123G LaunchPad Evaluation Kit and you like Visual Studio Code here is how to setup debugging on this board.




This is the tutorial how to do that on clean Ubuntu 16.04 LTS.


ARM GCC Compiler Setup



Download the latest GCC cross compiler for the ARM from here: https://launchpad.net/gcc-arm-embedded/+download

In the time of writing this text, the last one is  gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2

Run this commands in Linux console.
wget https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q3-update/+download/gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2
tar -jxf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2
rm gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2

exportline="export PATH=$HOME/gcc-arm-none-eabi-5_4-2016q3/bin:\$PATH"
echo $exportline >> ~/.profile
source ~/.profile

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 lib32ncurses5


Without i386 architecture you will experience "bash: ~/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gcc: No such file or directory" error, so make sure you install it before you start using arm-none-eabi-gcc.

If you experience this error "arm-none-eabi-gdb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory" it means you are missing lib32ncurses5.


Now you have the compiler for your ARM Cortex M4F  microcontroller on your LunchPad.


OpenOCD Setup


Next step is to download and build OpenOCD (Open On-Chip Debugger) with ICDI (In-Circuit Debug Interface) support to flash and debug the LaunchPad.


sudo apt-get git
git clone git://git.code.sf.net/p/openocd/code openocd
cd openocd/
sudo apt-get install libtool
sudo apt-get install automake
./bootstrap
sudo apt-get install libusb-1.0-0-dev
./configure --prefix=/usr --enable-maintainer-mode --enable-stlink --enable-ti-icdi
make
sudo make install
OpenOCD will work with sudo because it needs privileges to access USB ports. 


sudo openocd -f /usr/share/openocd/scripts/board/ek-tm4c123gxl.cfg

But to make Visual Studio Code work with OpenOCD we need to do more configuration.



sudo cp ~/openocd/contrib/60-openocd.rules /etc/udev/rules.d/sudo udevadm trigger

This commands will allow openOCD to connect with a lot of boards including our LunchPad. 


You can now test it if everything works without sudo. Make sure your board is connected. After testing, kill the openOCD. We will create a setup to autostart from Visual Studio Code. 







Here we are ready to set up the Visual Studio Code. But first, we will download one project for our board. 

Project0 example

Clone this following git repository. Rebuild driver libraries.  Edit Makefile to build a project with debugging symbols.



git clone https://github.com/yuvadm/tiva-c
cd tiva-c/driverlib/
make clean
make
cd tiva-c/boards/ek-tm4c123gxl/project0/
code Makefile


Add the following lines:
#
# The rule to build project with debug support.
#

debug: CFLAGS+=-g -D DEBUG
debug: ${COMPILER}
debug: ${COMPILER}/project0.axf

It should look like as in the image below. 


Now run make with debugging.


make debug

Visual Studio Code setup.


Inside Visual Studio Code select Extensions button (1.) and after that Install C/C++ package (2.)





Once you have installed extension go to Open folder (3.) and inside path where are "project0" and press OK (4.).




After that press debug Icon (5.) then setup icon (6.) and select C++ (GDB/LLDB) (7.)






You will get into the launch.json config file. You need to insert the value from below. Take care to insert your home folder path. 



{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", "type": "cppdbg",
"request": "launch",
"miDebuggerPath": "arm-none-eabi-gdb",
"targetArchitecture": "arm",
"debugServerPath":"openocd",
"debugServerArgs":"-f /usr/share/openocd/scripts/board/ek-tm4c123gxl.cfg",
"filterStderr": true,
"serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware",
"program": "/home/osboxes/tiva-c/boards/ek-tm4c123gxl/project0/gcc/project0.axf",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{ "text" : "target extended-remote :3333"},
{ "text" : "monitor halt"},
{ "text" : "load /home/osboxes/tiva-c/boards/ek-tm4c123gxl/project0/gcc/project0.axf"}
]
}
]
}


After that, you will be able to start debugging.



 If you find this useful you can consider buying me a coffee

Comments

  1. Almost 2 years later... it worked for me!

    Only one problem... when I set a breakpoint anywhere, HW interrupts kept being serviced and that makes debugging really unusable. I'll try to figure out how to fix this

    Thanks for the totorial.

    ReplyDelete

Post a Comment

Popular posts from this blog

AUTOSAR and CRC calculation

Flashing/debugging/running code at external memory in the memory-mapped mode