Skip to content

Commit 528f605

Browse files
committed
docs: Add chip type detection explanation
1 parent 929ae79 commit 528f605

File tree

3 files changed

+74
-6
lines changed

3 files changed

+74
-6
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
blockdiag chip_type_detection_chart {
2+
node_height = 40;
3+
node_width = 150;
4+
span_width = 40;
5+
span_height = 45;
6+
default_fontsize = 12
7+
orientation = portrait;
8+
edge_layout = flowchart;
9+
default_group_color = none;
10+
11+
// nodes
12+
start [label = "Start", shape = flowchart.terminator];
13+
get_chip_id [label = "get chip-id by\nget-security-info", shape = box];
14+
id_success_cond [label = "Success?", shape = flowchart.condition];
15+
reg_success_cond [label = "Success?", shape = flowchart.condition];
16+
find_by_id [label = "Find ID in list", shape = box];
17+
18+
get_magic_reg [label = "Read magic register", shape = box];
19+
find_by_reg [label = "Find magic number\nin list", shape = box];
20+
21+
try_esp32s2 [label = "detected ESP32-S2\nin SDM", shape = box];
22+
23+
finish [label = "Finish", shape = flowchart.terminator];
24+
25+
// edges
26+
start -> get_chip_id -> id_success_cond;
27+
id_success_cond -> find_by_id [label = "Yes"];
28+
find_by_id -> finish;
29+
30+
id_success_cond -> get_magic_reg [label = "No"];
31+
get_magic_reg -> reg_success_cond;
32+
reg_success_cond -> find_by_reg [label = "Yes"];
33+
find_by_reg -> finish;
34+
reg_success_cond -> try_esp32s2 [label = "No"];
35+
36+
try_esp32s2 -> finish
37+
}

docs/en/advanced-topics/diag/download_procedure_chart.diag

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ blockdiag download_procedure_diagram {
1010

1111
// nodes
1212
start [label = "Start", shape = flowchart.terminator];
13-
sync [label = "Synchronization", shape = box];
13+
init [label = "Initialization", shape = box];
1414
success_cond [label = "Success?", shape = flowchart.condition];
1515
erase_data [label = "Erase data", shape = box];
1616
transmit_data [label = "Transmit data", shape = box];
@@ -22,11 +22,11 @@ blockdiag download_procedure_diagram {
2222
fincon_fin [shape = none];
2323

2424
// edges
25-
start -> sync -> success_cond;
25+
start -> init -> success_cond;
2626
success_cond -> erase_data [label = "Yes"];
2727
erase_data -> transmit_data;
2828
transmit_data -> finish_cond;
29-
success_cond -- succ_fin [label = "Timeout"];
29+
success_cond -- succ_fin [label = "Failure"];
3030
finish_cond -> transmit_finish [label = "Yes"];
3131
finish_cond -- fincon_fin [label = "Failure"];
3232
succ_fin -- fincon_fin;

docs/en/advanced-topics/serial-protocol.rst

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,21 +340,52 @@ Functional Description
340340
.. note::
341341
This flow chart is used to illustrate the download procedure (writing to flash), other commands have different flows.
342342

343-
Initial Synchronisation
344-
^^^^^^^^^^^^^^^^^^^^^^^
343+
Initialization
344+
^^^^^^^^^^^^^^
345345
.. list::
346346

347347
:esp8266: * The ESP chip is reset into UART bootloader mode. The host starts by sending SYNC commands. These commands have a large data payload which is also used by the ESP chip to detect the configured baud rate. The ESP8266 will initialise at 74800bps with a 26MHz crystal and 115200bps with a 40MHz crystal. However the sync packets can be sent at any baud rate, and the UART peripheral will detect this.
348348
:not esp8266: * The ESP chip is reset into UART bootloader mode. The host starts by sending SYNC commands. These commands have a large data payload which is also used by the ESP chip to detect the configured baud rate. {IDF_TARGET_NAME} always initialises at 115200bps. However the sync packets can be sent at any baud rate, and the UART peripheral will detect this.
349349
* The host should wait until it sees a valid response to a SYNC command, indicating the ESP chip is correctly communicating.
350+
* Chip type detection then uses various methods to identify chip type, subtype, revision, etc. See below.
350351
* Esptool then (by default) uses the "RAM Download" sequence to upload :ref:`stub loader <stub>` code to IRAM of the chip. The MEM_END command contains the entry-point address to run the stub loader.
351352
The stub loader then sends a custom SLIP packet of the sequence OHAI (``0xC0 0x4F 0x48 0x41 0x49 0xC0``), indicating that it is now running. This is the only unsolicited packet ever sent by the ESP.
352353
If the ``--no-stub`` argument is supplied to esptool, this entire step is skipped.
353-
* esptool then uses READ_REG commands to read various addresses on the chip, to identify chip subtype, revision, etc.
354354
:not esp8266: * For commands which need to use the flash, the {IDF_TARGET_NAME} ROM an stub loader requires the SPI_ATTACH and SPI_SET_PARAMS commands. See `SPI Configuration Commands`_.
355355
:esp8266: * For stub loader, the host can send a CHANGE_BAUD command to set the baud rate to an explicit value. Compared to auto-detecting during the SYNC pulse, this can be more reliable for setting very high baud rate. Esptool tries to sync at (maximum) 115200bps and then sends this command to go to a higher baud rate, if requested.
356356
:not esp8266: * For stub loader and/or {IDF_TARGET_NAME} ROM loader, the host can send a CHANGE_BAUD command to set the baud rate to an explicit value. Compared to auto-detecting during the SYNC pulse, this can be more reliable for setting very high baud rate. Esptool tries to sync at (maximum) 115200bps and then sends this command to go to a higher baud rate, if requested.
357357

358+
Initialization - Chip Type Detection
359+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
360+
{IDF_TARGET_NAME} Chip Detection
361+
""""""""""""""""""""""""""""""""
362+
.. only:: esp8266 or esp32
363+
364+
{IDF_TARGET_NAME} does not support **GET_SECURITY_INFO (0x14)** command and its **chip-id** value. So, chip is detected by using **READ_REG** and his magic value.
365+
366+
.. only:: esp32s2
367+
368+
{IDF_TARGET_NAME} supports the **GET_SECURITY_INFO (0x14)** command, but the output lacks the **chip-id**. Therefore, esptool uses the **magic register** as a fallback for this chip as well.
369+
If reading the register also fails, it indicates the chip is in **secure download** mode.
370+
371+
.. only:: not esp8266 and not esp32 and not esp32s2
372+
373+
{IDF_TARGET_NAME} is detected by using **GET_SECURITY_INFO (0x14)** command and its **chip-id** value.
374+
375+
376+
Overview of Detection for All Chips
377+
"""""""""""""""""""""""""""""""""""
378+
.. blockdiag:: diag/chip_type_detection_chart.diag
379+
:caption: All chips detection flow chart
380+
:align: center
381+
382+
On older devices that do not support the **GET_SECURITY_INFO (0x14)** command (which provides the **chip-id**), esptool falls back to reading a **magic register** to determine the chip type.
383+
384+
The main exception is the **ESP32-S2**: although it supports the **GET_SECURITY_INFO (0x14)** command, the output lacks the **chip-id**. Therefore, esptool uses the **magic register** as a fallback for this chip as well.
385+
If reading the register also fails, it indicates the chip is in **secure download** mode.
386+
387+
For details see: `esptool chip detection code <https://github.com/espressif/esptool/blob/v5.0.2/esptool/cmds.py#L101>`__
388+
358389
Writing Data
359390
^^^^^^^^^^^^
360391

0 commit comments

Comments
 (0)