One of the most frustrating things for people new to microcontrollers is starting a new project from scratch. The main reason being that, unlike the Arduino platform, you have to install and configure different drivers and configuration files before you can even start your project. Arduino already includes all these files and settings in its platform, which is why it is so appealing to hobbyists.
The purpose of this project is to introduce the Tiva C Series LaunchPad and the Keil µVision embedded development tool to make the on-board LED blink.
The purpose of this project is to introduce the Tiva C Series LaunchPad and the Keil µVision embedded development tool to make the on-board LED blink.
This article will show you the steps to install
the IDE, create a project and load the code to the LaunchPad board.
TIVA C SERIES LAUNCHPAD AND KEIL µVISION 4
The Tiva C Series LaunchPad is a family of low-cost microcontroller
evaluation boards developed by Texas Instruments. For this project, we will be
using the TM4C LaunchPad (EK-TM4C123GXL). This board features an 80-MHz, 32-bit
ARM Cortex-M4 CPU with floating point, 256 kBytes of 100,000 write-erase cycles
of flash memory, and a wide range of peripherals including motion control PWMs,
1-MSPS ADCs, eight UARTs, four SPIs, four I2Cs, USB, and up to 27 timers. The
board includes two general purpose switches, a reset switch, a power LED, and user
programmable RGB LEDs for user interface.
For more details about the Tiva C Launchpad, you can visit Texas Instruments’ website
Fig 1. Tiva C Series Evaluation Board
µVision v4 is an ARM embedded development platform created
by Keil that provides project management, code editing, compilation, debugging,
and simulation. Even though µVision v5 has recently been released, we’ll be
using v4 because it is more stable, you’ll find more online resources to
support this version and more importantly, it’s the one I know how to use
better.
For more information about Keil µVision 4.0 you can visit Keil’swebsite
Fig 2. Opening image for Keil µVision 4
2. INSTALLING THE SOFTWARE (IDE)
a. First, we need to install Keil µVision v4. Go to https://www.keil.com/demo/eval/armv4.htm.
Enter your contact information and then download the file MDK474.exe to install the IDE. The download file size is
approximately 590MB.
b. Run the MDK-ARM v4 installer, in the next screens accept the
License Agreement, select the installation folder, enter your contact
information and wait until the IDE installs. Next, check the box to “Add
example projects…” and in the last screen, uncheck the “Launch Driver
Installation” box.
c. After installing Keil, we need to install the drivers to be able to interface the
microcontroller with our computer. You will need the LaunchPad board for this
step. First, go to http://www.ti.com/tool/stellaris_icdi_drivers
to download the drivers for the Tiva C LaunchPad. At the bottom of the page you’ll
find a PDF file with instructions on how to install the drivers for different
operating systems. You can also access the PDF using this link
3. CREATING A NEW PROJECT
After Keil and the drivers are installed, we can start our
new project.
a. Open Keil µVision v4. Click on Project >> New µVision
Project and enter a name for the project
b. You’ll be asked to select a target microcontroller. For
our board, select Texas Instruments and the device number TM4C123GH6PM
Fig 3. Selecting a microcontroller for new project
c. Accept copying the Startup project file when prompted
Fig 4. System prompt to install project startup file
d. Your Project window should now show the startup file
under Target1 >> Source Group
Fig 5. Screenshot of Keil with startup file
e. Next, we need to copy the file system_TM4C123.c
to our project folder. This file contains microcontroller specific code to
enable the system clocks. The file can be found in the Keil installation folder.
In my case, I found it in C:\Keil\ARM\Startup\TI\TM4C123\system_TM4C123.c
f. After the file has been copied to your project folder,
right-click on Source Group 1 in the Project window, click on Add existing files to Group ‘Source Group 1’
and select the file system_TM4C123.c
Fig 6. Adding files to Keil project
g. Finally, right-click on Source Group 1 again and click Add New Item to Group ‘Source Group 1’. Then
select C File(.c), enter file name at the bottom and click Add. This will be
your main program file.
f. The IDE should show the startup, system and main file that you created under Source Group 1
Fig 7. Screenshot of Keil after project files were added
4. PROGRAMMING
a. Go to https://github.com/sphanlung/TivaC/blob/master/LedBlink.c
and copy the code to the C file that you created. The link will take you to my Github
repository.
b. Click on Project
and Build Target. This command will
compile your code and report any errors or warnings in the Build Output window.
Fig 8. Screenshot of Keil with command to compile code
c. Click on Project and Options for Target ‘Target 1’. Find
the Utilities tab and under Configure Flash Menu Command, uncheck
the Use Debug Driver box. Then, under
Use Target Driver for Flash Programming
select the Stellaris ICDI driver and
hit OK. This will allow us to program the board through USB.
Fig 9. Configuring drivers to load code into LaunchPad
d. Click on Flash and then Download. This will load the
compiled code to the microcontroller. The Build Output window will report the
status of the process or any errors.
5. BOARD TEST
Perfect my friend keepp the good job!
ReplyDeleteNice thanks for the advice.... I was doing this since yesterday ...but without adding system_TM4C123.c but the header file tm4c123gh6pm.h
ReplyDeleteI was getting error and my .axf file was not getting generated....thanks it worked now...
Do you have other projects on tivac controller?
Please share if can...
Nice article. It helped to solve my problem
ReplyDeleteiv'e been looking around forever for this please continue the good work.
ReplyDeletecant express my appreciation enough.
i downloaded keil 5 and installed all the packages for the board but i can't find any of the startup .s or .c files. can i find them explicitly somewhere?
ReplyDeleteYou don't have to copy the files when using Keil 5. When you create a project and select the microcontroller that you'll be using (i.e. TM4H123GH6PM), the Manage Run Time Environment window will appear. Just click on Device and check the box that says Startup. I'll be posting a video on how to create a project soon.
DeleteThe blink example doesn't work on my lm4f120h5qr board
ReplyDeleteThe lm4f120h5qr is the Stellaris Launchpad which uses a different microcontroller. You'd have to use the header files for that specific device provided by TI or download them through Keil. You'll also have to look at the register addresses in the datasheet since the I/O and control addresses may be different.
Deletethanks man , i almost lost hope , thanks again
ReplyDeleteMe too, Walid Osama. ><
ReplyDeleteWhile uploading the code I am getting an error.
ReplyDeletecould not find device cortex-M in the device chain.
Error: Flash Download failed - Target DLL has been cancelled
how to get rid of this error? Any help is appreciable.
Thank you
Hello, I got solution for the problem, in my PC required drivers were not installed
ReplyDeleteFor that i have followed this link:
http://www.ti.com/tool/stellaris_icdi_drivers
Hi, sorry for the late reply. I'm happy you were able to fix your issue. Good luck.
Deletehi,could you please tell me how I could modify the code to make the LED blink at first at a steady rate then slow down when SW1 is pressed and make the LED faster when SW2 is pressd and then when both switches are pressed the LED turns red
ReplyDeleteYou could write separate functions for each LED. Notice that they both rely on the delay() function. You could write a function with a smaller delay (fast blinking) and a function with larger delay (slower blinking) and choose which one to use based on the button pressed. Even better, you could use the same delay function and choose the length of the delay based on the button being pressed.
ReplyDelete