ESP32 SDIO AT Guide
ESP32 SDIO AT uses SDIO rather than UART as the communication interface between ESP32 (SDIO slave) and the host MCU.
SDIO can use either 1-bit or 4-bit data transfer mode.
For 1-bit mode at least 4 pins are required: CMD, CLK, DAT0, DAT1; where DAT1 runs as the interrupt pin.
For 4-bit mode, two more pins (DAT2 and DAT3) are needed.
The SDIO slave pins are as below:
CLK is GPIO14
CMD is GPIO15
DAT0 is GPIO2
DAT1 is GPIO4
DAT2 is GPIO12 (for 4-bit mode only)
DAT3 is GPIO13 (for 4-bit mode only)
Implement SDIO AT
Before testing SDIO AT communication, please configure ESP32 hardware according to SD Pull-up Requirements, otherwise, exceptions may occur during SDIO communication.
By default, the ESP-AT project uses UART as the the communication interface. When ESP32 serves as the SDIO slave, please go to
./build.py menuconfig ->
Component config ->
communicate method for AT command ->
AT via SDIO to switch to the SDIO interface. Then, recompile the ESP-AT project, flash and run the new bin.
ESP-AT provides the at_sdio_host example for ESP32 or STM32 serving as the SDIO host. For ESP32 serving as the host, you can use the esp-idf of the AT project to compile and flash; for STM32, as the provided solution is based on STM32F103ZET, please use Keil5 to compile and flash as the application.
For other devices working as SDIO hosts, you can develop based on the above example.
SDIO Data Transimission
Initialize the SDIO host
The SDIO host initialization is mainly the initialization of the SDIO protocol, including setting 1-bit or 4-bit transfer mode, SDIO frequency, and SD mode.
Negotiate SDIO communication
Negotiate SDIO parameters with the slave according to the SDIO specification. Please note that if the host and slave reboot at the same time, the host must wait until the slave startup is done to start the negotiation. Usually, the host needs to add a delay at boot time to achieve it.
When the SDIO host detects an interrupt from DAT1 and determines that the slave sends new packets, the host will read those data by CMD53.
In SDIO AT demo, the data inputs from a serial port. When the SDIO host gets the data, it will transfer it to the slave through SDIO by CMD53.
Please note that if the sending time out, there may be something wrong with the slave, please re-initiate both the host and slave.
When the SDIO slave receives data from the SDIO host, it will inform the AT core and give the data to the AT core to handle. After the AT core finishes the work, the slave will send data to the host as feedback.
Initialize the SDIO slave
sdio_slave_initializeto initialize the SDIO slave driver.
sdio_slave_recv_register_bufto register receiving buffer. To make it faster to receive data, you can register multiple buffers.
sdio_slave_recv_load_bufto load the receiving buffer to receive data.
sdio_slave_set_host_intenato set host interrupts, of which the
SDIO_SLAVE_HOSTINT_SEND_NEW_PACKETis used to notify that a new packet is sent from the host.
sdio_slave_startto start SDIO hardware transmission.
Since the SDIO slave data transmission is via DMA, you need to copy the data from AT core to the memory which DMA can read firstly. Call
sdio_slave_transmitto send the data.
To speed up the data transmission, after receiving data by
sdio_slave_recv, a circular linked list is used to transmit the received data to the AT core.