Hi ,
Thanks for reaching out to Microsoft Q&A.
- 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
- 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
STM32Cube MCU Package for your device (e.g., STM32CubeF4)
- 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:
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.