Arduino_STM32/tools/linux
Alberto Alonso 9b03f0841d
Solve race condition with arduino IDE monitoring serial port
I encountered a race condition upon which, even though the udev rules were working and uploads succeed, the serial monitor can not re-establish communications.

If the serial monitor is left open when doing an upload the error shown is:

[...]
Copying data from PC to DFU device
Starting download: [##################################################] finished!
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present
Done!
Resetting USB to switch back to runtime mode
Waiting for /dev/ttyACM0 serial...Done
processing.app.SerialException: Error opening serial port '/dev/ttyACM0'. Try consulting the documentation at http://playground.arduino.cc/Linux/All#Permission
	at processing.app.Serial.<init>(Serial.java:145)
	at processing.app.Serial.<init>(Serial.java:82)
	at processing.app.SerialMonitor$4.<init>(SerialMonitor.java:101)
	at processing.app.SerialMonitor.open(SerialMonitor.java:101)
	at processing.app.AbstractMonitor.resume(AbstractMonitor.java:104)
	at processing.app.Editor.resumeOrCloseSerialMonitor(Editor.java:2218)
	at processing.app.Editor.access$2200(Editor.java:79)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2196)
	at java.lang.Thread.run(Thread.java:748)
Error opening serial port '/dev/ttyACM0'. Try consulting the documentation at http://playground.arduino.cc/Linux/All#Permission

I traced it to the device being opened prior to the permissions/ownership changes.

When testing via -c the upload script waits for the character device creation, but at that point the udev rules have not changed the permissions. By testing the readability of the device via the -r test, we wait until the new permissions have been applied.

I imagine this is specific to the Linux kernel and the speed of the machine being used. In my case:
arduino-1.8.5
Linux 4.4.0-98-generic #121-Ubuntu SMP
but the change should work on any system with proper udev rules / permissions.
2017-11-13 12:15:07 -06:00
..
dfu-util Bugfix for HardWire/I2C + configured/compiled dfu-util to work on Linux again 2015-08-01 18:58:14 +01:00
src Started to add linux 64 bit support, by copying the linux folder to linux64 and changeing platform.txt. Also copied scr folder into each platform's folder to allow the src to be distributed even if the tools are split up when using the Board Manager 2016-05-07 08:02:54 +10:00
stlink added linux32 versions of stm32flash and stlink binaries and used scripts from OSX for these in linux as the scripts are identical 2015-05-02 19:09:45 +10:00
stm32flash Built Linux binary and also changed printed message to indicate this is a special version built for Arduino STM32 2015-07-08 19:48:57 +10:00
45-maple.rules Updated Linux 45-maple.rules 2016-12-02 10:32:17 +11:00
49-stlinkv1.rules Install udev-rules for ST-link 2016-04-17 09:34:46 +03:00
49-stlinkv2-1.rules Install udev-rules for ST-link 2016-04-17 09:34:46 +03:00
49-stlinkv2.rules Install udev-rules for ST-link 2016-04-17 09:34:46 +03:00
install.sh Install udev-rules for ST-link 2016-04-17 09:34:46 +03:00
jlink_upload Fixed path an permissions issue with linux jlink upload script 2016-10-17 12:43:16 +11:00
maple_upload Solve race condition with arduino IDE monitoring serial port 2017-11-13 12:15:07 -06:00
readme.txt Added files and made changes to support linux upload 2014-12-30 08:26:50 +11:00
serial_upload Changed serial upload speed to 115200 as this speed is compatible with most USB to Serial adaptors 2017-11-08 15:29:25 +11:00
stlink_upload Effecively disabled the code that waits for serial device re-enumeration 2016-07-16 09:15:32 +10:00
upload-reset Updated linux tools to contain upload-reset (bin) utility, and modified maple-upload script to use this utility to reset the bootloader prior to upload. Also changed maple-upload so that it uses the pre-compiled dfu-util binary that is now part of the repo 2015-06-28 11:06:00 +10:00
upload_router Updated linux upload router with version from @ahull 2015-04-07 08:50:06 +10:00

readme.txt

The maple upload script needs its rights to be set to 755