CCS Note 06: Lesson 1. Basic I/O Setting And Application

Hsueh-Ju Wu 吳學儒
TI Code Composer Studio
6 min readJun 30, 2023

Instruction

Configure General Purpose Input/Output (GPIO) pins and their fundamental applications using Code Composer Studio (CCS).

Environment

This document utilizes the following setup:
Operating System: Windows x64
Code Composer Studio Version: 11.2.0.00007
Development Board: LAUNCHXL-F28379D (STM320F28379D)

Tutorial List

Reference Materials

Register Data, System, and Module Details

TMS320F2837xD Dual-Core Delfino Microcontrollers Technical Reference Manual (Rev. I) (ti.com)

Pin Mapping

LAUNCHXL-F28379D Overview User’s Guide (Rev. C) (ti.com)

Module Memory & Flash Architecture

The TMS320F2837xD Architecture: Achieving a New Level of High Performance (ti.com)

Memory Allocation Setting

TMS320C28x Assembly Language Tools v22.6.0.LTS User’s Guide (Rev. Y) (ti.com)

Some Magic Bugs Records

TMS320F2837xD Dual-Core Real-Time MCUs Silicon Errata (Rev. M)

Import Example from C2000Ware

Example: CPU1 — gpio_toggle (CPU1 means single core.)

Project Path: C:\ti\c2000\C2000Ware_4_01_00_00\device_support\f2837xd\examples\cpu1\gpio_toggle

Section 1. Basics Exercise

Implement the high/low voltage output of I/O pins using GPIO through the following two methods.

Methods:

(i) GPIO Set and Clear Register
GpioDataRegs.GPxSET
GpioDataRegs.GPxCLEAR

(ii) GPIO Toggle Register
GpioDataRegs.GPxTOGGLE

Write a program to control the output of GPIO14 so that it displays the pulse waveform with the following requirements.
(a) Frequency = 4.1578kHz, Period = 240.51us (Example settings)
(b) Frequency = 2kHz, Period = 500us
(c) Frequency = 8kHz, Period = 125us

Section 1.1 GPIO Module Setting

GpioToggle.c (Main program)

A. Firmware initialization flow

B. Configure GPIO Module

EALLOW and EDIS macro for write protection.

EALLOW and EDIS are special instructions in TI’s DSPs. EALLOW allows privileged access to specific protected registers, typically critical to system operation. EDIS restricts this access, safeguarding against accidental modifications. The typical sequence is applying EALLOW, accessing or modifying a register, then using EDIS to restore protection.

Section 1.2 Introduction to Registers

From Technical Reference Manual

A. Overview

B. Mux Setting

GPIO x Mux 1 Register (GPxMUX1, GPIOn to n+15)
GPIO x Mux 2 Register (GPxMUX2, GPIOn+15 to n+30)

GPIO x Peripheral Group Mux (GPxGMUX1)

C. Input / Output Direction Setting

GPIO x Direction Register (GPADIR, GPIOn to n+31)

D. Output State Control

Sub Register: GPIO x Data Register (GPxDAT, GPIOn to n+31)

Avoid Using GPADAT to Write Outputs State
Avoid Using GPADAT to Write Outputs State
Avoid Using GPADAT to Write Outputs State

Recommend: Read the output state only.

GPADAT can lead to “read-modify-write” hazards. Using GPADAT, tasks can unintentionally modify bits not targeted initially due to simultaneous GPIO data alterations. To avoid these issues, it’s advised to use set (GPASET) and clear (GPACLEAR) registers, enabling safer operations.

Sub Register: GPIO x Data Set Register (GPxSET, GPIOn to n+31)

Sub Register: GPIO x Data Clear Register (GPxCLEAR, GPIOn to n+31)

Sub Register: GPIO x Data Toggle Register (GPxTOGGLE, GPIOn to n+31)

Section 1.3 Code Composition

The main program is typically written within the void main(void) block after the initialization block in the [main].c file.

Step 1. Program Structure Introduce

The pseudocode for the “GpioToggle.c” (main program) is a didactic tool that mirrors the original code. It facilitates comprehension of the program execution by presenting the flow in a simplified yet correspondingly structured manner.

Step 2. Example Code

The program employs the #if directive in the macro preprocessing phase to control the flow of the program. This directive is part of the C preprocessor’s conditional inclusion feature. It allows for blocks of code to be included or excluded depending on certain conditions, offering a flexible way to customize the compilation of the code. This can be particularly useful for platform-specific code or feature toggles scenarios.

The main function of the program invokes the following subsidiary routines:

The “delay” subroutine is implemented using a for loop, but this implementation is not recommended.

In MCU programming, a delay subroutine is commonly used to introduce a pause or wait period in program execution for synchronization, precise timing, or flow control. However, implementing delays using a for loop is not recommended due to certain limitations. When a delay is implemented using a for loop, the program execution is blocked during the delay, preventing the MCU from performing other tasks or responding to external events. This can result in delays in critical operations. Additionally, for loops, delays may lead to inaccurate timing due to variations in loop execution time, waste computational resources, and increase power consumption. Alternative methods, such as hardware timers, interrupts, or specialized delay functions, should be considered for efficient and accurate delay implementation in MCU programming.

Step 3. At this point, you can burn/flash the program onto the MCU.

Connect the development board and follow the below video.

Button [Green Bugs] for debug mode.
Button [Hammer] for compile program only, not perform.

Section 1.3 Experiment Code

[Hidden] Do it yourself!!

[Hidden] Do it yourself!!

[Hidden] Do it yourself!!

Section 1.5 Experiment Results

The measured results obtained in practice differed slightly from our initial expectations. The main contributing factor to this deviation is the precision concerns associated with the delay function implementation.

(a) Frequency = 4.1578kHz, Period = 240.51us (Example settings)

(b) Frequency = 2kHz, Period = 500us

(c) Frequency = 8kHz, Period = 125us

Section 2. Advanced Exercise

Connect LEDs to pins GPIO0(Pin 40) to GPIO3(Pin 37), and use GPIO4(Pin 36) as an input.

When GPIO4(Pin 36) receives a low voltage (0V), the four LEDs should flash in a back-and-forth manner (like a marquee light), completing a full cycle of flashing in 1 second.

When GPIO4(Pin 36) receives a high voltage (3.3V), the four LEDs should alternate their flashing, with each alternation occurring every 0.5 seconds.

Accomplish this task using the following suggested methods:

Methods:

(i) (I/O Setting) GPIO I/O Setup
GpioCtrlRegs.GPxDIR

(ii) (I/O Setting) GPIO Input Pull-Up Resistor
GpioDataRegs.GPxPUD

(iii) (Write) GPIO Set and Clear Register
GpioDataRegs.GPxSET
GpioDataRegs.GPxCLEAR

(iv) (Write) GPIO Toggle Register
GpioDataRegs.GPxTOGGLE

(v) (Read) GPIO State Register
GpioDataRegs.GPxDAT

GPIO x Pull Up Disable Register (GPxPUD, GPIOn to n+31)

Section 2.1 Experiment Code

[Hidden] Do it yourself!!

[Hidden] Do it yourself!!

[Hidden] Do it yourself!!

Section 2.2 Experimental Results

In the video, it can be seen that by pulling GPIO4(Pin 36) high or low, different LED behaviors can be achieved.

--

--