If you have issues in Linux with uploading Arduino firmwares - Page 1
Forum section: electronics / general

author: Nominal Animal
author_rank: Super Contributor
timestamp: December 08, 2019, 11:15:54 pm
content: in Ubuntu 18.04 or later, or similar Debian derivatives, it looks likeudevrules no longer stop ModemManager from interfering with the serial device enough to confuseavrdude, so uploading from the Arduino environment usually fails.The only option is to stop ModemManager:sudo systemctl stop ModemManager.serviceIf you do not use modems, you can safely disable the entire service,sudo systemctl disable ModemManager.servicejust remember to enable it first if you ever need to use a modem.I do believe the root cause is a race window in systemd (udev, specifically), that allows ModemManager access to the device regardless of the environment variables, and just happens to be remarkably easy to hit on some computers.This is what happens when you let crap programmers aggregate useful-looking code and push it to millions of users.I only found out about this when a friend was having odd problems with Pro Micro clones in the Arduino environment on Ubuntu 18.04 LTS.If the defaultdialoutgroup ownership does not work, you can create say/lib/udev/rules.d/81-arduino.rulesto change the device group to whatever suits you better. For Arduino Leonardo and Pro Micro clones,Code:# Arduino Leonardo, Pro Micro clonesATTRS{idVendor}=="2341", ATTRS{idProduct}=="0036", GROUP:="dialout", MODE:="0660", ENV{ID_MM_CANDIDATE}:="", ENV{ID_MM_DEVICE_IGNORE}:="1", ENV{ID_MM_PORT_IGNORE}:="1", ENV{MTP_NO_PROBE}:="1"ATTRS{idVendor}=="2341", ATTRS{idProduct}=="8036", GROUP:="dialout", MODE:="0660", ENV{ID_MM_CANDIDATE}:="", ENV{ID_MM_DEVICE_IGNORE}:="1", ENV{ID_MM_PORT_IGNORE}:="1", ENV{MTP_NO_PROBE}:="1"Just remember to runsudo udevadm control --reloadto tell udev to use the new rules.I also change my Arduinoboards.txtto haveCode:leonardo.upload.use_1200bps_touch=falseas I prefer to have a set sequence for updating sketches: connecting RST to GND for a couple of seconds, then selecting the board in Tool > Port and hitting Sketch > Update, within eight seconds of disconnecting RST from GND. (They're next to each other on the Pro Micro clones.)The default "set baud rate to 1200" trick to reset the microcontrollers and run the bootloader is problematic, again due to how systemd's udev handles the device attach/detach cases. It is avoidable by completely reworking the way the Arduino environment selects and accesses microcontrollers that switch USB VID:PID to a different one during firmware upload, but the way Arduino does it, used to work.. the systemd developers don't give a shit about that, though.(Basically, the baud rate reset by the microcontroller causes udev to give the usb serial interface a new USB serial device, and since Arduino assumes it stays the same [for historical reasons!], it loses the serial connection to the boot loader on the microcontroller. Keeping the RST at GND for a second makes sure the old device is removed first, so when you disconnect RST from GND, udevshouldgive it the same USB serial device.)The proper way, of course, is to label each microcontroller based on their USB device path, and retry access every 0.1s or so for a couple of seconds, as the USB device will be down during resets/switching to bootloader mode. You could easily support any number of simultaneously connected microcontrollers then too.I'm tempted to do something about this. Why the hell do people insist on building big frameworks and overcomplicated monolithic applications? Small modular tools and the Unix philosophy has a proven track record over decades, whereas big sprawly blobs rarely survive a decade without a drastic rewrite!

author: agehall
author_rank: Frequent Contributor
timestamp: December 09, 2019, 07:19:19 am
content: Quote from: Nominal Animal on December 08, 2019, 11:15:54 pmIn the case of systemd and the likes of it, it feels very much like the Linux community saw what Solaris did with SMF and felt they needed to have the same thing. The only problem being that the linux versions of SMF sucks.If you have the time to do something about it, please do. I think it would be a huge step forward for Linux distros.