A lightweight FreeRTOS C driver that connects the STM32F769I-Discovery board to WiFi using an ESP8266 module over UART5 and AT commands.
| Component | Details |
|---|---|
| STM32F769I-Discovery | Main board |
| ESP8266 module | ESP-01 or any ESP8266 breakout |
| 3.3 V power supply | The ESP8266 must be powered at 3.3 V — do not use 5 V |
| 4 jumper wires | TX, RX, RST, GND |
Important: The STM32F769I-Discovery GPIO pins are 3.3 V. The ESP8266 is also 3.3 V. No level shifter is needed.
STM32F769I-Discovery ESP8266
───────────────────── ───────
PC12 (UART5_TX) ──────► RX
PD2 (UART5_RX) ◄────── TX
PJ14 (GPIO output) ──────► RST
GND ──────► GND
3.3 V ──────► VCC + CH_PD (enable pin)
Pin locations on the Discovery board (UM2033 Table 14):
| Signal | Connector | Pin |
|---|---|---|
| UART5_TX | A | 12 |
| UART5_RX | D | 12 |
| RST GPIO | C | 9 |
CH_PD (also called EN) must be pulled HIGH (3.3 V) for the ESP8266 to turn on.
The ESP8266 is controlled entirely through AT commands sent over UART at 115200 baud. Each command is a plain text string ending with \r\n. The module responds with OK, ERROR, or specific status strings.
Key commands used by this driver:
| AT Command | Purpose |
|---|---|
AT |
Check module is alive |
ATE0 |
Disable echo |
AT+GMR |
Read firmware version |
AT+RST |
Software reset |
AT+CWMODE=1 |
Set station mode (client, not AP) |
AT+CWAUTOCONN=0 |
Disable auto-connect on boot |
AT+CWJAP="ssid","pass" |
Join a WiFi network |
AT+CIFSR |
Read assigned IP address |
esp_init() creates a dedicated FreeRTOS task (ESP, priority 3, 2048-word stack). That task:
- Detects the module — tries baud rates 115200 / 9600 / 57600 / 38400 automatically, resets the module via the RST pin, reads firmware version
- Connects to WiFi — sends
AT+CWJAPand waits up to 30 seconds forWIFI GOT IP - Enters the main loop — listens for runtime reconnect requests on a FreeRTOS queue
All public functions are non-blocking. The caller submits a request to a FreeRTOS queue and returns immediately. The ESP task picks it up in the background.
Your application task ESP task (background)
────────────────────── ──────────────────────────────
esp_connect_wifi_async() ───► puts credentials on wifi_queue
xQueueReceive → wifi_connect_to()
esp_wifi_status() ◄─── reads s_wifi_status (volatile)
The driver writes human-readable status messages to a ring buffer (24 × 80 chars). Poll it from your application with esp_log_read() to display progress on an LCD, serial terminal, or anywhere else.
Edit firmware/esp_config.h:
#define ESP_WIFI_SSID "YourNetworkName"
#define ESP_WIFI_PASS "YourPassword"In your CMakeLists.txt:
target_sources(your_target PRIVATE
firmware/esp8266.c
)
target_include_directories(your_target PRIVATE
firmware/
)#include "esp8266.h"
int main(void)
{
HAL_Init();
esp_init(); // starts the ESP FreeRTOS task
xTaskCreate(your_task, ...);
vTaskStartScheduler();
return 1;
}char log[80];
while (esp_log_read(log, sizeof(log)))
printf("[ESP] %s\r\n", log); // or show on LCD
if (esp_wifi_status() == ESP_WIFI_CONNECTED) {
// WiFi is up — do something
}See examples/connect_wifi/main_example.c for a complete working example.
void esp_init(void);Sets up UART5, GPIO (TX/RX/RST), FreeRTOS queues, and starts the ESP task. Call once before vTaskStartScheduler().
void esp_connect_wifi_async(const char *ssid, const char *password);Submits a WiFi connect request. Non-blocking — the ESP task handles it in the background. Can be called at any time to switch networks.
EspWifiStatus esp_wifi_status(void);Returns the current connection state. Safe to call from any task.
typedef enum {
ESP_WIFI_DISCONNECTED = 0,
ESP_WIFI_CONNECTING,
ESP_WIFI_CONNECTED,
} EspWifiStatus;int esp_log_read(char *buf, int maxLen);Reads one log message from the ring buffer. Returns 1 if a message was available, 0 if the buffer was empty. Call in a loop to drain all pending messages.
| Define | Default | Description |
|---|---|---|
ESP_UART |
UART5 |
UART peripheral |
ESP_TX_PIN / PORT |
PC12 |
UART TX pin |
ESP_RX_PIN / PORT |
PD2 |
UART RX pin |
ESP_RST_PIN / PORT |
PJ14 |
Hardware reset pin |
ESP_BAUD |
115200 |
Initial baud rate (auto-detected if wrong) |
ESP_WIFI_SSID |
"YOUR_WIFI_SSID" |
Network name |
ESP_WIFI_PASS |
"YOUR_WIFI_PASSWORD" |
Network password |
| Symptom | Likely cause | Fix |
|---|---|---|
ESP: Module not found |
Bad wiring or power | Check TX/RX are not swapped; verify 3.3 V on VCC and CH_PD |
WiFi: Wrong credentials |
SSID or password wrong | Double-check esp_config.h |
WiFi: No IP — check network |
Network issue or weak signal | Move closer to the router; check router DHCP |
| Module detected but WiFi never connects | Auto-connect interfering | The driver sends AT+CWAUTOCONN=0 — if a previous firmware had saved credentials these may conflict; flash a clean AT firmware to the ESP8266 |
| No log output | esp_log_read() not being called |
Call it regularly from a task (every 100–500 ms) |
- Board: STM32F769I-Discovery (UM2033)
- Module: ESP-01 (ESP8266 with AT firmware v1.7.x)
- STM32Cube FW: F7 V1.17.2
- FreeRTOS: bundled with STM32Cube F7
- Toolchain: arm-none-eabi-gcc 12.3.1
MIT — free to use, modify, and distribute.