Getting Started With Tivaware Launchpad - Basics ⚓
About the project
Program a 32-bit Tivaware Board (TM4C123x series) from Texas Instruments using Embedded C from scratch. Contains TM4C123G ARM-cortex MCU.
Project info
Difficulty: Easy
Platforms: Texas Instruments, Arm
Estimated time: 1 hour
License: GNU Lesser General Public License version 3 or later (LGPL3+)
Items used in this project
Story
📌 More such tutorials, and projects on Embedded systems and IoT, follow Akshayan Sinha on Hackster (https://www.hackster.io/akshayansinha)📌
What is Tivaware? 🎒
Texas Instruments, also known as TI, is an embedded design company, who designs, manufactures, and sells embedded systems. These systems include semiconductor, integrated circuits, development boards etc, for industrial, commercial, automotive and personal electronics. Tivaware is an initiative by TI to manufacture a series of MCUs that support a common SDK.
Get PCBs For Your Projects Manufactured
You must check out PCBWAY for ordering PCBs online for cheap!
You get 10 good-quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files onto PCBWAY to get them manufactured with good quality and quick turnaround time. PCBWay now could provide a complete product solution, from design to enclosure production. Check out their online Gerber viewer function. With reward points, you can get free stuff from their gift shop.
Getting Started 🗽
The TivaWare for software development kit (SDK) provides all of the components necessary for engineers to evaluate and develop applications for the Texas Instruments TM4C Arm Cortex - M4F device family. Based on Embedded C language, it allows developers to get started quickly, use already-tested development methods and drivers that take less time to build and create.
In our case, we'll be using a basic microcontroller board TM4C123GXL, which has the same properties as an STM Nucleo Board. TI Boards for this series are termed as 'Launchpad' due to its ability to support other booster drivers and boards that'll give extra support to provide more features.
Hardware Section 🔧
This Tivaware Launchpad (TM4C123GXL) has the below features :
- Tiva TM4C123GH6PMI microcontroller
- Motion control PWM
- USB micro-A and micro-B connector for USB device, host, and on-the-go (OTG) connectivity
- RGB user LED
- Two user switches (application/wake)
- Available I/O brought out to headers on a 0.1-in (2.54-mm) grid
- On-board ICDI
- Switch-selectable power sources: – ICDI – USB device
- Reset switch
- Preloaded RGB quickstart application
Let us check more about the TM4C123GH6PMMCU :
- 80MHz 32-bit ARM Cortex-M4-based microcontrollers CPU
- 256KB Flash, 32KB SRAM, 2KB EEPROM
- Two Controller Area Network (CAN) modules (requires CAN transceivers)
- USB 2.0 Host/Device/OTG + PHY
- Dual 12-bit 2MSPS ADCs, motion control PWMs
- 8 UART, 6 I2C, 4 SPI
This board provides more features than any other Arduino Board. What's special about it, is the 32 bit MCU taking control of the board.
Software Requirements 👨💻
To be able to upload and run codes on the Tiva launchpad, we need to download the IDE and library, then make a couple of configurations. Below are the software to be downloaded -
- Download and Install Code Composer Studio from here.Then click on 'Download Options' > select 'Windows single file (offline)'
- Now, Download the library for TM4Cxx family - SW-TM4Cfrom here.Then click on 'Download Options' > select 'TivaWare for TM4C Series'
- Move the downloaded library file in a separate folder. It can also be kept inside the Code Composer Studio folder after it's installation. Note the location of this file.
- There are other libraries for the particular board. Even though I used EK-TM4C123GXL board in this article. You can use any other board, and hence download the whole library, instead of a particular board series.
Installing Code Composer Studio -
- Run the CCS (Code Composer Studio) setup file.
- Choose the Location to install the CCS. Tip - All the code files are saved in that location.
- Choose 'Custom Installation', since we will only be using TM4C123GXL board, select 'TM4C12x ARM Cortex M4F core-based MCU'
Running CCS forTM4C Library -
- Open CCS and create a new project > select Device - TM4C123GH6PM, connection - Stellaris ICD > Create project with main.c file
- Now, right click on the project > and select properties > go to Build > go to the ARM Compiler section > click on the Include Options > click the icon with green plus sign to add file > browse to the downloaded library file (previously noted location)
- Now, let us use the ARM Linker > go to File Search Path > add the driverlib.lib file here (found atCCS installed location -....TivaWare_C_Series-v.er.siondriverlibccsDebugdriverlib.lib).
- Once we are done, click 'Apply and Close' to continue with the build.
Alright! We can now begin with Write - Build - Upload to the Launchpad !!
❗❗ We can also follow the Documentation for a guidance of the functions used for peripherals of the board. Download the documentation - TivaWare™ Peripheral Driver Library for C Series User's Guide(Rev. E). ❗❗
PORTs - How to use it? 🔌
Ports are the peripheral pins on an embedded system, or SoC to communicate with the external environment. Whenever a port receives a HIGH or LOW signal, it communicates throughout the system.
- A PORT is usually bit-packed, i.e. each port is represented with 8 bit binary number. The number count starts from right to left. So when we mention a pin's address as 0x0E - it means we are pointing at the pins which are O according to below representation -X X X X O O O X
- If we convert 0x0E to binary number, it becomes - 00001110. Here the pins 1, 2, 3 are pointed at to be controlled. Because the pin counting goes reverse - 7 6 5 4 3 2 1 0 (8 pins) And therefore it looks similar to above representation.
- When we mention GPIO_PIN_1, we mean 0x02, in binary - 0000 0010. This turns the pin 1 on port F emit HIGH signal.
- For example, if we have enabled port A, which has 8 pins. And we require the use of only 2 of the pins on that port. To enable those 2 pins according to their arrangement, we can use an 8 bit number to assign it.PortA - X X X X O X O X, which means - 0x0AWe have enabled PIN 1 and PIN 3.
- Above we can see that O represents the pins we require to enable. We can use hexadecimal format to assign. Therefore we shall be using the function asGPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, 0x0A);
- Similarly, if we require to turn ON the LEDs on this port alternatively, we can use the below command -
while(1)
{
GPIOPinWrite(GPIO_PORTA_BASE,0x0A, 0x02);
SysCtlDelay(1333333);
GPIOPinWrite(GPIO_PORTA_BASE,0x0A, 0x08);
SysCtlDelay(1333333);
}
- As you can see above, when the command with value 0x02 is run, only PIN 1 will be giving HIGH signal - 0000 0010
- When the command with value 0x08 is run, only PIN 3 will be giving HIGH signal - 0000 1000
- In both the commands, the other LED will turn off since it has 0 on its pin.
Congratulations! You can now understand other functions that use the ports, directly from the documentation by TI.
First Project - LED Blinking 🚀
We shall be using the inbuilt RGB LED present on the board itself. The LEDs are internally connected to GPIO 1 on Port F.
- We can see from above diagram, the pin we are trying to control has inbuilt RED LED. If you look carefully, the pin name is PF_1. Rest PF_2 and PF_3 are Blue and Green LED respectively.
- Also, we require to set the System Clock Frequency to 40 MHz. Therefore, we'll use the below parameters (in sequence) -- SYSCTL_XTAL_16MHZ - Precise Internal OSC- SYSCTL_USE_OSC - Forwarding the OSC- SYSCTL_USE_PLL - Generates 400 MHz, then divided by 2 = 200 MHz- SYSCTL_SYSDIV_5 - OSC divided by 5 = 40MHz
- Using the SysCtlClockSet() function, we can set the clock configuration required - Final Clock frequency = 40 MHz
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_XTAL_16MHZ | SYSCTL_USE_PLL | SYSCTL_USE_OSC);
- Let us enable the peripheral for the GPIO of the port to be used. We'll be enabling the port F for use.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
- Enable the pin 1 to be used as OUTPUT Pin -
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
- To turn ON the GPIO, use the command -
GPIOPinWrite(GPIO_PORTF_BASE,0x0E, GPIO_PIN_1);
- Using the delay command is simple, use the below formula to calculate the delay in terms of clock cycle -SysCtlDelay(DelayTimeInSeconds*Clk/30));Incase we require 1 sec delay, 1*40000000/30 = 1333333.33loops
- To test the function, use below code -
#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
/**
* main.c
*/
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_XTAL_16MHZ | SYSCTL_USE_PLL | SYSCTL_USE_OSC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
while(1)
{
GPIOPinWrite(GPIO_PORTF_BASE,0x0E, GPIO_PIN_1);
SysCtlDelay(1333333);
GPIOPinWrite(GPIO_PORTF_BASE,0x0E, !(GPIO_PIN_1));
SysCtlDelay(1333333);
}
}
Hurray! 🎉
We have learned anotherMicrocontroller Board - TivaCLaunchpad (32 bit Microcontroller).
Tune in or Head to (https://www.hackster.io/akshayansinha) now, and check out AWESOME CONTENT on Wireless Devices and use IoT in every possible EmbeddedDevice by yourself!!
-----------------x------------------x------------------x-----------------x------------------
School of IoTMake-athon2023 | Theme - DIY your Own GadgetsFor more information - https://www.linkedin.com/in/akshayansinha/
Leave your feedback...