diff --git a/resource/tools/enter_dfu.py b/resource/tools/enter_dfu.py new file mode 100755 index 0000000..7111c8a --- /dev/null +++ b/resource/tools/enter_dfu.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import serial +import serial.tools.list_ports as list_ports + +DFUCMD=b'\x11\xef\x03\xf2\x00\x00\x00\x00\x0b\x00' + +port = None +for comport in list_ports.comports(): + if comport.vid == 0x1915 and comport.pid == 0x521f: + print("Chameleon already in DFU mode") + exit(0) + if comport.vid == 0x6868 and comport.pid == 0x8686: + port = comport.device + break + +if port is None: + print("Chameleon not found") + exit(1) + +try: + serial_instance = serial.Serial(port=port, baudrate=115200) + serial_instance.dtr = 1 # must make dtr enable + serial_instance.timeout = 0 # noblock + serial_instance.write(DFUCMD) +except Exception as e: + print(f"Serial Error {e}.") + exit(1) +finally: + serial_instance.close() diff --git a/resource/tools/enter_dfu_over_ble.py b/resource/tools/enter_dfu_over_ble.py new file mode 100755 index 0000000..70430a9 --- /dev/null +++ b/resource/tools/enter_dfu_over_ble.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +import asyncio +from bleak import BleakClient +from bleak import BleakScanner + +UUID_NORDIC_TX = "6e400002-b5a3-f393-e0a9-e50e24dcca9e" +UUID_NORDIC_RX = "6e400003-b5a3-f393-e0a9-e50e24dcca9e" +DFUCMD=b'\x11\xef\x03\xf2\x00\x00\x00\x00\x0b\x00' + +async def main(): + print("Searching ChameleonUltra...") + device = await BleakScanner.find_device_by_name("ChameleonUltra") + if device is None: + print("Could not find ChameleonUltra") + return + print("Found!") + print("Sending DFU command") + async with BleakClient(device) as client: + c=DFUCMD + await client.write_gatt_char(UUID_NORDIC_TX, bytearray(DFUCMD), False) + print("Done!") + +asyncio.run(main())