Skip to content

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

STM32F769I-Discovery + ESP8266 WiFi Driver

A lightweight FreeRTOS C driver that connects the STM32F769I-Discovery board to WiFi using an ESP8266 module over UART5 and AT commands.


Hardware Required

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.


Wiring

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.


How It Works

1. AT Commands

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

2. FreeRTOS Task

esp_init() creates a dedicated FreeRTOS task (ESP, priority 3, 2048-word stack). That task:

  1. Detects the module — tries baud rates 115200 / 9600 / 57600 / 38400 automatically, resets the module via the RST pin, reads firmware version
  2. Connects to WiFi — sends AT+CWJAP and waits up to 30 seconds for WIFI GOT IP
  3. Enters the main loop — listens for runtime reconnect requests on a FreeRTOS queue

3. Non-blocking API

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)

4. Log Ring Buffer

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.


Quick Start

Step 1 — Configure credentials

Edit firmware/esp_config.h:

#define ESP_WIFI_SSID   "YourNetworkName"
#define ESP_WIFI_PASS   "YourPassword"

Step 2 — Add files to your build

In your CMakeLists.txt:

target_sources(your_target PRIVATE
    firmware/esp8266.c
)

target_include_directories(your_target PRIVATE
    firmware/
)

Step 3 — Call esp_init() before vTaskStartScheduler()

#include "esp8266.h"

int main(void)
{
    HAL_Init();
    esp_init();                     // starts the ESP FreeRTOS task
    xTaskCreate(your_task, ...);
    vTaskStartScheduler();
    return 1;
}

Step 4 — Poll status from your task

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.


API Reference

Initialisation

void esp_init(void);

Sets up UART5, GPIO (TX/RX/RST), FreeRTOS queues, and starts the ESP task. Call once before vTaskStartScheduler().


WiFi

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;

Logging

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.


Configuration Reference (esp_config.h)

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

Troubleshooting

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)

Tested On

  • 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

License

MIT — free to use, modify, and distribute.

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages