TI CC3220 and AWS FreeRTOS

You can check the latest version of tutorial and code in Github

AWS FreeRTOS

AWS FreeRTOS is the IoT operating system for MCUs (microcontrollers) from Amazon. Amazon FreeRTOS extends the FreeRTOS kernel, a popular open source operating system for microcontrollers, with software libraries that make it easy to securely connect your small, low-power devices to AWS cloud services like AWS IoT Core or to more powerful edge devices running AWS IoT Greengrass.

  • AWS FreeRTOS website: [link]
  • AWS FreeRTOS partner devices: [link]
  • AWS FreeRTOS introduction video: [link]
  • FreeRTOS kernel: [link]
  • AWS FreeRTOS getting started guide: [link]
  • Getting Started with the Texas Instruments CC3220SF-LAUNCHXL: [link]

TI CC3220SF Launchpad

TI CC3220SF launchpad’s full name is SimpleLink™ Wi-Fi® CC3220SF wireless microcontroller LaunchPad™ development kit [link]. The hardware architecture is shown here

TI CC3220SF Launchpad Architecture
  • The hardware user guide: [link]
  • TI CC3220SF has one onboard XDS110 JTAG Emulator. You can direct program and debug the board without external debuggers. It provide many advanced JTag debug features, i.e., trace, step-by-step, breakpoint.
  • It supports both 4-wire JTAG and 2-wire SWD
  • Long-range transmission with a highly optimized antenna (200-meter typical in open air with a 6-dBi antenna AP)
  • It can be powered externally, working down to 2.3 V
  • The block diagram is shown below
CC3220 block diagram
  • It has two onboard sensors (BMA222 and TMP006)
  • It has one Sense on Power (SOP) jumper (J13). It has four different modes, based on the state of the sense-on-power (SOP) lines.
    • SOP[2…0] mode ‘100’ is used for programming the serial flash with the application binary and/or the service pack. After flashing, the board should be reset and the mode set to ‘000’ (no jumpers in place) to run/execute the contents of flash
    • SOP[2…0] mode ‘010’ is the flash and execute mode which is similar to the ‘100’ mode except that after flashing, the contents of flash are executed immediately without having to reset or remove all jumpers. This mode is also used when using the CCS to connect to the device for loading and debugging
SOP setting
  • TI CC3220SF launchpad also has two booster pack connectors for external sensor/device connection

TI CC3220SF Launchpad is based on the SimpleLink Wi-Fi CC3220 chip [link] [], which is a single-chip microcontroller (MCU) with built-in Wi-Fi connectivity for the ecosystem. It integrates a high-performance ARM Cortex-M4 MCU and lets customers develop an entire application with one device. The hardware architecture of the CC3220 chip is shown in the following figure

CC3220 Architecture

TI CC3220SF Development Environment

TI CC3220SF supports multiple IDEs. The TI Code Composer Studio (CCS) is the most supported IDE. You can download the CCS from here [link] via the Download Options of CCSTUDIO — Code Composer Studio (CCS) Integrated Development Environment (IDE). The latest version of CCSTUDIO is 10.3. You can download Windows, Linux, or Mac OS version. One alternative is to use the CCS cloud version (CCSTUDIO-CLOUD) instead of the CCS local software IDE. Visit dev.ti.com to access Cloud-based development tools. However, in the current stage, Cloud-based CCS does not support FreeRTOS. If you need to use FreeRTOS (including AWS FreeRTOS), you need to download the CCS locally.

  • When you install the CCS, select custom installation. You also need to select the Processor support. For example, we need to select the “SimpleLink WiFi CC32xx Wireless MCUs”.
Select CC32xx device support
  • When you finished the installation, you can see the main page of the CCS

  • You can click the “Resource Explorer” to access all the examples and docs.
  • Install CC3220SDK: you need to open “Resource Explorer” , and search “CC3220SF” in the search bar.
  • After you opened the CC3220SDK, you can click download and install button

CCS Uniflash is a standalone tool used to program on-chip flash memory on TI MCUs. Install Uniflash from http://www.ti.com/tool/UNIFLASH (Uniflash provides Windows, Linux, and Mac version)

  • Uniflash guide: [link]
  • Uniflash has a GUI, command line, and scripting interface.

 Install the Latest Service Pack via Uniflash

  • On your TI CC3220SF-LAUNCHXL, place the SOP jumper on the middle set of pins (position = 1, 010) and reset the board.
  • Start Uniflash, and from the list of configurations, choose CC3220SF-LAUNCHXL. Or, you can click the “Start Now” button to auto-detect the connected board
  • When your CC3220 board has been detected, you can click the Start button
  • You will see the  Image Creator page
  • Choose New Project
  • On the Start new project page, enter a name for your project. For Device Type, choose CC3220SF. For Device Mode, choose Develop, and then choose Create Project
  • You will see this project papge of UniFlash

  • Click the Connect button, you can connect your CC3220 board and got all the information of this board.
  • You can note down the MAC address for future use.
  • From the left column, choose Service Pack.
  • Choose Browse, and then navigate to where you installed the CC3220SF SimpleLinkSDK. The service pack is located at ti\simplelink_cc32xx_sdk_VERSION\tools\cc32xx_tools\servicepack-cc3x20\sp_VERSION.bin
  • After you selected the service pack, you can Click the burn button
  • Then choose Program Image (Create & Program) to install the service pack.

Download Amazon FreeRTOS

  • Amazon tutorial: [Getting Started with the Texas Instruments CC3220SF-LAUNCHXL]
  • Amazon FreeRTOS supports two IDEs for the TI CC3220SF-LAUNCHXL development kit: Code Composer Studio and IAR Embedded Workbench. In this tutorial, we will use Code Composer Studio.
  • In the previous steps, you already installed Code Composer Studio, SimpleLinkCC3220 SDK, and updated the service pack using Uniflash.
  • To download the Amazon FreeRTOS, you can log in to your amazon AWS account, select AWS IoT, click the software tab in the left side.
  • You can click “Configure download” in Amazon FreeRTOS device software part.
  • Select “Connect to AWS IoT – TI” package (not the greengrass package), and download the Amazon FreeRTOS package
  • You can also click the “Quick connect” button to start the step-by-step AWS configuration process. It will show the major steps
  • You can select your hardware
  • Register the AWS IoT Things (you can do this step in the main menu of the AWS IoT->Manage create a thing)
  • After you created the thing, you can download the certificate for your thing (you must download it now, otherwise you will not get the private key again). This step helps you generate your private key, public key, and certificate (this is the same to create a thing in the main menu). This step also help you created the aws_clientcredential.h and aws_clientcredential_keys.h files. You can eliminate the client credential setup steps in the future.
  • Last step is to follow the tutorial to setup the WiFi

Import Amazon FreeRTOS to TI CCS

In the previous step, you already downloaded the Amazon FreeRTOS package and the Certificates folder.

  • Your certificate folder has the following files

  • Unzip the Amazon FreeRTOS package, you will see this folder
  • Copy the aws_clientcredential.h and aws_clientcredential_keys.h files in your certificate folder into folder “Connect_to_AWS_IoT_-_TI\AmazonFreeRTOS\demos\include”
  • If you do not have the aws_clientcredential.h and aws_clientcredential_keys.h files in your certificate folder, no worry, you can edit the aws_clientcredential.h and aws_clientcredential_keys.h files (in “Connect_to_AWS_IoT_-_TI\AmazonFreeRTOS\demos\include” ) manually.
    • First, open aws_clientcredential.h file
    • Browse to the AWS IoT console
      In the navigation pane, choose Settings
      The AWS IoT endpoint is displayed in Endpoint. It should look like <1234567890123>-ats.iot.<us-east-1>.amazonaws.com
    • In aws_clientcredential.h file, specify values for the following #define constants:clientcredentialMQTT_BROKER_ENDPOINT Your AWS IoT endpoint: a53l6idwvzofq-ats.iot.us-west-2.amazonaws.com; clientcredentialIOT_THING_NAME The AWS IoT thing name of your board: FreeRTOS-TICC3220a
  • In the aws_clientcredential.h, you also need to configure your wifi connection.
    • Specify values for the following #define constants:clientcredentialWIFI_SSID The SSID for your Wi-Fi network
      clientcredentialWIFI_PASSWORD The password for your Wi-Fi network
      clientcredentialWIFI_SECURITY The security type of your Wi-Fi network
  • If you do not have the aws_clientcredential_keys.h files, or this file does not have the certificate and private key inside
    • open <BASE_FOLDER>\tools\certificate_configuration\CertificateConfigurator.html
    • Under Certificate PEM file, choose the <ID>-certificate.pem.crt that you downloaded from the AWS IoT console
    • Under Private Key PEM file, choose the <ID>-private.pem.key that you downloaded from the AWS IoT console
    • Choose Generate and save aws_clientcredential_keys.h, and then save the file in <BASE_FOLDER>\demos\common\include. This overwrites the existing file in the directory

After you have the modified aws_clientcredential.h and aws_clientcredential_keys.h files, you can import the project into CCS.

  • Open CCS->Project->Import CCS project, search the directory of your downloaded Amazon FreeRTOS project
  • It will detect multiple projects, only select the aws_demos project, do not select “copy to workspace”, then click finish, you will see the project in your CCS ide.
  • Click Build the project, you should not see any errors after build
  • We can click the Debug button to download the code and debug the project
  • If you see some errors like missing configuration file (usually happens in MAC or Linux), you can create a new debug configuration file under File-New

  • In the configuration, select XDS110 as the connection, and CC3220SF as the board. You can save the configuration and test the connection until no error.
  • If you see other errors when downloading the code, you can re-connect the board and restart CCS.
  • After you successfully downloaded the code, you show see the following screen (your point stoped at the main function).

You can open terminal (tera term for example) to see the message output of the board.

  • Connect to the second COM port (XDS110 Application/User UART). If you are using MAC or Linux, the COM port name may not clear. You need to try which port is the right one.
  • Setup the speed as 115200
  • To check whether AWS IoT received your message or not, you can use AWS IoT Console test subscription for topics like “iotdemo/topic/1”
  • You can continue run the code in CCS via Resume (F8) button, or perform step-by-step run
  • You will see the following message output in your terminal, this means your wifi connection is success.
  • If you see other errors, double check your previous aws_clientcredential.h and aws_clientcredential_keys.h setup.
  • You will also see MQTT topics in your terminal
  • You will see the data has been received by the AWS IoT subscription

If you are on campus and want to connect the campus wifi, you need to go to SJSU My device protal [link] to setup the device, then you can connect to SJSU_MyDevice (not SJSU_premier). In the portal, you need to put the MAC address of your device (you can get it from the Uniflash after connection). Once the SJSU My device has your device MAC address, your device can connect it.

  • To setup the WiFi, you can change the clientcredentialWIFI_SSID in aws_clientcredential.h to “SJSU_MyDevice”, leave the password empty, and change the clientcredentialWIFI_SECURITY to eWiFiSecurityOpen. You will see your device is successfully connected via SJSU_MyDevice wifi in the terminal.

The MQTT topic name can be changed in the following code.

  • The main process code is inside the RunMqttDemo function

TI AWS IoT Plugin

Recently, TI CCS contains the AWS IoT plugin. You can download the AWS IoT plugin in CCS Resource Explorer

  • You can expand the Simplelink CC32XX SDK AWS IoT Plugin to see the documents and sample code.
  • You can import the first sample code ( subscribe_publish_sample ) from the folder of AWS_INSTALL_DIR\examples\rtos\CC3220SF_LAUNCHXL\aws\subscribe_publish_sample. Or, you can directly import the project from Resource Explore (select, TI-RTOS->CCS)

  • After the project has been imported, open the aws_iot_config.h file, found in the subscribe_publish_sample project, Update the value of the macro “AWS_IOT_MQTT_HOST” with AWS IoT host address, and AWS_IOT_MY_THING_NAME with thing name (in your AWS IoT thing registration).
  • The certificate file variables “AWS_IOT_ROOT_CA_FILENAME”, “AWS_IOT_CERTIFICATE_FILENAME”, and “AWS_IOT_PRIVATE_KEY_FILENAME” can be updated to specify the location to where the files should be written in flash on the device. You can use the default values, if desired.
  • Open the file certs.h, found in the subscribe_publish_sample project, update the CA root certificate string, the client certificate string, and the client (private) key string
    • Each line of the certificate must be updated to end with the character sequence \r\n.
    • Amazon root ca: https://www.amazontrust.com/repository/AmazonRootCA1.pem
  • Configure the WiFi, Open the file wificonfig.h, found in the subscribe_publish_sample project. Search for “USER STEP” and update the Wi-Fi SSID and SECURITY_KEY macros
    • update the security setting to WPA2
#define SECURITY_TYPE SL_WLAN_SEC_TYPE_WPA_WPA2

Leave a Reply

Your email address will not be published. Required fields are marked *