Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python support for uart_tsi #1677

Open
2 tasks done
T-K-233 opened this issue Dec 1, 2023 · 2 comments
Open
2 tasks done

Add Python support for uart_tsi #1677

T-K-233 opened this issue Dec 1, 2023 · 2 comments
Assignees

Comments

@T-K-233
Copy link
Member

T-K-233 commented Dec 1, 2023

Background Work

Feature Description

Add Python support for uart_tsi so that the bringup program can run on Windows/Mac.

Motivating Example

Use pyserial to enable unified UART interface in Python program. This will also allow us to interface with other applications running on the host PC, such as RoSE simulations.

@T-K-233 T-K-233 self-assigned this Dec 1, 2023
@jerryz123
Copy link
Contributor

Yes a python uart_tsi library would be good.

@T-K-233
Copy link
Member Author

T-K-233 commented Dec 29, 2023

A preliminary implementation for those who need the functionality now:

import struct

import serial

port = "/dev/ttyUSB3"
baudrate = 115200

ser = serial.Serial(port=port, baudrate=baudrate)


CMD_READ = 0x00
CMD_WRITE = 0x01


def readWord(address):
    command = CMD_READ
    header = struct.pack("<LQQ", command, address, 0)
    ser.write(header)

    received = ser.read(4)
    rx_data, = struct.unpack("<L", received)
    return rx_data

def writeWord(address, data):
    command = CMD_WRITE
    header = struct.pack("<LQQ", command, address, 0)
    payload = struct.pack("<L", data)
    buffer = header + payload
    ser.write(buffer)


if __name__ == "__main__":

    writeWord(0x08000000, 0xdeadbeef)
    
    print(hex(readWord(0x08000000)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants