@@ -282,30 +282,38 @@ def _write_data_address(self, address: int, value: int):
282282 self .send_int (value )
283283 self .get_ack ()
284284
285- def enable_uart_passthrough (self , baudrate : int , persist = False ):
285+ def enable_uart_passthrough (self , baudrate : int ):
286286 """Relay all data received by the device to TXD/RXD.
287287
288- If a period > 0.5 seconds elapses between two transmit/receive events,
289- the device resets and resumes normal mode. This timeout feature has
290- been implemented in lieu of a hard reset option.
291-
292288 Can be used to load programs into secondary microcontrollers with
293289 bootloaders such ATMEGA or ESP8266
294290
295291 Parameters
296292 ----------
297293 baudrate : int
298- Baudrate of the UART bus.
299- persist : bool, optional
300- If set to True, the device will stay in passthrough mode until the
301- next power cycle. Otherwise(default scenario), the device will
302- return to normal operation if no data is sent/received for a period
303- greater than one second at a time.
294+ Baudrate of the UART2 bus.
304295 """
296+ if self .firmware .major < 3 :
297+ self ._uart_passthrough_legacy (baudrate )
298+ else :
299+ self ._uart_passthrough (baudrate )
300+
301+ def _uart_passthrough (self , baudrate : int ) -> None :
305302 self .send_byte (CP .PASSTHROUGHS )
306303 self .send_byte (CP .PASS_UART )
307- self .send_byte (1 if persist else 0 )
308- self .send_int (int (round (((64e6 / baudrate ) / 4 ) - 1 )))
304+ self .send_int (self ._get_brgval (baudrate ))
305+ self .interface .baudrate = baudrate
306+
307+ def _uart_passthrough_legacy (self , baudrate : int ) -> None :
308+ self .send_byte (CP .PASSTHROUGHS_LEGACY )
309+ self .send_byte (CP .PASS_UART )
310+ disable_watchdog = 1
311+ self .send_byte (disable_watchdog )
312+ self .send_int (self ._get_brgval (baudrate ))
313+
314+ @staticmethod
315+ def _get_brgval (baudrate : int ) -> int :
316+ return int ((CP .CLOCK_RATE / (4 * baudrate )) - 1 )
309317
310318 def read_log (self ):
311319 """Read hardware debug log.
0 commit comments