Trouble Flashing Your ESP8266? Meet DIO And QIO

[Pete] was building a hot tub controller, using a WEMOS board based on the venerable ESP8266. After assembly, the board was plugged into USB and [Pete] hit the flash button. No dice. Investigation with some terminal software indicated a checksum error.

Assuming the board was dead, [Pete] grabbed another — and suffered the same problem.  The WEMOS boards wouldn’t program, but other boards had no issues. Sensing that something may be amiss, further research was in order. A forum post turned up discussing different programming modes for the ESP8266.

It turns out that there are different types of flash used with the ESP8266, and the correct programming mode must be selected for a given hardware setup. These modes are known as DIO and QIO, meaning “dual IO” and “quad IO” respectively. This refers to the number of IO line used to talk to the flash memory. There are also further modes, known as DOUT and QOUT. It’s important to identify the modes supported by the flash chip on board, by looking at the datasheet. Obviously this can be difficult on some pre-built modules, so experimentation is the key here.

With the wrong mode selected, writes to the flash will fail, and reading back will turn up a checksum error. It’s a simple matter of changing a line in the make file and trying different modes, to see which one works. This forum post has a more in-depth coverage of the issue. 

By choosing different flash memory parts and selecting the DIO or DOUT modes, it’s actually possible to free up more GPIO pins as well. This knowledge is handy when optimizing ESP8266 designs for memory speed or maximum IO flexibility. It’s a good lesson that it always pays to look at the datasheet to get the best out of your parts.

13 thoughts on “Trouble Flashing Your ESP8266? Meet DIO And QIO

          1. 5V on VCC will fry an ESP almost instantly.

            5V on the other pins is perfectly fine. I do it all the time and the Espressif CEO said it was ok on Facebook. I’m not sure why this hasn’t gotten more attention or why Espressif hasn’t advertised it but:

            > Teo Swee Ann i can reply officially here: it is 5V tolerant at the IO. while the supply voltage is at 3.3V.

            https://www.facebook.com/groups/1499045113679103/permalink/1731855033731442/?hc_location=ufi

            (Teo Swee Ann is the CEO of Espressif)

  1. I had similar problems with firmware chips pulled from old stuff. I couldn’t dump/write to them properly, and it took me a month to realize they were configured as QIO instead of normal one-bit SPI (the configuration registers are non-volatile).
    After sending some magic commands, they worked as expected.

  2. The SPI Flash chips have 8 pins: VCC, GND, CLK, /CS, DI, DO, /HOLD and /WP. The first 3 pins are obvious, the 5 remaining ones have different functions depending on their operating mode.

    In Standard SPI mode, /CS pin enables and disables device operation, /WP pin prevents the status register from being written, thus from 4KB sector to the entire memory array can be hardware protected. /HOLDl pin is used to pause the device and put the DO output pin in Z-state. DI is MOSI and used to write instructions, address or data to the device, while DO is MISO and used to read data or status from the device

    In DOUT mode, this is the same as standard SPI, but DI becomes IO0 and DO becomes IO1, and are used as 2-bit output pins to read data or status from the device. Please note that the single pin DI is still used as MOSI to write instructions, address or data to the device.

    In DIO mode, this is the same as DOUT, but DI (as IO0) and DO (as IO1) are also used to write addresses and data to the device. Please note that the single pin DI is still used as MOSI to write instructions.

    In QOUT mode,, this is the same as standard SPI, but the /WP pin becomes IO2 and the /HOLD pin becomes IO3, and DI (as IO0), DO (as IO1), /WP (as IO2) and /HOLD (as IO3) are used as 4-bit output pins to read data or status from the device. Please note that the single pin DI is still used as MOSI to write instructions, address or data to the device.

    In QIO mode, this is the same as QUOT mode, but DI (as IO0), DO (as IO1), /WP (as IO2) and /HOLD (as IO3) are also used to write addresses and data to the device. Please note that the single pin DI is still used as MOSI to write instructions.

    In terms of performance, QIO > QOUT > DIO > DOUT > SPI, bit not all SPI Flash chips support all the modes.

    However, because the command itself (and the read status command) are sent using only standard SPI, doubling the SPI clock speed provides a bigger speed boost than switching from DOUT to QIO.

    OTOH, DIO/DOUT modes free the GPIO 9 and 10 for other uses, unless they are tied to the /WP and /HOLD SPI FLash chip input pins inside the module…

    In Pete’s case, the WEMOS manufacturer is to blame: they chose a different ESP12 module.This pin diagram from AI-Thinker seems to indicate that GPIO9 and GPIO10 can only be used on ESP12-D (Dual?), not on ESP12E or ESP12-Q (Quad?):
    http://www.esp8266.com/wiki/lib/exe/detail.php?id=esp8266-module-family&media=esp-12_pindef.png

    And of course, GPIO 9 & 10 are not available on ESP12-S, and ESP12-F is just the same as ESP12-E but with better PCB antenna.

  3. DIO is dual Input output, and DOUT is dual output only.

    In any SPI flash transaction, we have a command sent from master, an address argument from master and the data recieved by master when the command is acknowledged and processed by the slave.
    In DOUT mode, command and address are sent via regular “single” mode SPI, but the data is recieved in the faster dual mode. This makes this mode compatible with virtually any flash chip with dual-mode support.

    In DIO mode, command is sent via single-mode SPI, but the address is sent via dual-mode SPI. Data is also recieved in the dual mode. Some dual-mode flash chips may not support this mode.

    The case is similar for QOUT/QIO, only instead of dual mode they use quad mode (4 simultaneous comm lines).

    So the order of speed would be QIO > QOUT > DIO > DOUT.
    (Source: https://github.com/espressif/esptool/wiki/SPI-Flash-Modes)

Leave a Reply to Squonk42Cancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.