ESP8266 AT Commands With STM32 – WiFi Tutorial

In this tutorial, we’ll discuss how to use the ESP8266 AT commands with STM32 microcontrollers to connect an STM32 to a WiFi network. You’ll learn how the ESP8266 works as a WiFi co-processor, how to check which AT firmware your ESP8266 module is running and how to update it, how to wire the ESP8266 to an STM32 Blue Pill, and how to configure the STM32 UART with DMA in CubeMX to talk to it.

Then, we’ll build three STM32 ESP8266 example projects with our own non-blocking ESP-AT driver: talking to the module, joining a WiFi network with automatic reconnection, and a TCP client that sends and receives data. We’ll also measure the old and the updated ESP8266 AT firmware on the bench, and finish with a complete ESP8266 AT commands list with the real replies from our module. This is the second part of our STM32 WiFi tutorial series. Without further ado, let’s get right into it!

STM32 WiFi Tutorial Series: Part 2 of 8
1 STM32 WiFi2 STM32 ESP82663 STM32 ESP32-C34 HTTP Client5 Web Server6 MQTT7 OTA Update8 WebSocket

Note: The STM32 code examples in this tutorial are tested with: STM32 Blue Pill (STM32F103C8T6), ESP8266 (ESP-01, 1MB) with ESP8266 NonOS AT firmware.


STM32 ESP8266 WiFi: How It Works

The ESP8266 is a WiFi chip with its own processor, RAM, and TCP/IP stack. When it runs Espressif’s AT firmware, it behaves like a WiFi modem: the STM32 sends it text commands over a UART ( AT+CWJAP="MyWiFi","password" to join a network, AT+CIPSTART to open a TCP connection, AT+CIPSEND to send data), and the ESP8266 answers with text replies ( OK, ERROR, +IPD,... for received data).

This means the STM32 doesn’t need a TCP/IP stack, an RTOS, or a lot of RAM. A Blue Pill with 20KB of RAM can run a WiFi application, because all the networking happens inside the ESP8266. The price is speed and control: everything goes through one UART, and the STM32 only gets the features the AT firmware offers. We compared this approach with the other ways of adding WiFi to an STM32 in the STM32 WiFi guide, which is the first part of this series.

STM32 ESP8266 WiFi architecture: the STM32 application and ESP_AT driver talk over UART to the ESP8266 AT firmware, which runs the TCP/IP stack and the WiFi radio


ESP8266 AT Firmware Versions: Which One Is on Your Module?

Before writing any STM32 code, check the AT firmware on your ESP8266 module. ESP8266 modules have been sold since 2014, and the AT firmware they ship with differs a lot: an old module may not support half of the commands in this tutorial, and it may not even talk at the baud rate you expect. There are three generations of ESP8266 AT firmware:

AT FirmwareBuilt OnFlash NeededAT Port (UART)Notes
AT 0.2x (2014 to 2015)ESP8266 SDK 0.9.x512KBGPIO1 (TX), GPIO3 (RX)No AT+PING, no AT+UART_CUR, no _CUR/_DEF commands. Often set to 9600 baud
NonOS AT 1.x (up to v1.7.6, June 2024)ESP8266 NonOS SDK (last: v3.0.6)1MB or moreGPIO1 (TX), GPIO3 (RX)The best fit for 1MB ESP8266 modules. 115200 baud
ESP-AT 2.x for ESP8266 (v2.2.x, v2.3.0.0)ESP8266 RTOS SDK2MB or moreGPIO15 (TX), GPIO13 (RX)Same command set as the ESP32 ESP-AT. The AT port moves to GPIO13/GPIO15, which the common 8-pin modules don’t break out

The ESP8266 AT 2.x firmware uses GPIO13 and GPIO15 for the AT commands, as listed in Espressif’s ESP8266 AT hardware connection guide, and needs 2MB of flash. So for the common 1MB ESP8266 modules, the newest firmware you can use is the NonOS AT v1.7.6, the last release of the ESP8266 NonOS SDK. That’s the firmware we use in this tutorial.

To see what your module runs, send AT+GMR. Our first ESP8266 module replied with a 2015 firmware:

And this is the reply after we updated our second module to NonOS AT v1.7.6 (the steps are below):

Note: Check the module’s flash size before you plan a firmware update. My first trial used an ESP8266 module with only 512KB of flash, so it couldn’t take any AT firmware newer than 0.2x. Read the flash size with esptool flash-id (shown below). Modules sold as ESP-01S usually have 1MB.


STM32 ESP8266 Wiring

Required Parts

QTY.Component NameAmazon.comAliExpress
1STM32 Blue Pill (STM32F103C8T6)AmazonAliExpress
1ST-Link V2 DebuggerAmazonAliExpress
1ESP8266 module (ESP-01 / ESP-01S, 1MB) + 2×4 breadboard adapterAmazonAliExpress
1USB-TTL (UART) Converter, 3.3VAmazonAliExpress
1BreadBoardAmazonAliExpress
1Jumper Wires PackAmazonAliExpress

ESP-01 (ESP8266) Pinout

The most common ESP8266 module is the ESP-01 (and the ESP-01S, which has 1MB of flash and a pull-up on its reset pin). It has an 8-pin 2×4 header:

ESP-01 PinFunctionHow We Connect It
VCC (3V3)3.3V supply, up to about 300mA peaks while transmittingBlue Pill 3.3V (with the Blue Pill powered from USB)
GNDGroundGND
TX (GPIO1)UART0 TX: AT replies (and the boot log at 74880 baud)STM32 PA10 (USART1 RX)
RX (GPIO3)UART0 RX: AT commandsSTM32 PA9 (USART1 TX)
CH_PD (EN)Chip enable, must be high to run3.3V
RSTReset, active lowNot connected (or a GPIO for hardware reset)
GPIO0Boot mode: low at reset = flash modeNot connected (low only to update the firmware)
GPIO2General purpose, UART1 TX (log)Not connected
ESP-01 pinout: VCC, GND, TX, RX, CH_PD (EN), RST, GPIO0, and GPIO2 of the ESP8266 module

STM32 Blue Pill to ESP8266 Wiring

Connect the STM32’s USART1 to the ESP8266, and USART2’s TX pin to your USB-TTL adapter for the log (see the Blue Pill pinout for the pin locations). TX goes to RX, RX goes to TX, and all the grounds are connected:

PA9 USART1 TX, goes to the ESP8266 RX: the AT commands.

PA10 USART1 RX, goes to the ESP8266 TX: the replies, events, and received data.

3.3V Goes to the ESP8266 VCC and CH_PD (EN) pins.

PA2 USART2 TX, goes to the USB-TTL adapter’s RX: the log to your PC at 115200 baud.

GND Goes to the ESP8266 GND and the USB-TTL GND: common ground.

STM32 ESP8266 wiring diagram: Blue Pill PA9 to ESP8266 RX, PA10 to ESP8266 TX, 3.3V to VCC and CH_PD, and PA2 to a USB-TTL adapter

STM32 Blue Pill wired to an ESP8266 ESP-01 module on its 3.3V adapter board

STM32 Blue Pill ESP8266 / USB-TTL PA9 (USART1 TX) ESP8266 RX PA10 (USART1 RX) ESP8266 TX 3.3V VCC 3.3V CH_PD (EN) GND GND PA2 (USART2 TX) USB-TTL RX GND USB-TTL GND

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 Blue Pill from its micro-USB port when its 3.3V pin feeds the ESP8266. The ST-Link’s 3.3V output can’t carry the ESP8266’s transmit current peaks (about 300mA), and the module resets during the WiFi join. On the common 2×4 breadboard adapters, CH_PD (EN) is not pulled up, so wire it to 3.3V yourself. Otherwise, the module stays off, and its TX line sits low.


Testing ESP8266 AT Commands With a USB-TTL Converter

Before connecting the ESP8266 to the STM32, it’s worth a quick test from your PC. It proves the module, its power, and its baud rate on their own, so any later problem is on the STM32 side. Connect the ESP8266 to a 3.3V USB-TTL converter instead of the Blue Pill (ESP8266 TX to converter RX, ESP8266 RX to converter TX, GND to GND), open a serial terminal at 115200 baud with CR+LF line endings, and type AT:

Each command is echoed back (the echo is on by default), followed by the reply and OK. Our updated module answered every command in 30 to 40ms. If you get nothing, try 9600 baud (old firmware), check that CH_PD is at 3.3V, and swap TX and RX. If you get unreadable characters only at power-up, that’s the ESP8266 boot log, which is sent at 74880 baud.


How to Update the ESP8266 AT Firmware

If AT+GMR shows an AT version below 1.7, update the module. You need the same USB-TTL converter, esptool, and the AT binaries from the NonOS SDK. If you have the Arduino ESP8266 or ESP32 core installed, esptool is already on your PC (in the core’s tools/esptool_py folder), or install it with pip install esptool.

Step 1: Put the ESP8266 in Flash Mode

Keep the USB-TTL wiring from the test above, and connect GPIO0 to GND. Then reset the module (briefly connect RST to GND, or power-cycle it). With GPIO0 low at reset, the ESP8266 starts its ROM bootloader instead of the AT firmware.

Step 2: Check the Flash Size

Read the flash chip ID (replace COM20 with your converter’s port):

Our second ESP8266 module reported Detected flash size: 1MB, so it can take the NonOS AT v1.7.6. Our first module reported 512KB, and we stopped there.

Step 3: Download the AT Binaries

From the ESP8266 NonOS SDK v3.0.6 bin folder, download boot_v1.7.bin, esp_init_data_default_v08.bin, blank.bin, and at/512+512/user1.1024.new.2.bin (the 512+512 “Nano AT” build, which is the one that fits 1MB of flash).

Step 4: Erase and Write the Flash

Write all the files in one command. The addresses are for a 1MB flash:

esptool checks each region after writing it ( Hash of data verified). The whole update took about 30 seconds on our module. Then disconnect GPIO0 from GND, reset the module, and send AT+GMR again to confirm the new version.

Note: Use -fm dout: many ESP8266 modules don’t boot with the faster QIO flash mode. On Linux or macOS, replace the ^ line continuations with \. If you prefer a GUI, Espressif’s Flash Download Tool for Windows uses the same files and addresses.

Note: After the update, the module starts in SoftAP mode ( +CWMODE:2) and creates its own WiFi network. Our driver switches it to station mode ( AT+CWMODE_CUR=1) before joining your network.


STM32 CubeMX Configuration Steps

All three examples use the same CubeMX configuration: USART1 with DMA for the ESP8266, USART2 for the log, and the on-board LED on PC13.

#1

Open STM32CubeMX, create a new project, and select the STM32F103C8T6 in the MCU selector

#2

Set SYS > Debug to Serial Wire

STM32CubeMX SYS Debug set to Serial Wire: PA13 SWDIO and PA14 SWCLK on the Blue Pill

#3

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

STM32CubeMX RCC High Speed Clock (HSE) set to Crystal/Ceramic Resonator on PD0 and PD1

STM32CubeMX clock configuration for the Blue Pill: 8MHz HSE, PLL x9, HCLK 72MHz, APB1 /2

#4

Enable USART1 in Asynchronous mode (115200 baud, 8N1)

STM32CubeMX USART1 in Asynchronous mode at 115200 baud on PA9 (TX) and PA10 (RX) for the ESP8266 AT link

#5

In USART1’s DMA Settings tab, add USART1_RX with Mode set to Circular, and add USART1_TX (Mode Normal)

STM32CubeMX USART1 DMA Settings: USART1_RX in Circular mode and USART1_TX in Normal mode for the ESP8266 AT driver

#6

In USART1’s NVIC Settings tab, enable the USART1 global interrupt (the two DMA channel interrupts are enabled by CubeMX)

STM32CubeMX USART1 NVIC Settings: USART1 global interrupt and the DMA1 channel 4 and 5 interrupts enabled

#7

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

STM32CubeMX USART2 in Asynchronous mode on PA2 (TX) and PA3 (RX) for the debug log

#8

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

STM32CubeMX GPIO configuration of PC13 as Output Push Pull with the user label LED

Here’s the finished pin configuration:

STM32CubeMX pinout for the STM32 ESP8266 examples: USART1 on PA9/PA10, USART2 on PA2/PA3, and PC13 as the LED output on the Blue Pill

#9

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

STM32CubeMX Project Manager with the project name and Toolchain/IDE set to STM32CubeIDE


STM32 ESP8266 AT Commands Driver (ESP_AT)

Sending AT and waiting for OK is easy. The hard part is everything else the ESP8266 sends: WIFI DISCONNECT when the router goes away, +IPD frames when data arrives, busy p... when a command comes too early, and a boot log at another baud rate when the module resets. A blocking HAL_UART_Receive loop misses these lines, and the code that waits for OK freezes the whole application.

So for this series, we wrote our own ESP_AT driver: plain C, HAL called directly, two files ( ESP_AT.c and ESP_AT.h), no dynamic memory, and about 8.8KB of flash and 3.9KB of RAM per module. It works with all three ESP8266 AT generations and with ESP-AT on the ESP32 family. Here is what it does:

  • DMA reception in circular mode: every byte from the ESP8266 lands in a 2KB ring buffer with no CPU work, and the driver reads the buffer by the DMA counter. Nothing is lost while the main loop is busy (the STM32 UART DMA tutorial explains the mechanism).
  • Non-blocking jobs: each task (begin, join, connect, send) is a small state machine run by ESP_AT_Process() in the main loop. It ends with an event. Every job also has a _Blocking version for simple programs.
  • Events: WiFi connected, got IP, disconnected, link opened and closed, received data, and any other line the module sends by itself.
  • Binary-safe receive: +IPD,<length>: data is read by its length, not by searching for text, so binary data and \r\n inside the data are safe.
  • Auto-baud and baud switching: the driver finds the module’s baud rate (115200, 9600, 74880, and others) and can switch it to 921600 with AT+UART_CUR.
  • Firmware detection: AT+GMR tells the driver which commands exist (for example, AT+CWJAP_CUR on NonOS AT 1.x, so the network isn’t written to flash on every join).
  • Auto reconnect after a WiFi drop, busy p... retries, and passwords that are escaped as the AT manual requires and never printed in the log.
How the STM32 ESP_AT driver receives ESP8266 replies: UART DMA in circular mode fills a ring buffer, and the parser turns it into replies, events, and +IPD data

To add the driver to your project, copy the ESP_AT folder next to Core, and add it to the include paths and source locations (Project > Properties > C/C++ General > Paths and Symbols). The download at the end of this tutorial has the driver and all three projects ready to build. These are the functions the examples use:

FunctionWhat It Does
ESP_AT_Init(&esp, &cfg)Checks the UART and DMA setup and starts the reception
ESP_AT_Process(&esp)Runs the parser, the jobs, and the timers. Call it in the main loop as often as possible
ESP_AT_Begin(&esp)Auto-baud, ATE0, AT+GMR (firmware detection), and the optional baud switch
ESP_AT_Command(&esp, cmd, timeout)Sends any AT command and collects its reply
ESP_AT_WiFiJoin(&esp, ssid, pwd)Station mode, joins the network, and reads the IP address
ESP_AT_Connect(&esp, link, type, host, port)Opens a TCP, UDP, or SSL connection
ESP_AT_Send(&esp, link, data, len)Sends data with AT+CIPSEND (long data is split into 2048-byte chunks)
ESP_AT_..._Blocking()The same jobs, waiting until they finish (for simple programs)

STM32 ESP8266 WiFi Example 1: AT Commands

In the first example project, the STM32 finds the ESP8266, reads its firmware version, and sends ten common AT commands, printing each reply and how long it took. It’s the STM32 version of the USB-TTL test above, and it’s the first thing to run when you wire a new module.

Wiring: PA9 to ESP8266 RX, PA10 to ESP8266 TX, 3.3V to VCC and CH_PD, PA2 to the USB-TTL RX, and GND to both.

Here is The Application Code For This Example Project (main.c). Only the USER CODE sections are shown; the rest of the file is generated by CubeMX:

STM32 ESP8266 Example 1 Code Explanation

OnTrace() prints every line the driver sends ( >>) and receives ( <<) on USART2, so you see the whole AT exchange. HAL_UART_ErrorCallback() hands UART errors to the driver, because the HAL stops the DMA reception after a framing or overrun error (which happens every time the ESP8266 prints its boot log at 74880 baud).

ESP_AT_Begin_Blocking() sends AT at each baud rate in the driver’s list until the module answers, then turns the echo off with ATE0 and reads AT+GMR. After that, esp.baudRate, esp.version, and esp.firmware tell the application what it’s talking to. The loop then sends each command in demoCommands[] with ESP_AT_Command_Blocking() and prints the result and the time from esp.lastCmdMs.

STM32 ESP8266 Example 1 Testing

This is the real hardware testing result for this example project on my Blue Pill and ESP8266 (network names and access point MAC addresses are hidden):

The module answered at 115200 baud on the first try, and most commands answered in 2 to 20ms. AT+CWLAP (the WiFi scan) took 1.7 seconds, because the module listens on every channel. Notice that AT+SYSRAM? shows about 51KB of free RAM inside the ESP8266, which is more than the Blue Pill has in total.


STM32 ESP8266 Example 2: Connect to WiFi and Get IP Address

In this example project, the STM32 joins your WiFi network, prints the IP address, gateway, and netmask, and then runs a non-blocking loop that keeps the connection alive:

  • The on-board LED is on while the ESP8266 is connected, and blinks fast while it isn’t.
  • When the module reports WIFI DISCONNECT (router restarted, out of range), the driver joins the network again by itself, with a growing delay between attempts.
  • To show this without touching the router, the example drops the WiFi once with AT+CWQAP 30 seconds after the start.

Write your WiFi name and password in Core/Inc/wifi_secrets.h:

Here is The Application Code For This Example Project (main.c). Only the USER CODE sections are shown; the rest of the file is generated by CubeMX:

STM32 ESP8266 Example 2 Code Explanation

Setting cfg.autoReconnect = 1 is all it takes to keep the connection: the driver remembers the network from ESP_AT_WiFiJoin_Blocking() and joins it again after every WIFI DISCONNECT. OnEvent() receives the WiFi events and the end of each job, so the application knows the state without polling the module.

The main loop only calls ESP_AT_Process() and updates the LED from ESP_AT_IsWiFiConnected(). It never waits for the module. That’s the pattern for every real application: the STM32 keeps doing its own work, and the WiFi runs in the background.

Note: The old AT 0.2x firmware doesn’t send WIFI DISCONNECT at all. For that firmware, the example sets esp.cfg.wifiCheckMs = 5000, and the driver polls AT+CIPSTATUS every 5 seconds instead.

STM32 ESP8266 Example 2 Testing

This is the real hardware testing result for this example project:

The ESP8266 joined the network in 6.1 seconds: WIFI CONNECTED came 4.3 seconds after the start, and WIFI GOT IP (the router’s DHCP answer) 1.4 seconds later. When the example dropped the WiFi at 30 seconds, the driver started a new join 2 seconds after the WIFI DISCONNECT event, and the module had its IP address back 5.8 seconds after the drop.


STM32 ESP8266 WiFi Example 3: TCP Client (Send and Receive Data)

In this example project, the STM32 connects to a TCP server on your PC through the ESP8266 and exchanges data with it in both directions:

  • The STM32 sends a text line every 2 seconds.
  • The PC server sends each line back ( echo: ...), and the STM32 measures how long the echo takes.
  • Every 6 seconds, the server sends LED TOGGLE, and the STM32 toggles its on-board LED.
  • If the server stops, the STM32 tries to reconnect every 3 seconds, and it continues by itself when the server is back.

In other words, this is the skeleton of any STM32 WiFi device that reports data and takes commands. The whole application is a non-blocking state machine.

How AT+CIPSEND and +IPD Work

Sending data takes two steps. The STM32 sends AT+CIPSEND=<length>, waits for the ESP8266’s > prompt, and then sends exactly that many bytes. The module answers Recv <n> bytes and SEND OK when the data is on its way. Received data arrives at any time, as +IPD,<length>: followed by the data:

ESP8266 AT+CIPSEND sequence: command, > prompt, data, Recv and SEND OK, then received data as +IPD frames

The PC TCP Server

Run this Python script on your PC (Python 3, no extra packages), and set SERVER_IP in wifi_secrets.h to your PC’s IP address ( ipconfig on Windows). Allow Python through the Windows firewall when it asks.

Here is The Application Code For This Example Project (main.c). Only the USER CODE sections are shown; the rest of the file is generated by CubeMX:

STM32 ESP8266 Example 3 Code Explanation

The application has five states: begin, wait for begin, join, wait for join, and online. Each state starts a non-blocking job ( ESP_AT_Begin(), ESP_AT_WiFiJoin()) and moves on when ESP_AT_GetJobStatus() is no longer ESP_AT_RUNNING. In the online state, the STM32 opens link 0 with ESP_AT_Connect() when it’s closed, and sends a line every 2 seconds with ESP_AT_Send().

Received data comes as ESP_AT_EVT_DATA events. A large +IPD frame is delivered in chunks of up to 256 bytes, with d->remaining telling you how many bytes of the same frame are still to come, so a 1460-byte TCP packet needs only 256 bytes of RAM on the STM32. The example collects the bytes into lines and acts on LED ON, LED OFF, and LED TOGGLE.

Note: The buffer you pass to ESP_AT_Send() must stay unchanged until the send job ends, because the driver sends it after the > prompt arrives. That’s why txMsg is a static buffer and not a local variable.

STM32 ESP8266 Example 3 Testing

This is the real hardware testing result for this example project, the STM32 side first:

And the PC side:

All 12 lines came back, with an echo round trip of 32 to 89ms through the ESP8266, the router, and the PC. In our longer run, 38 of 38 lines came back, and when we stopped the server, the STM32 got CLOSED, retried every 3 seconds, and continued by itself when the server was back.


Measured: Old vs Updated ESP8266 AT Firmware

We ran the same tests on our two ESP8266 modules: the first one with its original AT 0.21.0.0 firmware (2015, 512KB flash, it can’t be updated), and the second one after the update to NonOS AT v1.7.6. Both were driven by the same Blue Pill at 115200 baud:

TestAT 0.21.0.0 (SDK 0.9.5)NonOS AT v1.7.6 (SDK 3.0.6)
WiFi join time3.1 to 5.1s, some joins failed5.0 to 6.1s, 5 of 5 joins OK
WIFI CONNECTED / GOT IP / DISCONNECT eventsNot sentSent
Automatic reconnect after a dropNeeds pollingIP back in 5.8s
AT+PING to the routerNot supported4ms average (5 of 5)
Baud rate switch (AT+UART_CUR)Not supported115200 to 921600 in 71ms
TCP upload throughputLimited to 115200 baud7.2KB/s at 115200, 31.8KB/s at 921600
AT+RST to ready (at 921600)–331ms
Free RAM inside the ESP8266 (AT+SYSRAM?)Not supportedabout 51KB

The old firmware joined the network faster, but it failed some joins and has none of the features a robust application needs: no WiFi events, no ping, and no way to raise the baud rate. With the updated firmware, the UART speed is the throughput limit. At 921600 baud, the 64KB upload ran at 31.8KB/s, more than 4 times the 115200 baud result, and 71,719 bytes echoed back by the PC arrived in 351 +IPD frames with no byte lost.

ESP8266 AT firmware benchmark on an STM32 Blue Pill: AT 0.21 vs NonOS AT 1.7.6 join time, ping, and TCP throughput

ESP8266 AT Commands on The Oscilloscope

Here’s what an AT command and its reply look like on my oscilloscope captures. CH1 (yellow) is PA9, the STM32’s TX line to the ESP8266, and CH3 (blue) is PA10, the ESP8266’s TX line back to the STM32.

The first command of Example 2 is AT plus CR LF: 4 bytes in 0.35ms at 115200 baud. The cursors show that the ESP8266’s reply starts 720µs after the command starts, so the module answered about 0.38ms after it received the last byte:

Oscilloscope capture of the STM32 sending AT to the ESP8266 on PA9 and the OK reply on PA10, 720 microseconds later, at 115200 baud
Oscilloscope capture of the STM32 sending AT to the ESP8266 on PA9 and the OK reply on PA10, 720 microseconds later, at 115200 baud

The WiFi join is a different story. At 500ms/div, the cursors run from the AT+CWJAP_CUR command (X1) to the module’s WIFI GOT IP line (X2): 3.70 seconds in this run. WIFI CONNECTED came at 2.43 seconds, and the OK came at 4.06 seconds, right before the STM32 asked for the IP address with AT+CIPSTA_CUR?. During all that time, the STM32 is free: the driver doesn’t wait in a loop, it gets the result as events:

Oscilloscope capture of the ESP8266 WiFi join: AT+CWJAP sent by the STM32, then WIFI CONNECTED at 2.43s and WIFI GOT IP at 3.75s on the ESP8266 TX line
Oscilloscope capture of the ESP8266 WiFi join: AT+CWJAP sent by the STM32, then WIFI CONNECTED at 2.43s and WIFI GOT IP at 3.75s on the ESP8266 TX line

Notice the short dips on both lines in the join capture, every 93ms. They aren’t UART bytes: the lines never go low enough. Zooming into one of them at 200µs/div shows that the ESP8266’s TX idle level drops from 3.16V to 2.28V for 0.67ms, and the STM32’s TX line dips at the same moment. Both lines follow the same 3.3V supply, so this is the supply itself sagging while the ESP8266’s radio transmits during the network scan. The UART still works because 2.28V is still a valid high level for the STM32, but it’s the reason the ESP8266 needs a strong 3.3V supply and a capacitor close to its VCC pin:

Oscilloscope capture of the ESP8266 3.3V supply dip during WiFi transmission: the ESP8266 TX idle level drops from 3.16V to 2.28V for 0.67ms
Oscilloscope capture of the ESP8266 3.3V supply dip during WiFi transmission: the ESP8266 TX idle level drops from 3.16V to 2.28V for 0.67ms


ESP8266 AT Commands List (With Real Replies)

These are the ESP8266 AT commands you’ll use most with an STM32, grouped by function, with the real replies from our ESP8266 module running NonOS AT v1.7.6. Every command ends with \r\n. The full reference is Espressif’s ESP8266 AT Instruction Set.

ESP8266 AT Commands List: Basic, WiFi, and TCP/IP (click to expand)

Basic AT Commands

CommandWhat It DoesReply From Our ESP8266Time (ms)
ATTests that the module is aliveOK2
ATE0 / ATE1Turns the command echo off / onOK2
AT+GMRAT and SDK versionsAT version:1.7.6.0(Jan 24 2022 08:56:02)
SDK version:3.0.6-dev(072755c)
compile time:Jun 17 2024 07:38:00
Bin version(Wroom 02):1.7.6
OK
19
AT+RSTRestarts the moduleOK, then the boot log at 74880 baud, then ready264 to ready
AT+UART_CUR?Current UART settings (not saved): baud, data bits, stop bits, parity, flow control+UART_CUR:115273,8,1,0,18
AT+UART_CUR=921600,8,1,0,0Changes the baud rate until the next resetOK (then the module talks at 921600)71
AT+UART_DEF?UART settings saved in flash+UART_DEF:0,0,0,0,0 (blank after the update, the module boots at 115200)6
AT+SLEEP?Sleep mode (0 off, 1 light, 2 modem sleep)+SLEEP:24
AT+SYSRAM?Free RAM inside the ESP8266, in bytes+SYSRAM:516086
AT+RFPOWER=82Maximum TX power (0 to 82, in 0.25dBm steps)OK3

WiFi AT Commands

CommandWhat It DoesReply From Our ESP8266Time (ms)
AT+CWMODE?WiFi mode: 1 station, 2 SoftAP, 3 both+CWMODE:14
AT+CWMODE_CUR=1Station mode, not saved in flashOK3
AT+CWJAP_CUR="ssid","pwd"Joins a network (the _DEF version saves it in flash)WIFI CONNECTED
WIFI GOT IP
OK
5035
AT+CWJAP_CUR?The network the module is connected to: SSID, BSSID, channel, RSSI+CWJAP_CUR:"MyWiFi","xx:xx:xx:xx:xx:xx",9,202,013
AT+CWLAPScans for WiFi networks+CWLAP:(3,"MyWiFi",-47,"xx:xx:xx:xx:xx:xx",9,23,0,4,4,7,1)
... one line per network
OK
1648
AT+CWQAPDisconnects from the networkOK
WIFI DISCONNECT
4
AT+CWAUTOCONN?Joins the last network automatically after power-up (1 = on)+CWAUTOCONN:16
AT+CWDHCP_CUR?DHCP state (bit 0 SoftAP, bit 1 station)+CWDHCP_CUR:35
AT+CWHOSTNAME?The module’s host name on your network+CWHOSTNAME:ESP-111F497
AT+CIPSTAMAC_CUR?Station MAC address+CIPSTAMAC_CUR:"d8:bf:c0:11:1f:49"10
AT+CIPSTA_CUR?IP address, gateway, and netmask+CIPSTA_CUR:ip:"192.168.1.108"
+CIPSTA_CUR:gateway:"192.168.1.1"
+CIPSTA_CUR:netmask:"255.255.255.0"
16
AT+CIFSRIP and MAC address (works on every firmware)+CIFSR:STAIP,"192.168.1.108"
+CIFSR:STAMAC,"d8:bf:c0:11:1f:49"
11

TCP/IP AT Commands

CommandWhat It DoesReply From Our ESP8266Time (ms)
AT+CIPSTATUSStatus: 2 got IP, 3 connected, 4 disconnected, 5 no WiFiSTATUS:24
AT+CIPMUX?Single (0) or multiple (1) connections+CIPMUX:05
AT+CIPMODE?0 normal mode, 1 transparent (passthrough) mode+CIPMODE:05
AT+CIPSTO?TCP server timeout, in seconds+CIPSTO:1805
AT+CIPDOMAIN="www.google.com"DNS lookup+CIPDOMAIN:142.251.154.11959
AT+PING="192.168.1.1"Pings a host, the reply is the time in ms+27
AT+CIPSNTPCFG=1,0,"pool.ntp.org"Enables SNTP time (time zone 0 = UTC)OK6
AT+CIPSNTPTIME?Date and time from the SNTP server+CIPSNTPTIME:Thu Nov 26 05:41:13 202611
AT+CIPSTART="TCP","192.168.1.101",5000Opens a TCP connection (“UDP” and “SSL” also work)CONNECT
OK
24
AT+CIPSEND=5Sends 5 bytes: wait for the > prompt, then send the dataOK
>
Recv 5 bytes
SEND OK
54 to SEND OK
(received data)Data from the server, sent by the module at any time+IPD,28:Hello STM32, this is the PC–
AT+CIPCLOSECloses the connectionCLOSED
OK
6

STM32 ESP8266 Troubleshooting

The ESP8266 doesn’t answer AT commands

Check, in this order: CH_PD (EN) is at 3.3V, TX and RX are crossed (STM32 TX to ESP8266 RX), the grounds are connected, and the baud rate matches (old firmware is often at 9600, and our driver tries the common rates by itself). Then test the module alone with a USB-TTL converter, as shown above. If its TX line stays low, the module isn’t running.

Garbage characters at power-up

The ESP8266 prints its boot log at 74880 baud on the same UART as the AT commands. Ignore everything until the module prints ready or answers AT. On the STM32 side, these bytes cause framing errors that stop the HAL’s DMA reception, which is why our driver restarts it in HAL_UART_ErrorCallback().

The module resets or disconnects during the WiFi join

That’s power. The ESP8266 draws about 300mA peaks when it transmits, and a weak 3.3V supply sags and resets it. On our breadboard, the 3.3V line dipped by 0.88V for 0.67ms with each transmission (see the scope capture above). Power the Blue Pill from USB (not from the ST-Link), keep the wires short, and add a 100µF capacitor across the module’s VCC and GND.

AT+CWJAP returns FAIL or ERROR

The reply +CWJAP:<code> tells you why: 1 = timeout, 2 = wrong password, 3 = network not found, 4 = connection failed. The ESP8266 is 2.4GHz only, so it can’t see a 5GHz network. Commas, double quotes, and backslashes in the SSID or password must be escaped with a backslash (our driver does it).

The reply is busy p…

It’s short for (busy processing…); the module is still working on the previous command (a join, a connection). Wait for its OK or ERROR before sending the next command. Our driver resends the command after 200ms, up to 25 times.

AT+PING or AT+UART_CUR returns ERROR

The module runs the old AT 0.2x firmware, which doesn’t have these commands. Check with AT+GMR and update the firmware if the flash size allows it.

esptool can’t connect, or the flash read fails

GPIO0 must be low while the module resets, and then the ROM bootloader answers at 115200 baud. Remove anything else on the TX and RX lines (the STM32, oscilloscope probes): we had corrupted flash reads with the scope probes still on the lines.


STM32 ESP8266 FAQ

Can the STM32 Blue Pill power the ESP8266?

Yes, from its 3.3V pin, as long as the Blue Pill itself is powered from its micro-USB port. Its regulator can supply the ESP8266’s transmit peaks. The ST-Link’s 3.3V output can’t, so don’t power the setup from the ST-Link alone.

Do I need a level shifter between the STM32 and the ESP8266?

No. Both run at 3.3V, so their UART pins connect directly.

What is the difference between the ESP-01 and the ESP-01S?

The ESP-01S has 1MB of flash (many older ESP-01 boards have 512KB), pull-up resistors on CH_PD, RST, and GPIO0, and a blue LED on GPIO2 instead of the TX pin. For the AT firmware in this tutorial, choose the ESP-01S or any module with 1MB or more.

What is the default baud rate of the ESP8266 AT firmware?

115200 baud for NonOS AT 1.x and ESP-AT 2.x. Many old AT 0.2x modules were set to 9600. The boot log is always at 74880 baud.

Should I use an ESP8266 or an ESP32-C3 with STM32?

For a new design, the ESP32-C3: it costs about the same, its AT port is separate from its boot log, and it gets the current ESP-AT releases. The ESP8266 is a good choice when you already have one. The same STM32 code and driver work with both, as we show in the ESP32 AT commands with STM32 tutorial.

Can I program the ESP8266 itself instead of using AT commands?

Yes. With the Arduino ESP8266 core or the ESP8266 SDK, the ESP8266 runs your own firmware, and the STM32 talks to it with your own protocol. We’ll do that in the WebSocket part of this series, where the ESP runs as a smart bridge.


STM32 WiFi Tutorial Series

This tutorial is the second 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 ESP_AT driver:

PartTutorialWhat You’ll Build
1STM32 WiFiChoosing a WiFi module, quick start, ESP32-C3 vs ESP8266 measured
2ESP8266 AT Commands With STM32 (this tutorial)ESP8266 AT firmware, commands, and our ESP_AT driver
3ESP32 AT Commands (ESP-AT) With STM32ESP-AT firmware, commands, SNTP time, and our ESP_AT driver
4STM32 HTTP Client Over WiFiGET, POST, HTTPS, and JSON parsing
5STM32 Web ServerControl GPIOs and read sensors from a browser
6STM32 MQTTPublish and subscribe, Home Assistant
7STM32 OTA Firmware UpdateUpdate the STM32’s firmware over WiFi
8STM32 WebSocketReal-time data with an ESP32 smart bridge

Download STM32 ESP8266 Example Projects + ESP_AT Driver

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 used the ESP8266 AT commands with an STM32 Blue Pill to connect it to WiFi. We checked the module’s AT firmware, updated it to NonOS AT v1.7.6, configured the STM32 UART with circular DMA, and built three example projects with our ESP_AT driver: talking to the module, joining WiFi with automatic reconnection, and a TCP client that sends and receives data. The measurements showed why the firmware matters: the updated module sends the WiFi events, supports ping, and reaches 31.8KB/s at 921600 baud.

In the next part of this series, we’ll run the same driver and examples on an ESP32-C3 with the current ESP-AT firmware. 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.

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

Leave a Comment