In this tutorial, we’ll discuss STM32 WiFi and every practical way to connect an STM32 microcontroller to a WiFi network. You’ll learn why STM32 microcontrollers don’t have WiFi built in, the four architectures you can choose from, and how the WiFi modules used with STM32 (ESP32-C3, ESP-01 / ESP8266, ST’s new ST67W611M1, WizFi360, and others) compare to each other.
Then, we’ll get an STM32 Blue Pill online with an ESP32-C3 WiFi co-processor and a few AT commands, and we’ll measure how the ESP32-C3 and the ESP8266 compare on the bench. This is the first part of our STM32 WiFi tutorial series, where we’ll build HTTP clients, a web server, MQTT, WebSocket, and OTA updates on top of it. Without further ado, let’s get right into it!
Does STM32 Have WiFi?
No STM32 microcontroller has WiFi built in. To add WiFi to an STM32, you connect a WiFi module (a co-processor) that runs the radio and, in most cases, the whole TCP/IP stack too. The STM32 talks to it over UART, SPI, or SDIO. For most projects (and for this tutorial series), the simplest option is an ESP32-C3 running Espressif’s ESP-AT firmware on a UART: it works with any STM32, even a Blue Pill, and the STM32 only sends short text commands like AT+CWJAP. ST’s own option is the ST67W611M1 Wi-Fi 6 module, controlled with AT commands over SPI.
Note: ST’s wireless STM32 microcontrollers (the W series) don’t do WiFi either: the STM32WB and STM32WBA are Bluetooth LE and IEEE 802.15.4 (Zigbee, Thread, Matter), and the STM32WL is a sub-GHz radio for LoRa. The STM32MP1 and STM32MP2 are microprocessors that run Linux, and their WiFi also comes from a separate chip.
Note: The STM32 code examples in this tutorial are tested with: STM32 Blue Pill (STM32F103C8T6), ESP32-C3, and ESP8266 with ESP-AT firmware.
How to Add WiFi to STM32: The 4 Architectures
Every way of connecting an STM32 to a network comes down to one question: where does the TCP/IP stack run? On the WiFi module, on the STM32 itself, on a Linux processor, or in a hardwired Ethernet chip. That one choice decides how much flash, RAM, and code the STM32 has to spend on networking, which is why it’s the first thing to settle before you pick a module.

1. AT Command WiFi Co-Processor (UART)
The WiFi module runs the radio, the TCP/IP stack, TLS, and even MQTT and HTTP clients. The STM32 sends it plain-text AT commands over a UART ( AT+CWJAP="MyWiFi","password" to join a network, AT+CIPSTART to open a TCP connection, and so on) and gets text replies like OK or WIFI GOT IP. The STM32 needs only a UART and a small command driver, so this works on the smallest STM32 parts. This is the approach of the ESP32-C3 and ESP32 with ESP-AT, the ESP-01 (ESP8266), the WizFi360, and the ST67W611M1 in its “LwIP off-load” mode (ST calls it architecture T01, with AT commands over SPI).
2. Network Co-Processor (SPI / SDIO)
The WiFi module only handles the radio and the WiFi link, and passes raw network packets to the STM32 over SPI or SDIO. The STM32 runs the TCP/IP stack (usually LwIP), TLS (Mbed TLS), and a host driver, mostly on top of an RTOS. You get full control and standard sockets, but you need a bigger STM32 (F4, F7, H5, H7, U5) and a lot more firmware. Examples: Espressif’s ESP-Hosted, Murata and Infineon CYW43xxx modules, and the ST67W611M1 in its “LwIP on host” mode (architecture T02).
3. Linux Microprocessor + WiFi Chip
The STM32MP1 and STM32MP2 run embedded Linux, so WiFi works like on any Linux board: a WiFi chip on SDIO or USB with a Linux driver, and the Linux network stack. ST’s STM32MP157C-DK2 kit, for example, carries a Murata WiFi/Bluetooth module. This is a different world from microcontroller firmware, so we’ll leave it out of this series.
4. Wired Ethernet (When WiFi Isn’t a Must)
If the device can reach the router with a cable, Ethernet is simpler and more reliable than any radio. The WIZnet W5500 has a hardware TCP/IP stack and connects to any STM32 over SPI, while larger STM32 parts (F4, F7, H7) have an Ethernet MAC and only need a PHY chip like the LAN8720 plus LwIP.
STM32 WiFi Modules Compared
Here is how the WiFi options you’ll find for STM32 compare. “Works with a Blue Pill” means it runs with an STM32F103C8T6 (64KB flash, 20KB RAM) without an RTOS or a TCP/IP stack on the STM32.
| WiFi Option | Interface to STM32 | TCP/IP + TLS Runs On | WiFi Standard | Works With a Blue Pill? | Notes |
|---|---|---|---|---|---|
| ESP32-C3 + ESP-AT | UART (AT commands) | Module | 802.11 b/g/n, 2.4GHz | Yes | Current Espressif AT firmware, cheap tiny boards, also has BLE. Used in this series. |
| ESP-01 (ESP8266) + AT | UART (AT commands) | Module | 802.11 b/g/n, 2.4GHz | Yes | Cheapest and most common in old tutorials. Needs a 3.3V supply that can deliver its current peaks. Also covered in this series. |
| ST67W611M1 (ST + Qualcomm) | SPI (AT commands) | Module (T01) or STM32 with LwIP (T02) | Wi-Fi 6 (802.11 b/g/n/ax), 2.4GHz + BLE 5.4 | No (ST’s package targets U5, H5, H7S, N6 Nucleo boards) | ST’s official STM32 WiFi path: X-CUBE-ST67W61 software and the X-NUCLEO-67W61M1 expansion board |
| WizFi360 (WIZnet) | UART (AT commands) | Module | 802.11 b/g/n, 2.4GHz | Yes | AT command WiFi module from the maker of the W5500 |
| ESP-Hosted (ESP32-C3/C6 …) | SPI / SDIO / UART | STM32 (host) | Depends on the ESP chip | No | Turns an ESP32 into a network co-processor; the host runs the network stack |
| Murata / Infineon CYW43xxx | SDIO / SPI | STM32 (host) | 802.11 b/g/n (ac on some) | No | Certified modules for products; needs a big STM32, an RTOS and LwIP |
| Inventek ISM43362 | SPI (AT-style commands) | Module | 802.11 b/g/n, 2.4GHz | Possible | The WiFi module on ST’s B-L475E-IOT01A Discovery kit |
| W5500 Ethernet (no WiFi) | SPI | W5500 chip (hardwired) | 10/100 Ethernet | Yes | Choose it when a cable to the router is acceptable |
Which WiFi Module Should You Pick for STM32?

- Learning, hobby projects, or a small STM32: an ESP32-C3 with ESP-AT over UART. It’s cheap, current, and Espressif still releases new AT firmware for it.
- You already have an ESP-01: it works with exactly the same AT commands for the basics, as long as you give it a proper 3.3V supply.
- A product built on a bigger STM32 that has to stay inside ST’s ecosystem: the ST67W611M1 with X-CUBE-ST67W61.
- You need sockets and LwIP on the STM32 itself: a network co-processor (ESP-Hosted, ST67W611M1 in T02 mode, CYW43xxx).
- The device sits next to the router: Ethernet with a W5500.
STM32 + ESP32-C3 vs STM32 + ESP8266 (ESP-01)
Both modules speak Espressif’s AT command set over a UART, so the STM32 side is almost the same for both. The differences are in the module itself:

The ESP8266 connects the same way: its TX to PA10 and its RX to PA9, plus a common ground. Its VCC and CH_PD (enable) pins go to 3.3V. The Blue Pill’s 3.3V pin can feed it, as long as the Blue Pill itself is powered from its USB port and not from the ST-Link’s 3.3V pin. On the common 2×4 breadboard adapters, CH_PD (EN) is not pulled up, so you must wire it to 3.3V yourself, or the module stays off, and its TX line sits low:
PA9 USART1 TX, goes to the ESP8266 RX.
PA10 USART1 RX, goes to the ESP8266 TX.
3.3V Goes to the ESP8266 VCC and CH_PD (EN) pins (Blue Pill powered from its USB port).
GND Goes to the ESP8266 GND: common ground.

| ESP32-C3 (ESP-AT) | ESP-01 (ESP8266 AT) | |
|---|---|---|
| CPU | 32-bit RISC-V, up to 160MHz | 32-bit Tensilica L106, 80/160MHz |
| Radio | WiFi 802.11 b/g/n + Bluetooth LE 5 | WiFi 802.11 b/g/n |
| AT command port | UART1: GPIO6 (RX), GPIO7 (TX), optional RTS/CTS on GPIO4/GPIO5 | UART0: the TX and RX pins of the 8-pin header |
| Boot and log output | UART0 / USB, separate from the AT port | Same UART as the AT port (boot messages at 74880 baud) |
| Current AT firmware | ESP-AT v4.x (v4.1.1.0 is a direct download, v4.2.0.0 is on request from Espressif) | ESP8266 AT branch, v2.3.0.0 (Aug 2025), for 2MB+ flash modules; many 1MB ESP-01 boards ship with older 1.x AT firmware |
| Flashing new firmware | Over USB on most C3 boards | Needs a USB-UART adapter and GPIO0 pulled low |
We use the ESP32-C3 first in this series because its AT port is separate from its boot output (so the STM32 never sees boot garbage), it can be reflashed over plain USB, and it runs the current ESP-AT releases. The ESP8266 is further discussed in the ESP8266 AT commands with STM32 tutorial, because it’s still the module most people already have in a drawer.
Measured: Connect Time, Ping, and Throughput
To compare them on real hardware, the same Blue Pill ran the same benchmark firmware with each module: the time from AT+RST to ready, the time to join the WiFi network ( AT+CWJAP, 5 runs), the ping round trip to a PC on the same network ( AT+PING, 10 runs), and the TCP upload speed (64KB in 1KB AT+CIPSEND blocks) at 115200 and 921600 baud.
| Measurement (Blue Pill + module, ESP AT firmware) | ESP32-C3 (ESP-AT v4.1.1.0) | ESP-01 (ESP8266 AT 0.21.0.0, SDK 0.9.5) |
|---|---|---|
| Boot: AT+RST until the module answers AT again | 1.22 s | about 0.05 s (this old firmware answers AT almost at once after AT+RST) |
| Join WiFi (AT+CWJAP until OK), 20 runs | 1.11 to 1.96 s (average 1.40 s) | 3.09 to 5.09 s, 7 of 10 runs joined (AT 0.21.0.0) |
| Ping to the WiFi router (AT+PING), 10 per run | 4 to 6 ms average, 40/40 replies | not available: AT+PING does not exist in AT 0.21 |
| TCP upload at 115200 baud (64KB in 1KB AT+CIPSEND blocks) | 9.9 to 10.0 KB/s | not measured: the TCP test did not run on AT 0.21 |
| TCP upload at 921600 baud | 46.7 to 47.5 KB/s | not available: AT+UART_CUR does not exist in AT 0.21 |
The ESP8266 in our test still runs the AT firmware it shipped with, version 0.21.0.0 on SDK 0.9.5 (from 2015). It joins the network in 3 to 5 seconds, fails to join in some runs, and doesn’t have AT+PING or AT+UART_CUR at all. Most ESP8266 modules sold today are similar, which is the strongest reason to start with an ESP32-C3. We’ll update the ESP-01’s firmware in the ESP8266 part of this series and compare it again.
The upload speed at 115200 baud is limited by the UART, not the WiFi: 115200 baud carries at most 11.5KB/s (10 bits per byte), and the AT command overhead takes part of that. Raising the AT UART baud rate is the first thing to do when an STM32 application needs to move more data.
STM32 WiFi Example: Blue Pill + ESP32-C3 (AT Commands)
Now let’s get an STM32 online. In this example, the Blue Pill sends a handful of AT commands to an ESP32-C3 to join your WiFi network, prints every reply on a serial terminal, turns on its on-board LED when it gets an IP address, and then pings a server every 5 seconds to show that the link is alive.
Required Parts
| QTY. | Component Name | Amazon.com | AliExpress |
|---|---|---|---|
| 1 | STM32 Blue Pill (STM32F103C8T6) | Amazon | AliExpress |
| 1 | ST-Link V2 Debugger | Amazon | AliExpress |
| 1 | ESP32-C3 board (ESP32-C3 SuperMini; we use the WeAct ESP32-C3 Core Board) | Amazon | AliExpress |
| 1 | ESP-01 (ESP8266) module + breadboard adapter (optional, for the comparison) | Amazon | AliExpress |
| 1 | USB-TTL (UART) Converter, 3.3V | Amazon | AliExpress |
| 1 | BreadBoard | Amazon | AliExpress |
| 1 | Jumper Wires Pack | Amazon | AliExpress |
STM32 ESP32-C3 Wiring
Connect the STM32’s USART1 to the ESP32-C3’s AT port (UART1), and USART2’s TX pin to your USB-UART adapter for the log (see the Blue Pill pinout for the pin locations, and the STM32 USB-TTL converter tutorial if you haven’t used one before). Remember that TX goes to RX and RX goes to TX, and that the grounds must be connected.
PA9 USART1 TX, goes to the ESP32-C3 GPIO6 (AT RX): AT commands from the STM32 to the module.
PA10 USART1 RX, goes to the ESP32-C3 GPIO7 (AT TX): the module’s replies and events.
PA2 USART2 TX, goes to the USB-UART adapter’s RX: the log to your PC at 115200 baud.
GND Goes to the ESP32-C3 GND and the USB-UART GND: common ground.
| Blue Pill Pin | Connects To | Purpose |
|---|---|---|
| PA9 (USART1 TX) | ESP32-C3 GPIO6 (AT RX) | Commands to the module |
| PA10 (USART1 RX) | ESP32-C3 GPIO7 (AT TX) | Replies from the module |
| GND | ESP32-C3 GND | Common ground |
| PA2 (USART2 TX) | USB-UART RX | Log to your PC (115200 baud) |
| GND | USB-UART GND | Common ground |

The ST-Link stays on the Blue Pill’s SWD header (SWDIO, SWCLK, GND) as usual and isn’t shown in the diagram.

Note: Power the ESP32-C3 board from its own USB port (or 5V on its 5V pin), and power the Blue Pill from its micro-USB port, not from the ST-Link’s 3.3V pin. The ST-Link’s 3.3V output can’t carry a WiFi module’s transmit current peaks, and the Blue Pill’s supply sags with it.
Flash the ESP-AT Firmware on the ESP32-C3
A new ESP32-C3 board doesn’t come with the AT firmware. Download the ESP32-C3 AT firmware from Espressif’s ESP-AT releases (for this tutorial: ESP32-C3-MINI-1-AT-V4.1.1.0.zip), connect the board to your PC with USB, and write the single factory image to address 0x0 with esptool:
|
1 |
esptool --chip esp32c3 --port COM5 --baud 460800 write_flash 0x0 factory/factory_MINI-1.bin |
Replace COM5 with your board’s port. If you have the Arduino ESP32 core installed, esptool is already on your PC (in the core’s tools/esptool_py folder). The AT firmware listens on UART1 (GPIO6 RX, GPIO7 TX) at 115200 baud, as listed in Espressif’s ESP32-C3 AT hardware connection guide. We’ll cover the AT firmware, its versions, and the web flasher in detail in the ESP32 AT commands with STM32 tutorial.
To check the firmware, connect a USB-UART adapter to GPIO6/GPIO7 and send AT+GMR, or just run the example below, which prints it. Our WeAct ESP32-C3 Core Board replied with:
|
1 2 3 4 5 6 |
AT version:4.1.1.0(ba4dd0e - ESP32C3 - Jul 31 2025 08:38:07) SDK version:v5.4.1-643-g8ad0d3d8f2-dirty compile time(7c092f9a):Aug 1 2025 05:35:19 Bin version:v4.1.1.0(MINI-1) OK |
STM32 CubeMX Configuration Steps
#1
Open STM32CubeMX, create a new project, and select the STM32F103C8T6 in the MCU selector
#2
Set SYS > Debug to Serial Wire (so the board stays programmable over SWD)

#3
Set RCC > High Speed Clock (HSE) to Crystal/Ceramic Resonator, and set HCLK to 72MHz in the Clock Configuration tab


#4
Enable USART1 in Asynchronous mode (115200 baud, 8N1) and enable the USART1 global interrupt in its NVIC Settings tab


#5
Enable USART2 in Asynchronous mode (115200 baud, 8N1) for the log

#6
Set PC13 as GPIO_Output with the user label LED_ONBOARD (the Blue Pill’s on-board LED)

Here’s the finished pin configuration: USART1 on PA9 (TX) and PA10 (RX) for the ESP32-C3, USART2 on PA2 (TX) and PA3 (RX) for the log, and PC13 driving the on-board LED.

#7
In Project Manager, name the project, set the Toolchain/IDE to STM32CubeIDE, and click Generate Code

STM32 WiFi Example Code (ESP32-C3 AT Commands)
Create a wifi_secrets.h file in Core/Inc with your WiFi name and password:
|
1 2 3 4 5 6 7 8 9 10 11 |
/* * wifi_secrets.h * Your WiFi network name and password. Keep this file out of any project you share. */ #ifndef WIFI_SECRETS_H_ #define WIFI_SECRETS_H_ #define WIFI_SSID "YOUR_WIFI_NAME" #define WIFI_PASSWORD "YOUR_WIFI_PASSWORD" #endif /* WIFI_SECRETS_H_ */ |
Then add the following code to main.c, inside the matching USER CODE sections (the rest of the file is generated by CubeMX):
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
/* USER CODE BEGIN Includes */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "wifi_secrets.h" /* USER CODE END Includes */ /* USER CODE BEGIN 0 */ /*--------------------------------------------------------------------------- * Minimal AT command helper (quick-start code, blocking with timeouts). * USART1 talks to the ESP module, USART2 prints the log to your PC. * Received bytes from the ESP go into a ring buffer from the UART interrupt, * so nothing is lost while the main code is busy printing. *---------------------------------------------------------------------------*/ #define AT_RX_BUF_SIZE 1024 static uint8_t rxByte; static uint8_t rxRing[AT_RX_BUF_SIZE]; static volatile uint16_t rxHead = 0; // written by the UART interrupt static uint16_t rxTail = 0; // read by the main code static char atReply[AT_RX_BUF_SIZE]; static uint16_t atReplyLen = 0; static uint32_t atLastTime_ms = 0; // how long the last command took void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { if (huart->Instance == USART1) { rxRing[rxHead] = rxByte; rxHead = (rxHead + 1) % AT_RX_BUF_SIZE; HAL_UART_Receive_IT(&huart1, &rxByte, 1); } } void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) { if (huart->Instance == USART1) { /* An overrun or noise error stops the reception, so start it again */ HAL_UART_Receive_IT(&huart1, &rxByte, 1); } } static void Log(const char *text) { HAL_UART_Transmit(&huart2, (uint8_t *)text, strlen(text), 1000); } static void AT_Flush(void) { rxTail = rxHead; } static void AT_Write(const uint8_t *data, uint16_t len) { HAL_UART_Transmit(&huart1, (uint8_t *)data, len, 1000); } static int EndsWith(const char *text, uint16_t len, const char *tail) { uint16_t n = strlen(tail); return (len >= n) && (memcmp(text + len - n, tail, n) == 0); } /* * Wait until the reply contains 'expect' (or ends with OK / ERROR / FAIL when expect is NULL). * Returns 1 on success, 0 on ERROR/FAIL, -1 on timeout. The reply text is kept in atReply. */ static int AT_WaitFor(const char *expect, uint32_t timeout_ms) { uint32_t t0 = HAL_GetTick(); atReplyLen = 0; atReply[0] = 0; while ((HAL_GetTick() - t0) < timeout_ms) { while (rxTail != rxHead) { char c = rxRing[rxTail]; rxTail = (rxTail + 1) % AT_RX_BUF_SIZE; if (atReplyLen < AT_RX_BUF_SIZE - 1) { atReply[atReplyLen++] = c; atReply[atReplyLen] = 0; } if (expect != NULL) { if (strstr(atReply, expect)) { atLastTime_ms = HAL_GetTick() - t0; return 1; } } else if (EndsWith(atReply, atReplyLen, "OK\r\n")) { atLastTime_ms = HAL_GetTick() - t0; return 1; } if (EndsWith(atReply, atReplyLen, "ERROR\r\n") || EndsWith(atReply, atReplyLen, "FAIL\r\n")) { atLastTime_ms = HAL_GetTick() - t0; return 0; } } } atLastTime_ms = HAL_GetTick() - t0; return -1; } /* Send one command (without \r\n) and wait for its final OK / ERROR */ static int AT_Command(const char *cmd, uint32_t timeout_ms) { AT_Flush(); AT_Write((const uint8_t *)cmd, strlen(cmd)); AT_Write((const uint8_t *)"\r\n", 2); return AT_WaitFor(NULL, timeout_ms); } /* Print a command, its reply and the result line on the log UART */ static int AT_CommandLog(const char *cmd, const char *shownAs, uint32_t timeout_ms) { char line[96]; int r = AT_Command(cmd, timeout_ms); Log("> "); Log(shownAs ? shownAs : cmd); Log("\r\n"); Log(atReply); snprintf(line, sizeof(line), "[%s in %lu ms]\r\n\r\n", (r == 1) ? "OK" : (r == 0) ? "ERROR" : "TIMEOUT", (unsigned long)atLastTime_ms); Log(line); return r; } /* USER CODE END 0 */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ char cmd[128]; /* Start receiving from the ESP module, one byte per interrupt */ HAL_UART_Receive_IT(&huart1, &rxByte, 1); Log("\r\nSTM32 WiFi Quick Start (Blue Pill + ESP AT module)\r\n\r\n"); /* 1. Wait until the module answers "AT" (it needs a moment after power-up) */ while (AT_Command("AT", 500) != 1) { Log("Waiting for the ESP module...\r\n"); } /* 2. Stop the module from echoing our commands, then read its firmware version */ AT_CommandLog("ATE0", NULL, 1000); AT_CommandLog("AT+GMR", NULL, 1000); /* 3. Station mode, then join the WiFi network (this can take a few seconds) */ AT_CommandLog("AT+CWMODE=1", NULL, 1000); snprintf(cmd, sizeof(cmd), "AT+CWJAP=\"%s\",\"%s\"", WIFI_SSID, WIFI_PASSWORD); if (AT_CommandLog(cmd, "AT+CWJAP=\"<your WiFi>\",\"********\"", 20000) == 1) { /* Connected: on-board LED on (PC13 is active low) */ HAL_GPIO_WritePin(LED_ONBOARD_GPIO_Port, LED_ONBOARD_Pin, GPIO_PIN_RESET); /* 4. Read the IP address the router gave us */ AT_CommandLog("AT+CIPSTA?", NULL, 1000); } else { Log("Could not join the network. Check WIFI_SSID / WIFI_PASSWORD in wifi_secrets.h\r\n"); } /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ /* Ping a server every 5 seconds to show the link is alive */ AT_CommandLog("AT+PING=\"www.google.com\"", NULL, 5000); HAL_Delay(5000); } /* USER CODE END 3 */ } |
STM32 WiFi Code Explanation
The ESP module can send bytes at any time (replies, but also messages like WIFI DISCONNECT), so the code never waits for a fixed number of bytes. Every byte from USART1 lands in a ring buffer from the UART receive interrupt ( HAL_UART_RxCpltCallback re-arms a 1-byte HAL_UART_Receive_IT each time), and the main code reads from that buffer whenever it wants. That way, nothing is lost while the STM32 is busy printing the log on USART2. If an overrun error stops the reception, HAL_UART_ErrorCallback simply starts it again.
AT_Command() sends one command followed by \r\n and collects the reply until it ends with OK, ERROR, or FAIL, or until the timeout expires. AT_CommandLog() does the same and prints the command, the reply, the result, and how long it took. Notice that joining the network gets a 20-second timeout, because AT+CWJAP only answers after the module has associated with the router and received an IP address from DHCP.
The sequence in main() is the minimum every STM32 WiFi application goes through:
| Command | What It Does | Expected Reply |
|---|---|---|
AT | Checks that the module is alive (retried until it answers) | OK |
ATE0 | Turns off the command echo, so replies contain only the answer | OK |
AT+GMR | Reads the AT firmware version | AT version, SDK version, OK |
AT+CWMODE=1 | Station mode (the module joins a router, it doesn’t create a network) | OK |
AT+CWJAP="ssid","pwd" | Joins your WiFi network | WIFI CONNECTED, WIFI GOT IP, OK |
AT+CIPSTA? | Reads the IP address, gateway and netmask | +CIPSTA:ip:"192.168.x.x"… |
AT+PING="www.google.com" | Pings a host on the internet | +PING:<time in ms>, OK |
Tip: This quick-start code is deliberately short and blocking, so you can see every AT exchange. In the next parts of this series, we’ll replace it with our own non-blocking ESP-AT driver (UART DMA + IDLE line detection, timeouts, events, automatic reconnect), the way it should be done in a real STM32 application.
STM32 WiFi Example Testing
Flash the code, open a serial terminal on the USB-UART adapter’s port at 115200 baud, and reset the Blue Pill. You should see each command with its reply, the IP address your router gave the module, and then a ping every 5 seconds:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
STM32 WiFi Quick Start (Blue Pill + ESP AT module) > ATE0 OK [OK in 3 ms] > AT+GMR AT version:4.1.1.0(ba4dd0e - ESP32C3 - Jul 31 2025 08:38:07) SDK version:v5.4.1-643-g8ad0d3d8f2-dirty compile time(7c092f9a):Aug 1 2025 05:35:19 Bin version:v4.1.1.0(MINI-1) OK [OK in 18 ms] > AT+CWMODE=1 OK [OK in 3 ms] > AT+CWJAP="<your WiFi>","********" WIFI DISCONNECT WIFI CONNECTED WIFI GOT IP OK [OK in 1125 ms] > AT+CIPSTA? +CIPSTA:ip:"192.168.1.200" +CIPSTA:gateway:"192.168.1.1" +CIPSTA:netmask:"255.255.255.0" OK [OK in 12 ms] > AT+PING="www.google.com" +PING:44 OK [OK in 1061 ms] > AT+PING="www.google.com" +PING:46 OK [OK in 1007 ms] > AT+PING="www.google.com" +PING:65 OK [OK in 1007 ms] > AT+PING="www.google.com" +PING:46 OK [OK in 1007 ms] |
The module joined the network in about 1.1 seconds, and the router gave it an IP address. The first WIFI DISCONNECT line is normal when the module was already connected from an earlier run: joining a network drops the old connection first. Also notice that each AT+PING takes about 1 second to answer even though the ping itself took 44 to 65ms. ESP-AT v4.1.1.0 sends the reply only after that 1-second window, so don’t use AT+PING to time anything.
Here’s what the exchange looks like on the wires. CH1 (yellow) is PA9, the STM32’s TX line to the ESP32-C3, and CH3 (blue) is PA10, the module’s reply line. The AT+PING="www.google.com" command is 25 bytes, and at 115200 baud it takes 2.2ms on the wire. The reply (16 bytes: +PING:44 and OK) arrives 1 second later and takes 1.4ms:
That’s the real speed limit of the AT approach: at 115200 baud, every byte takes 87µs (10 bits). Short commands and replies don’t matter, but bulk data does, which is why the benchmark below also tests 921600 baud.
STM32 WiFi Troubleshooting
The ESP module doesn’t answer “AT”
Check, in this order: TX and RX are crossed (STM32 TX to module RX), the grounds are connected, you’re on the right module UART (on the ESP32-C3 the AT port is GPIO6/GPIO7, not the USB port or GPIO20/21), the baud rate is 115200, and the module really has the AT firmware (a new ESP32-C3 board usually runs a demo sketch). Connect the module’s AT port to a USB-UART adapter and type AT from a serial terminal (with CR+LF line endings) to check the module on its own.
AT+CWJAP returns FAIL or ERROR
The reply +CWJAP:<code> tells you why: 1 = connection timeout, 2 = wrong password, 3 = the network (SSID) wasn’t found, 4 = connection failed. Most ESP modules are 2.4GHz only, so they can’t see a 5GHz-only network. Also check that your SSID and password don’t contain characters that need escaping in AT commands (commas, double quotes, and backslashes must be escaped with a backslash).
The module keeps printing WIFI DISCONNECT / WIFI CONNECTED
This is usually power. A WiFi module pulls short current peaks when it transmits, and a weak 3.3V supply sags and resets the radio. Power the module from its own USB or regulator, keep the wires short, and add a bulk capacitor (100µF or more) close to the module’s 3.3V pin.
The ESP-01 never answers, and its TX line stays low
On the plain 2×4 breadboard adapters, the CH_PD (EN) pin of the ESP-01 is left floating, so the chip never starts. Wire CH_PD to 3.3V. A running ESP-01 holds its TX line high (idle) between bytes. If the STM32 receives only 0x00 bytes, the line is low most of the time, or the module talks at a slower baud rate than the STM32 (older ESP-01 firmware is often set to 9600 baud).
Garbage characters at power-up (ESP-01)
The ESP8266 prints its boot messages at 74880 baud on the same UART as the AT port, so the STM32 receives a burst of unreadable bytes right after power-up. Ignore everything until the module prints ready, or until it answers AT (that’s what the retry loop in the example does).
Replies get cut off or bytes go missing
Don’t read the module’s UART with blocking HAL_UART_Receive calls between other work, because the module doesn’t wait for you. Receive with an interrupt or DMA into a buffer, like the example does. At higher baud rates (921600), use DMA with IDLE line detection.
STM32 WiFi FAQ
Can STM32 connect to WiFi?
Yes, with an external WiFi module. The STM32 controls the module over UART, SPI, or SDIO, and the module handles the radio (and usually the TCP/IP stack). The simplest combination is an ESP32-C3 or ESP-01 with AT firmware on a UART.
Which STM32 has WiFi built in?
None. ST’s wireless STM32 microcontrollers (STM32WB, STM32WBA, STM32WL) support Bluetooth LE, 802.15.4, and sub-GHz/LoRa, not WiFi. ST’s WiFi solution is the separate ST67W611M1 module.
Is STM32 better than ESP32 for WiFi projects?
For a project that is mostly about WiFi, an ESP32 on its own is simpler, because the WiFi is on the chip (see our ESP32 WiFi library tutorial). An STM32 makes sense when the project needs what STM32 parts do best (advanced timers, motor control, precise ADCs, CAN, low-power modes, long-term availability, or an existing STM32 design) and WiFi is one feature among others. Then the STM32 runs the application and an ESP32-C3 handles WiFi.
Can I use SPI instead of UART to connect the WiFi module?
Yes. ESP-AT also supports SPI and SDIO as the AT command interface on some chips (it needs a custom ESP-AT build), the ST67W611M1 uses SPI, and network co-processors like ESP-Hosted use SPI or SDIO. UART is the easiest to start with, and at 921600 baud or more it’s fast enough for most sensor and control applications.
Does the STM32 need LwIP or FreeRTOS for WiFi?
Not with an AT command module. The module runs the TCP/IP stack, so a bare-metal STM32 is enough. You need LwIP (and usually an RTOS) only with a network co-processor, where the STM32 itself handles TCP/IP.
Can an STM32 Blue Pill do HTTPS?
Yes, through the module. ESP-AT has SSL/TLS connections and an HTTP client built in, so the TLS work happens on the ESP32-C3, not on the Blue Pill’s 20KB of RAM. The STM32 HTTP client tutorial shows HTTPS GET and POST requests from a Blue Pill.
Is the ESP8266 still supported?
Yes. Espressif keeps a separate ESP8266 AT branch (v2.3.0.0 was released in August 2025). New designs are better off with an ESP32-C3, which is just as cheap and gets the main ESP-AT releases.
Can STM32 do WiFi 6?
Yes, with ST’s ST67W611M1 module (802.11ax on 2.4GHz, plus Bluetooth LE 5.4), which is controlled from the STM32 over SPI.
Can STM32 use Bluetooth instead?
Yes. For a short-range wireless link to a phone or a PC, a Bluetooth module is simpler than WiFi. See the STM32 HC-05 Bluetooth module tutorial, or use an STM32WB / STM32WBA, which have Bluetooth LE built in.
STM32 WiFi Tutorial Series
This tutorial is the first part of our STM32 WiFi tutorial series. Each part builds one complete, tested project with an STM32 Blue Pill and an ESP WiFi module, using our own plain-C ESP-AT driver:
| Part | Tutorial | What You’ll Build |
|---|---|---|
| 1 | STM32 WiFi (this tutorial) | Choosing a WiFi module, quick start, ESP32-C3 vs ESP-01 measured |
| 2 | ESP8266 AT Commands With STM32 | ESP8266 AT firmware, commands, and our ESP_AT driver |
| 3 | ESP32 AT Commands (ESP-AT) With STM32 | ESP-AT firmware, commands, SNTP time, and our ESP_AT driver |
| 4 | STM32 HTTP Client Over WiFi | GET, POST, HTTPS, and JSON parsing |
| 5 | STM32 Web Server | Control GPIOs and read sensors from a browser |
| 6 | STM32 MQTT | Publish and subscribe, Home Assistant |
| 7 | STM32 OTA Firmware Update | Update the STM32’s firmware over WiFi |
| 8 | STM32 WebSocket | Real-time data with an ESP32 smart bridge |
Download STM32 WiFi Example Projects (ESP32-C3 / ESP-01 AT)
Download all attachment files for this Article/Tutorial (project files, schematics, code, etc.) using the link below. Everything is tested and verified to work on real hardware, as you’ve seen in the demo videos & screenshots. Please consider supporting my work if it helped you.
Wrap Up
To conclude this tutorial, we’ve seen that STM32 microcontrollers don’t have WiFi built in, and that the four ways of connecting them to a network differ in where the TCP/IP stack runs. For most STM32 projects, a WiFi co-processor running AT firmware over a UART is the fastest and lightest route, and the ESP32-C3 is the module we recommend for it. We got a Blue Pill online with a few AT commands, and measured how the ESP32-C3 and the ESP-01 compare.
In the next parts of this series, we’ll build our own non-blocking ESP-AT driver and use it for HTTP, a web server, MQTT, OTA updates, and WebSocket. If you’re new to the STM32 UART, the STM32 UART tutorial and the STM32 UART IDLE line detection tutorial are a good place to start, since everything in this series runs over a UART.