Início Rápido: Compilar o aplicativo Blink com o Visual StudioQuickstart: Build the Blink application with Visual Studio

Este início rápido mostra como habilitar o desenvolvimento de aplicativos em um dispositivo do Azure Sphere e como compilar e depurar um aplicativo de alto nível.This quickstart shows how to enable application development on an Azure Sphere device and how to build and debug a high-level application. Ele usa o exemplo de Blink, que faz parte do SDK do Azure Sphere.It uses the Blink sample, which is part of the Azure Sphere SDK. O exemplo do Blink pisca um LED, para que você possa verificar que o dispositivo do Azure Sphere e as ferramentas são instaladas e configuradas corretamente.The Blink sample blinks an LED, so that you can verify that the Azure Sphere device and tools are installed and set up correctly.

Pré-requisitosPrerequisites

As etapas neste início rápido supõem que:The steps in this quickstart assume that:

  • Seu dispositivo do Azure Sphere está conectado ao seu computadorYour Azure Sphere device is connected to your PC
  • Você concluiu todas as etapas para instalar o Azure SphereYou have completed all the steps to install Azure Sphere

Importante

Essas instruções pressupõem que você está usando hardware que segue o design de quadro de referência MT3620 (RBD), como o Kit de desenvolvimento Seeed MT3620.These instructions assume that you are using hardware that follows the MT3620 reference board design (RBD), such as the Seeed MT3620 Development Kit. Se você estiver usando um hardware Azure Sphere diferente, consulte a documentação do fabricante para descobrir se o GPIO está exposto e como acessá-lo.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. Você talvez precise atualizar o código de exemplo e o campo "Gpio" do arquivo app_manifest.json para usar um GPIO diferente.You might need to update the sample code and the "Gpio" field of the app_manifest.json file to use a different GPIO.

Preparar o seu dispositivo para desenvolvimento e depuraçãoPrepare your device for development and debugging

Antes de criar um aplicativo de exemplo em seu dispositivo do Azure Sphere ou desenvolver novos aplicativos para ele, você deve habilitar o sideload.Before you can build a sample application on your Azure Sphere device or develop new applications for it, you must enable development and sideloading. Por padrão, dispositivos do Azure Sphere são "bloqueados", ou seja, não permitem que aplicativos em desenvolvimento sejam carregados de um PC e não permitem a depuração de aplicativos.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. Preparar o dispositivo para sideload remove essa restrição.Preparing the device for sideloading removes this restriction.

O comando azsphere device enable-development configura o dispositivo para aceitar os aplicativos de um PC para depuração e carrega o servidor de depuração no dispositivo.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. Também atribui o dispositivo a um grupo de dispositivos que não permite atualizações de aplicativo de nuvem.It also assigns the device to a device group that does not allow cloud application updates. Durante o desenvolvimento e a depuração de aplicativos, você deve deixar o dispositivo neste grupo para que as atualizações de aplicativos de nuvem não substituam o aplicativo em desenvolvimento.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.

Para preparar o seu dispositivoTo prep your device

  1. Verifique se o dispositivo Azure Sphere está conectado ao seu PC e se o computador está conectado à Internet.Make sure that your Azure Sphere device is connected to your PC, and your PC is connected to the internet.

  2. Em uma janela de Prompt de Comando do Desenvolvedor do Azure Sphere, digite o seguinte comando:In an Azure Sphere Developer Command Prompt window, type the following command:

    azsphere device enable-development
    

    Você deverá ver uma saída semelhante ao seguinte: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.

  1. If you are new to Visual Studio, consider the Quickstart or Guided Tour to learn about navigating and using it.

  2. 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.

  3. 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);
  4. In Visual Studio, select View>Output to display the Output window.

  5. Ensure that your device is connected to your PC by USB. Then select GDB Debugger (HLCore) from the menu bar or press F5.

    Remote GDB Debugger button

  6. 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.

    Dica

    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.

  7. 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.

  8. When you run the program, you should see an LED blink.

Next steps

This quickstart showed how to prepare your Azure Sphere device for debugging and how to build and debug a high-level application.

Next: