NOTE: You can download the empty project
Session 1¶
Step 1: Booting the virtual machine or setting up environment¶
For this lab work you You can use your own computer or use any of the University workstations. We strongly recommend using the university workstations. In any case at this stage only one member of the team need to do the setup.
If you want to use your computer¶
In this case you have also two options:
- Option 1 Install Virtual Box and Virtual Box Extension Pack . The extension Pack can be installed using the following instructions. After that follow the same instructions as for the users utilizing university workstations (see below)
- Option 2 Set up CCSStudio IDE:
This is the longer path. You will need to follow instructions in Lovelace for setting up CCS Studio IDE (that actually you should have already followed at home)
If you are using the university workstation¶
- Download the virtual image (.ova file). Can be found in Lovelace section Virtual Machine and history
- In Virtual Box select
File -> Import appliance
and select the previous .ova file. In the next screen select the folder where you want to deploy the image,and press import. - After a while you can see an image like this one. Select the corresponding virtual image and press start at the top right.

This will start your virtual image, and get you ready for the next step.
Step 2: Intro to CCSStudio IDE¶
Starting the IDE¶
- Start Code Compose Studio in your machine.
- You can create a new working space if you want, although you can use the default one (located at
/home/linuxlite/workspace_v10
If you are using a virtual machine). If you create a new Workspace, please do it inside your home space(/home/linuxlite/
in the virtual machine) otherwise, you might have permissions problems. - You can explore the files in your workspace using the OS File Manager, but we recommend always to import files using the IDE.

- Explore quickly the interface on your own. Have a look to all Menus. Get familar to the different tools.
- Have a look to the different perspectives of CCS Studio. You can open a new perspective by clicking in the
Open Perspective button
at the top-right (see image below). Open at least the CCS Debut, CCS Simple and Git perspective. You still do not have to do anything. Just explore the UI.

Move to CCS Edit perspective. Now you are ready to create a new project but before that, let's check that the versions of libraries used are adequate.
Checking libraries versions¶
Sometimes course staff might ask which is the TI-RTOS library version that you are using or which version of XDCtools (a set of tools utilized to compile, link and optimize the code for the TI microcontrollers. You can check the version in
Window->Preferences->Code Composer Studio -> Products
Current version of TI-RTOS should be 2.21.1.08 and version of the XDC Tools should be 3.62.1.15_core.
If you need to install a new version of the software at some point in the future, you should do it through this window.
Importing an empty project¶
- There are a lot of configuration files that you would need to take into consideration when creating a new file with CCS Studio (depending on the device you are using). Generally, CCSStudio offers different wizards to create new project depending on your microcontroller. However, the microcontroller that we use in the course is not offering good support for the board anymore, so we will import an empty project.
- Download the .zip containing the empty project and extract it in a folder under your home folder.
- From the Menu
Project
selectImport CCS Projects
. Add the place where you extracted the empty space. Mark also the optionCopy projects into workspace
. We want to have the project in our workspace. - Important note: If you are using the virtual machine provided by the course, you are going to see an error message
A Project with the same name already exists
. You need to first remove the existing project from your workspace. Go toProject Explorer
(open it fromView -> File Explorer
, select the project, pressDelete
and mark theRemove files from disk
box.

- Import the project.
- Open the
Project Explorer
and open theempty.c
. Check that this project hasmain
function. It is important to know that a single project can have only one main in the whole project. We will see how you can bring multiple files withmain
to your project while you are debugging. - Check also two important files:
Board.h
which contains the constants that are used to make TI-RTOS reusable through different families of boards. Observe that it contains aliases for different pins and registers in your board. Open also theCC2650STK.h
and the {{{CC2650STK.c). The first file includes the pin names for the SensorTag. The second one is in charge of importing all necessary drivers and configuring default settings for different Outputs, Communications and peripherals, such as the UART. Please, do not modify any of those files. - Let's get back to the file
empty.c
. Observe the#includes
. If you want to create a new file from scratch you would need to include at least the same includes (necessary drivers and header files). - At this stage, you do not need to understand the code yet (we will cover that in Session 2). At this stage, it is it enough to know that the provided code will The code in
empty.c
will turn SensorTag LED on / off alternatively every second.
Compiling and uploading the code to the sensor tag¶
Now that the code is ready, you need to compile it, and hence create the
.out
file (binary), that will be uploaded to the SensorTag. Compiling is done either through the Project -> Build Project
or pressing the icon with the hammer at the top. 
- Compile the code.
- You should observe the output in two windows: the
Console
, and theProblems
. The console will provide a detaile information of the process, including warning and compiling errors. TheProblems
shows you which are the problems and warnings that you should take care of in an ordered way. The way you should procceed: - Try to solve first the warnings and make them dissappear (unless it is something not produced by your code)
- Start by the errors in which the Resource is your file (e.g
empty.c
). Start solving those errors from bottom to up. Many times the errors are chained, and solving one problem will remove rest of the errors.

- In this case the code should not report any errors and you can continue.
- Now, let's upload the code to the SensorTag. Code can be uploaded by pressing the
Flash
button next to theCompile
button. Do the uploading.

- If you forgot to connect the SensorTag, or your computer cannot recognize the sensor tag: you will receive a message like this:

- Sometimes you need to update the software of the XDS110 (the debugger board that is included with the sensor tag). The program will guide you in the process.
- Now connect the SensorTag to the computer, and press the
Flash button
. At the end of the process you should see a success message. You should see that the green LED of the sensor tag is blinking. Check that the LED that is blinking is the LED of the SensorTag not the LEds of the XDS110. - Important NOTE if you are using the virtual machine: Be sure that you connect the SensorTag also in the Virtual Machine. To do that, got to the VirtualBox menu and select
Devices -> USB
and tick on theTexas Instruments XDS110
- Important NOTE: Sometimes the Flash button is not working. Use the
Debug
option then.
More about compilingDefine which files to include in the compilation.¶
Imagine that you want to test two different applications in your SensorTag (or two different versions of the same application, each one in a different file. In that case, you cannot have a
main
function in each file, and hence you will have a compilation error. Let's see an example and how we can correct it.- Download HelloWorld.c
- Add it to the project:
Project -> Add Files
- Try to compile it. Atter linking you will see an error:
error #10056: symbol "main" redefined: first defined in "./empty.obj"; redefined in "./helloWorld.obj"
This basically means that you have two
main
in your app. - Let's not compile the old
empty.c
file, and just usehelloWorld.c
. For that, click with the right button in theempty.c
and selectExclude from Build
. Now compile again the project. You should be able to compile thehelloworld.c
. If you check the code it just prints on the screen - Flash the project in the Sensor Tag. In this case, you should see in the Console something like:
[Cortex_M3_0] Hello World
Please, note that the Console window is actually 4 different windows. You can change between the compilation console and the debugging console (the one from which you will see the
System_printf
using the Display Selected Console
button at the top of the Console.
Correcting errors¶
- Download the task_example.c file add it to your project, and ensure that other files you have edited before are not going to be built.
- First include all necessary libraries. Take
empty.c
as reference. - Run the program and correct the different errors. You must use the
Console
and theProblems
window to identify the errors. The yellow arrows at the top of the console help you to move among errors. In addition, you can use theSave Build to Log File
button to explore the whole log in a text editor. In addition, from theProblems
Window, making double click in a line, you will be redirected to the piece of code that causes the problem

- Be sure that you are able to run your program in the device, otherwise, ask help from the staff
Check memory¶
Sometimes your code crashes or cannot be upload to the board due to memory issues. You can always check the Memory occupied by your code itself (Flash memory) and part of the the memory used for execution in (SRAM) (including the Stack). You can see the Memory Allocation from your project (once it has been compiled) from
View -> Memory allocation
. You can see also the usage of Stack from View->Stack usage
Compile vs Clean¶
Another important point. The compile option tries to compile only the files that have been changed from the previous compile. However, when you have multiple files this might be a problem. If you want to compile your whole project again. You must use
Project -> Clean
. Many times this solve many compilation problems so try to use it when working in your own project. Debugging¶
Sometimes you want to know what is the value of different variables at certain point during execution, or how the different functions are called (e.g. when a function is executed, in which order different functions are executed ...). For that, we should use a debugger similar to the one explained in the course material for desktop c programs.
- Change the perspective to CCS Debug. Remember that, for changing perspective, you would need to use the button at the top right corner:

Setting Breakpoints¶
First thing we need to do is define which are the lines of the code that we want to explore. The debugger will stop the execution of the program, when it reaches such points. From them we can visualize the values of different variables, move to the next breakpoint, or explore the code line-by-line.
- Open the
task_example.c
file that you have previously modified. - Let's create a breakpoint in the function
myTaskFxn
exactly when it reads:System_printf("This is task %ld\n", arg0);
. To do that double click on the left of the line number or click with the right at the same place and selectTogle Breakpoint

- At the top right corner, you should see the list of lines with breakpoints. You can enable or disable them by clicking on the tick. Let's keep it enabled.

- Let's test how the breakpoint works: Press the
Debug
button (the button with a bug icon).

- The code will compile again, link, sent to the device, and run.
- Observe how code stops in
main
function. This happens always when you run the debugger, even if you did not set breakpoints - At the top you can see the Call stack (which functions were called), and also some controllers to manage the execution. A green triangle means Resume (move to next breakpoint), the red square means stop. There are three arrows on the right, the most interesting for us (although you might use all of them during the course) is the one in the middle: it is used to move to the next line(it is named
Step over
.

- Press the
Resume
button, so our code continues to the breakpoint we set up in a previous step. - Once there, press the
Step over
button. You will see that it moves to the next line. Do it twice. It should stop in the lineTask_sleep(1000000L / Clock_tickPeriod);
- Click the
Resume
button again. The task will be called again and stop at the same point. Let's see what else we can do when our code is stopped at breakpoint.
Visualizing variables values¶
When you are stopped at a breakpoint you can visualize and modify the value of a local variable. Those values appear at the top right window, inside the
<!image=jtkj-harjoitus-17|alt=Visualizing variables|caption=Visualizing variables>
Variables
tab. <!image=jtkj-harjoitus-17|alt=Visualizing variables|caption=Visualizing variables>
- Check the value of the local variables arg0 and arg1. In your case should read 2 and 0 respectively.
- Click on the
Value
for thearg0
and change it to 3. - Click Resume. The console should show
This is task 3
You can also see global variables, or evaluate the value of Expressions. You can do that in the
Expressions
tab.- Let's check the value of
programState
. You should writeprogramState
as expression. The value should readIDLE
- Using an expression, change the value of
programState
to READY. Remember that Expression can be either the name of a variable, or any expression in C that generates and output. - If you resume your code, the variable programState should read now READY. Observe also that you can even access the value that it has in memory using
View Memory
Restarting the app¶
Sometimes, you want to try the same code multiple times, without doing any change. It would be a loose of time if you need to compile and start debugger again. You can speed up the process by pressing the
Restart
button. - Click the
Restart
button
<!image=jtkj-harjoitus-18|alt=Restart and Reset|caption=Restart and Reset>
The
The
Restart
just uses the debugger to go back to the initial position. Sometimes is necessary to send a reset signal to the CPU. You have the CPU Reset
button next to the Restart
. Writing in terminal using UART¶
Sometimes, you want to send commands to another device, or you just want to debug your code using the UART (that allows for instance interaction, being able to send commands to the board. We will explore this further in the next exercise session, but let's see how quickly we can create a UART connection.
In order to utilize the UART, you would need to follow the steps provided in Lovelace. We have created a file already for you, because in this task, we are just interested that you know how to create a new terminal. Next session you will need to implement your own UART task.
- Please, download the file uart_task.c, add it to your project, and make sure it compiles.
This application contains just one task, that presents which is the current state of the application. It uses the UART to send the state to an external device. In this case, your computer. Let's see how we can read this data sent by the sensorTag.
- Check the code
UART_Params_init(&uartParams); uartParams.writeDataMode = UART_DATA_TEXT; uartParams.readDataMode = UART_DATA_TEXT; uartParams.readEcho = UART_ECHO_OFF; uartParams.readMode=UART_MODE_BLOCKING; uartParams.baudRate = 9600; // nopeus 9600baud uartParams.dataLength = UART_LEN_8; // 8 uartParams.parityType = UART_PAR_NONE; // n uartParams.stopBits = UART_STOP_ONE; // 1
It defines the connection parameters.
- In CCS you can open a Serial Terminal, to be used to read data written by the sensor tag.
- Go to
View -> Terminal
- In the new open terminal click
Open Terminal
and choose as TerminalSerial Terminal
- Insert the right settings, they have to be the same as the ones defined in your code. The way of finding the port depends if you are using Linux or Windows. In Linux
/dev/ttyACM0 or /dev/ttyACM1
is a good bet. In Windows you would need to use the Device Manager, and check which USB port you are using.

Run the code. You should see in the Terminal: Current state: 0
- Let's keep it just like this, but we could send commands using the terminal. Let's explore this next session.
Saving projects using GIT¶
If you want to save the status of your project while working in the virtual machine and share the changes you are doing to your code with the rest of the members of the team, best option is using Git repo. Git is integrated in CCS studio. Let see how you can synchronize your changes with a remote repo from Gitlab or Github:
1. 'Create local repo:
- Open the GIT perspective (bottom up button)
- From the menu on the left select
create a new local git repository

- Select the folder of your project (if you are using the virtualmachine should be inside
linuxlite/workspace_v10
, and clickOpen
and thenCreate
. - On the left you should see now the GIT repositosry with Tags, Branches, Remote and Working tree.

2. Save current status in local repo:
- Select the project.
- Next you need to add the project to the stage area. In the bottom window (
Git Staging
) see the unstaged changes and clickAdd all files
-> this is the equivalent ofgit add --all

- Now you should see all your files in the
Staged Changes
window. Let's commit them: - Write a commit message in
Commit Message
- Write your name and email both in
Author
andCommiter
- Press the
Commit
button. - All this process is the equivalent of
git commit -m "Initial Commit"
- Rename the branch to
main
: Open the project contextual menu (mouse right-button) and clickRename branch
.

3. 'Create a remote repository.
- Open Github or Gitlab and create a
New Project
. Project should be empty/blank and should not have any file (not even README.md). We have tested it only with public projects. - Get the clone address of the repo. Select the one with HTTPS and copy it in the clipboard
- Go back to CCS Studio and select Remotes
- In the contextual menu select (mouse right-button), select
Create Remote
and name it origin.

- In the next screen, next to URI, click on
Change
.

- In the new Window, include the URL of your remote repo. You can also add authentication parameters (your login/password in Gitlab/Github). If you want to add them there, be sure that they are in
Secure Store
. If you have problems with authentication see next section.

- Click
Save
- Now
origin
should be shown in yourRemotes

4. Push to the remote repo
- Select again the project and in the contextual menu (mouse right-button}}} select
Push branch main

- In the next screen check that remote is correct and that branch is
main
. Press Preview button.

- In the following screen press the
Push
button. (See below if you see errors related to authentication) - Now your GIT is ready
Important NOTE ABOUT AUTHENTICATION
Depending on the online platform that you are using (Gitlab or Github) you would need to perfrom additional steps to push and pull ot the repo:
Depending on the online platform that you are using (Gitlab or Github) you would need to perfrom additional steps to push and pull ot the repo:
- Gitlab: Login and password authentication should work
- Github: Login and password authentication do not work. You can either push from terminal using the Git Credential Manager installed in the virtual machine or create a Personal Access Token.
- Push using terminal. You are going to authenticate using login and password using the browser.
- Instead of pushing or pulling using the CCS Studio user interface, you are using the terminal. For that, go to the project contextual menu and select
Show In
>Terminal

- In the terminal type
git push origin main
(for pushing) orgit pull origin main
(for pulling) - In the new window select
Sigin with your browser
- Authenticate normally in your browser

- Generate Personal Access token. In this case, instead of using a password, we are going to create a token specifically created for this project:
- Go to Github. On the top righ icon (usually showing your user icon) Select
settings

- In the left menu select
Developer settings
(at the bottom of the menu) - Select
Personal access tokens
>Fine-grained tokens

- Press the button
Generate new token
. Completetoken name
(e.g. JTKJ),Expiration
(e.g. 60 days), andRepository access
toOnly Selected repositories
. Choose the repository in which you have your JTKJ project.

- In the repository permissions add
Access:Read and write
toCommit statuses
andContent

- Press
Generate token
- Copy the token in a safe place. You can use this token instead of the password when you want to authenticate.
5. Normal work
- You should repeat steps 2 and 4 everytime that you would like to save new information to the remote repository.
- If you would like to create a local repository in a different computer you should:
- First clone the Git repository in the new computer

- After that, everytime you would like to retrieve data from the remote repository, use
Pull
