Quickstart: Build the Blink application with Visual Studio
This quickstart shows how to enable application development on an Azure Sphere device and how to build and debug a high-level application. It uses the Blink sample, which is part of the Azure Sphere SDK. The Blink sample blinks an LED, so that you can verify that the Azure Sphere device and tools are installed and set up correctly.
The steps in this quickstart assume that:
- Your Azure Sphere device is connected to your PC
- You have completed all the steps to install Azure Sphere
These instructions assume that you are using hardware that follows the MT3620 reference board design (RBD), such as the Seeed MT3620 Development Kit. If you are using different Azure Sphere hardware, consult the manufacturer's documentation to find out whether the GPIO is exposed and how to access it. You might need to update the sample code and the "Gpio" field of the app_manifest.json file to use a different GPIO.
Prepare your device for development and debugging
Before you can build a sample application on your Azure Sphere device or develop new applications for it, you must enable development and sideloading. By default, Azure Sphere devices are "locked"; that is, they do not allow applications under development to be loaded from a PC, and they do not allow debugging of applications. Preparing the device for sideloading removes this restriction.
The azsphere device enable-development command configures the device to accept applications from a PC for debugging and loads the debugging server onto the device. It also assigns the device to a device group that does not allow cloud application updates. During application development and debugging, you should leave the device in this group so that cloud application updates do not overwrite the application under development.
To prep your device
Make sure that your Azure Sphere device is connected to your PC, and your PC is connected to the internet.
In an Azure Sphere Developer Command Prompt window, type the following command:
azsphere device enable-development
You should see output similar to the following:
Getting device capability configuration for application development. Downloading device capability configuration for device ID '<device ID>'. Successfully downloaded device capability configuration. Successfully wrote device capability configuration file 'C:\Users\user\AppData\Local\Temp\tmpD732.tmp'. Setting device group ID 'a6df7013-c7c2-4764-8424-00cbacb431e5' for device with ID '<device ID>'. Successfully disabled over-the-air updates. Enabling application development capability on attached device. Applying device capability configuration to device. Successfully applied device capability configuration to device. The device is rebooting. Installing debugging server to device. Deploying 'C:\Program Files (x86)\Microsoft Azure Sphere SDK\DebugTools\gdbserver.imagepackage' to the attached device. Image package 'C:\Program Files (x86)\Microsoft Azure Sphere SDK\DebugTools\gdbserver.imagepackage' has been deployed to the attached device. Application development capability enabled. Successfully set up device '<device ID>' for application development, and disabled over-the-air updates. Command completed successfully in 00:00:38.3299276.
The device remains enabled for debugging and closed to cloud application updates until you explicitly change it. To disable debugging and allow application updates, use the azsphere device enable-cloud-test command.
Build and run the Blink sample with Visual Studio
In Visual Studio, create a new project based on the Azure Sphere Blink template. Enter a name and location for the project and select OK. The project opens with main.c in the editor.
If you are using hardware on which GPIO 9 is not accessible, change the GPIO. For example, on the Seeed Mini Dev Board, change GPIO 9 to GPIO 7:
- In app_manifest.json, change
"Gpio": [ 9 ],to
"Gpio": [ 7 ],
- In main.c, edit the call to GPIO_OpenAsOutput to specify GPIO 7 instead of GPIO 9:
int fd = GPIO_OpenAsOutput(7, GPIO_OutputMode_PushPull, GPIO_Value_High);
- In app_manifest.json, change
In Visual Studio, select View>Output to display the Output window.
Ensure that your device is connected to your PC by USB. Then select GDB Debugger (HLCore) from the menu bar or press F5.
If you are prompted to build the project, select Yes. Visual Studio compiles the application, creates an image package, sideloads it onto the board, and starts it in debug mode. Sideloading means that the application is delivered directly from the PC over a wired connection, rather than delivered through the cloud.
Note the path in the Build output, which indicates the location of the output image package on your PC. You'll use the image package later in the Deployment Quickstart.
By default, the Output window shows output from Device Output. To see messages from the debugger, select Debug from the Show output from: dropdown menu. You can also inspect the program disassembly, registers, or memory through the Debug>Windows menu.
When you run the program, you should see an LED blink.
This quickstart showed how to prepare your Azure Sphere device for debugging and how to build and debug a high-level application.