Search by Tags

Build and Run your First C Application

 

Your progress

 

Overview

Torizon offers a Microsoft Environment for developers familiar with Visual Studio. This lesson will show how to use it, build applications and deploy it to the target module.

In this module you will:

  • Cross-compile your application using Torizon Microsoft Environment.
  • Deploy it to the target module.
Typographic Conventions

Prerequisites

For this Getting Started Guide:

  • Development computer with Windows 10 Pro / Enterprise / Education.
  • Successfully completed the previous lesson from this guide.

For this lesson:

  • Visual Studio 2017 installed with Visual C++ for Linux Development extension (if you haven't already installed it you can add it by launching the Visual Studio Installer and modifying your current setup).
  • Toradex hardware and computer on the same network.

Step 1

To be able to use the Torizon Microsoft Environment, head to the Visual Studio Marketplace, download and install Torizon C/C++ Application development.

Warning: The extension is available for Visual Studio 2017 only!

Check that the installation was successful by opening the extension list under Tools > Extensions and Updates:


  • Torizon Microsoft Environment Extension

    Torizon Microsoft Environment Extension

Step 2

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 serial port device detection.


  • Toradex Devices Window

    Toradex Devices Window

Step 3

Find out which COM port corresponds to the USB-to-Serial connection to the board, by opening the Windows Device Manager:


  • Windows Device Manager

    Windows Device Manager

See from the example above that it is listed as Prolific USB-to-Serial Comm Port (COM5). The whole string may change depending on the manufacturer of the converter, but we only need the COM number, which is 5 in the example.

Step 4

To add your device to this list, select "Detect device on serial port" and set your connection as illustrated below, changing your "Serial Port" to the one found on the previous step:


  • Adding new devices

    Adding new devices

Note: Remember that the credentials are username: torizon and password: torizon

After adding, refresh the device on the list and see the collected data:


  • Toradex Devices Window Refreshed

    Toradex Devices Window Refreshed

Step 5

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 6

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


  • New Project Dialog

    New Project Dialog

Step 7

Select the platform you want to use for running your application. Platforms are base container images which provide different sets of features.

Select Debian LXDE Buster and add "torizon" to username.


  • Platform choice dialog

    Platform choice dialog

Note: In this getting started guide we stick to the platform that has the LXDE desktop environment since it is the full-featured ease-of-use platform offered by Toradex.

Step 8

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

Step 9

Open the solution explorer menu and change the main.cpp file to:

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

Step 10

To build your sample application, select Build > Build Torizon Application from the menu bar. When you build an application for the first time, it will take a while.

Note: On the first build it may take up to 10 minutes. Depending on your PC configuration, you may occasionally see "not responding" messages which can be ignored.

Step 11

When the build is finished, deploy it to target device selecting Debug > Deploy and debug Torizon and select which device to send the application to:


  • Device deployment

    Device deployment

Note: This step also takes a while since the module has to load the container.

Step 12

To debug your application, insert breakpoints to the left of the line number. For instance, insert a breakpoint relative to the printf command (line 7).


  • Breakpoint set

    Breakpoint set

Now, when you select Debug > Deploy and debug Torizon it is possible to use Visual Studio debugging features to step through your code.

FAQ

Where do I find more information about the Torizon Microsoft Environment?