MCPcopy Create free account
hub / github.com/ExpressLRS/ExpressLRS / reset_to_bootloader

Function reset_to_bootloader

src/python/BFinitPassthrough.py:114–147  ·  view source on GitHub ↗
(port, baud, target, action, accept=None, chip_type='ESP82')

Source from the content-addressed store, hash-verified

112
113
114def reset_to_bootloader(port, baud, target, action, accept=None, chip_type='ESP82') -> int:
115 dbg_print("======== RESET TO BOOTLOADER ========")
116 s = serial.Serial(port=port, baudrate=baud,
117 bytesize=8, parity='N', stopbits=1,
118 timeout=1, xonxoff=0, rtscts=0)
119 rl = SerialHelper.SerialHelper(s, 3.)
120 rl.clear()
121 BootloaderInitSeq = bootloader.get_init_seq(chip_type)
122 dbg_print(" * Using full duplex (CRSF)")
123 #this is the training sequ for the ROM bootloader, we send it here so it doesn't auto-neg to the wrong baudrate by the BootloaderInitSeq that we send to reset ELRS
124 rl.write(b'\x07\x07\x12\x20' + 32 * b'\x55')
125 time.sleep(0.2)
126 rl.write(BootloaderInitSeq)
127 s.flush()
128 rx_target = rl.read_line().strip().upper()
129 if target is not None:
130 flash_target = re.sub("_VIA_.*", "", target.upper())
131 ignore_incorrect_target = action == "uploadforce"
132 if rx_target == "":
133 dbg_print("Cannot detect RX target, blindly flashing!")
134 elif ignore_incorrect_target:
135 dbg_print(f"Force flashing {flash_target}, detected {rx_target}")
136 elif rx_target != flash_target and rx_target != accept:
137 if query_yes_no("\n\n\nWrong target selected! your RX is '%s', trying to flash '%s', continue? Y/N\n" % (rx_target, flash_target)):
138 dbg_print("Ok, flashing anyway!")
139 else:
140 dbg_print("Wrong target selected your RX is '%s', trying to flash '%s'" % (rx_target, flash_target))
141 return ElrsUploadResult.ErrorMismatch
142 elif flash_target != "":
143 dbg_print("Verified RX target '%s'" % (flash_target))
144 time.sleep(.5)
145 s.close()
146
147 return ElrsUploadResult.Success
148
149def init_passthrough(source, target, env) -> int:
150 env.AutodetectUploadPort([env])

Callers 2

init_passthroughFunction · 0.85
mainFunction · 0.85

Calls 6

clearMethod · 0.95
writeMethod · 0.95
read_lineMethod · 0.95
query_yes_noFunction · 0.90
dbg_printFunction · 0.70
flushMethod · 0.45

Tested by

no test coverage detected