🛠 FreeRTOS sur le Nucleo STM32H743ZI : le projet officiel CubeH7, tâches et file d'attente

STM32H7 Nucleo-144 (porte-drapeau : NUCLEO-H743ZI) · intermediaire · Schéma : IMG-stm32h7-nucleo-intermediaire-3-stm32h743zi-freertos-tasks.svg — trois tâches FreeRTOS (capteur, affichage, log) échangeant via une file d'attente au-dessus de la Nucleo-144 STM32H743ZI, chronogramme d'ordonnancement préemptif à droite, flat vector style, étiquettes en français, fond blanc.

What you will build

STM32CubeH7 ships a ready-made FreeRTOS application for this exact board at Projects/NUCLEO-H743ZI/Applications/FreeRTOS — the fastest route to a working RTOS baseline on the H743ZI. We will open it, then add a producer/consumer pair: a sensor task sampling one of the 3× 16-bit ADCs and a logging task draining a queue to the ST-LINK virtual COM port.

Why FreeRTOS on this board

Step 1 — Open the official project

  1. git clone --recursive https://github.com/STMicroelectronics/STM32CubeH7.git
  2. Open Projects/NUCLEO-H743ZI/Applications/FreeRTOS in STM32CubeIDE (or regenerate your own variant from CubeMX with FreeRTOS enabled in the middleware tree).
  3. Build and flash through the on-board ST-LINK/V2-1.

Step 2 — Producer/consumer tasks

/* Add to the generated project (CubeMX FreeRTOS skeleton). */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"

static QueueHandle_t q_samples;

void SensorTask(void *arg)
{
  uint32_t raw;
  for (;;) {
    HAL_ADC_Start(&hadc1);                       /* 16-bit ADC, up to 3.6 MSPS */
    HAL_ADC_PollForConversion(&hadc1, 10);
    raw = HAL_ADC_GetValue(&hadc1);
    xQueueSend(q_samples, &raw, pdMS_TO_TICKS(10));
    vTaskDelay(pdMS_TO_TICKS(100));
  }
}

void LogTask(void *arg)
{
  uint32_t raw;
  for (;;) {
    if (xQueueReceive(q_samples, &raw, portMAX_DELAY) == pdTRUE) {
      printf("ADC1=%lu\r\n", raw);  /* retarget printf to UART3 / ST-LINK VCP */
    }
  }
}

void start_tasks(void)   /* called after HAL init and clock config */
{
  q_samples = xQueueCreate(16, sizeof(uint32_t));
  xTaskCreate(SensorTask, "sensor", 128, NULL, 3, NULL);
  xTaskCreate(LogTask,    "log",    128, NULL, 2, NULL);
  vTaskStartScheduler;
  for (;;) {}
}

Step 3 — Priorities that make sense

Give the sensor task the higher priority and let the log task run at low priority: the ADC producer never waits on the slow console, and the queue (16 deep) absorbs console stalls. On a 480 MHz M7 with 192 KB of TCM RAM, context switches are tiny — but keep stacks in the default RAM sections before micro-optimizing placement (see the advanced memory tutorial).

Expected result

The official demo's LED choreography runs ; after your edit, the terminal on the ST-LINK VCP (115200) prints one ADC1=... line every 100 ms while the LED tasks keep their timing — that is preemptive scheduling proving itself.

Common pitfalls

Autres tutoriels pour cette carte

Exemples de code pour cette carte

← Retour à la fiche 🛠 Tous les tutoriels