Merge pull request #35 from doegox/phil_tools_dfu

Add helper scripts to enter DFU from USB or from BLE
This commit is contained in:
DXL
2023-07-22 14:00:36 +08:00
committed by GitHub
2 changed files with 54 additions and 0 deletions
+30
View File
@@ -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()
+24
View File
@@ -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())