Created by Shaun Gruenig, last modified on Jul 21, 2014
This page discusses how to begin programming and interfacing with Texas Instruments’ TM4C123GXL LaunchPad using Keil’s µVision IDE (Integrated Development Environment) on a Microsoft Windows operating system.
- TM4C123GXL User Guide tm4c123g_user_guide.pdf (1.0 MB) - The user guide for this particular evaluation board.
- TM4C123GH6PM MCU Datasheet - The datasheet for the microcontroller contained on the evaluation board.
- TivaWare Peripheral Driver Library - TI’s guide for programming the various on-chip peripherals using TI’s C libraries.
- Keil’s µVision IDE - A programming environment used for programming various types of microcontrollers. A free, 32KB code-limited evaluation version is available which works for most small projects.
- TivaWare Development Kit - TI’s dev kit for the TivaWare C series, which includes C libraries for various on-chip peripherals and example code that can be used in µVision (as well as other supported IDEs).
- Stellaris ICDI Drivers - drivers for the In-Circuit Debug Interface, which are necessary for µVision to properly communicate with the device.
- TeraTerm - An open-source, free serial terminal emulator which is very useful for sending debugging messages over the 123G’s UART 0 peripheral.
The TI TM4C123GXL LaunchPad is an evaluation/development platform for TI’s TM4C123GH6PM microcontroller, which is part of the ARM Cortex-M4F family of microcontrollers. The LaunchPad provides an easy way to test the capabilities and features of the microcontroller as well as a means to easily program and debug the microcontroller with JTAG through a simple USB connection. This allows for quick prototype development and testing, which is a common use of evaluation boards of this nature.
This board provides access to most, if not all, of the peripherals on the TM4C123GH6PM MCU. This includes GPIO ports, UART ports, SSI ports (which can be used to implement the SPI protocol), I²C buses, PWM modules, timer/counters, and various other peripherals. This article will attempt to show how to get started with the eval board and some of the aforementioned peripherals using µVision and TI’s example projects (which use the C programming language). Additional information and example code (much of which was used in creating this article) can be found at Digi-Key’s product page and Texas instruments’ product page.
A similar wiki article, created by TI, can be found on TI’s wiki (here); this article will try to avoid redundancies between the two articles. The TI article has more in-depth information on the features of the device (which can also be found in the datasheet on TI’s product page). However, as of this writing, many of the lab exercises on TI’s article are missing; this article will attempt to help users get started with the actual programming of and interfacing with the TM4C123GXL. In addition, TI’s examples use TI’s proprietary Code Composer Studio (CCS) IDE to program the device; we will cover programming the TM4C123GXL using Keil’s µVision IDE.
Note: This article uses the terms microcontroller, MCU, and processor interchangeably.
Running an Example Project
Download Necessary Software
First, download and install Keil’s µVision IDE here. For this tutorial we will use the trial version of MDK-ARM v4, since (as of this writing) this is latest stable release of the IDE for use with ARM processors. Registration on Keil’s site is necessary to download the IDE, but is completely free. Then simply run the installer; the default installation settings will work fine for this tutorial. If Windows does not create a shortcut to the IDE for you, it can be found in …\Keil\UV4\UV4.exe.
Next, download TI’s TivaWare development kit. This contains many useful files, including example µVision projects, which provide a good starting point for programming the TM4C123G, as well as many drivers and libraries for the TM4C123G’s peripherals. The software can be found here. For the TM4C123GXL eval board, we will want to download SW-EK-TM4C123GXL-126.96.36.19973.exe. Just like Keil’s site, registration is required to download the software kit, but is completely free. Run this executable and install it into a location of your choice. For this tutorial, we will assume the default directory C:\ti\TivaWare_C_Series… was used.
From TI’s site, we will also want to download the drivers for the In-Circuit Debug Interface (ICDI) that allows us to upload and debug code on the TM4C123GXL. They can be found here.
Finally, download a serial terminal program so that we can easily see the output of the TM4C123G, which can help greatly when debugging. TeraTerm is simple and easy to use, so we will use it for this tutorial. It can be downloaded from SourceForge here. For this tutorial, the standard installation will work fine.
Now that all the necessary software is installed, we can connect our LaunchPad eval board to the computer via the MicroUSB cable that came with the device. Be sure to use the ‘DEBUG’ MicroUSB port on the device, and that the ‘DEVICE/DEBUG’ switch on the board is set to DEBUG. Windows may automatically install the appropriate drivers for the device, which it will likely recognize as a Stellaris ICDI (In-Circuit Debug Interface) device. If Windows does not automatically recognize the device, navigate to the Device Manager (in the Control Panel of Windows) and under “Other Devices”, you should see three new devices which do not yet have drivers. Right click on the first device and choose the update driver option. Then select the option to browse for drivers, and point windows to the folder containing the Stellaris ICDI device drivers we downloaded earlier (you may need to unzip the file they came in). Repeat this process for the other two devices listed under “Other Devices”. For Windows 8 and 8.1 users, you may need to disable “driver signature enforcement” in order to install the drivers. A quick google search should explain how to do this (the process differs slightly depending on which version of Windows 8 you have).
Now open TeraTerm, and under File, choose ‘New Connection’. Select the radio button for serial, and in the dropdown menu, chose the option for Stellaris Virtual Serial Port (the number of the COM port is assigned somewhat arbitrarily by windows, and is inconsequential). For the example code we will be starting with, the UART peripheral is configured for a baud rate of 115,200, with 8 data bits, 1 stop bit, and no parity bits, so we need to make sure that TeraTerm is configured with the same settings to ensure proper communication between the MCU and the serial terminal. In the top menu of TeraTerm, choose ‘Setup->Serial port…’ and ensure that the settings match those shown below (except for the port, which may be different depending on what port number Windows assigned to your device):
Compiling and Downloading an Example Project
At this point, we can open the µVision IDE. In the menu at the top of the screen, chose Project->Open Project… and navigate to the TivaWare software we installed earlier. We will want to go to ti\TivaWare_C_Series-2.1…\examples\boards\ek-tm4c123gxl. Here you will find TI’s various examples for this particular eval board. For now, navigate to the ‘hello’ folder and open ‘hello.uvproj’. This is a simple hello world program which will output “Hello, world!” via the MCU’s UART 0 peripheral (which is connected to the same virtual serial port we have TeraTerm connected to).
To compile the program, click the ‘Rebuild’ button, shown in the picture below (alternatively, you can rebuild the project by choosing ‘Project->Rebuild all target files’ from the top menu). This will recompile all the source files in the project.
If the compilation and linking was successful, the ‘Build Output’ window at the botttom of µVision should show 0 errors. Now the code is compiled, but still needs to be uploaded to the board. To do this, click the ‘download’ button show below (or choose ‘Flash->Download’ from the top menu).
If the download process is successful, the ‘Build Output’ window will show “Erase Done. Programming Done. Verify OK.” Now that the project has been successfully loaded into our microcontroller, press the ‘RESET’ button on the eval board. This causes the program on the board to execute from the beginning, and should result in the string “Hello, world!” being output to the serial terminal (TeraTerm, in the case of this tutorial) and the LED on the eval board blinking.
TI’s example code which we have just loaded onto the board is a great starting point for developing your own programs for the TM4C123GXL. I suggest trying some of the other example projects located in the folder where we found the ‘hello’ project. Analyzing these projects can provide great insight into programming the MCU’s various peripherals using the C libraries furnished by TI. Many of the functions in these libraries simply modify the contents of the various peripherals’ hardware registers, so to get a better understanding of the hardware, you can opt to modify these registers yourself instead of using TI’s functions. A complete list of these registers, and much more information on the peripherals and other features of the microcontroller can be found in the TM4C123GH6PM datasheet.
Here are some examples, made by me, of using the TM4C123GXL and its on-chip peripherals :
- When programming the 123G, always place an infinite loop (such as
;) at the end of the main function. If no infinite loop exists, undefined behavior can occur. This is due (in part) to the fact that the peripherals on the MCU can act independently of the linear execution of the code, and if the main function ends in the middle of peripheral activity, that activity can be interrupted (though there may be other reasons for this undefined behavior). In addition, interrupts will not execute properly if the main function is allowed to end.
- After loading new code onto the board, don’t forget to press the ‘RESET’ button on the board! This prompts the MCU to begin executing the newly loaded code.
- The ‘ConfigureUART()’ function found in TI’s ‘hello’ example project (among others) is very useful (combined with TeraTerm) for outputting simple debugging messages during application development. This function sets up the UART 0 peripheral to work with TI’s ‘uartstdio’ library, which provides access to the ‘UARTprintf()’ function. This functions much like the C standard I/O ‘printf()’ function, and allows you to easily print variables like strings and integers to the serial terminal.
Any questions or comments please go to Digi-Key’s TechForum