USB communication

I want to make a communication with Hifive1 board through USB so that when i give some inputs from Terminals like GTK term, the controller should give the output.

what is the solution?

If CDC… how to establish cdc in hifive1?

It’s very easy! As explained in the “Getting Started” guide, you can use GNU screen.

sudo screen /dev/ttyUSB1 115200

Or you can use another terminal emulator such as minicom.

You can also write and read /dev/ttyUSB1 using shell scripts or programs written in C, python or whatever you want. Anything you write to the port appears on stdin for the HiFive1 program, and anything you read comes from stdout on the HiFive1.

If you use your own program or script you’ll first want to run …

sudo stty -F /dev/ttyUSB1 115200

The other settings will usually be OK already. You only need to do this once per reboot of the PC usually, but more often doesn’t hurt anything.

Thanks Bruce.I will try it out then.

const char * instructions_msg = "
\n
SIFIVE, INC.\n
\n
5555555555555555555555555\n
5555 5555\n
5555 5555\n
5555 5555\n
5555 5555555555555555555555\n
5555 555555555555555555555555\n
5555 5555\n
5555 5555\n
5555 5555\n
5555555555555555555555555555 55555\n
55555 555555555 55555\n
55555 55555 55555\n
55555 5 55555\n
55555 55555\n
55555 55555\n
55555 55555\n
55555 55555\n
55555 55555\n
555555555\n
55555\n
5\n
\n
SiFive E-Series Software Development Kit ‘demo_gpio’ program.\n
Every 2 second, the Timer Interrupt will invert the LEDs.\n
(Arty Dev Kit Only): Press Buttons 0, 1, 2 to Set the LEDs.\n
Pin 19 (HiFive1) or A5 (Arty Dev Kit) is being bit-banged\n
for GPIO speed demonstration.\n
\n
";

void print_instructions() {

write (STDOUT_FILENO, instructions_msg, strlen(instructions_msg));

}
in main function when this is func is called it writes the msg to STDOUT_FILENO and i can see the o/p as…

but how to read the input from terminal emulator ?? what is the c code ?

i tried read() func it shows me error

If you look in the led_fade sample program you’ll see some input from the terminal.

Great!! yeah…i got it

Thanks for your guidance Bruce.
God bless.:grinning:

I seem to have fallen down a rat hole and can not get out :frowning:

For reasons unknown “screen” simply won’t start and issues a nasty message over and over that it “Cannot open your terminal” and then aborts right away. I did plug in the hifive board to USB and saw that al lwas well in the “dmesg” system log output. Sure enough there are device entries :

root@charon:~# ls -lapbp /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 0 Aug  1 10:34 /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 1 Aug  1 10:34 /dev/ttyUSB1

This is a debian machine so the group is called “dialout” and not “plugdev” and that is no big deal.
I also did create a rules file for udev in /lib/udev/rules.d/ exactly as seen in the getting started guide and then “udevadm control --reload-rules” works just fine.

root@charon:~# udevadm info -q path -n /dev/ttyUSB0
/devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0/ttyUSB0/tty/ttyUSB0

Query that device path with udevadm :

root@charon:~# udevadm test -a -p /devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0/ttyUSB0/tty/ttyUSB0
calling: test
.
.
.
GROUP 20 /lib/udev/rules.d/99-openocd.rules:14
MODE 0664 /lib/udev/rules.d/99-openocd.rules:14
handling device node '/dev/ttyUSB0', devnum=c188:0, mode=0664, uid=0, gid=20
set permissions /dev/ttyUSB0, 020664, uid=0, gid=20
preserve already existing symlink '/dev/char/188:0' to '../ttyUSB0'
found 'c188:0' claiming '/run/udev/links/\x2fserial\x2fby-id\x2fusb-FTDI_Dual_RS232-HS-if00-port0'
creating link '/dev/serial/by-id/usb-FTDI_Dual_RS232-HS-if00-port0' to '/dev/ttyUSB0'
preserve already existing symlink '/dev/serial/by-id/usb-FTDI_Dual_RS232-HS-if00-port0' to '../../ttyUSB0'
found 'c188:0' claiming '/run/udev/links/\x2fserial\x2fby-path\x2fpci-0000:00:14.0-usb-0:9:1.0-port0'
creating link '/dev/serial/by-path/pci-0000:00:14.0-usb-0:9:1.0-port0' to '/dev/ttyUSB0'
preserve already existing symlink '/dev/serial/by-path/pci-0000:00:14.0-usb-0:9:1.0-port0' to '../../ttyUSB0'
created db file '/run/udev/data/c188:0' for '/devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0/ttyUSB0/tty/ttyUSB0'
.ID_PORT=0
ACTION=-p
DEVLINKS=/dev/serial/by-path/pci-0000:00:14.0-usb-0:9:1.0-port0 /dev/serial/by-id/usb-FTDI_Dual_RS232-HS-if00-port0
DEVNAME=/dev/ttyUSB0
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0/ttyUSB0/tty/ttyUSB0
ID_BUS=usb
ID_MODEL=Dual_RS232-HS
ID_MODEL_ENC=Dual\x20RS232-HS
ID_MODEL_FROM_DATABASE=FT2232C Dual USB-UART/FIFO IC
ID_MODEL_ID=6010
ID_PATH=pci-0000:00:14.0-usb-0:9:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_9_1_0
ID_PCI_CLASS_FROM_DATABASE=Serial bus controller
ID_PCI_INTERFACE_FROM_DATABASE=XHCI
ID_PCI_SUBCLASS_FROM_DATABASE=USB controller
ID_REVISION=0700
ID_SERIAL=FTDI_Dual_RS232-HS
ID_TYPE=generic
ID_USB_DRIVER=ftdi_sio
ID_USB_INTERFACES=:ffffff:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=FTDI
ID_VENDOR_ENC=FTDI
ID_VENDOR_FROM_DATABASE=Future Technology Devices International, Ltd
ID_VENDOR_ID=0403
MAJOR=188
MINOR=0
SUBSYSTEM=tty
TAGS=:systemd:
USEC_INITIALIZED=285053913247
Unload module index
Unloaded link configuration context.
root@charon:~# 

All of that looks just fine.

However when I login as the user to “talk” to the board I get a nasty :

$ su - --login --shell /bin/bash rsv 
Password: 
rsv@charon:~$ id
uid=50001(rsv) gid=20002(devl) groups=20002(devl),20(dialout)
rsv@charon:~$ ls -lapd /dev/ttyUSB*
crw-rw-r-- 1 root dialout 188, 0 Aug  1 11:58 /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 1 Aug  1 12:22 /dev/ttyUSB1
rsv@charon:~$ 
rsv@charon:~$ ls -lapb /dev/pts/ | grep "rsv"
rsv@charon:~$ 
rsv@charon:~$ screen /dev/ttyUSB1 115200
Cannot open your terminal '/dev/pts/1' - please check.
rsv@charon:~$ 

It looks like there is no way to ssh into a machine that has these sort of UART serial devices attached via USB and then communicate with them? Or does one have to actually fully log out of a machine and then log back in and then only as a certian user and then only locally on that machine? Anyways I have fallen down a rat hole going in circles trying to figure out what to do that will create a proper pseudo terminal session in /dev/pts that allows screen to work. Thus far it has been baffling.

Dennis