Skip to content

Commit

Permalink
Fix UART passthrough on v6
Browse files Browse the repository at this point in the history
  • Loading branch information
bessman committed Aug 18, 2024
1 parent c66fcac commit 8dc9bf7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pslab/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@
# --------COMMUNICATION PASSTHROUGHS--------
# Data sent to the device is directly routed to output ports such as (SCL, SDA for UART)

PASSTHROUGHS = Byte.pack(15)
PASS_UART = Byte.pack(1)
# PASSTHROUGHS = Byte.pack(15)
# PASS_UART = Byte.pack(1)

# /*--------STOP STREAMING------*/
# STOP_STREAMING = Byte.pack(253)
Expand Down
30 changes: 18 additions & 12 deletions pslab/sciencelab.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,29 +282,35 @@ def _write_data_address(self, address: int, value: int):
self.send_int(value)
self.get_ack()

def enable_uart_passthrough(self, baudrate: int, persist=False):
def enable_uart_passthrough(self, baudrate: int):
"""Relay all data received by the device to TXD/RXD.
If a period > 0.5 seconds elapses between two transmit/receive events,
the device resets and resumes normal mode. This timeout feature has
been implemented in lieu of a hard reset option.
Can be used to load programs into secondary microcontrollers with
bootloaders such ATMEGA or ESP8266
Parameters
----------
baudrate : int
Baudrate of the UART bus.
persist : bool, optional
If set to True, the device will stay in passthrough mode until the
next power cycle. Otherwise(default scenario), the device will
return to normal operation if no data is sent/received for a period
greater than one second at a time.
"""
self.send_byte(CP.PASSTHROUGHS)
if "V6" in self.version:
self._uart_passthrough_v6(baudrate)
else:
self._uart_passthrough_v5(baudrate)

def _uart_passthrough_v6(self, baudrate: int) -> None:
passthrough = 12
self.send_byte(passthrough)
self.send_byte(CP.PASS_UART)
self.send_int(int(round(((64e6 / baudrate) / 4) - 1)))
self.interface.baudrate = baudrate

def _uart_passthrough_v5(self, baudrate: int) -> None:
passthrough = 15
self.send_byte(passthrough)
self.send_byte(CP.PASS_UART)
self.send_byte(1 if persist else 0)
disable_watchdog = 1
self.send_byte(disable_watchdog)
self.send_int(int(round(((64e6 / baudrate) / 4) - 1)))

def read_log(self):
Expand Down

0 comments on commit 8dc9bf7

Please sign in to comment.