From 5495f411700870ed1708f2b8400643522bdbfa33 Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Mon, 26 Jun 2023 12:49:26 +1200 Subject: [PATCH] Update ETX flashing fro 2.9 release of EdgeTX --- python/ETXinitPassthrough.py | 55 --------------------- python/binary_flash.py | 7 +-- python/build_env_setup.py | 3 -- python/external/esptool/esptool/__init__.py | 2 +- python/external/esptool/esptool/loader.py | 15 ++++++ targets/txbp_esp.ini | 2 +- 6 files changed, 19 insertions(+), 65 deletions(-) delete mode 100644 python/ETXinitPassthrough.py diff --git a/python/ETXinitPassthrough.py b/python/ETXinitPassthrough.py deleted file mode 100644 index 7ad42b0..0000000 --- a/python/ETXinitPassthrough.py +++ /dev/null @@ -1,55 +0,0 @@ -import serial, time, sys -import argparse -import serials_find -import external.streamexpect as streamexpect - -def dbg_print(line=''): - sys.stdout.write(line + '\n') - sys.stdout.flush() - -def etx_passthrough_init(port, requestedBaudrate): - sys.stdout.flush() - dbg_print("======== PASSTHROUGH INIT ========") - dbg_print(" Trying to initialize %s @ %s" % (port, requestedBaudrate)) - - s = serial.Serial(port=port, baudrate=requestedBaudrate, - bytesize=8, parity='N', stopbits=1, - timeout=1, xonxoff=0, rtscts=0) - - with streamexpect.wrap(s) as rl: - rl.flush() - rl.write(b"set pulses 0\n") - time.sleep(0.1) - rl.write(b"set rfmod 0 bootpin 1\n") - time.sleep(0.1) - rl.write(b"set rfmod 0 bootpin 0\n") - time.sleep(0.1) - cmd = "serialpassthrough rfmod 0 %s" % requestedBaudrate - dbg_print("Enabling serial passthrough...") - dbg_print(" CMD: '%s'" % cmd) - rl.write(cmd.encode("utf-8")) - rl.write(b'\n') - time.sleep(.2) - rl.flush() - - s.close() - dbg_print("======== PASSTHROUGH DONE ========") - -def init_passthrough(source, target, env): - env.AutodetectUploadPort([env]) - port = env['UPLOAD_PORT'] - etx_passthrough_init(port, env['UPLOAD_SPEED']) - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description="Initialize EdgeTX passthrough to internal module") - parser.add_argument("-b", "--baud", type=int, default=57600, - help="Baud rate for passthrough communication") - parser.add_argument("-p", "--port", type=str, - help="Override serial port autodetection and use PORT") - args = parser.parse_args() - - if (args.port == None): - args.port = serials_find.get_serial_port() - - etx_passthrough_init(args.port, args.baud) diff --git a/python/binary_flash.py b/python/binary_flash.py index dbfd166..14ff5a6 100644 --- a/python/binary_flash.py +++ b/python/binary_flash.py @@ -12,7 +12,6 @@ from os.path import dirname import UnifiedConfiguration -import ETXinitPassthrough import serials_find import upload_via_esp8266_backpack @@ -73,9 +72,8 @@ def upload_esp8266_uart(args): def upload_esp8266_etx(args): if args.port == None: args.port = serials_find.get_serial_port() - ETXinitPassthrough.etx_passthrough_init(args.port, 460800) try: - esptool.main(['--passthrough', '--chip', 'esp8266', '--port', args.port, '--baud', '460800', '--before', 'no_reset', '--after', 'hard_reset', 'write_flash', '0x0000', args.file.name]) + esptool.main(['--passthrough', '--chip', 'esp8266', '--port', args.port, '--baud', '460800', '--before', 'etx', '--after', 'hard_reset', 'write_flash', '0x0000', args.file.name]) except: return ElrsUploadResult.ErrorGeneral return ElrsUploadResult.Success @@ -102,10 +100,9 @@ def upload_esp32_uart(args): def upload_esp32_etx(args): if args.port == None: args.port = serials_find.get_serial_port() - ETXinitPassthrough.etx_passthrough_init(args.port, 460800) try: dir = os.path.dirname(args.file.name) - esptool.main(['--passthrough', '--chip', 'esp32', '--port', args.port, '--baud', '460800', '--before', 'no_reset', '--after', 'hard_reset', 'write_flash', '-z', '--flash_mode', 'dio', '--flash_freq', '40m', '--flash_size', 'detect', '0x1000', 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]) + esptool.main(['--passthrough', '--chip', 'esp32', '--port', args.port, '--baud', '460800', '--before', 'etx', '--after', 'hard_reset', 'write_flash', '-z', '--flash_mode', 'dio', '--flash_freq', '40m', '--flash_size', 'detect', '0x1000', 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 return ElrsUploadResult.Success diff --git a/python/build_env_setup.py b/python/build_env_setup.py index 7de722e..7824f4e 100644 --- a/python/build_env_setup.py +++ b/python/build_env_setup.py @@ -3,7 +3,6 @@ import shutil import upload_via_esp8266_backpack import esp_compress -import ETXinitPassthrough import UnifiedConfiguration platform = env.get('PIOPLATFORM', '') @@ -27,8 +26,6 @@ def copy_bootfile(source, target, env): if "_WIFI" in target_name: env.Replace(UPLOAD_PROTOCOL="custom") env.Replace(UPLOADCMD=upload_via_esp8266_backpack.on_upload) - if "_ETX" in target_name: - env.AddPreAction("upload", ETXinitPassthrough.init_passthrough) elif platform in ['espressif32']: if "_WIFI" in target_name: diff --git a/python/external/esptool/esptool/__init__.py b/python/external/esptool/esptool/__init__.py index b45cb31..7d6dd2c 100644 --- a/python/external/esptool/esptool/__init__.py +++ b/python/external/esptool/esptool/__init__.py @@ -129,7 +129,7 @@ def main(argv=None, esp=None): parser.add_argument( "--before", help="What to do before connecting to the chip", - choices=["default_reset", "usb_reset", "no_reset", "no_reset_no_sync", "passthru"], + choices=["default_reset", "usb_reset", "no_reset", "no_reset_no_sync", "passthru", "etx"], default=os.environ.get("ESPTOOL_BEFORE", "default_reset"), ) diff --git a/python/external/esptool/esptool/loader.py b/python/external/esptool/esptool/loader.py index c350538..840feb2 100644 --- a/python/external/esptool/esptool/loader.py +++ b/python/external/esptool/esptool/loader.py @@ -536,6 +536,21 @@ def bootloader_reset(self, usb_jtag_serial=False, extra_delay=False, mode="defau time.sleep(0.2) self._setDTR(False) # IO0=HIGH, done time.sleep(0.1) + elif mode == 'etx': + self._port.flush() + self._port.write(b"set rfmod 0 power off\n") + time.sleep(0.1) + self._port.write(b"set pulses 0\n") + time.sleep(0.5) + self._port.write(b"set rfmod 0 power on\n") + time.sleep(2.5) + self._port.write(b"set rfmod 0 bootpin 1\n") + time.sleep(0.1) + self._port.write(b"set rfmod 0 bootpin 0\n") + time.sleep(0.1) + cmd = "serialpassthrough rfmod 0 %s" % self._port.baudrate + self._port.write(cmd.encode("utf-8")) + self._port.write(b'\n') elif mode != 'no_reset': self._setDTR(False) # IO0=HIGH self._setRTS(True) # EN=LOW, chip in reset diff --git a/targets/txbp_esp.ini b/targets/txbp_esp.ini index 0046bf0..91fe55e 100644 --- a/targets/txbp_esp.ini +++ b/targets/txbp_esp.ini @@ -14,7 +14,7 @@ upload_resetmethod = nodemcu [env:ESP_TX_Backpack_via_ETX] extends = env:ESP_TX_Backpack_via_UART upload_speed = 460800 -upload_command = python "$PROJECT_DIR/python/external/esptool/esptool.py" --passthrough -b $UPLOAD_SPEED ${UPLOAD_PORT and "-p "+UPLOAD_PORT} -c esp8266 --before no_reset --after soft_reset write_flash 0x0000 "$SOURCE" +upload_command = python "$PROJECT_DIR/python/external/esptool/esptool.py" --passthrough -b $UPLOAD_SPEED ${UPLOAD_PORT and "-p "+UPLOAD_PORT} -c esp8266 --before etx --after soft_reset write_flash 0x0000 "$SOURCE" [env:ESP_TX_Backpack_via_WIFI] extends = env:ESP_TX_Backpack_via_UART