AZURE IOT FOR MIDDLEWARE

Amara Rakesh 5 Reputation points
2025-05-29T06:46:16.3033333+00:00

Hello Experts,

I am looking to implement Azure IoT Middleware for FreeRTOS on my STM32F series board. I have reviewed the GitHub repositories related to Azure IoT Middleware, but I couldn't find clear information or step-by-step instructions.

Could you please guide me with a detailed procedure to set it up on my STM32F platform?

Thank you in advance for your support.

Best regards, Rakesh

Azure IoT Plug and Play
Azure IoT Plug and Play
A Microsoft technology based on an open modeling language that enables developers to connect internet of things (IoT) devices to the cloud without having to write any code.
20 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Vinodh247 34,661 Reputation points MVP Volunteer Moderator
    2025-05-29T07:32:16.1266667+00:00

    Hi ,

    Thanks for reaching out to Microsoft Q&A.

    1. Overview

    Azure IoT Middleware for FreeRTOS enables STM32 (and other MCUs) to securely connect to Azure IoT Hub or DPS using FreeRTOS. This is achieved by integrating:

    • Azure IoT SDK

    FreeRTOS

    Azure IoT Middleware

    Device SDKs (TLS, MQTT, etc.)

    ST’s STM32Cube HAL


    1. Prerequisites

    Hardware

    STM32F4 or STM32F7 series board (e.g., Nucleo-F429ZI)

    ST-LINK debugger

    Ethernet/WiFi (depending on connectivity)

    Software

    STM32CubeMX

    STM32CubeIDE

    Azure IoT Middleware for FreeRTOS repo

    FreeRTOS repo

    Azure SDK for C

    STM32Cube MCU Package for your device (e.g., STM32CubeF4)


    1. Step-by-Step Setup

    Step 1: Create FreeRTOS + LWIP Project

    Open STM32CubeMX.

    Create a new project for your STM32F board.

    Enable:

    FreeRTOS middleware

    LWIP TCP/IP stack (Ethernet)

    Generate code and open in STM32CubeIDE.

    Step 2: Add Azure IoT Middleware

    Clone the following repos:

    https://github.com/Azure/azure-sdk-for-c

    https://github.com/azure-rtos/azure-iot-middleware-freertos

    https://github.com/FreeRTOS/FreeRTOS

    Copy required folders into your CubeIDE project:

    Azure SDK for C: sdk/src/

    Middleware: middleware/azure-iot

    FreeRTOS and portable: freertos/FreeRTOS-Kernel

    Add these to your include paths and source files.

    Step 3: Integrate TLS and MQTT

    You will need:

    mbedTLS (included in STM32CubeMX with LWIP)

    Port MQTT and TLS layers to STM32 HAL using examples from Azure Middleware repo.

    Configure:

    Platform abstraction (e.g., time, memory, logging)

    tlsio_mbedtls.c (or implement tlsio_stm32.c)

    Use mqtt_client from Azure SDK

    Step 4: Connect to Azure IoT Hub

    Use IoT Hub Device Connection String (or DPS if needed).

    Implement sample connection logic from:

    demos/

    Example flow:

    Initialize FreeRTOS

    ----->

    Initialize MQTT

    ----->

    Use Azure SDK to:
    
          ----->
    
          Format telemetry messages
    
               ----->
    
                Send data to IoT Hub
    

    Step 5: Run and Debug

    Flash firmware using ST-LINK

    Monitor serial console output (UART)

    Validate connection in Azure IoT Hub (Device twin, telemetry)

    Reference Examples

    STMicroelectronics Azure SDK Pack

    ST provides a reference pack:

    https://github.com/STMicroelectronics/STM32CubeExpansion_Azure

    Includes:

    Azure middleware

    Sample for STM32L4/Nucleo boards

    Integration with CubeMX and IDE

    Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.

    0 comments No comments

  2. Manas Mohanty 5,620 Reputation points Microsoft External Staff Moderator
    2025-06-02T11:15:24.01+00:00

    Hi Amara Rakesh

    Trying to summarize the steps mentioned here for STM32 boards

    https://github.com/Azure-Samples/iot-middleware-freertos-samples/tree/main/demos/projects/ST/stm32h745i-disco/cm7

    Prerequisites:

    Setup Steps

    1. Enable longpath support for Windows and Git
         git config --system core.longpaths true
      
    2. Clone and initialize the Repository:
          git clone https://github.com/Azure-Samples/iot-middleware-freertos-samples.git
          git submodule update --init --recursive
         
      
    3. Configure Azure IoT Hub:
    4. Update Configuration Files: Update the file **iot-middleware-freertos-samples/demos/projects/ST/stm32h745i-disco/cm7/config/demo_config.h** with your device credentials (IoT Hub connection string/primary key or DPS info). Prepare the device
    5. Build the image: navigate to the iot-middleware-freertos-samples directory and run the following commands:
         cmake -G Ninja -DVENDOR=ST -DBOARD=stm32h745i-disco -Bstm32h745i-disco .
         cmake --build stm32h745i-disco
         
         
      
      After the build completes, confirm that a folder named stm32h745i-disco/ was created and it contains a file named demo/projects/ST/stm32h745i-disco/iot-middleware-sample.bin.
    6. Flash the Firmware:
      1. Connect the Micro USB cable to the USB STLINK port on the STM DevKit, and then connect it to your computer.
      2. In File Explorer, find the binary file that you created in the previous section and copy it.
      3. In File Explorer, find the STM Devkit that's connected to your computer. The device appears as a drive on your system with the drive label DIS_H745XI.
      4. Paste the binary file into the root folder of the STM Devkit. Flashing starts automatically and completes in a few seconds.
      5. Connect an Ethernet cable to your STM DevKit and your network equipment.
    7. Monitor Output:
      • You can use one of the terminal applications to monitor communication and confirm that your device is set up correctly.
      • Go to Device Manager in Windows to determine which COM port your device was assigned. The following settings can be used to monitor serial data:
      • Baud Rate: 115200
      • Data Bits: 8
      • Stop Bits: 1
      • Parity: none
      • Flow Control: none
      • The device should connect to Azure IoT Hub and start sending telemetry.

    Hope it provides more clarity. Please let us know if it helps

    Thank you


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.