Skip to main content

Practical Sections

Setting Up FreeRTOS on ESP-32

Two cores in ESP-32 let this low-power microcontroller operate:

  • CPU0: Handles BLE, Bluetooth, and Wi-Fi wireless protocols. 
  • CPU1: Executes code for user apps. 

Installing and configuring the ESP-32 Arduino Core: 
1. Obtain the most recent Arduino IDE and install it. 
2. Launch Arduino IDE then go to File / Preferences. Enter in the field Additional Boards Manager URLs:

https://dl.espressif.com/dl/package_esp32_index.json

3. Go to Tools / Board / Boards Manager, look for esp32, and install the most recent release from Espressif Systems. 
4. Go to Tools / Board / ESP32 Arduino and pick the right board (like ESP32 Dev Module or ESP32 Wrover Module).

All about FreeRTOS APIs

1. xTaskCreate()
  • Purpose: Creates a new task and dynamically allocates the required memory. Returns a handle to the created task, or NULL if creation fails. Syntax:
BaseType_t xTaskCreate(
    TaskFunction_t pvTaskCode,
    const char * const pcName,
    const uint32_t usStackDepth,
    void * const pvParameters,
    UBaseType_t uxPriority,
    TaskHandle_t * const pvCreatedTask
);

Parameters

  1. pvTaskCode: Pointer to the function that implements the task. The function must have a prototype of void vTaskCode(void * pvParameters).
  2. pcName: Descriptive name of the task (helps with debugging).
  3. usStackDepth: Stack size in words (not bytes) for the task.
  4. pvParameters: Pointer to the arguments passed to the task function.
  5. uxPriority: Priority of the task execution (higher number = higher priority).
  6. pvCreatedTask: Pointer to the variable that will receive the created task handle.

Return Value

  1. pdPASS: The task was successfully created and added to the ready list.
  2. errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY: The task could not be created because there is not enough heap memory available.