Skip to content

Files

Latest commit

 

History

History
267 lines (177 loc) · 13.6 KB

quickstart-devkit-stm-b-l475e-freertos.md

File metadata and controls

267 lines (177 loc) · 13.6 KB
title description author ms.author ms.service ms.devlang ms.topic ms.date ms.custom
Connect an STMicroelectronics B-L475E to Azure IoT Central quickstart
Use Azure IoT middleware for FreeRTOS to connect an STMicroelectronics B-L475E-IOT01A Discovery kit to Azure IoT and send telemetry.
timlt
timlt
iot-develop
c
quickstart
01/27/2022
mode-other

Quickstart: Connect an STMicroelectronics B-L475E-IOT01A Discovery kit to Azure IoT Central

Applies to: Embedded device development
Total completion time: 30 minutes

In this quickstart, you use the Azure IoT middleware for FreeRTOS to connect the STMicroelectronics B-L475E-IOT01A Discovery kit (from now on, the STM DevKit) to Azure IoT Central.

You complete the following tasks:

  • Install a set of embedded development tools to program an STM DevKit
  • Build an image and flash it onto the STM DevKit
  • Use Azure IoT Central to create cloud components, view properties, view device telemetry, and call direct commands

Prerequisites

Operating system: Windows 10 or Windows 11

Hardware:

  • STM B-L475E-IOT01A devkit
  • USB 2.0 A male to Micro USB male cable
  • Wi-Fi 2.4 GHz

Prepare the development environment

To set up your development environment, first you clone a GitHub repo that contains all the assets you need for the tutorial. Then you install a set of programming tools.

Clone the repo

Clone the following repo to download all sample device code, setup scripts, and offline versions of the documentation. If you previously cloned this repo in another tutorial, you don't have to do it again.

To clone the repo, run the following command:

git clone --recursive https://github.com/Azure-Samples/iot-middleware-freertos-samples

Install Ninja

Ninja is a build tool that you use to build an image for the STM DevKit.

  1. Download Ninja and unzip it to your local disk.
  2. Add the path to the Ninja executable to a PATH environment variable.
  3. Open a new console to recognize the update, and confirm that the Ninja binary is available in the PATH environment variable:
    ninja --version

Install the tools

The cloned repo contains a setup script that installs and configures the required tools. If you installed these tools in another tutorial in the getting started guide, you don't have to do it again.

Note: The setup script installs the following tools:

To install the tools:

  1. From File Explorer, navigate to the following path in the repo and run the setup script named get-toolchain.bat:

    iot-middleware-freertos-samples\tools\get-toolchain.bat

  2. After the installation, open a new console window to recognize the configuration changes made by the setup script. Use this console to complete the remaining programming tasks in the tutorial. You can use Windows CMD, PowerShell, or Git Bash for Windows.

  3. Run the following code to confirm that CMake version 3.20 or later is installed.

    cmake --version

[!INCLUDE iot-develop-embedded-create-central-app-with-device]

Prepare the device

To connect the STM DevKit to Azure, modify configuration settings, build the image, and flash the image to the device.

Add configuration

  1. Open the following file in a text editor:

    iot-middleware-freertos-samples/demos/projects/ST/b-l475e-iot01a/config/demo_config.h

  2. Set the Wi-Fi constants to the following values from your local environment.

    Constant name Value
    WIFI_SSID {Your Wi-Fi ssid}
    WIFI_PASSWORD {Your Wi-Fi password}
    WIFI_SECURITY_TYPE {One of the enumerated Wi-Fi mode values in the file}
  3. Set the Azure IoT device information constants to the values that you saved after you created Azure resources.

    Constant name Value
    democonfigID_SCOPE {Your ID scope value}
    democonfigREGISTRATION_ID {Your Device ID value}
    democonfigDEVICE_SYMMETRIC_KEY {Your Primary key value}
  4. Save and close the file.

Build the image

  1. In your console, run the following commands from the iot-middleware-freertos-samples directory to build the device image:

    cmake -G Ninja -DVENDOR=ST -DBOARD=b-l475e-iot01a -Bb-l475e-iot01a .
    cmake --build b-l475e-iot01a
  2. After the build completes, confirm that the binary file was created in the following path:

    iot-middleware-freertos-samples\b-l475e-iot01a\demos\projects\ST\b-l475e-iot01a\iot-middleware-sample-gsg.bin

Flash the image

  1. On the STM DevKit board, locate the Reset button (1), the Micro USB port (2), which is labeled USB STLink, and the board part number (3). You will refer to these items in the next steps. All of them are highlighted in the following picture:

    :::image type="content" source="media/quickstart-devkit-stm-b-l475e-freertos/stm-devkit-board-475.png" alt-text="Locate key components on the STM DevKit board":::

  2. Connect the Micro USB cable to the USB STLINK port on the STM DevKit, and then connect it to your computer.

    [!NOTE] For detailed setup information about the STM DevKit, see the instructions on the packaging, or see B-L475E-IOT01A Resources

  3. In File Explorer, find the binary file named iot-middleware-sample-gsg.bin that you created previously.

  4. In File Explorer, find the STM Devkit board that's connected to your computer. The device appears as a drive on your system with the drive label DIS_L4IOT.

  5. Paste the binary file into the root folder of the STM Devkit. The process to flash the board starts automatically and completes in a few seconds.

    [!NOTE] During the process, an LED toggles between red and green on the STM DevKit.

Confirm device connection details

You can use the Termite app to monitor communication and confirm that your device is set up correctly.

  1. Start Termite.

    [!TIP] If you are unable to connect Termite to your devkit, install the ST-LINK driver and try again. See Troubleshooting for additional steps.

  2. Select Settings.

  3. In the Serial port settings dialog, check the following settings and update if needed:

    • Baud rate: 115,200
    • Port: The port that your STM DevKit is connected to. If there are multiple port options in the dropdown, you can find the correct port to use. Open Windows Device Manager, and view Ports to identify which port to use.

    :::image type="content" source="media/quickstart-devkit-stm-b-l475e/termite-settings.png" alt-text="Screenshot of serial port settings in the Termite app":::

  4. Select OK.

  5. Press the Reset button on the device. The button is black and is labeled on the device.

  6. In the Termite app, check the output to confirm that the device is initialized and connected to Azure IoT. After some initial connection details, you should begin to see your board sensors sending telemetry to Azure IoT.

    Successfully sent telemetry message
    [INFO] [MQTT] [receivePacket:885] Packet received. ReceivedBytes=2.
    [INFO] [MQTT] [handlePublishAcks:1161] Ack packet deserialized with result: MQTTSuccess.
    [INFO] [MQTT] [handlePublishAcks:1174] State record updated. New state=MQTTPublishDone.
    Puback received for packet id: 0x00000003
    [INFO] [AzureIoTDemo] [ulCreateTelemetry:197] Telemetry message sent {"magnetometerX":-204,"magnetometerY":-215,"magnetometerZ":-875}
    
    Successfully sent telemetry message
    [INFO] [MQTT] [receivePacket:885] Packet received. ReceivedBytes=2.
    [INFO] [MQTT] [handlePublishAcks:1161] Ack packet deserialized with result: MQTTSuccess.
    [INFO] [MQTT] [handlePublishAcks:1174] State record updated. New state=MQTTPublishDone.
    Puback received for packet id: 0x00000004
    [INFO] [AzureIoTDemo] [ulCreateTelemetry:197] Telemetry message sent {"accelerometerX":22,"accelerometerY":4,"accelerometerZ":1005}
    
    Successfully sent telemetry message
    [INFO] [MQTT] [receivePacket:885] Packet received. ReceivedBytes=2.
    [INFO] [MQTT] [handlePublishAcks:1161] Ack packet deserialized with result: MQTTSuccess.
    [INFO] [MQTT] [handlePublishAcks:1174] State record updated. New state=MQTTPublishDone.
    Puback received for packet id: 0x00000005
    [INFO] [AzureIoTDemo] [ulCreateTelemetry:197] Telemetry message sent {"gyroscopeX":0,"gyroscopeY":-700,"gyroscopeZ":350}
    

    [!IMPORTANT] If the DNS client initialization fails and notifies you that the Wi-Fi firmware is out of date, you'll need to update the Wi-Fi module firmware. Download and install the Inventek ISM 43362 Wi-Fi module firmware update. Then press the Reset button on the device to recheck your connection, and continue with this quickstart.

Keep Termite open to monitor device output in the remaining steps.

Verify the device status

To view the device status in the IoT Central portal:

  1. From the application dashboard, select Devices on the side navigation menu.

  2. Confirm that the Device status of the device is updated to Provisioned.

  3. Confirm that the Device template of the device has been updated to STM L475 FreeRTOS Getting Started Guide.

    :::image type="content" source="media/quickstart-devkit-stm-b-l475e-freertos/iot-central-device-view-status.png" alt-text="Screenshot of device status in IoT Central":::

View telemetry

In IoT Central, you can view the flow of telemetry from your device to the cloud.

To view telemetry in IoT Central:

  1. From the application dashboard, select Devices on the side navigation menu.

  2. Select the device from the device list.

  3. Select the Overview tab on the device page, and view the telemetry as the device sends messages to the cloud.

    :::image type="content" source="media/quickstart-devkit-stm-b-l475e-freertos/iot-central-device-telemetry.png" alt-text="Screenshot of device telemetry in IoT Central":::

Call a command on the device

You can also use IoT Central to call a command that you have implemented on your device. In this section, you call a method that enables you to turn an LED on or off.

To call a command in IoT Central portal:

  1. Select the Command tab from the device page.

  2. Set the State dropdown value to True, and then select Run. The LED light should turn on.

    :::image type="content" source="media/quickstart-devkit-stm-b-l475e-freertos/iot-central-invoke-method.png" alt-text="Screenshot of calling a direct method on a device in IoT Central":::

  3. Set the State dropdown value to False, and then select Run. The LED light should turn off.

View device information

You can view the device information from IoT Central.

Select About tab from the device page.

:::image type="content" source="media/quickstart-devkit-stm-b-l475e-freertos/iot-central-device-about.png" alt-text="Screenshot of device information in IoT Central":::

Tip

To customize these views, edit the device template.

Troubleshoot and debug

If you experience issues when you build the device code, flash the device, or connect, see Troubleshooting.

To debug the application, see Debugging with Visual Studio Code.

Clean up resources

If you no longer need the Azure resources created in this tutorial, you can delete them from the IoT Central portal. Optionally, if you continue to another article in this Getting Started content, you can keep the resources you've already created and reuse them.

To keep the Azure IoT Central sample application but remove only specific devices:

  1. Select the Devices tab for your application.
  2. Select the device from the device list.
  3. Select Delete.

To remove the entire Azure IoT Central sample application and all its devices and resources:

  1. Select Administration > Your application.
  2. Select Delete.

Next Steps

In this quickstart, you built a custom image that contains the Azure IoT middleware for FreeRTOS sample code. Then you flashed the image to the STM DevKit device. You also used the IoT Central portal to create Azure resources, connect the STM DevKit securely to Azure, view telemetry, and send messages.

As a next step, explore the following articles to learn how to work with embedded devices and connect them to Azure IoT.

[!div class="nextstepaction"] Azure IoT middleware for FreeRTOS samples [!div class="nextstepaction"] Azure RTOS embedded development quickstarts [!div class="nextstepaction"] Azure IoT device development documentation