From 3ba0d52ca7a58210efd765f692a5cbc93bdd58df Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 10 Mar 2025 18:29:35 +0100 Subject: [PATCH] Start implementing support for SX1268, not working yet. --- Boards.h | 48 ++++++++++++------- CHANGELOG.md | 10 ++++ Display.h | 2 +- ...firmware-and-compile-it_MeesElectronics.md | 34 ++++++------- Makefile | 18 +++---- Power.h | 2 +- Utilities.h | 13 +++-- 7 files changed, 79 insertions(+), 48 deletions(-) diff --git a/Boards.h b/Boards.h index 3c8a409..b343c0c 100644 --- a/Boards.h +++ b/Boards.h @@ -127,7 +127,9 @@ #define MODEL_FF 0xFF // Homebrew board, max 14dBm output power // Board added by Mees Electronics - #define BOARD_WAVESHARE_ESP32_S3_PICO 0x61 // Waveshare ESP32 S3 Pico + #define BOARD_MEES_ESP32_S3 0x61 // Mees Electronics ESP32 S3 board + #define MODEL_F1 0xF1 // SX1278 + #define MODEL_F2 0xF2 // SX1268 // Displays #define OLED 0x01 @@ -1028,7 +1030,7 @@ }; // Board definition added by Mees Electronics - #elif BOARD_MODEL == BOARD_WAVESHARE_ESP32_S3_PICO + #elif BOARD_MODEL == BOARD_MEES_ESP32_S3 #define IS_ESP32S3 true #define HAS_DISPLAY false #define HAS_BLUETOOTH false @@ -1050,6 +1052,7 @@ #endif #endif + #if BOARD_VARIANT == MODEL_F1 const uint8_t interfaces[INTERFACE_COUNT] = {SX1278}; const bool interface_cfg[INTERFACE_COUNT][3] = { // SX1278 @@ -1059,21 +1062,6 @@ false // DIO2_AS_RF_SWITCH }, }; - /*const int8_t interface_pins[INTERFACE_COUNT][10] = { - // SX1278 - { - 39, // pin_ss - 38, // pin_sclk - 37, // pin_mosi - 36, // pin_miso - -1, // pin_busy - 35, // pin_dio - 40, // pin_reset - -1, // pin_txen - -1, // pin_rxen - -1 // pin_tcxo_enable - } - };*/ const int8_t interface_pins[INTERFACE_COUNT][10] = { // SX1278 { @@ -1089,6 +1077,32 @@ -1 // pin_tcxo_enable } }; + #elif BOARD_VARIANT == MODEL_F2 + const uint8_t interfaces[INTERFACE_COUNT] = {SX1262}; + const bool interface_cfg[INTERFACE_COUNT][3] = { + // SX1262 + { + false, // DEFAULT_SPI + true, // HAS_TCXO + true // DIO2_AS_RF_SWITCH + }, + }; + const int8_t interface_pins[INTERFACE_COUNT][10] = { + // SX1262 + { + 10, // pin_ss + 12, // pin_sclk + 11, // pin_mosi + 13, // pin_miso + 16, // pin_busy + 15, // pin_dio + 14, // pin_reset + -1, // pin_txen + 17, // pin_rxen + -1 // pin_tcxo_enable + } + }; + #endif #else #error An unsupported ESP32 board was selected. Cannot compile RNode firmware. diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a4572a..8af473f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,16 @@ All notable changes to this project will be documented in this file. Fixed : for any bug fixes. Security : in case of vulnerabilities. +### 2025-03-10 + +#### Changed + +Renamed BOARD_WAVESHARE_ESP32_S3_PICO to MEES_ESP32_S3 in source code. Also renamed firmware-waveshare-esp32-s3-pico to firmware-mees-esp32-s3, upload-waveshare-esp32-s3-pico to upload-mees-esp32-s3 and release-waveshare-esp32-s3-pico to release-mees-esp32-s3. This way it is obvious the firmware works for all generic ESP32 S3 boards. + +#### Added + +Two BOARD_VARIANTs: 0xF1 for SX1278 and 0xF2 for SX1268. Can be chosen during compile time. + ### 2025-03-03 Final pinout of LoRa module defined. Should work on most ESP32-S3 development boards. diff --git a/Display.h b/Display.h index 3384f8f..e6797fb 100644 --- a/Display.h +++ b/Display.h @@ -483,7 +483,7 @@ bool display_init() { disp_mode = DISP_MODE_PORTRAIT; display.setRotation(3); // Added by Mees Electronics - #elif BOARD_MODEL == BOARD_WAVESHARE_ESP32_S3_PICO + #elif BOARD_MODEL == BOARD_MEES_ESP32_S3 disp_mode = DISP_MODE_LANDSCAPE; display.setRotation(0); #else diff --git a/Documentation/HOWTO-change-firmware-and-compile-it_MeesElectronics.md b/Documentation/HOWTO-change-firmware-and-compile-it_MeesElectronics.md index 54901a1..5a8412d 100644 --- a/Documentation/HOWTO-change-firmware-and-compile-it_MeesElectronics.md +++ b/Documentation/HOWTO-change-firmware-and-compile-it_MeesElectronics.md @@ -58,7 +58,7 @@ Be patient, this can take up to 15 minutes to complete. Wait for the command pro Go to the directory `~/RNode_Firmware_CE`. This is the source code of the RNode firmware. Here you will find all the files needed to compile the firmware. You can edit these files with any text editor you like. -Let's say we want to add support for the Waveshare ESP32-S3 Pico with an SX1278 LoRa transceiver. First we have to define a BOARD_MODEL. This is an 8 bit value that is used in the source code to select the right code for the hardware. Let's choose 0x61 as the BOARD_MODEL as this number is not used yet. Optional we can also define a BOARD_VARIANT. This defines the variant of the board. A board could come with different LoRa transceivers, for example. It is also a unique 8 bit number. For now, we ignore this BOARD_VARIANT and only use the BOARD_MODEL. +Let's say we want to add support for our homebrew ESP32-S3 with an SX1278 LoRa transceiver. First we have to define a BOARD_MODEL. This is an 8 bit value that is used in the source code to select the right code for the hardware. Let's choose 0x61 as the BOARD_MODEL as this number is not used yet. Optional we can also define a BOARD_VARIANT. This defines the variant of the board. A board could come with different LoRa transceivers, for example. It is also a unique 8 bit number. For now, we ignore this BOARD_VARIANT and only use the BOARD_MODEL. ### Makefile @@ -68,13 +68,13 @@ Every target board has a section `firmware-`, `upload-` ``` # Added board from Mees Electronics -firmware-waveshare-esp32-s3-pico: +firmware-mees-esp32-s3: arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x61\"" ``` ``` # Added board from Mees Electronics -upload-waveshare-esp32-s3-pico: +upload-mees-esp32-s3: arduino-cli upload -p $(or $(port), /dev/ttyACM0) --fqbn esp32:esp32:esp32s3 @sleep 1 rnodeconf $(or $(port), /dev/ttyACM0) --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware_CE.ino.bin) @@ -83,17 +83,17 @@ upload-waveshare-esp32-s3-pico: ``` ``` -release-waveshare-esp32-s3-pico: +release-mees-esp32-s3: arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x61\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_waveshare-esp32-s3-pico.boot_app0 - cp build/esp32.esp32.waveshare-esp32-s3-pico/RNode_Firmware_CE.ino.bin build/rnode_firmware_waveshare-esp32-s3-pico.bin - cp build/esp32.esp32.waveshare-esp32-s3-pico/RNode_Firmware_CE.ino.bootloader.bin build/rnode_firmware_waveshare-esp32-s3-pico.bootloader - cp build/esp32.esp32.waveshare-esp32-s3-pico/RNode_Firmware_CE.ino.partitions.bin build/rnode_firmware_waveshare-esp32-s3-pico.partitions - zip --junk-paths ./Release/rnode_firmware_waveshare-esp32-s3-pico.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_waveshare-esp32-s3-pico.boot_app0 build/rnode_firmware_waveshare-esp32-s3-pico.bin build/rnode_firmware_waveshare-esp32-s3-pico.bootloader build/rnode_firmware_waveshare-esp32-s3-pico.partitions + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_mees-esp32-s3.boot_app0 + cp build/esp32.esp32.mees-esp32-s3/RNode_Firmware_CE.ino.bin build/rnode_firmware_mees-esp32-s3.bin + cp build/esp32.esp32.mees-esp32-s3/RNode_Firmware_CE.ino.bootloader.bin build/rnode_firmware_mees-esp32-s3.bootloader + cp build/esp32.esp32.mees-esp32-s3/RNode_Firmware_CE.ino.partitions.bin build/rnode_firmware_mees-esp32-s3.partitions + zip --junk-paths ./Release/rnode_firmware_mees-esp32-s3.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_mees-esp32-s3.boot_app0 build/rnode_firmware_mees-esp32-s3.bin build/rnode_firmware_mees-esp32-s3.bootloader build/rnode_firmware_mees-esp32-s3.partitions rm -r build ``` -The `upload-waveshare-esp32-s3-pico` section assumes the ESP32 S3 is connected to serial port /dev/ttyACM0. On your system, this could be another port. Manual change all the `/dev/ttyACM0` to the port on your system. +The `upload-mees-esp32-s3` section assumes the ESP32 S3 is connected to serial port /dev/ttyACM0. On your system, this could be another port. Manual change all the `/dev/ttyACM0` to the port on your system. ### Boards.h @@ -102,7 +102,7 @@ The file `Board.h` is the most important file to edit. This is the place where t First, the new board has to be defined at the beginning of the file. Search for the line `#define MODEL_FF 0xFF // Homebrew board, max 14dBm output power` and add the new definition below that line: // Board added by Mees Electronics - #define BOARD_WAVESHARE_ESP32_S3_PICO 0x61 // Waveshare ESP32 S3 Pico + #define BOARD_MEES_ESP32_S3 0x61 // Mees electronics ESP32 S3 Next, search for the line `#if MCU_VARIANT == MCU_ESP32`. This is the part where all the ESP32 variant are defined. This section stops at the line `#elif MCU_VARIANT == MCU_NRF52`. From here the definitions for the NRF52 board begin. @@ -115,7 +115,7 @@ Somewhere between these to lines we have to add our board definition. It is good The new code: // Board definition added by Mees Electronics - #elif BOARD_MODEL == BOARD_WAVESHARE_ESP32_S3_PICO + #elif BOARD_MODEL == BOARD_MEES_ESP32_S3 #define IS_ESP32S3 true #define HAS_DISPLAY false #define HAS_BLUETOOTH false @@ -185,7 +185,7 @@ In this file, the routines for the optional external LEDs are defined. If the ne Search for the line `#if MCU_VARIANT == MCU_ESP32`. Because there are several of these lines, make sure you have the right one: the next line should be `#if HAS_NP == true`. Here you will find a bunch of `#elif BOARD_MODEL ==` lines. Find the last one of this if block, which ends with `#endif`. Add the new section for our board just before the `#endif`: - #elif BOARD_MODEL == BOARD_WAVESHARE_ESP32_S3_PICO + #elif BOARD_MODEL == BOARD_MEES_ESP32_S3 void led_rx_on() { digitalWrite(pin_led_rx, HIGH); } void led_rx_off() { digitalWrite(pin_led_rx, LOW); } void led_tx_on() { digitalWrite(pin_led_tx, HIGH); } @@ -241,7 +241,7 @@ After adding our new board section, the code looks something like this: #elif BOARD_MODEL == BOARD_GENERIC_ESP32 if (model == MODEL_FF || model == MODEL_FE) { // Added by Mees Electronics - #elif BOARD_MODEL == BOARD_WAVESHARE_ESP32_S3_PICO + #elif BOARD_MODEL == BOARD_MEES_ESP32_S3 if (model == MODEL_A4) { #else ``` @@ -293,7 +293,7 @@ if (model == MODEL_A1) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN); if (model == MODEL_A4) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN); ``` -The `MODEL_A4` is an 8 bit value read from the EEPROM. This is the value we will write to the EEPROM later in this document with the command `rnodeconf /dev/ttyACM0 -r --platform ESP32 --model a4 --product f0 --hwrev 3`. The model number a4 is chosen from a list published in the file [https://git.meezenest.nl/marcel/RNode_Firmware_CE/src/branch/master/Documentation/BUILDING.md](https://git.meezenest.nl/marcel/RNode_Firmware_CE/src/branch/master/Documentation/BUILDING.md). It is shared with another board and it is probably better to choose a unique value. But it could be that Reticulum uses this value and maybe choosing a new number breaks Reticulum. Further research is needed. But for now let's use a4, because it works. +The `MODEL_A4` is an 8 bit value read from the EEPROM. This is the value we will write to the EEPROM later in this document with the command `rnodeconf /dev/ttyACM0 -r --platform ESP32 --model a4 --product f0 --hwrev 3`. The model number a4 is chosen from a list published in the file [https://git.meezenest.nl/marcel/RNode_Firmware_CE/src/branch/master/Documentation/BUILDING.md](https://git.meezenest.nl/marcel/RNode_Firmware_CE/src/branch/master/Documentation/BUILDING.md). It is shared with another board and it is probably better to choose a unique value. But `rnodeconf` uses this value and choosing a new number breaks Reticulum. Further research is needed. But for now let's use a4, because it works. ### Display.h @@ -315,11 +315,11 @@ If you are flashing a custom board, you will need to generate a signing key in r Compile the code: - $ make firmware-waveshare-esp32-s3-pico + $ make firmware-mees-esp32-s3 Than flash the firmware: - $ make upload-waveshare-esp32-s3-pico + $ make upload-mees-esp32-s3 This first time you flash a new board, this command will end with the error `This device has not been provisioned yet, cannot set firmware hash`. That is because the EEPROM is not programmes yet You will need to provision the EEPROM before use: diff --git a/Makefile b/Makefile index 4a5231c..1275867 100644 --- a/Makefile +++ b/Makefile @@ -156,9 +156,9 @@ firmware-heltec_t114_gps: arduino-cli compile --log --fqbn Heltec_nRF52:Heltec_nRF52:HT-n5262 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3C\" \"-DBOARD_VARIANT=0xCB\"" # Added board from Mees Electronics -firmware-waveshare-esp32-s3-pico: +firmware-mees-esp32-s3: #arduino-cli compile --fqbn esp32:esp32:ttgo-lora32 $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x61\"" - arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x61\"" + arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x61\" \"-DBOARD_VARIANT=0xF2\"" upload-tbeam: arduino-cli upload -p $(or $(port), /dev/ttyACM0) --fqbn esp32:esp32:t-beam @@ -274,7 +274,7 @@ upload-techo: rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes from_device /dev/ttyACM0) # Added board from Mees Electronics -upload-waveshare-esp32-s3-pico: +upload-mees-esp32-s3: arduino-cli upload -p $(or $(port), /dev/ttyACM0) --fqbn esp32:esp32:esp32s3 @sleep 1 python3 ./Release/esptool/esptool.py --port $(or $(port), /dev/ttyACM0) --chip esp32-s3 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin @@ -529,11 +529,11 @@ release-heltec_t114: rm -r build # Added by Mees Electronics -release-waveshare-esp32-s3-pico: +release-mees-esp32-s3: arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x61\" \"-DBOARD_VARIANT=0x31\"" - cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_waveshare-esp32-s3-pico.boot_app0 - cp build/esp32.esp32.waveshare-esp32-s3-pico/RNode_Firmware_CE.ino.bin build/rnode_firmware_waveshare-esp32-s3-pico.bin - cp build/esp32.esp32.waveshare-esp32-s3-pico/RNode_Firmware_CE.ino.bootloader.bin build/rnode_firmware_waveshare-esp32-s3-pico.bootloader - cp build/esp32.esp32.waveshare-esp32-s3-pico/RNode_Firmware_CE.ino.partitions.bin build/rnode_firmware_waveshare-esp32-s3-pico.partitions - zip --junk-paths ./Release/rnode_firmware_waveshare-esp32-s3-pico.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_t3s3_sx126xrnode_firmware_waveshare-esp32-s3-pico.boot_app0 build/rnode_firmware_waveshare-esp32-s3-pico.bin build/rnode_firmware_waveshare-esp32-s3-pico.bootloader build/rnode_firmware_waveshare-esp32-s3-pico.partitions + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_mees-esp32-s3.boot_app0 + cp build/esp32.esp32.mees-esp32-s3/RNode_Firmware_CE.ino.bin build/rnode_firmware_mees-esp32-s3.bin + cp build/esp32.esp32.mees-esp32-s3/RNode_Firmware_CE.ino.bootloader.bin build/rnode_firmware_mees-esp32-s3.bootloader + cp build/esp32.esp32.mees-esp32-s3/RNode_Firmware_CE.ino.partitions.bin build/rnode_firmware_mees-esp32-s3.partitions + zip --junk-paths ./Release/rnode_firmware_mees-esp32-s3.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_t3s3_sx126xrnode_firmware_mees-esp32-s3.boot_app0 build/rnode_firmware_mees-esp32-s3.bin build/rnode_firmware_mees-esp32-s3.bootloader build/rnode_firmware_mees-esp32-s3.partitions rm -r build diff --git a/Power.h b/Power.h index 828c764..057be08 100644 --- a/Power.h +++ b/Power.h @@ -164,7 +164,7 @@ bool bat_voltage_dropping = false; float bat_delay_v = 0; float bat_state_change_v = 0; -#elif BOARD_MODEL == BOARD_WAVESHARE_ESP32_S3_PICO +#elif BOARD_MODEL == BOARD_MEES_ESP32_S3 #define BAT_V_MIN 3.15 #define BAT_V_MAX 4.3 #define BAT_V_CHG 4.48 diff --git a/Utilities.h b/Utilities.h index ae215a0..3c5e0f3 100644 --- a/Utilities.h +++ b/Utilities.h @@ -293,7 +293,7 @@ uint8_t boot_vector = 0x00; void led_tx_off() { digitalWrite(pin_led_tx, LOW); } void led_id_on() { } void led_id_off() { } - #elif BOARD_MODEL == BOARD_WAVESHARE_ESP32_S3_PICO + #elif BOARD_MODEL == BOARD_MEES_ESP32_S3 void led_rx_on() { digitalWrite(pin_led_rx, HIGH); } void led_rx_off() { digitalWrite(pin_led_rx, LOW); } void led_tx_on() { digitalWrite(pin_led_tx, HIGH); } @@ -1259,7 +1259,14 @@ void setTXPower(RadioInterface* radio, int txp) { if (model == MODEL_FF) radio->setTxPower(txp, PA_OUTPUT_RFO_PIN); // Added by Mees Electronics - if (model == MODEL_A4) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN); + if (model == MODEL_A4) { + if (interfaces[radio->getIndex()] == SX1278) { + radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN); + } else { + radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN); + } + + } } uint8_t getRandom(RadioInterface* radio) { @@ -1543,7 +1550,7 @@ bool eeprom_model_valid() { #elif BOARD_MODEL == BOARD_GENERIC_ESP32 if (model == MODEL_FF || model == MODEL_FE) { // Added by Mees Electronics - #elif BOARD_MODEL == BOARD_WAVESHARE_ESP32_S3_PICO + #elif BOARD_MODEL == BOARD_MEES_ESP32_S3 if (model == MODEL_A4) { #else if (false) {