Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low-level ESP32 bootloader SLIP communication protocol #887

Merged
merged 29 commits into from
Nov 29, 2021

Conversation

gemenerik
Copy link
Member

Low-level implementation of ESP32 ROM bootloader communication protocol. First stepping stone to wireless flashing of ESP32 from zip.

The ESP32 bootloader sends no unsolicited messages. The exchange function can be called from a higher level with a variation of instructions and data (to write). The exchange executes the following tasks:

  1. Clear the UART buffer. Despite the ESP32 ROM bootloader otherwise not sending any unsolicited packets, it does send several responses upon successful synchronization, overflowing the UART buffer and potentially putting the SLIP packet decoding state machine in a wrong state. Clearing the UART buffer before sending a new SLIP packet avoids this.
  2. Construct a SLIP packet out of 1) a struct containing header information (esp_slip_send_packet) and 2) a buffer containing to be sent data
  3. Send this buffer in parts over UART with DMA
  4. Receive the response from the ESP32 ROM bootloader, read out the status byte.
  5. Return true for status byte indicating success, return false otherwise

@gemenerik gemenerik force-pushed the rik/esp-slip branch 4 times, most recently from 18bdb2f to b8f5c67 Compare November 23, 2021 15:54
@gemenerik gemenerik force-pushed the rik/esp-slip branch 2 times, most recently from bcd540b to c00ae70 Compare November 24, 2021 07:44
Supports intuitive assembling/interpretation without buffer fiddling.
Buffer to send will be sent to ESP32 over UART2.
*coms_sendbuffer_t
Function takes buffer to write to ESP32 over UART.

*coms_getDataWithTimeout_t
*c is a pointer to to be written char
timeoutTicks is the number of ticks before returning timeout (false)

Allows for mocking UART comms in test environment.
Includes escape sequence for 0xC0 and 0xDB in data.
Fed data size excludes escape sequence bytes.
This function allows clearing the buffer before sending a new package.
The ESP32 sends no unsollicited SLIP packages (READ_FLASH is exception).
ESP32 sends confirmation package several times upon synchronization.
This can overflow incoming buffer.
Clearing buffer avoids putting packet receiving FSM in the wrong state.
Builds receiving packet struct using SLIP decoding state machine.
1. Clears incoming buffer
2. Assembles buffer to send
3. Sends buffer
4. Receives response from ESP32
src/drivers/esp32/interface/esp_slip.h Outdated Show resolved Hide resolved
src/drivers/esp32/interface/esp_slip.h Outdated Show resolved Hide resolved
src/drivers/esp32/interface/esp_slip.h Outdated Show resolved Hide resolved
src/drivers/esp32/src/esp_slip.c Outdated Show resolved Hide resolved
src/drivers/esp32/src/esp_slip.c Outdated Show resolved Hide resolved
src/drivers/esp32/src/esp_slip.c Outdated Show resolved Hide resolved
src/drivers/esp32/src/esp_slip.c Outdated Show resolved Hide resolved
Allows for static sendBuffer. Can be compared to actual transmission buffer size on a higher level. Designed such that buffer can be sent over UART2 DMA which has a limited buffer size.
Copy link
Contributor

@jonasdn jonasdn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general really really nice and clean code! Well done @gemenerik !

src/drivers/esp32/src/esp_slip.c Outdated Show resolved Hide resolved
src/drivers/esp32/src/esp_slip.c Outdated Show resolved Hide resolved
src/drivers/esp32/src/esp_slip.c Outdated Show resolved Hide resolved
src/drivers/esp32/src/esp_slip.c Outdated Show resolved Hide resolved
src/drivers/esp32/src/esp_slip.c Outdated Show resolved Hide resolved
src/drivers/esp32/src/esp_slip.c Outdated Show resolved Hide resolved
src/drivers/esp32/src/esp_slip.c Outdated Show resolved Hide resolved
src/drivers/esp32/interface/esp_slip.h Show resolved Hide resolved
src/drivers/esp32/interface/esp_slip.h Outdated Show resolved Hide resolved
src/drivers/esp32/src/esp_slip.c Outdated Show resolved Hide resolved
@krichardsson krichardsson merged commit 1db7201 into master Nov 29, 2021
@gemenerik gemenerik deleted the rik/esp-slip branch November 29, 2021 10:45
@knmcguire knmcguire added this to the next release milestone Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants