Search by Tags

Build and Run your First C Application

 

Your progress

 

Overview

When it comes to Linux development, it is possible to choose several IDEs, workflows and programming languages for development. Aiming to simplify your development experience Toradex provides TorizonCore IDE integration with Visual Studio Code for Windows and Linux PCs, and Visual Studio for Windows PCs.

In this module you will:

  • Use the Visual Studio IDE.
  • Cross-compile your application using the Torizon Extension for Visual Studio.
  • Deploy it to the target module and debug it remotely from your development PC.

Note: support for a more complex workflow on Visual Studio will be presented to you at the end of the quickstart guide, as well as support for other programming languages on Visual Studio Code. If you have a Linux PC for development, you can also try the quickstart guide for Torizon with Linux selected as Development PC OS.

Typographic Conventions

Prerequisites

For this Quickstart Guide:

  • Development computer with Windows 10 version 2004 (a.k.a. May 2020 update) or higher.
  • Successfully completed the previous lesson from this guide.

For this lesson:

  • Visual Studio 2019.
  • Toradex hardware and computer on the same network.

Note: Carefully read this module's cover page clicking on "Module 2: First Steps with Torizon" on the left menu bar before starting this lesson.

Step 1

When installing Visual Studio make sure you select at least the following workloads for the correct operation of the Torizon Extension for Visual Studio.

If you already have Visual Studio installed, run the Visual Studio Installer and modify your current setup:


  • Select Desktop development with C++

    Select Desktop development with C++


  • Select Linux development with C++

    Select Linux development with C++

Step 2

The latest versions of the Toradex Torizon Support extension can be found on the Visual Studio marketplace, in two versions:

Close all running instances of Visual Studio. Choose one of Torizon extensions from the above, download and install it.

Tip: The extension is available for Visual Studio 2019 only!

Check that the installation was successful by opening the extension list under Extensions > Manage Extensions:


  • Torizon Extension for Visual Studio

    Torizon Extension for Visual Studio

Step 3

Select Tools > Download/update base and sdk containers:


  • Download Base and SDK Containers

    Download Base and SDK Containers

Note: Be patient! This process can take a while.

Step 4

The extension provides some windows and toolbars but they are hidden by default. You can show the device list by selecting View > Other Windows > Torizon devices from the menu bar in Visual Studio.

Once it shows up, you can detect devices through serial port or network. In this guide we will use the network device detection.


  • Torizon Devices Window

    Torizon Devices Window

Step 5

To add your device to this list, select Detect device on the network and set your board's IP or hostname as found out on the previous lessons:


  • Adding new devices

    Adding new devices

Note: Remember that the credentials are username: torizon and password: <custom password you have set during the first login>

Attention: As soon as you click Detect, the board will reboot! All instances of Putty will close with a Connection Lost message.

Step 6

After the board reboots, refresh the device on the list. The Windows Defender will ask you to allow moses.exe.

Moses is the Torizon Extension back-end. Click on Allow Access.

Step 7

See the collected data from the board:


  • Torizon Devices Window Refreshed

    Torizon Devices Window Refreshed

Step 8

Enable the Torizon toolbar on Visual Studio selecting Tools > Customize, scroll down the list, select "Torizon Toolbar" and hit Close:


  • Torizon Toolbar

    Torizon Toolbar

Step 9

Create a New Project and select Torizon C/C++ Application from the Visual C++ category:


  • New Project Dialog

    New Project Dialog

Step 10

Give a Project Name to your project and make sure to mark the checkbox Place solution and project in the same directory:


  • Configure Your New Project

    Configure Your New Project

Step 11

When you click Create in the previous step, a dialog will ask you to Select supported platforms.

Select debian arm64v8 bullseye and verify that torizon is the username:


  • Select Your Platform

    Select Your Platform

Note: Please notice that the list of platforms may change. New updates of the extension will make additional platforms available with new releases of debian and specialized platforms with specific libraries pre-installed.

Step 12

Open Debug > Linux Console so you can see the application output.

Step 13

On the Solution Explorer menu open the main.cpp file and slightly modify it to make our debug fun:

main.cpp
#include <cstdio> int main() { int var = 1, i; for(i = 0; i < 5; i++){ var = 2*var; printf("Loop %d - var=%d\n", i, var); } return 0; }

Step 14

Add a breakpoint by clicking on the left of the line number. For instance, insert a breakpoint relative to the printf command (line 7).


  • Breakpoint set

    Breakpoint set

Step 15

Either choose Debug > Deploy and debug Torizon or click on Deploy and Debug Torizon Application on the Torizon Toolbar:


  • Deploy and Debug

    Deploy and Debug

A dialog will ask if you want to build the application. Choose Yes:


  • Build

    Build

Note: This step takes a while to finish since the app has to be built.

See the expected output in the animated illustration below:


  • Successful build output

    Successful build output

Step 16

When the build is finished, deploy the application to the computer on module by selecting Debug > Deploy and debug Torizon and selecting your board:


  • Device deployment

    Device deployment

Warning: This step takes a while, when run for the first time, since the container has to be built and deployed to the target.

Step 17

You can use the Visual Studio debugging features to step through your code and observe variable values, functions, etc.


  • Debugging Torizon Application on Visual Studio

    Debugging Torizon Application on Visual Studio

Takeaway

As the Quickstart is a step-by-step guide, the current lesson is only a brief introduction to application development with Torizon. For a great development experience, you can choose to use the Visual Studio Extension For Torizon and write your application in C/C++ or use the Visual Studio Code Extension for Torizon and write your application in C/C++, C#/.NET or Python.

You can also use other programming languages, or even ready-to-use technologies such as databases, by either choosing a container image from the community as the official Node.js container image or building your own container based on a community one or our Debian Containers for Torizon.

FAQ