I’m new to the HiFive 1 and I need to execute some C scripts through Python and obtain their performance counters, I can execute them through the console line using the freedom-e-sdk and using the metal.h library I can obtain these but within the same script. But I need to do the process via Python. Is there a way to get a result from the board to the code in Python?
I imagine you mean the host Python, not a e.g MicroPython running on the board itself? And you want to communicate with something running on the board?
If so you’d generally communicate through the USB UART as that’s what is available anyway, and define some protocol over it. E.g. for a simple text-based, line-based request-reply protocol:
import serial
# Adapt this as needed-
UART='/dev/serial/by-id/usb-FTDI_Dual_RS232-HS-if01-port0'
BAUDRATE=115200
ser = serial.Serial(port=UART, baudrate=BAUDRATE)
ser.write("getstats\n")
line = ser.readline()
… # parse result line
Other options would be raw binary, or SLIP which is fairly common for serial protocols as it’s self-synchronizing. But this is testable using a terminal program.
(Alternatively, I realize, you could periodically report statistics from the program running on the board without any kind of interactive protocol, and parse those; it depends on the kind of synchronization you need between host and board)