Skip to content

Commit

Permalink
Merge pull request #106 from rtlopez/esp32s3
Browse files Browse the repository at this point in the history
ESP32-S3 and ESP32-S2 support (for devs only)
  • Loading branch information
rtlopez authored Feb 2, 2024
2 parents 683c99f + 585e0c0 commit 6ec2dcd
Show file tree
Hide file tree
Showing 22 changed files with 672 additions and 281 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
target: ['esp32', 'esp32c3', 'esp8266']
target: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp8266']
steps:
- uses: actions/checkout@v4
- name: Extract Version
Expand Down Expand Up @@ -97,11 +97,15 @@ jobs:
env:
PLATFORMIO_BUILD_FLAGS: -DESPFC_REVISION=${{ env.build_sha }} -DESPFC_VERSION=${{ env.build_tag }}

- name: Merge ESP32 Target
if: ${{ startsWith(matrix.target, 'esp32') }}
run: |
python3 ~/.platformio/packages/tool-esptoolpy/esptool.py --chip ${{ matrix.target }} merge_bin -o .pio/build/${{ matrix.target }}/firmware_merged.bin --target-offset 0x0 --flash_mode keep --flash_freq keep --flash_size 4MB 0x1000 .pio/build/${{ matrix.target }}/bootloader.bin 0x8000 .pio/build/${{ matrix.target }}/partitions.bin 0xe000 ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 .pio/build/${{ matrix.target }}/firmware.bin
# - name: Merge ESP32 Target
# if: ${{ matrix.target == 'esp32' }}
# run: |
# python3 ~/.platformio/packages/tool-esptoolpy/esptool.py --chip ${{ matrix.target }} merge_bin -o .pio/build/${{ matrix.target }}/firmware_merged.bin --target-offset 0x0 --flash_mode keep --flash_freq keep --flash_size 4MB 0x1000 .pio/build/${{ matrix.target }}/bootloader.bin 0x8000 .pio/build/${{ matrix.target }}/partitions.bin 0xe000 ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 .pio/build/${{ matrix.target }}/firmware.bin

# - name: Merge ESP32-S3 Target
# if: ${{ matrix.target == 'esp32s3' }}
# run: |
# python3 ~/.platformio/packages/tool-esptoolpy/esptool.py --chip ${{ matrix.target }} merge_bin -o .pio/build/${{ matrix.target }}/firmware_merged.bin --target-offset 0x0 --flash_mode keep --flash_freq keep --flash_size 16MB 0x0000 .pio/build/${{ matrix.target }}/bootloader.bin 0x8000 .pio/build/${{ matrix.target }}/partitions.bin 0xe000 ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 .pio/build/${{ matrix.target }}/firmware.bin

- name: Create Development Artifact
uses: actions/upload-artifact@v4
Expand All @@ -115,7 +119,7 @@ jobs:
if: ${{ !startsWith(github.ref, 'refs/tags/') && startsWith(matrix.target, 'esp32') }}
with:
name: "${{ env.build_file_devel }}_0x00.bin"
path: .pio/build/${{ matrix.target }}/firmware_merged.bin
path: .pio/build/${{ matrix.target }}/firmware_0x00.bin


- name: Create Release Artifact
Expand All @@ -130,4 +134,4 @@ jobs:
if: ${{ startsWith(github.ref, 'refs/tags/') && startsWith(matrix.target, 'esp32') }}
with:
name: ${{ env.build_file_release }}_0x00.bin
path: .pio/build/${{ matrix.target }}/firmware_merged.bin
path: .pio/build/${{ matrix.target }}/firmware_0x00.bin
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ Here are more details about [how to setup](/docs/setup.md).

[![ESP-FC example wiring diagrams](/docs/images/espfc_wiring_combined.png)](/docs/wiring.md)

## Supported chips

- **ESP32** - recommended
- **ESP32-S2** - experimantal
- **ESP32-S3** - experimantal
- **ESP32-C3** - experimantal
- **RP2040** - experimantal
- **ESP8266** - deprecated, may stop being developed

## Supported protocols

Expand Down
59 changes: 59 additions & 0 deletions docs/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,63 @@ https://github.com/espressif/esptool/wiki/ESP32-Boot-Mode-Selection
CMD(11) SD3(10) | | SD0(07) CLK(06)
+----|---|----+
USB
```

# ESP32-S3

https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/gpio.html

```
Pin | Function | ESPFC external device
----+------+---------------+----------------------------------------------
0 | Strapping |
1 | ADC1_CH0 | ADC_VOLTAGE
2 | ADC1_CH1 | DEBUG
3 | ADC1_CH2, Strapping |
4 | ADC1_CH3 | ADC_CURRENT
5 | ADC1_CH4 | BUZZER
6 | ADC1_CH5 | PPM
7 | ADC1_CH6 | SPI_CS_BARO
8 | ADC1_CH7 | SPI_CS_GYRO
9 | ADC1_CH8 | I2C_0_SDA
10 | ADC1_CH9 | I2C_0_SCK
11 | ADC2_CH0 | SPI_0_MOSI
12 | ADC2_CH1 | SPI_0_SCK
13 | ADC2_CH2 | SPI_0_MISO
14 | ADC2_CH3 | ?
15 | ADC2_CH4 | RX1
16 | ADC2_CH5 | TX1
17 | ADC2_CH6 | RX2
18 | ADC2_CH7 | TX2
19 | ADC2_CH8, USB | USB
20 | ADC2_CH9, USB | USB
21 | RTC_21 | ?
38 | RGB | LED_RGB
39 | | M0
40 | | M1
41 | | M2
42 | | M3
43 | U1TX | TX0
44 | U1RX | RX0
45 | | ?
46 | Strapping | SPI_CS_SD
47 | Strapping | ?
48 | | ?
RESERVED
26 | FLASH |
27 | FLASH |
28 | FLASH |
29 | FLASH |
30 | FLASH |
31 | FLASH |
32 | FLASH |
33 | FLASH |
34 | FLASH |
35 | FLASH |
36 | FLASH |
37 | FLASH |
UNAVAILABLE
22, 23, 24, 25
```
9 changes: 9 additions & 0 deletions lib/EscDriver/src/EscDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ class EscDriverBase
#define ESC_DRIVER_MOTOR_TIMER ESC_DRIVER_TIMER0
#define ESC_DRIVER_SERVO_TIMER ESC_DRIVER_TIMER1

#elif defined(ESP32S3) || defined(ESP32S2)

#define ESC_CHANNEL_COUNT 4
#include "EscDriverEsp32.h"
#define EscDriver EscDriverEsp32

#define ESC_DRIVER_MOTOR_TIMER 0
#define ESC_DRIVER_SERVO_TIMER 1

#elif defined(ESP32)

#define ESC_CHANNEL_COUNT RMT_CHANNEL_MAX
Expand Down
2 changes: 1 addition & 1 deletion lib/EscDriver/src/EscDriverEsp32.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if defined(ESP32) and not defined(ESP32C3) //where is this defined???
#if defined(ESP32) && !defined(ESP32C3)

#include "EscDriverEsp32.h"

Expand Down
6 changes: 5 additions & 1 deletion lib/EscDriver/src/EscDriverEsp32.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _ESC_DRIVER_ESP32_H_
#define _ESC_DRIVER_ESP32_H_

#if defined(ESP32) and not defined(ESP32C3) //where is this defined???
#if defined(ESP32) && !defined(ESP32C3)

#include "EscDriver.h"
#include <Arduino.h>
Expand All @@ -16,7 +16,11 @@ static const int32_t DURATION_MAX = 0x7fff; // max in 15 bits

// faster esc response, but unsafe (no task synchronisation)
// set to 0 in case of issues
#if defined(ESP32S3) || defined(ESP32S2)
#define ESPFC_RMT_BYPASS_WRITE_SYNC 0
#else
#define ESPFC_RMT_BYPASS_WRITE_SYNC 1
#endif

#if ESPFC_RMT_BYPASS_WRITE_SYNC
IRAM_ATTR static esp_err_t _rmt_fill_tx_items(rmt_channel_t channel, const rmt_item32_t* item, uint16_t item_num, uint16_t mem_offset)
Expand Down
5 changes: 2 additions & 3 deletions lib/EspWire/src/esp_twi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static uint32_t esp_twi_clockStretchLimit;
#define SCL_LOW() (GPES = (1 << esp_twi_scl))
#define SCL_HIGH() (GPEC = (1 << esp_twi_scl))
#define SCL_READ() ((GPI & (1 << esp_twi_scl)) != 0)
#elif defined(ESP32C3) //where is this defined???
#elif defined(ESP32C3)
//#define SDA_LOW() (GPIO.enable_w1ts.enable_w1ts = ((uint32_t) 1 << esp_twi_sda)) //Enable SDA (becomes output and since GPO is 0 for the pin, it will pull the line low)
static inline void SDA_LOW() { GPIO.enable_w1ts.enable_w1ts = (uint32_t) 1 << esp_twi_sda; GPIO.out_w1tc.out_w1tc = (uint32_t) 1 << esp_twi_sda; }
#define SDA_HIGH() (GPIO.enable_w1tc.enable_w1tc = ((uint32_t) 1 << esp_twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high)
Expand Down Expand Up @@ -184,8 +184,7 @@ void esp_twi_stop(void){

static inline IRAM_ATTR unsigned int _getCycleCount()
{

#if defined(ESP32C3) //where is this defined???
#if defined(ESP32C3)
return esp_cpu_get_ccount();
#elif defined(ESP32) || defined(ESP8266)
unsigned int ccount = 0;
Expand Down
68 changes: 34 additions & 34 deletions lib/Espfc/src/Cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,9 @@ class Cli
PSTR("available commands:"),
PSTR(" help"), PSTR(" dump"), PSTR(" get param"), PSTR(" set param value ..."), PSTR(" cal [gyro]"),
PSTR(" defaults"), PSTR(" save"), PSTR(" reboot"), PSTR(" scaler"), PSTR(" mixer"),
PSTR(" stats"), PSTR(" status"), PSTR(" devinfo"), PSTR(" version"),
PSTR(" stats"), PSTR(" status"), PSTR(" devinfo"), PSTR(" version"), PSTR(" logs"),
//PSTR(" load"), PSTR(" eeprom"),
//PSTR(" fsinfo"), PSTR(" fsformat"), PSTR(" logs"), PSTR(" log"),
//PSTR(" fsinfo"), PSTR(" fsformat"), PSTR(" log"),
NULL
};
for(const char ** ptr = helps; *ptr; ptr++)
Expand Down Expand Up @@ -1190,9 +1190,27 @@ class Cli
s.print(F(", "));
s.println(_model.state.inputAutoFactor);

static const char* armingDisableNames[] = {
PSTR("NO_GYRO"), PSTR("FAILSAFE"), PSTR("RX_FAILSAFE"), PSTR("BAD_RX_RECOVERY"),
PSTR("BOXFAILSAFE"), PSTR("RUNAWAY_TAKEOFF"), PSTR("CRASH_DETECTED"), PSTR("THROTTLE"),
PSTR("ANGLE"), PSTR("BOOT_GRACE_TIME"), PSTR("NOPREARM"), PSTR("LOAD"),
PSTR("CALIBRATING"), PSTR("CLI"), PSTR("CMS_MENU"), PSTR("BST"),
PSTR("MSP"), PSTR("PARALYZE"), PSTR("GPS"), PSTR("RESC"),
PSTR("RPMFILTER"), PSTR("REBOOT_REQUIRED"), PSTR("DSHOT_BITBANG"), PSTR("ACC_CALIBRATION"),
PSTR("MOTOR_PROTOCOL"), PSTR("ARM_SWITCH")
};
const size_t armingDisableNamesLength = sizeof(armingDisableNames) / sizeof(armingDisableNames[0]);

s.println();
s.print(F(" arming disabled:"));
for(size_t i = 0; i < armingDisableNamesLength; i++)
{
if(_model.state.armingDisabledFlags & (1 << i)) {
s.print(' ');
s.print(armingDisableNames[i]);
}
}
s.println();
s.print(F(" arming disabled: "));
s.println(_model.state.armingDisabledFlags);
}
else if(strcmp_P(cmd.args[0], PSTR("stats")) == 0)
{
Expand All @@ -1206,6 +1224,7 @@ class Cli
int time = lrintf(_model.state.stats.getTime(c));
float load = _model.state.stats.getLoad(c);
int freq = lrintf(_model.state.stats.getFreq(c));
int real = lrintf(_model.state.stats.getReal(c));

s.print(FPSTR(_model.state.stats.getName(c)));
s.print(": ");
Expand All @@ -1214,6 +1233,11 @@ class Cli
s.print(time);
s.print("us, ");

if(real < 100) s.print(' ');
if(real < 10) s.print(' ');
s.print(real);
s.print("us/i, ");

if(load < 10) s.print(' ');
s.print(load, 1);
s.print("%, ");
Expand All @@ -1232,36 +1256,6 @@ class Cli
s.print(F("%"));
s.println();
}
else if(strcmp_P(cmd.args[0], PSTR("fsinfo")) == 0)
{
_model.logger.info(&s);
}
else if(strcmp_P(cmd.args[0], PSTR("fsformat")) == 0)
{
s.print(F("wait... "));
_model.logger.format();
s.println(F("OK"));
}
else if(strcmp_P(cmd.args[0], PSTR("logs")) == 0)
{
_model.logger.list(&s);
}
else if(strcmp_P(cmd.args[0], PSTR("log")) == 0)
{
if(!cmd.args[1])
{
_model.logger.show(&s);
return;
}
int id = String(cmd.args[1]).toInt();
if(!id)
{
s.println(F("invalid log id"));
s.println();
return;
}
_model.logger.show(&s, id);
}
else if(strcmp_P(cmd.args[0], PSTR("reboot")) == 0)
{
Hardware::restart(_model);
Expand All @@ -1274,6 +1268,12 @@ class Cli
{
_active = false;
}
else if(strcmp_P(cmd.args[0], PSTR("logs")) == 0)
{
s.print(_model.logger.c_str());
s.print(PSTR("total: "));
s.println(_model.logger.length());
}
else
{
s.print(F("unknown command: "));
Expand Down
4 changes: 3 additions & 1 deletion lib/Espfc/src/Debug_Espfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ extern Stream * _debugStream;
static inline void initDebugStream(Stream * p) { _debugStream = p; }

#define LOG_SERIAL_INIT(p) _debugStream = p;
#define LOG_SERIAL_DEBUG(v) if(_debugStream) { _debugStream->print(' '); _debugStream->print(v); }
#define LOG_SERIAL_DEBUG(v) if(_debugStream) { _debugStream->print(v); }
#define LOG_SERIAL_DEBUG_HEX(v) if(_debugStream) { _debugStream->print(v, HEX); }

template <typename T>
void D(T t)
Expand All @@ -47,6 +48,7 @@ static inline void initDebugStream(Stream * p) {}

#define LOG_SERIAL_INIT(p)
#define LOG_SERIAL_DEBUG(v)
#define LOG_SERIAL_DEBUG_HEX(v)
#define D(...)

#endif
Expand Down
9 changes: 5 additions & 4 deletions lib/Espfc/src/Espfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,25 @@ class Espfc

int begin()
{
_serial.begin();
_model.logStorageResult();
_hardware.begin();
_model.begin();
_mixer.begin();
//_mixer.begin();
_sensor.begin();
_input.begin();
_actuator.begin();
_controller.begin();
_blackbox.begin();
_model.state.buzzer.push(BEEPER_SYSTEM_INIT);

return 1;
}

int beginOther()
{
_serial.begin();
_model.logStorageResult();
_mixer.begin();
_buzzer.begin();
_model.state.buzzer.push(BEEPER_SYSTEM_INIT);
return 1;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Espfc/src/Hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

namespace {
#if defined(ESPFC_SPI_0)
#if defined(ESP32C3)
#if defined(ESP32C3) || defined(ESP32S3) || defined(ESP32S2)
static SPIClass SPI1(HSPI);
#elif defined(ESP32) //where is this defined???
#elif defined(ESP32)
static SPIClass SPI1(VSPI);
#endif
static Espfc::Device::BusSPI spiBus(ESPFC_SPI_0_DEV);
Expand Down
Loading

0 comments on commit 6ec2dcd

Please sign in to comment.