Udev rules
.
Description
Just a rule to facilitate reading data from Serial, e.g.:
cat /dev/ttyACM0
the rule for the defaults :
/etc/udev/rules.d/99-STMicro.rules
ACTION=="add", SUBSYSTEM=="tty", ENV{ID_VENDOR}=="STMicroelectronics", ENV{ID_MM_CANDIDATE}="0", RUN+="/bin/stty -F $devnode 9600 cs8 -cstopb -parenb"
Next
Reload the rules to take effect
udevadm control --reload && udevadm trigger # reinsert USB
Notes
If necessary, change ID_VENDOR to a more unique attribute from
udevadm info /dev/ttyACM0
More Info
from the stty manual
- 9600 : "set the input and output speeds to N bauds"
- cs8 : "set character size to N bits, N in [5..8]"
- -cstopb : "use two stop bits per character (one with '-')"
- -parenb : "generate parity bit in output and expect parity bit in input"
Debug Info
ID_MM_CANDIDATE is set to prevent modemmanager (line 16) to take control of the device and mess the settings up. One could also disable line 16, but it will be updated, probably.
/lib/udev/rules.d/80-mm-candidate.rules in Gentoo Linux
# do not edit this file, it will be overwritten on update # Tag any devices that MM might be interested in; if ModemManager is started # up right after udev, when MM explicitly requests devices on startup it may # get devices that haven't had all rules run yet. Thus, we tag devices we're # interested in and when handling devices during MM startup we ignore any # that don't have this tag. MM will still get the udev 'add' event for the # device a short while later and then process it as normal. ACTION!="add|change|move", GOTO="mm_candidate_end" # Opening bound but disconnected Bluetooth RFCOMM ttys would initiate the # connection. Don't do that. KERNEL=="rfcomm[0-9]*", DEVPATH=="*/virtual/*", GOTO="mm_candidate_end" SUBSYSTEM=="tty", ENV{ID_MM_CANDIDATE}="1" SUBSYSTEM=="net", ENV{ID_MM_CANDIDATE}="1" KERNEL=="cdc-wdm*", SUBSYSTEM=="usb", ENV{ID_MM_CANDIDATE}="1" KERNEL=="cdc-wdm*", SUBSYSTEM=="usbmisc", ENV{ID_MM_CANDIDATE}="1" LABEL="mm_candidate_end"
- tested with NUCLEO-F303RE -
Import programBlink_n_Print
Blink the onboard LED, and Print it's status in Serial
Please log in to post comments.