From 532a52354f13a34fecfd5f449699b5c907e52e91 Mon Sep 17 00:00:00 2001 From: Bryce Gruber Date: Tue, 28 May 2024 23:29:48 -0500 Subject: [PATCH 1/9] Fix NH board and test LR mode --- hardware/targets.json | 2 +- src/Timer_main.cpp | 7 +++++-- src/Vrx_main.cpp | 1 + targets/timer.ini | 13 ++++++++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/hardware/targets.json b/hardware/targets.json index 8e26c94b..eeb94689 100644 --- a/hardware/targets.json +++ b/hardware/targets.json @@ -479,7 +479,7 @@ }, "NuclearHazard": { "product_name": "NuclearHazard", - "firmware": "TIMER_ESP32_Backpack", + "firmware": "NuclearHazard_Backpack", "upload_methods": ["wifi"], "platform": "esp32" } diff --git a/src/Timer_main.cpp b/src/Timer_main.cpp index dec612e1..b5da1727 100644 --- a/src/Timer_main.cpp +++ b/src/Timer_main.cpp @@ -342,15 +342,18 @@ void SetSoftMACAddress() firmwareOptions.uid[0] = firmwareOptions.uid[0] & ~0x01; WiFi.mode(WIFI_STA); - WiFi.begin("network-name", "pass-to-network", 1); - WiFi.disconnect(); // Soft-set the MAC address to the passphrase UID for binding #if defined(PLATFORM_ESP8266) wifi_set_macaddr(STATION_IF, firmwareOptions.uid); + WiFi.setOutputPower(20.5); #elif defined(PLATFORM_ESP32) esp_wifi_set_mac(WIFI_IF_STA, firmwareOptions.uid); + WiFi.setTxPower(WIFI_POWER_19_5dBm); + esp_wifi_set_protocol(WIFI_IF_STA , WIFI_PROTOCOL_LR); #endif + WiFi.begin("network-name", "pass-to-network", 1); + WiFi.disconnect(); } void resetBootCounter() diff --git a/src/Vrx_main.cpp b/src/Vrx_main.cpp index 8c6ec54e..e741ac03 100644 --- a/src/Vrx_main.cpp +++ b/src/Vrx_main.cpp @@ -306,6 +306,7 @@ void SetSoftMACAddress() WiFi.setOutputPower(20.5); #elif defined(PLATFORM_ESP32) WiFi.setTxPower(WIFI_POWER_19_5dBm); + esp_wifi_set_protocol( WIFI_IF_STA, WIFI_PROTOCOL_11B| WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_LR); #endif WiFi.begin("network-name", "pass-to-network", 1); WiFi.disconnect(); diff --git a/targets/timer.ini b/targets/timer.ini index b2200366..26f0ec57 100644 --- a/targets/timer.ini +++ b/targets/timer.ini @@ -33,4 +33,15 @@ build_flags = -D PIN_LED=2 [env:TIMER_ESP12F_Backpack_via_WIFI] -extends = env:TIMER_ESP12F_Backpack_via_UART \ No newline at end of file +extends = env:TIMER_ESP12F_Backpack_via_UART + +[env:NuclearHazard_Backpack_via_UART] +extends = env_common_esp32, timer_backpack_common +build_flags = + ${env_common_esp32.build_flags} + ${timer_backpack_common.build_flags} + -D PIN_BUTTON=0 + -D PIN_LED=15 + +[env:NuclearHazard_Backpack_via_WIFI] +extends = env:NuclearHazard_Backpack_via_UART From d2552bb24215bb58b34c7ce7b8c40fee4bc90f8f Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Sun, 21 Jul 2024 11:33:22 +1200 Subject: [PATCH 2/9] Fixes so wifi continues to work correctly All ESP32 devices now do LR mode --- html/scan.js | 2 +- src/Timer_main.cpp | 17 ++++++++++------- src/Tx_main.cpp | 1 + src/Vrx_main.cpp | 4 ++-- targets/common.ini | 4 ++-- targets/debug.ini | 18 +++++++++++++++++- 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/html/scan.js b/html/scan.js index 89ae10ed..10e0c1fd 100644 --- a/html/scan.js +++ b/html/scan.js @@ -28,7 +28,7 @@ function get_mode() { mui.tabs.activate('pane-justified-2'); _('tx_tab').style.display = 'none'; } - if(data['product-name']) _('product-name').textContent = data['product-name']; + if(data['product-name'] && _('product-name')) _('product-name').textContent = data['product-name']; } }; xmlhttp.open("POST", json_url, true); diff --git a/src/Timer_main.cpp b/src/Timer_main.cpp index b5da1727..b73f1665 100644 --- a/src/Timer_main.cpp +++ b/src/Timer_main.cpp @@ -342,18 +342,21 @@ void SetSoftMACAddress() firmwareOptions.uid[0] = firmwareOptions.uid[0] & ~0x01; WiFi.mode(WIFI_STA); - - // Soft-set the MAC address to the passphrase UID for binding #if defined(PLATFORM_ESP8266) - wifi_set_macaddr(STATION_IF, firmwareOptions.uid); WiFi.setOutputPower(20.5); #elif defined(PLATFORM_ESP32) - esp_wifi_set_mac(WIFI_IF_STA, firmwareOptions.uid); WiFi.setTxPower(WIFI_POWER_19_5dBm); - esp_wifi_set_protocol(WIFI_IF_STA , WIFI_PROTOCOL_LR); #endif WiFi.begin("network-name", "pass-to-network", 1); WiFi.disconnect(); + + // Soft-set the MAC address to the passphrase UID for binding + #if defined(PLATFORM_ESP8266) + wifi_set_macaddr(STATION_IF, firmwareOptions.uid); + #elif defined(PLATFORM_ESP32) + esp_wifi_set_mac(WIFI_IF_STA, firmwareOptions.uid); + esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR); + #endif } void resetBootCounter() @@ -439,12 +442,12 @@ void setup() } esp_now_register_recv_cb(OnDataRecv); - + #if defined(PLATFORM_ESP32) esp_now_register_send_cb(OnDataSent); xSemaphoreGive(semaphore); #endif - + registerPeer(firmwareOptions.uid); memcpy(sendAddress, firmwareOptions.uid, 6); diff --git a/src/Tx_main.cpp b/src/Tx_main.cpp index b4c280bb..3ce4facf 100644 --- a/src/Tx_main.cpp +++ b/src/Tx_main.cpp @@ -258,6 +258,7 @@ void SetSoftMACAddress() WiFi.setOutputPower(20.5); #elif defined(PLATFORM_ESP32) WiFi.setTxPower(WIFI_POWER_19_5dBm); + esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR); #endif WiFi.begin("network-name", "pass-to-network", 1); WiFi.disconnect(); diff --git a/src/Vrx_main.cpp b/src/Vrx_main.cpp index e741ac03..0c56fac5 100644 --- a/src/Vrx_main.cpp +++ b/src/Vrx_main.cpp @@ -306,7 +306,7 @@ void SetSoftMACAddress() WiFi.setOutputPower(20.5); #elif defined(PLATFORM_ESP32) WiFi.setTxPower(WIFI_POWER_19_5dBm); - esp_wifi_set_protocol( WIFI_IF_STA, WIFI_PROTOCOL_11B| WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N|WIFI_PROTOCOL_LR); + esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR); #endif WiFi.begin("network-name", "pass-to-network", 1); WiFi.disconnect(); @@ -480,7 +480,7 @@ void loop() turnOffLED(); ESP.restart(); } - #endif + #endif if (connectionState == wifiUpdate) { diff --git a/targets/common.ini b/targets/common.ini index d9c850ce..be837052 100644 --- a/targets/common.ini +++ b/targets/common.ini @@ -37,7 +37,7 @@ build_flags = # ------------------------- COMMON ESP32 DEFINITIONS ----------------- [env_common_esp32] -platform = espressif32@5.2.0 +platform = espressif32@6.7.0 board = esp32dev ; board_build.partitions = min_spiffs.csv upload_speed = 460800 @@ -49,7 +49,7 @@ build_flags = # ------------------------- COMMON ESP32 DEFINITIONS ----------------- [env_common_esp32c3] -platform = espressif32@6.4.0 +platform = espressif32@6.7.0 board = esp32-c3-devkitm-1 board_build.partitions = min_spiffs.csv upload_speed = 460800 diff --git a/targets/debug.ini b/targets/debug.ini index cf5bbff7..d6c0c1f4 100644 --- a/targets/debug.ini +++ b/targets/debug.ini @@ -4,11 +4,11 @@ [env:DEBUG_ESP_RX_Backpack_via_UART] extends = env_common_esp8285, steadyview_vrx_backpack_common +upload_resetmethod = nodemcu build_flags = ${env_common_esp8285.build_flags} ${steadyview_vrx_backpack_common.build_flags} -D DEBUG_LOG - -D DEBUG_ELRS_WIFI -D PIN_LED=16 -D PIN_MOSI=12 ;Some pin (not a UART) -D PIN_CLK=0 ;Boot pad @@ -17,6 +17,21 @@ build_flags = [env:DEBUG_ESP_RX_Backpack_via_WIFI] extends = env:DEBUG_ESP_RX_Backpack_via_UART +[env:DEBUG_ESP32_RX_Backpack_via_UART] +extends = env_common_esp32, steadyview_vrx_backpack_common +upload_resetmethod = nodemcu +build_flags = + ${env_common_esp32.build_flags} + ${steadyview_vrx_backpack_common.build_flags} + -D DEBUG_LOG + -D PIN_LED=2 + -D PIN_MOSI=18 ;Some pin (not a UART) + -D PIN_CLK=19 ;Boot pad + -D PIN_CS=5 ;Some other pin (not a UART) + +[env:DEBUG_ESP32_RX_Backpack_via_WIFI] +extends = env:DEBUG_ESP32_RX_Backpack_via_UART + # ******************************** # Transmitter backpack targets # ******************************** @@ -41,6 +56,7 @@ extends = env_common_esp32, tx_backpack_common build_flags = ${env_common_esp32.build_flags} ${tx_backpack_common.build_flags} + -D DEBUG_LOG -D PIN_BUTTON=0 -D PIN_LED=4 lib_ignore = STM32UPDATE From 2706d5aad05599af88855ce725de910ed24aac21 Mon Sep 17 00:00:00 2001 From: Bryce Gruber Date: Sat, 20 Jul 2024 20:56:52 -0500 Subject: [PATCH 3/9] s3 & c3 targets --- hardware/targets.json | 26 +++++++++++++++++++++++++- targets/common.ini | 14 +++++++++++++- targets/timer.ini | 24 +++++++++++++++++++++++- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/hardware/targets.json b/hardware/targets.json index eeb94689..b47257e1 100644 --- a/hardware/targets.json +++ b/hardware/targets.json @@ -459,6 +459,18 @@ "firmware": "TIMER_ESP12F_Backpack", "upload_methods": ["uart", "wifi"], "platform": "esp8285" + }, + "esp32c3": { + "product_name": "Backpack for Race Timer with ESP32C3", + "firmware": "TIMER_ESP32C3_Backpack", + "upload_methods": ["uart", "wifi"], + "platform": "esp32-c3" + }, + "esp32s3": { + "product_name": "Backpack for Race Timer with ESP32S3", + "firmware": "TIMER_ESP32S3_Backpack", + "upload_methods": ["uart", "wifi"], + "platform": "esp32-s3" } } }, @@ -482,7 +494,19 @@ "firmware": "NuclearHazard_Backpack", "upload_methods": ["wifi"], "platform": "esp32" + }, + "esp32c3": { + "product_name": "ESP32C3 Module (DIY)", + "firmware": "TIMER_ESP32C3_Backpack", + "upload_methods": ["uart", "wifi"], + "platform": "esp32-c3" + }, + "esp32s3": { + "product_name": "ESP32S3 Module (DIY)", + "firmware": "TIMER_ESP32S3_Backpack", + "upload_methods": ["uart", "wifi"], + "platform": "esp32-s3" } } } -} +} \ No newline at end of file diff --git a/targets/common.ini b/targets/common.ini index d9c850ce..3bad3a17 100644 --- a/targets/common.ini +++ b/targets/common.ini @@ -47,7 +47,7 @@ board_build.f_cpu = 240000000L build_flags = -D PLATFORM_ESP32=1 -# ------------------------- COMMON ESP32 DEFINITIONS ----------------- +# ------------------------- COMMON ESP32C3 DEFINITIONS ----------------- [env_common_esp32c3] platform = espressif32@6.4.0 board = esp32-c3-devkitm-1 @@ -60,6 +60,18 @@ build_flags = -D PLATFORM_ESP32=1 lib_ignore = STM32UPDATE +# ------------------------- COMMON ESP32S3 DEFINITIONS ----------------- +[env_common_esp32s3] +platform = espressif32@6.4.0 +board = esp32-s3-devkitc-1 +; board_build.partitions = min_spiffs.csv +upload_speed = 460800 +monitor_speed = 460800 +upload_resetmethod = nodemcu +board_build.f_cpu = 240000000L +build_flags = + -D PLATFORM_ESP32=1 + # ------------------------- COMMON TX-BACKPACK DEFINITIONS ----------------- [tx_backpack_common] build_flags = diff --git a/targets/timer.ini b/targets/timer.ini index 26f0ec57..3927e881 100644 --- a/targets/timer.ini +++ b/targets/timer.ini @@ -35,6 +35,28 @@ build_flags = [env:TIMER_ESP12F_Backpack_via_WIFI] extends = env:TIMER_ESP12F_Backpack_via_UART +[env:TIMER_ESP32C3_Backpack_via_UART] +extends = env_common_esp32c3, timer_backpack_common +build_flags = + ${env_common_esp32c3.build_flags} + ${timer_backpack_common.build_flags} + -D PIN_BUTTON=0 + -D PIN_LED=8 + +[env:TIMER_ESP32C3_Backpack_via_WIFI] +extends = env:TIMER_ESP32C3_Backpack_via_UART + +[env:TIMER_ESP32S3_Backpack_via_UART] +extends = env_common_esp32s3, timer_backpack_common +build_flags = + ${env_common_esp32s3.build_flags} + ${timer_backpack_common.build_flags} + -D PIN_BUTTON=0 + -D PIN_LED=21 + +[env:TIMER_ESP32S3_Backpack_via_WIFI] +extends = env:TIMER_ESP32S3_Backpack_via_UART + [env:NuclearHazard_Backpack_via_UART] extends = env_common_esp32, timer_backpack_common build_flags = @@ -44,4 +66,4 @@ build_flags = -D PIN_LED=15 [env:NuclearHazard_Backpack_via_WIFI] -extends = env:NuclearHazard_Backpack_via_UART +extends = env:NuclearHazard_Backpack_via_UART \ No newline at end of file From 81cd8c2dccafe72a63c3f41ec870230b72221346 Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Sun, 21 Jul 2024 14:10:55 +1200 Subject: [PATCH 4/9] Allow the binary flasher to flash ESP32-S3 and C3 --- python/binary_flash.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/binary_flash.py b/python/binary_flash.py index a93fb2f8..e0461ca3 100644 --- a/python/binary_flash.py +++ b/python/binary_flash.py @@ -93,7 +93,7 @@ def upload_esp32_uart(args): args.port = serials_find.get_serial_port() try: dir = os.path.dirname(args.file.name) - start_addr = '0x0000' if args.platform.startswith('esp32-c') else '0x1000' + start_addr = '0x0000' if args.platform.startswith('esp32-') else '0x1000' esptool.main(['--chip', args.platform.replace('-', ''), '--port', args.port, '--baud', str(args.baud), '--after', 'hard_reset', 'write_flash', '-z', '--flash_mode', 'dio', '--flash_freq', '40m', '--flash_size', 'detect', start_addr, os.path.join(dir, 'bootloader.bin'), '0x8000', os.path.join(dir, 'partitions.bin'), '0xe000', os.path.join(dir, 'boot_app0.bin'), '0x10000', args.file.name]) except: return ElrsUploadResult.ErrorGeneral @@ -104,7 +104,7 @@ def upload_esp32_etx(args): args.port = serials_find.get_serial_port() try: dir = os.path.dirname(args.file.name) - start_addr = '0x0000' if args.platform.startswith('esp32-c') else '0x1000' + start_addr = '0x0000' if args.platform.startswith('esp32-') else '0x1000' esptool.main(['--passthrough', '--chip', args.platform.replace('-', ''), '--port', args.port, '--baud', '460800', '--before', 'etx', '--after', 'hard_reset', 'write_flash', '-z', '--flash_mode', 'dio', '--flash_freq', '40m', '--flash_size', 'detect', start_addr, os.path.join(dir, 'bootloader.bin'), '0x8000', os.path.join(dir, 'partitions.bin'), '0xe000', os.path.join(dir, 'boot_app0.bin'), '0x10000', args.file.name]) except: return ElrsUploadResult.ErrorGeneral @@ -115,7 +115,7 @@ def upload_esp32_passthru(args): args.port = serials_find.get_serial_port() try: dir = os.path.dirname(args.file.name) - start_addr = '0x0000' if args.platform.startswith('esp32-c') else '0x1000' + start_addr = '0x0000' if args.platform.startswith('esp32-') else '0x1000' esptool.main(['--passthrough', '--chip', args.platform.replace('-', ''), '--port', args.port, '--baud', '230400', '--before', 'passthru', '--after', 'hard_reset', 'write_flash', '-z', '--flash_mode', 'dio', '--flash_freq', '40m', '--flash_size', 'detect', start_addr, os.path.join(dir, 'bootloader.bin'), '0x8000', os.path.join(dir, 'partitions.bin'), '0xe000', os.path.join(dir, 'boot_app0.bin'), '0x10000', args.file.name]) except: return ElrsUploadResult.ErrorGeneral From 7840b090fa7bd2cbaefe876193bd5f2986ccc6a3 Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Sun, 21 Jul 2024 14:36:21 +1200 Subject: [PATCH 5/9] Minor change to use the BOOT button on C3 boards --- targets/timer.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/timer.ini b/targets/timer.ini index 3927e881..185a083f 100644 --- a/targets/timer.ini +++ b/targets/timer.ini @@ -40,7 +40,7 @@ extends = env_common_esp32c3, timer_backpack_common build_flags = ${env_common_esp32c3.build_flags} ${timer_backpack_common.build_flags} - -D PIN_BUTTON=0 + -D PIN_BUTTON=9 -D PIN_LED=8 [env:TIMER_ESP32C3_Backpack_via_WIFI] From 221c0c6994c64b4a7f051c5119d032910ed708b8 Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Sun, 21 Jul 2024 16:24:18 +1200 Subject: [PATCH 6/9] Fix for AP not working with LR mode --- lib/WIFI/devWIFI.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/WIFI/devWIFI.cpp b/lib/WIFI/devWIFI.cpp index ad172110..14f6749f 100644 --- a/lib/WIFI/devWIFI.cpp +++ b/lib/WIFI/devWIFI.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #else #include #include @@ -646,6 +647,7 @@ static void HandleWebUpdate() WiFi.softAP(wifi_ap_ssid, wifi_ap_password); WiFi.scanNetworks(true); startServices(); + esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N); break; case WIFI_STA: DBGLN("Connecting to home network '%s' '%s'", station_ssid, station_password); From 978bc483fc76021e9e55b0eb9b011a09c857e9ae Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Sun, 21 Jul 2024 16:35:38 +1200 Subject: [PATCH 7/9] Protect the call to disable the LR mode to ESP32 only --- lib/WIFI/devWIFI.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/WIFI/devWIFI.cpp b/lib/WIFI/devWIFI.cpp index 14f6749f..0e38edbd 100644 --- a/lib/WIFI/devWIFI.cpp +++ b/lib/WIFI/devWIFI.cpp @@ -647,7 +647,9 @@ static void HandleWebUpdate() WiFi.softAP(wifi_ap_ssid, wifi_ap_password); WiFi.scanNetworks(true); startServices(); + #if defined(PLATFORM_ESP32) esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N); + #endif break; case WIFI_STA: DBGLN("Connecting to home network '%s' '%s'", station_ssid, station_password); From efda1c1cd9f246f54b643114a43bfd7b17ec617b Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Sun, 21 Jul 2024 17:26:01 +1200 Subject: [PATCH 8/9] Make all ESP32 variant use the same platform --- targets/common.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/common.ini b/targets/common.ini index 3a4aef0c..1405a4a3 100644 --- a/targets/common.ini +++ b/targets/common.ini @@ -62,7 +62,7 @@ lib_ignore = STM32UPDATE # ------------------------- COMMON ESP32S3 DEFINITIONS ----------------- [env_common_esp32s3] -platform = espressif32@6.4.0 +platform = espressif32@6.7.0 board = esp32-s3-devkitc-1 ; board_build.partitions = min_spiffs.csv upload_speed = 460800 From d67786a7e137150265c92b07f0c99774b318bf8f Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Mon, 22 Jul 2024 07:52:36 +1200 Subject: [PATCH 9/9] build consistency --- targets/common.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/targets/common.ini b/targets/common.ini index 1405a4a3..6a78c14c 100644 --- a/targets/common.ini +++ b/targets/common.ini @@ -39,13 +39,14 @@ build_flags = [env_common_esp32] platform = espressif32@6.7.0 board = esp32dev -; board_build.partitions = min_spiffs.csv +board_build.partitions = min_spiffs.csv upload_speed = 460800 monitor_speed = 460800 upload_resetmethod = nodemcu board_build.f_cpu = 240000000L build_flags = -D PLATFORM_ESP32=1 +lib_ignore = STM32UPDATE # ------------------------- COMMON ESP32C3 DEFINITIONS ----------------- [env_common_esp32c3] @@ -64,13 +65,14 @@ lib_ignore = STM32UPDATE [env_common_esp32s3] platform = espressif32@6.7.0 board = esp32-s3-devkitc-1 -; board_build.partitions = min_spiffs.csv +board_build.partitions = min_spiffs.csv upload_speed = 460800 monitor_speed = 460800 upload_resetmethod = nodemcu board_build.f_cpu = 240000000L build_flags = -D PLATFORM_ESP32=1 +lib_ignore = STM32UPDATE # ------------------------- COMMON TX-BACKPACK DEFINITIONS ----------------- [tx_backpack_common]