TI Tiva LaunchPad TM4C123GXL Tools Setup (Windows and Linux)

Embedded Systems Shape The World Course Notes


Last Updated: September 15, 2018 by Pepe Sandoval



Want to show support?

If you find the information in this page useful and want to show your support, you can make a donation

Use PayPal

This will help me to create more stuff and fix the existent content... or probably your money will be used to buy beer


Setup development tools for TI Tiva LaunchPad on Windows

This notes are to setup Keil and Eclipse to work with the TM4C123GXL launchpad in Windows using Eclipse is completely option you can program and debug only with Keil (which is my recommendation) since that's the fastest way to get started if you plan to use windows

Keil-Eclipse Windows Development Setup

Follow the steps which will import a Keil Project and set up eclipse to use Keil when compiling and debugging.

Eclipse will launch Keil to compile and debug when needed but all the interactions and editing will be done ONLY through Eclipse so you won't need to interact with Keil at all or switch to it during your development.

Compile

  1. Install Keil uVision 4.74 mdk474.exe (590Mb file). Device: TM4C123GH6PM. Check -> Keil Install Slides
  2. Install Eclipse CDT (C/C++ Developers Tools) Indigo

Keil Windows Setup

  1. Create a Keil project

    1. Open Keil, go to the menu Project and select New µVision Project

    2. Select the folder to store all the projects files and give a name to the .uvproj file (Creating a folder for this with the same name of the project is recommend)

    3. Select the target device (Stellaris Launchpad uses: TM4C123GH6PM)

    4. Click Yes when asked to add the .s startup files

    5. Right click of the 'Source Group 1' and select Add existing files to group 'Source Group 1'...

    6. Locate and Add the system device file usually called startup_<device>.c (for Stellaris its called system_TM4C123.c and it is in the C:\Keil\ARM\Startup\TI\TM4C123 directory)

    7. Right click on the 'Source Group 1' and select Add new item to group 'Source Group 1'... ; select C File (.c), name it main.c in the Name field and click the Add button.

      Creating a file with this method might not add it automatically so use Add existing files to group 'Source Group 1'... option in that case

    8. Add a main function to the main.c file and save it:

      int main(void){
      while(1){}
      }
    9. Now the code is ready to be compiled and downloaded to the target (In the menu Flash -> Configure Flash Tool... check the Debug tab)

      It's recommended to rename the Target 1 and Source Group 1 folders

  2. In the Keil project location create a file named build.cmd with the following content:

    c:\keil\uv4\uv4.exe -b ProjectName.uvproj -o errors.txt
     type errors.txt

    Make sure to change the ProjectName to the name of your project

Create Projects in Keil

Create New Project in Keil

  1. Open Keil and click on Project -> New uVision Project...

  2. Create a folder with the project name and save the .uvproj file there

  3. Select CPU -> TM4C123GH6PM and select Yes when asked whether to add Startup file

  4. In the Manage Project Items (Project -> Manage -> Components, Environments, Books...) In the Project Targets Column Rename from Target 1 to the name of your project

  5. Create a new file File -> New... and save it to the folder of the project (Use File -> Save As...) usually main.c

  6. Add code and add it your project with Right-click over Sources Group 1 and select Add Existing Files to Group Sources Group 1

    • Optionally change name of Sources Group 1 to whatever you want, usually Source
    #define GPIO_PORTF_DATA_R       (*((volatile unsigned long *) 0x400253FC))
    #define GPIO_PORTF_DIR_R        (*((volatile unsigned long *) 0x40025400))
    #define GPIO_PORTF_AFSEL_R      (*((volatile unsigned long *) 0x40025420))
    #define GPIO_PORTF_PUR_R        (*((volatile unsigned long *) 0x40025510))
    #define GPIO_PORTF_DEN_R        (*((volatile unsigned long *) 0x4002551C))
    #define GPIO_PORTF_LOCK_R       (*((volatile unsigned long *) 0x40025520))
    #define GPIO_PORTF_CR_R         (*((volatile unsigned long *) 0x40025524))
    #define GPIO_PORTF_AMSEL_R      (*((volatile unsigned long *) 0x40025528))
    #define GPIO_PORTF_PCTL_R       (*((volatile unsigned long *) 0x4002552C))
    #define SYSCTL_RCGC2_R          (*((volatile unsigned long *) 0x400FE108))

    unsigned long SW1,SW2;  // input from PF4,PF0
    unsigned long Out;      // outputs to PF3,PF2,PF1 (multicolor LED)

    //   Function Prototypes
    void PortF_Init(void);
    void Delay(void);

    int main(void){
        PortF_Init();  // make PF1 out (PF1 built-in LED)

        while(1){
            SW1 = GPIO_PORTF_DATA_R&0x10;       // read PF4 into SW1
            SW2 = GPIO_PORTF_DATA_R&0x01;       // read PF0 into SW2

            if (SW1 == 0 && SW2 == 0)           // both pressed
            {
                GPIO_PORTF_DATA_R = 0x04;       // LED is blue
            } else if (SW1 == 0 && SW2 != 0)    // just SW1 pressed
            {
                GPIO_PORTF_DATA_R = 0x02;       // LED is red
            } else if (SW1 != 0 && SW2 == 0)    // just SW2 pressed
            {
                GPIO_PORTF_DATA_R = 0x08;       // LED is green
            }else                               // neither switch
            {
                GPIO_PORTF_DATA_R = 0x00;       // LED is off
            }
        }
    }

    void PortF_Init(void){
        volatile unsigned long delay;
        SYSCTL_RCGC2_R |= 0x00000020;     // 1) F clock
        delay = SYSCTL_RCGC2_R;           // delay
        GPIO_PORTF_LOCK_R = 0x4C4F434B;   // 2) unlock PortF PF0
        GPIO_PORTF_CR_R = 0x1F;           // allow changes to PF4-0
        GPIO_PORTF_AMSEL_R = 0x00;        // 3) disable analog function
        GPIO_PORTF_PCTL_R = 0x00000000;   // 4) GPIO clear bit PCTL
        GPIO_PORTF_DIR_R = 0x0E;          // 5) PF4,PF0 input, PF3,PF2,PF1 output
        GPIO_PORTF_AFSEL_R = 0x00;        // 6) no alternate function
        GPIO_PORTF_PUR_R = 0x11;          // enable pullup resistors on PF4,PF0
        GPIO_PORTF_DEN_R = 0x1F;          // 7) enable digital pins PF4-PF0
    }

    void Delay(void){
        unsigned long volatile time;
        time = 145448;  // 0.1sec
        while(time){
            time--;
        }
    }
  1. In the Target Options (Project -> Options For Target) in the Target tab change Floating Point Hardware Field to Not Used
    • Optionally on the C/C++ Tab you can include paths if needed
  1. In the Target Options (Project -> Options For Target) in the Target tab change make sure Stellaris ICDI is selected in the Use Field
    • Need to add -dLaunchPad in the Dialog DLL -> Parameter in case you want to use simulator
  1. If you want to run code before reaching main you can define a void SystemInit(void)` function and will be called before the main

From Existing project

  1. Manually Copy the folder of a project
  2. Rename the Folder, .uvproj and .uvopt files
  3. Open the project (double clik on .uvproj) and clean it (Project -> Clean Target)
  4. On the Target Options (Project -> Options For Target) in the Output tab change the name of the executable in the Name of Executable Field
  5. On the Manage Project Items (Project -> Manage -> Components, Environments, Books...) In the Project Targets Column Rename to new name
  6. Modify existing file and rename by doing a Save As.. (File -> Save As...)
  7. Remove Original Files from source Right-click on file and Remove... and add previously created file (Right-click over Sources and select Add Existing Files to Group Source)
  8. Manually Remove Old Files

Eclipse Windows Setup

  1. Install Keil plugin (MDK-ARM Plug-in)
    1. In Eclipse go to menu: Help -> Install New Software... and click in the Add... button
    2. In Name field write: Keil MDK-ARM
    3. use Archive... button to browse to the plug-in location C:\Keil\Eclipse
    4. Disable Contact all update sites during install to find required software option before clicking the Next-> button
  1. Import your Keil project
    1. Go to menu: File -> Import select Existing code as Makefile project under the C/C++ category.
    2. Browse to the project location (directory where the .uvproj file is stored)
    3. Select C** and **ARM Tool Chain. Click Finish
  1. Set up the build command
    1. Right-click on the project and select Properties
    2. In the C/C++ Build uncheck the Use default built command option.
    3. In the Build command: field give the path to the file created in step 4, in this case just write build.cmd because the file is in the project directory (if you have been following this tutorial)

You can now build your project but the errors might not be correctly or in a nice way to configure that you can optionally define a custom error parser

Set up Custom Error Parser on Eclipse

  1. Go to Menu Window -> Preferences and select C/C++ -> Build -> Settings.
  2. Click the Add... button and give a name to your custom Error Parser
  3. Select the newly created error parser and in the Error Parser Options section click the Add... button and insert three items with the following data in the Severity and Pattern fields.
Severity Pattern
Error Error: (.*)\((\d+)\):\s+error:\s+(.*)
Warning Warning: (.*)\((\d+)\):\s+warning:\s+(.*)
Info Info: (.*)\((\d+)\):\s+info(.*)
  • Make sure the newly created Error Parser is enabled in your project properties go to Properties -> C/C++ Build -> Settings -> Error Parsers tab to check.

Debug Eclipse-Keil

Once you have successfully imported a Keil Project It can be debugged right away from Eclipse if the Keil Plug-In was installed successfully so you just have to right click over the project and select Debug As... -> µVision Project

To Change between the on board simulator and the actual on board debugger follow these steps:

  1. In the Debug configurations of the project (Right-click on project and select Debug As... -> Debug Configurations...)
  2. Select the the µVision Project -> Project Name.uvproj
  3. Click the Target Options... button which launches the Keil debugger target options
  4. In the Debug tab we can select to use the Simulator or a Debugging Interface (E.x. J-Link, PE Micro, Stellaris ICDI, etc.)

Other Notes

  • To add C99 support right click on the Target folder or Project folder and select Options for 'Target Name'... -> then in the C/C++ tab in the Misc. Controls field add --c99

Setup development tools for TI Tiva LaunchPad using Linux Ubuntu 14.04 LTS

This one time setup will allow you to build/compile, load and debug code on the Stellaris Launchpad on Linux

  1. Install dependencies

     sudo dpkg --add-architecture i386
     sudo apt-get update
     sudo apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev autoconf texinfo build-essential libftdi-dev python-yaml zlib1g-dev libtool
     sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
     sudo apt-get install libusb-1.0-0 libusb-1.0-0-dev
  1. Install the gcc-arm-none-eabi
    1. Get the gcc-arm-none-eabi tar for Linux
    2. Create dir for it and untar it
      • mkdir ~/embedded
      • tar -xvf ~/Downloads/gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2 -C ~/embedded
    3. Add to path
      • export PATH=$PATH:$HOME/embedded/gcc-arm-none-eabi-5_2-2015q4/bin
  1. Install and build TivaWare for Tiva C Series
    1. Get the .exe from TI’s Tiva C Series Software section. I got the SW-EK-TM4C123GXL-2.1.2.111.exe
    2. Create dir. and unzip content
      • mkdir ~/embedded/tivaware
      • mv ~/Downloads/SW-EK-TM4C123GXL-2.1.2.111.exe ~/embedded/tivaware/.
      • unzip ~/embedded/tivaware/SW-EK-TM4C123GXL-2.1.2.111.exe -d ~/embedded/tivaware/.
    3. Build TivaWare
      • (cd ~/embedded/tivaware/; make)
  1. Get lm4flash and build it. This is used to load binaries into our board

    1. (cd ~/embedded; git clone https://github.com/utzig/lm4tools.git)
    2. (cd ~/embedded/lm4tools/lm4flash/; make)

      Optionally you can add an alias on your .bashrc file to flash bins using only the command lm4flash. Add: alias lm4flash='sudo ~/embedded/lm4tools/lm4flash/lm4flash'

  1. Get OpenOCD, build and install it

     cd ~/embedded
     git clone http://git.code.sf.net/p/openocd/code openocd
     cd openocd
     ./bootstrap
     ./configure --enable-maintainer-mode --enable-ti-icdi --prefix=`pwd`/.
     make -j3
     sudo make install

    This should install OpenOCD in /usr/local/

Create, Build and Load

  1. Create a copy of one of the projects inside TivaWare and rename it to a more appropriate name (give it your project name)
    • cp -r ~/embedded/tivaware/examples/boards/ek-tm4c123gxl/blinky <path_to_project>
  2. Modify <path_to_project>/Makefile accordingly, usually you just need to modify the paths to TivaWare
  3. Use make to build the project
  4. Load the .bin file under the <path_to_project>/<compiler> folder using lm4flash
    • sudo ~/embedded/lm4tools/lm4flash/lm4flash <path_to_project>/<compiler>/<bin_name>.bin
    • Example: sudo ~/embedded/lm4tools/lm4flash/lm4flash ~/embedded/test/gcc/main.bin

Debug using gdb

  1. Build your project as you did on the Create, Build and Load section to get the .bin and .out files

  2. Open a new terminal and start OpenOCD with the right .cfg file

    • sudo openocd --file ~/embedded/openocd/tcl/board/ek-tm4c123gxl.cfg
  3. Open a new terminal and execute gdb and give the .out as input

    • arm-none-eabi-gdb -ex 'target remote localhost:3333;' <path_to_project>/build/<bin_name>.out
    • Example: arm-none-eabi-gdb -ex 'target remote localhost:3333;' ~/embedded/tiva-template/build/a.out
  1. Once gdb has started execute the following commands

     (gdb) monitor reset halt
     (gdb) load
     (gdb) monitor reset init
  2. After this you can execute regular gdb commands to debug. To test this execute the continue gdb command to run the program

You can use ctrl+c on the terminal where you executed the continue command to stop executing the program on the board and then use quit to exit gdb if prompt for active debug session hit yes (y)

Using a gdb commands file

Alternatively you can create a .in file with the previous gdb commands so you don't have type them every time

  1. Create a file in your project folder with the following contents (Using vim for example vim gdb_comms.in)
    # Specify remote target
    target extended-remote :3333

    # Reset to known state
    monitor reset halt
    load
    monitor reset init

    # Set a breakpoint at main().
    break main

    # Run to the breakpoint.
    continue
  1. OpenOCD must be running as we did on the Debug using gdb section

  2. Execute arm-none-eabi-gdb, use the --command and give the .in file that has the gdb commands

    • arm-none-eabi-gdb --command=<path_to_project>/gdb_comms.in <path_to_project>/build/<bin_name>.out
    • For example: arm-none-eabi-gdb --command=./gdb_comms.in build/a.out

References

Here are the links I used to put up this Note, basically I copied everything from other people 😜

Extras

  • sleep 7
  • xterm -hold -e 'sudo openocd --file ~/embedded/openocd/tcl/board/ek-tm4c123gxl.cfg' &
Want to show support?

If you find the information in this page useful and want to show your support, you can make a donation

Use PayPal

This will help me to create more stuff and fix the existent content... or probably your money will be used to buy beer