From 9556f0b91b67654427c20fab0377653af1a545ae Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 5 Oct 2024 02:47:54 +0200 Subject: [PATCH] Added support for T3S3 boards with SX127x modems --- Boards.h | 28 ++++++++++++++-------------- Config.h | 2 +- Makefile | 36 +++++++++++++++++++++++++++++++++--- RNode_Firmware.ino | 5 +++-- Utilities.h | 14 ++++++++------ sx127x.cpp | 7 ++++++- 6 files changed, 65 insertions(+), 27 deletions(-) diff --git a/Boards.h b/Boards.h index 05d2d5d..b4900ef 100644 --- a/Boards.h +++ b/Boards.h @@ -41,11 +41,11 @@ #define MODEL_A2 0xA2 // RNode v2.1, 433 MHz #define MODEL_A7 0xA7 // RNode v2.1, 868 MHz - #define BOARD_RNODE_NG_22 0x42 // RNode hardware revision v2.2 + #define BOARD_RNODE_NG_22 0x42 // RNode hardware revision v2.2 (T3S3) #define MODEL_A1 0xA1 // RNode v2.2, 433 MHz with SX1268 - #define MODEL_A5 0xA1 // RNode v2.2, 433 MHz with SX1278 + #define MODEL_A5 0xA5 // RNode v2.2, 433 MHz with SX1278 #define MODEL_A6 0xA6 // RNode v2.2, 868 MHz with SX1262 - #define MODEL_AA 0xA6 // RNode v2.2, 868 MHz with SX1276 + #define MODEL_AA 0xAA // RNode v2.2, 868 MHz with SX1276 #define PRODUCT_TBEAM 0xE0 // T-Beam devices #define BOARD_TBEAM 0x33 @@ -396,11 +396,6 @@ #elif BOARD_MODEL == BOARD_RNODE_NG_22 #define IS_ESP32S3 true - #define MODEM SX1262 - #define DIO2_AS_RF_SWITCH true - #define HAS_BUSY true - #define HAS_TCXO true - #define HAS_DISPLAY true #define HAS_CONSOLE false #define HAS_BLUETOOTH false @@ -414,8 +409,6 @@ #define HAS_SLEEP true #define PIN_WAKEUP GPIO_NUM_0 #define WAKEUP_LEVEL 0 - // #define PIN_DISP_SLEEP 21 - // #define DISP_SLEEP_LEVEL HIGH const int pin_btn_usr1 = 0; const int pin_cs = 7; @@ -423,10 +416,16 @@ const int pin_sclk = 5; const int pin_mosi = 6; const int pin_miso = 3; - const int pin_tcxo_enable = -1; - - const int pin_dio = 33; - const int pin_busy = 34; + const int pin_dio = 9; + + #if MODEM == SX1262 + #define DIO2_AS_RF_SWITCH true + #define HAS_BUSY true + #define HAS_TCXO true + const int pin_busy = 34; + const int pin_dio = 33; + const int pin_tcxo_enable = -1; + #endif const int pin_np = 38; const int pin_dac = 25; @@ -436,6 +435,7 @@ const int SD_MOSI = 11; const int SD_CLK = 14; const int SD_CS = 13; + #if HAS_NP == false #if defined(EXTERNAL_LEDS) const int pin_led_rx = 37; diff --git a/Config.h b/Config.h index dd325c0..07572aa 100644 --- a/Config.h +++ b/Config.h @@ -20,7 +20,7 @@ #define CONFIG_H #define MAJ_VERS 0x01 - #define MIN_VERS 0x4b + #define MIN_VERS 0x4c #define MODE_HOST 0x11 #define MODE_TNC 0x12 diff --git a/Makefile b/Makefile index 04e2125..a2dd2dd 100644 --- a/Makefile +++ b/Makefile @@ -76,7 +76,10 @@ firmware-tbeam_sx126x: check_bt_buffers arduino-cli compile --log --fqbn esp32:esp32:t-beam -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x33\" \"-DMODEM=0x03\"" firmware-t3s3: - arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\"" + arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x03\"" + +firmware-t3s3_sx127x: + arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x01\"" firmware-tdeck: arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3B\"" @@ -206,8 +209,8 @@ upload-t3s3: arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:esp32s3 @sleep 1 rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin) - @sleep 3 - python ./Release/esptool/esptool.py --chip esp32s3 --port /dev/ttyACM0 --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 + #@sleep 3 + #python ./Release/esptool/esptool.py --chip esp32s3 --port /dev/ttyACM0 --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 upload-featheresp32: arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:featheresp32 @@ -368,6 +371,33 @@ release-t3s3: zip --junk-paths ./Release/rnode_firmware_t3s3.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_t3s3.boot_app0 build/rnode_firmware_t3s3.bin build/rnode_firmware_t3s3.bootloader build/rnode_firmware_t3s3.partitions rm -r build +release-t3s3_sx127x: + arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x01\"" + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_t3s3_sx127x.boot_app0 + cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin build/rnode_firmware_t3s3_sx127x.bin + cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_t3s3_sx127x.bootloader + cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.partitions.bin build/rnode_firmware_t3s3_sx127x.partitions + zip --junk-paths ./Release/rnode_firmware_t3s3_sx127x.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_t3s3_sx127x.boot_app0 build/rnode_firmware_t3s3_sx127x.bin build/rnode_firmware_t3s3_sx127x.bootloader build/rnode_firmware_t3s3_sx127x.partitions + rm -r build + +release-tdeck: + arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3B\"" + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_tdeck.boot_app0 + cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin build/rnode_firmware_tdeck.bin + cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_tdeck.bootloader + cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.partitions.bin build/rnode_firmware_tdeck.partitions + zip --junk-paths ./Release/rnode_firmware_tdeck.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_tdeck.boot_app0 build/rnode_firmware_tdeck.bin build/rnode_firmware_tdeck.bootloader build/rnode_firmware_tdeck.partitions + rm -r build + +release-tbeam_supreme: + arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3D\"" + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_tbeam_supreme.boot_app0 + cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin build/rnode_firmware_tbeam_supreme.bin + cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_tbeam_supreme.bootloader + cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.partitions.bin build/rnode_firmware_tbeam_supreme.partitions + zip --junk-paths ./Release/rnode_firmware_tbeam_supreme.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_tbeam_supreme.boot_app0 build/rnode_firmware_tbeam_supreme.bin build/rnode_firmware_tbeam_supreme.bootloader build/rnode_firmware_tbeam_supreme.partitions + rm -r build + release-featheresp32: check_bt_buffers arduino-cli compile --fqbn esp32:esp32:featheresp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x34\"" cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_featheresp32.boot_app0 diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index 7884d7f..b91cb8a 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -1206,6 +1206,7 @@ void validate_status() { } } else { hw_ready = false; + Serial.write("Invalid EEPROM checksum\r\n"); #if HAS_DISPLAY if (disp_ready) { device_init_done = true; @@ -1215,7 +1216,7 @@ void validate_status() { } } else { hw_ready = false; - // Serial.write("Invalid EEPROM configuration\r\n"); + Serial.write("Invalid EEPROM configuration\r\n"); #if HAS_DISPLAY if (disp_ready) { device_init_done = true; @@ -1225,7 +1226,7 @@ void validate_status() { } } else { hw_ready = false; - // Serial.write("Device unprovisioned, no device configuration found in EEPROM\r\n"); + Serial.write("Device unprovisioned, no device configuration found in EEPROM\r\n"); #if HAS_DISPLAY if (disp_ready) { device_init_done = true; diff --git a/Utilities.h b/Utilities.h index eb7e41a..0a3fffb 100644 --- a/Utilities.h +++ b/Utilities.h @@ -1095,10 +1095,12 @@ void setTXPower() { if (model == MODEL_A2) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN); if (model == MODEL_A3) LoRa->setTxPower(lora_txp, PA_OUTPUT_RFO_PIN); if (model == MODEL_A4) LoRa->setTxPower(lora_txp, PA_OUTPUT_RFO_PIN); + if (model == MODEL_A5) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN); if (model == MODEL_A6) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN); if (model == MODEL_A7) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN); if (model == MODEL_A8) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN); if (model == MODEL_A9) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN); + if (model == MODEL_AA) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN); if (model == MODEL_B3) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN); if (model == MODEL_B4) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN); @@ -1326,11 +1328,11 @@ bool eeprom_lock_set() { } bool eeprom_product_valid() { - #if HAS_EEPROM - uint8_t rval = EEPROM.read(eeprom_addr(ADDR_PRODUCT)); - #elif MCU_VARIANT == MCU_NRF52 - uint8_t rval = eeprom_read(eeprom_addr(ADDR_PRODUCT)); - #endif + #if HAS_EEPROM + uint8_t rval = EEPROM.read(eeprom_addr(ADDR_PRODUCT)); + #elif MCU_VARIANT == MCU_NRF52 + uint8_t rval = eeprom_read(eeprom_addr(ADDR_PRODUCT)); + #endif #if PLATFORM == PLATFORM_AVR if (rval == PRODUCT_RNODE || rval == PRODUCT_HMBRW) { @@ -1360,7 +1362,7 @@ bool eeprom_model_valid() { #elif BOARD_MODEL == BOARD_RNODE_NG_21 if (model == MODEL_A2 || model == MODEL_A7) { #elif BOARD_MODEL == BOARD_RNODE_NG_22 - if (model == MODEL_A1 || model == MODEL_A6) { + if (model == MODEL_A1 || model == MODEL_A6 || model == MODEL_A5 || model == MODEL_AA) { #elif BOARD_MODEL == BOARD_HMBRW if (model == MODEL_FF || model == MODEL_FE) { #elif BOARD_MODEL == BOARD_TBEAM diff --git a/sx127x.cpp b/sx127x.cpp index 64f138d..5548d51 100644 --- a/sx127x.cpp +++ b/sx127x.cpp @@ -106,7 +106,12 @@ void sx127x::flush() { } bool sx127x::preInit() { pinMode(_ss, OUTPUT); digitalWrite(_ss, HIGH); - SPI.begin(); + + #if BOARD_MODEL == BOARD_RNODE_NG_22 + SPI.begin(pin_sclk, pin_miso, pin_mosi, pin_cs); + #else + SPI.begin(); + #endif // Check modem version uint8_t version;