From d74d99c7f13f5f49a16fccece06b1d14c83f3425 Mon Sep 17 00:00:00 2001 From: "Valentin V. Bartenev" Date: Fri, 1 May 2026 15:29:16 +0300 Subject: [PATCH] Add DIY ESP32S3 N16R8 E22 Back2back board support This closes #1. --- boards/diy_esp32s3_n16r8_e22_back2back.json | 44 ++++ .../DIYESP32S3N16R8E22Back2backBoard.h | 54 ++++ .../platformio.ini | 234 ++++++++++++++++++ .../target.cpp | 57 +++++ .../diy_esp32s3_n16r8_e22_back2back/target.h | 21 ++ variants/eastmesh_mqtt/platformio.ini | 25 ++ 6 files changed, 435 insertions(+) create mode 100644 boards/diy_esp32s3_n16r8_e22_back2back.json create mode 100644 variants/diy_esp32s3_n16r8_e22_back2back/DIYESP32S3N16R8E22Back2backBoard.h create mode 100644 variants/diy_esp32s3_n16r8_e22_back2back/platformio.ini create mode 100644 variants/diy_esp32s3_n16r8_e22_back2back/target.cpp create mode 100644 variants/diy_esp32s3_n16r8_e22_back2back/target.h diff --git a/boards/diy_esp32s3_n16r8_e22_back2back.json b/boards/diy_esp32s3_n16r8_e22_back2back.json new file mode 100644 index 00000000..e2997db0 --- /dev/null +++ b/boards/diy_esp32s3_n16r8_e22_back2back.json @@ -0,0 +1,44 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_16MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=0", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=0" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [["0x303A", "0x1001"]], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": ["esp-builtin"], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": ["arduino", "espidf"], + "name": "DIY_ESP32S3_N16R8_E22_Back2back", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://garden.struchkov.dev/ru/files/ESP32-S3-E22-%D1%81%D1%85%D0%B5%D0%BC%D0%B0-NanoVHF-v3.04.pdf", + "vendor": "DIY" +} diff --git a/variants/diy_esp32s3_n16r8_e22_back2back/DIYESP32S3N16R8E22Back2backBoard.h b/variants/diy_esp32s3_n16r8_e22_back2back/DIYESP32S3N16R8E22Back2backBoard.h new file mode 100644 index 00000000..5d1749a8 --- /dev/null +++ b/variants/diy_esp32s3_n16r8_e22_back2back/DIYESP32S3N16R8E22Back2backBoard.h @@ -0,0 +1,54 @@ +#pragma once + +#include +#include +#include + +class DIYESP32S3N16R8E22Back2backBoard : public ESP32Board { +public: + void begin() { + ESP32Board::begin(); + + esp_reset_reason_t reason = esp_reset_reason(); + if (reason == ESP_RST_DEEPSLEEP) { + long wakeup_source = esp_sleep_get_ext1_wakeup_status(); + if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep) + startup_reason = BD_STARTUP_RX_PACKET; + } + + rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS); + rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1); + } + } + + void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1) { + esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); + + // Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep + rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY); + rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1); + + rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS); + + if (pin_wake_btn < 0) { + esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet + } else { + esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn + } + + if (secs > 0) { + esp_sleep_enable_timer_wakeup(secs * 1000000); + } + + // Finally set ESP32 into sleep + esp_deep_sleep_start(); // CPU halts here and never returns! + } + + uint16_t getBattMilliVolts() override { + return 0; + } + + const char* getManufacturerName() const override { + return "DIY ESP32S3 N16R8 E22 Back2back"; + } +}; diff --git a/variants/diy_esp32s3_n16r8_e22_back2back/platformio.ini b/variants/diy_esp32s3_n16r8_e22_back2back/platformio.ini new file mode 100644 index 00000000..99457823 --- /dev/null +++ b/variants/diy_esp32s3_n16r8_e22_back2back/platformio.ini @@ -0,0 +1,234 @@ +[DIY_ESP32S3_N16R8_E22_Back2back] +extends = esp32_base +board = diy_esp32s3_n16r8_e22_back2back +build_flags = + ${esp32_base.build_flags} + ${sensor_base.build_flags} + -I variants/diy_esp32s3_n16r8_e22_back2back + -D DIY_ESP32S3_N16R8_E22_Back2back + -D USE_SX1262 + -D RADIO_CLASS=CustomSX1262 + -D WRAPPER_CLASS=CustomSX1262Wrapper + -D P_LORA_DIO_1=14 + -D P_LORA_NSS=46 + -D P_LORA_RESET=12 + -D P_LORA_BUSY=13 + -D P_LORA_SCLK=9 + -D P_LORA_MISO=11 + -D P_LORA_MOSI=10 + -D SX126X_TXEN=47 + -D SX126X_RXEN=48 + -D LORA_TX_POWER=7 ; configured as 7dbm, because the final output will be ~27dbm (~0.5w) if the PA is enabled. + -D MAX_LORA_TX_POWER=19 ; max output without burning out the PA + -D P_LORA_TX_LED=2 ; free pin (led TX) + -D PIN_BOARD_SDA=5 + -D PIN_BOARD_SCL=4 + -D PIN_USER_BTN=1 ; free pin (none Button key) + -D PIN_GPS_RX=3 ; free pin (none GPS) + -D PIN_GPS_TX=8 ; free pin (none GPS) + -D SX126X_DIO2_AS_RF_SWITCH=true + -D SX126X_DIO3_TCXO_VOLTAGE=1.8 + -D SX126X_CURRENT_LIMIT=140 + -D SX126X_RX_BOOSTED_GAIN=1 +build_src_filter = ${esp32_base.build_src_filter} + +<../variants/diy_esp32s3_n16r8_e22_back2back> + + +lib_deps = + ${esp32_base.lib_deps} + ${sensor_base.lib_deps} + +[env:DIY_ESP32S3_N16R8_E22_Back2back_repeater] +extends = DIY_ESP32S3_N16R8_E22_Back2back +build_flags = + ${DIY_ESP32S3_N16R8_E22_Back2back.build_flags} + -D ADVERT_NAME='"DIY ESP32S3 N16R8 E22 Back2back Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${DIY_ESP32S3_N16R8_E22_Back2back.build_src_filter} + +<../examples/simple_repeater> +lib_deps = + ${DIY_ESP32S3_N16R8_E22_Back2back.lib_deps} + ${esp32_ota.lib_deps} + +; [env:DIY_ESP32S3_N16R8_E22_Back2back_repeater_bridge_rs232] +; extends = DIY_ESP32S3_N16R8_E22_Back2back +; build_flags = +; ${DIY_ESP32S3_N16R8_E22_Back2back.build_flags} +; -D ADVERT_NAME='"RS232 Bridge"' +; -D ADVERT_LAT=0.0 +; -D ADVERT_LON=0.0 +; -D ADMIN_PASSWORD='"password"' +; -D MAX_NEIGHBOURS=50 +; -D WITH_RS232_BRIDGE=Serial2 +; -D WITH_RS232_BRIDGE_RX=5 +; -D WITH_RS232_BRIDGE_TX=6 +; -D BRIDGE_DEBUG=1 +; ; -D MESH_PACKET_LOGGING=1 +; ; -D MESH_DEBUG=1 +; build_src_filter = ${DIY_ESP32S3_N16R8_E22_Back2back.build_src_filter} +; + +; +<../examples/simple_repeater> +; lib_deps = +; ${DIY_ESP32S3_N16R8_E22_Back2back.lib_deps} +; ${esp32_ota.lib_deps} + +[env:DIY_ESP32S3_N16R8_E22_Back2back_repeater_bridge_espnow] +extends = DIY_ESP32S3_N16R8_E22_Back2back +build_flags = + ${DIY_ESP32S3_N16R8_E22_Back2back.build_flags} + -D ADVERT_NAME='"ESPNow Bridge"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 + -D WITH_ESPNOW_BRIDGE=1 +; -D BRIDGE_DEBUG=1 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${DIY_ESP32S3_N16R8_E22_Back2back.build_src_filter} + + + +<../examples/simple_repeater> +lib_deps = + ${DIY_ESP32S3_N16R8_E22_Back2back.lib_deps} + ${esp32_ota.lib_deps} + +[env:DIY_ESP32S3_N16R8_E22_Back2back_logging_repeater] +extends = DIY_ESP32S3_N16R8_E22_Back2back +build_flags = + ${DIY_ESP32S3_N16R8_E22_Back2back.build_flags} + -D ADVERT_NAME='"DIY ESP32S3 N16R8 E22 Back2back Logging Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 + -D MESH_PACKET_LOGGING=1 + -D SX126X_RX_BOOSTED_GAIN=1 +; -D MESH_DEBUG=1 +build_src_filter = ${DIY_ESP32S3_N16R8_E22_Back2back.build_src_filter} + +<../examples/simple_repeater> +lib_deps = + ${DIY_ESP32S3_N16R8_E22_Back2back.lib_deps} + ${esp32_ota.lib_deps} + +; [env:DIY_ESP32S3_N16R8_E22_Back2back_logging_repeater_bridge_rs232] +; extends = DIY_ESP32S3_N16R8_E22_Back2back +; build_flags = +; ${DIY_ESP32S3_N16R8_E22_Back2back.build_flags} +; -D ADVERT_NAME='"RS232 Bridge"' +; -D ADVERT_LAT=0.0 +; -D ADVERT_LON=0.0 +; -D ADMIN_PASSWORD='"password"' +; -D MAX_NEIGHBOURS=50 +; -D MESH_PACKET_LOGGING=1 +; -D SX126X_RX_BOOSTED_GAIN=1 +; -D WITH_RS232_BRIDGE=Serial2 +; -D WITH_RS232_BRIDGE_RX=5 +; -D WITH_RS232_BRIDGE_TX=6 +; -D BRIDGE_DEBUG=1 +; ; -D MESH_DEBUG=1 +; build_src_filter = ${DIY_ESP32S3_N16R8_E22_Back2back.build_src_filter} +; + +; +<../examples/simple_repeater> +; lib_deps = +; ${DIY_ESP32S3_N16R8_E22_Back2back.lib_deps} +; ${esp32_ota.lib_deps} + +[env:DIY_ESP32S3_N16R8_E22_Back2back_logging_repeater_bridge_espnow] +extends = DIY_ESP32S3_N16R8_E22_Back2back +build_flags = + ${DIY_ESP32S3_N16R8_E22_Back2back.build_flags} + -D ADVERT_NAME='"ESPNow Bridge"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 + -D MESH_PACKET_LOGGING=1 + -D SX126X_RX_BOOSTED_GAIN=1 + -D WITH_ESPNOW_BRIDGE=1 +; -D BRIDGE_DEBUG=1 +; -D MESH_DEBUG=1 +build_src_filter = ${DIY_ESP32S3_N16R8_E22_Back2back.build_src_filter} + + + +<../examples/simple_repeater> +lib_deps = + ${DIY_ESP32S3_N16R8_E22_Back2back.lib_deps} + ${esp32_ota.lib_deps} + +[env:DIY_ESP32S3_N16R8_E22_Back2back_room_server] +extends = DIY_ESP32S3_N16R8_E22_Back2back +build_src_filter = ${DIY_ESP32S3_N16R8_E22_Back2back.build_src_filter} + +<../examples/simple_room_server> +build_flags = + ${DIY_ESP32S3_N16R8_E22_Back2back.build_flags} + -D ADVERT_NAME='"DIY ESP32S3 N16R8 E22 Back2back Room"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D ROOM_PASSWORD='"hello"' +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +lib_deps = + ${DIY_ESP32S3_N16R8_E22_Back2back.lib_deps} + ${esp32_ota.lib_deps} + +[env:DIY_ESP32S3_N16R8_E22_Back2back_companion_radio_usb] +extends = DIY_ESP32S3_N16R8_E22_Back2back +build_flags = + ${DIY_ESP32S3_N16R8_E22_Back2back.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 +; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 +; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 +build_src_filter = ${DIY_ESP32S3_N16R8_E22_Back2back.build_src_filter} + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${DIY_ESP32S3_N16R8_E22_Back2back.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:DIY_ESP32S3_N16R8_E22_Back2back_companion_radio_ble] +extends = DIY_ESP32S3_N16R8_E22_Back2back +build_flags = + ${DIY_ESP32S3_N16R8_E22_Back2back.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D BLE_PIN_CODE=123456 + -D BLE_DEBUG_LOGGING=1 + -D OFFLINE_QUEUE_SIZE=256 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${DIY_ESP32S3_N16R8_E22_Back2back.build_src_filter} + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${DIY_ESP32S3_N16R8_E22_Back2back.lib_deps} + densaugeo/base64 @ ~1.4.0 + +[env:DIY_ESP32S3_N16R8_E22_Back2back_companion_radio_wifi] +extends = DIY_ESP32S3_N16R8_E22_Back2back +build_flags = + ${DIY_ESP32S3_N16R8_E22_Back2back.build_flags} + -I examples/companion_radio/ui-new + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D WIFI_DEBUG_LOGGING=1 + -D WIFI_SSID='"myssid"' + -D WIFI_PWD='"mypwd"' + -D OFFLINE_QUEUE_SIZE=256 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${DIY_ESP32S3_N16R8_E22_Back2back.build_src_filter} + + + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-new/*.cpp> +lib_deps = + ${DIY_ESP32S3_N16R8_E22_Back2back.lib_deps} + densaugeo/base64 @ ~1.4.0 diff --git a/variants/diy_esp32s3_n16r8_e22_back2back/target.cpp b/variants/diy_esp32s3_n16r8_e22_back2back/target.cpp new file mode 100644 index 00000000..121ef941 --- /dev/null +++ b/variants/diy_esp32s3_n16r8_e22_back2back/target.cpp @@ -0,0 +1,57 @@ +#include +#include "target.h" + +DIYESP32S3N16R8E22Back2backBoard board; + +#if defined(P_LORA_SCLK) + static SPIClass spi; + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +#else + RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +#endif + +WRAPPER_CLASS radio_driver(radio, board); + +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); + +#if ENV_INCLUDE_GPS + #include + MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock); + EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea); +#else + EnvironmentSensorManager sensors; +#endif + +bool radio_init() { + fallback_clock.begin(); + rtc_clock.begin(Wire); + +#if defined(P_LORA_SCLK) + spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI); + return radio.std_init(&spi); +#else + return radio.std_init(); +#endif +} + +uint32_t radio_get_rng_seed() { + return radio.random(0x7FFFFFFF); +} + +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { + radio.setFrequency(freq); + radio.setSpreadingFactor(sf); + radio.setBandwidth(bw); + radio.setCodingRate(cr); +} + +void radio_set_tx_power(int8_t dbm) { + radio.setOutputPower(dbm); +} + +mesh::LocalIdentity radio_new_identity() { + RadioNoiseListener rng(radio); + return mesh::LocalIdentity(&rng); // create new random identity +} + diff --git a/variants/diy_esp32s3_n16r8_e22_back2back/target.h b/variants/diy_esp32s3_n16r8_e22_back2back/target.h new file mode 100644 index 00000000..b13e2c24 --- /dev/null +++ b/variants/diy_esp32s3_n16r8_e22_back2back/target.h @@ -0,0 +1,21 @@ +#pragma once + +#define RADIOLIB_STATIC_ONLY 1 +#include +#include +#include +#include +#include +#include + +extern DIYESP32S3N16R8E22Back2backBoard board; +extern WRAPPER_CLASS radio_driver; +extern AutoDiscoverRTCClock rtc_clock; +extern EnvironmentSensorManager sensors; + +bool radio_init(); +uint32_t radio_get_rng_seed(); +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); +void radio_set_tx_power(int8_t dbm); +mesh::LocalIdentity radio_new_identity(); + diff --git a/variants/eastmesh_mqtt/platformio.ini b/variants/eastmesh_mqtt/platformio.ini index 82096f15..47bd33c8 100644 --- a/variants/eastmesh_mqtt/platformio.ini +++ b/variants/eastmesh_mqtt/platformio.ini @@ -863,3 +863,28 @@ build_flags = lib_deps = ${Xiao_S3_WIO.lib_deps} ${esp32_ota.lib_deps} + +# https://github.com/VBart/MeshCoreTel-firmware/issues/1 +[env:DIY_ESP32S3_N16R8_E22_Back2back_repeater_mqtt] +extends = DIY_ESP32S3_N16R8_E22_Back2back +build_flags = + ${DIY_ESP32S3_N16R8_E22_Back2back.build_flags} + -D ADVERT_NAME='"DIY ESP32S3 N16R8 E22 Back2back Repeater"' + -D ADVERT_LAT=0.0 + -D ADVERT_LON=0.0 + -D ADMIN_PASSWORD='"password"' + -D MAX_NEIGHBOURS=50 + -D SX126X_RX_BOOSTED_GAIN=1 + -D WITH_MQTT_UPLINK=1 + -D MQTT_DEBUG=1 + -D WIFI_SSID='"myssid"' + -D WIFI_PWD='"mypwd"' + -D MQTT_DEFAULT_IATA='"UNSET"' + -D CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=1 +build_src_filter = ${DIY_ESP32S3_N16R8_E22_Back2back.build_src_filter} + +<../examples/simple_repeater> + + + + +lib_deps = + ${DIY_ESP32S3_N16R8_E22_Back2back.lib_deps} + ${esp32_ota.lib_deps}