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
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1e8db32
Add UART2 DMA buffer size define
gemenerik Nov 23, 2021
edbf3fd
Initial commit protocol for SLIP packet handling
gemenerik Nov 23, 2021
9505aa0
Set maximum transmission unit
gemenerik Nov 23, 2021
c85e65e
Define ESP32 ROM bootloader commands
gemenerik Nov 23, 2021
6025da7
Define overhead length of SLIP packets for ESP32
gemenerik Nov 23, 2021
9909534
Define send and receive packet types.
gemenerik Nov 23, 2021
c890a39
Implement simple bitwise XOR checksum
gemenerik Nov 23, 2021
7d1a1d8
Assemble buffer to send from sender packet struct.
gemenerik Nov 23, 2021
71eedfd
Typedef UART comms functions.
gemenerik Nov 23, 2021
317fdb5
Implement function to send SLIP packets over comms
gemenerik Nov 23, 2021
5f2731d
Implement function to clear buffer.
gemenerik Nov 23, 2021
de1e5b1
Status of decoding state machine
gemenerik Nov 23, 2021
f9fcd40
Implement SLIP packet decoding state machine
gemenerik Nov 23, 2021
11b0ebb
Implement packet receiving function.
gemenerik Nov 23, 2021
d1d8815
Implement exchange function.
gemenerik Nov 23, 2021
572e1f1
Pass tx buffer size from function call
gemenerik Nov 24, 2021
3cbdebe
Define SLIP start/stop byte constant
gemenerik Nov 24, 2021
0d900e6
Remove references to UART, DMA
gemenerik Nov 24, 2021
f7592b1
Rename functions to match firmware style
gemenerik Nov 24, 2021
569445e
Define tx buffer size
gemenerik Nov 24, 2021
494f194
Add blank lines for legibility
gemenerik Nov 24, 2021
f155460
Remove initialization with 0 of static variables
gemenerik Nov 25, 2021
639aa8e
Add comments for clarification
gemenerik Nov 25, 2021
28459c1
Replace ternary with if statement
gemenerik Nov 25, 2021
448e3a1
Line breaks for legibility
gemenerik Nov 25, 2021
efbb8e5
Do while loop to appease the coding gods and avoid loop priming
gemenerik Nov 25, 2021
236dc52
Remove obsolete comment
gemenerik Nov 25, 2021
6106b99
Rename tx buffer size define
gemenerik Nov 29, 2021
c193faf
Implement esp_slip unit tests
gemenerik Nov 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions src/drivers/esp32/interface/esp_slip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* ,---------, ____ _ __
* | ,-^-, | / __ )(_) /_______________ _____ ___
* | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* | / ,--´ | / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* +------` /_____/_/\__/\___/_/ \__,_/ /___/\___/
*
* Crazyflie control firmware
*
* Copyright (C) 2021 Bitcraze AB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, in version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @file esp_slip.h
* Protocol for assembling, sending, receiving and decoding SLIP packets to/from the ESP32 ROM bootloader
*
*/

#pragma once

#include <stdbool.h>
#include <stdint.h>

#define ESP_MTU 4000

/* Commands */
#define DIR_CMD 0x00
#define FLASH_BEGIN 0x02
#define FLASH_DATA 0x03
#define FLASH_END 0x04
#define SYNC 0x08
#define SPI_FLASH_MD5 0x13
#define ERASE_FLASH 0xd0
#define READ_FLASH 0xd2
#define CHANGE_BAUDRATE 0x0f
#define SPI_ATTACH 0x0d

typedef void (*coms_sendbuffer_t)(uint32_t size, uint8_t *data);
gemenerik marked this conversation as resolved.
Show resolved Hide resolved
typedef bool (*coms_getDataWithTimeout_t)(uint8_t *c, const uint32_t timeoutTicks);

typedef enum
{
SLIP_DECODING,
SLIP_SUCCESS,
SLIP_ERROR
} slipDecoderStatus_t;

typedef struct
{
uint8_t direction;
uint8_t command;
uint16_t dataSize;
uint32_t checksum;
} __attribute__((packed)) esp_slip_send_packet;
gemenerik marked this conversation as resolved.
Show resolved Hide resolved

typedef struct
{
uint8_t direction;
uint8_t command;
uint16_t dataSize;
uint32_t value; // only for READ_REG command
uint8_t data[256];
uint8_t status;
uint8_t error;
} __attribute__((packed)) esp_slip_receive_packet;
gemenerik marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Called to send a SLIP packet to the ESP, and receive the response.
*
* @param *sendBuffer Pointer to the to be sent buffer
* @param *receiverPacket Pointer to receiver packet struct, which will be filled with the response
* @param *senderPacket Pointer to sender packet struct, which will be used to fill the send buffer header
* @param sendBufferFunction Function pointer to the function that sends the buffer (split into pages) to the ESP
* @param getDataWithTimeoutFunction Function pointer to the function that receives data (byte by byte) from the ESP
* @param timeoutTicks Number of ticks to wait for a response from the ESP
*
* @return true if ESP responds with a status byte indicating success.
**/
gemenerik marked this conversation as resolved.
Show resolved Hide resolved
bool espSlipExchange(uint8_t *sendBuffer, esp_slip_receive_packet *receiverPacket, esp_slip_send_packet *senderPacket, coms_sendbuffer_t sendBufferFunction, coms_getDataWithTimeout_t getDataWithTimeout, uint32_t timeoutTicks);
gemenerik marked this conversation as resolved.
Show resolved Hide resolved
Loading