femtoduino / ArduinoCore-atsamd21e18a

Arduino Core and Bootloader for the ATMEL SAM D21/R21 (E Variant) chips.
https://femto.io
29 stars 15 forks source link

OSX > USB port keeps on being renamed #28

Closed garnould closed 5 years ago

garnould commented 5 years ago

For an unknown reason and since a "bootloader mode reset" on the coin, the port keeps on announcing a new USB port each time it resets: /dev/cu.usbmodem58, /dev/cu.usbmodem60, ... /dev/cu.usbmodem71

Dongle, on its side, received only firmware updates through Arduino > update and has a stable port name (/dev/cu.usbmodem421231).

How to "stabilize" the coin port name ?

zrecore commented 5 years ago

Yes, that is annoying. I tried to do a bit of research https://forum.arduino.cc/index.php?topic=9367.0

It seems the bootloader (and possibly the core) needs to be modified to include a Serial number when USB enumeration occurs. I wonder if the main ArduinoCore repo already does this.

garnould commented 5 years ago

It looks like the problem shown on Arduino forum thread is the "normal" situation. My dongle, that as NOT been reseted into "bootload mode", works the way it is describe there (port is the same/stable when plug on the same USB slot).

On the other way - and this IS my problem - coin, that has been resetted into bootloader mode by shorting the two pins close to the USB port - changes of port name each time there's an interaction on USB port, example :

Very annoying.

garnould commented 5 years ago

According to SAM R21E datasheet (https://www.mouser.com/ds/2/268/Atmel-42223-SAM-R21_Datasheet-1065540.pdf) :

8.3.3 Serial Number Each device has a unique 128-bit serial number which is a concatenation of four 32-bit words contained at the following addresses: Word 0: 0x0080A00C Word 1: 0x0080A040 Word 2: 0x0080A044 Word 3: 0x0080A048 The uniqueness of the serial number is guaranteed only when using all 128 bits.

According to https://www.beyondlogic.org/usbnutshell/usb5.shtml#DeviceDescriptors, Serial number is a part of the DeviceDescriptor

As far as I understand ArduinoCore-atsamd21e18a/cores/arduino_osc32k/USB/USBCore.cpp and related include file, we could probably inject the device unique 128-bit (16 bytes) as the USB unique serial number.

My understanding of the device, how ever, does not let me see clearly what to do.

Does it make sense ?

garnould commented 5 years ago

Just figured out how to insert SAM R21E serial number as USB serial number. Will give a try next week.

zrecore commented 5 years ago

Hi Georges, nice work! I had to re-use the Arduino Zero PID and VID so that Windows machines could use the FemtoBeacon as an HID device. (I do not know if this is relevant information to the USB Serial number setting.)

On Fri, Nov 9, 2018, 12:07 PM Georges A notifications@github.com wrote:

Just figured out how to insert SAM R21E serial number as USB serial number. Will give a try next week.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/femtoduino/ArduinoCore-atsamd21e18a/issues/28#issuecomment-437480200, or mute the thread https://github.com/notifications/unsubscribe-auth/AAaLbGCXbJ9jL7t4olfb5yOifh6QyHH_ks5uteB8gaJpZM4YTVxn .

garnould commented 5 years ago

Last commit should fix Serial device being enumerated randomly (at least on OSX) Support SAM R21 serial number, injected (once XOR'ed) as USB Device serial number On OSX: port name (/dev/cu.usbmodemXXXXXXXX) is now stable.

garnould commented 5 years ago

@zrecore can you send feedback on this patch (if you can test on Windows at least) so that it could be merged ?

garnould commented 5 years ago

up

zrecore commented 5 years ago

@garnould I don't currently have a usable Windows machine.

garnould commented 5 years ago

Neither do I :( Did you test on a Linux machine ? Mine is OSX and I am using this patch with happiness & joy (stable port) :)

zrecore commented 5 years ago

Merged PR. If it breaks something, we can always create a new PR

zrecore commented 5 years ago

Tested on an old Windows 7 machine (HP G72 notebook) ...Seems to work just fine after windows finishes installing drivers.

garnould commented 5 years ago

Sounds great ! At the moment, this is just a "quick patch". It has a small weakness as it compacts "128 bits" to "32 bits" using XOR. Then there's a (small) chance of collision. I'll update it some day in order to transform this 128 bits value to some string (eg. "aZ4df9j"), meaning 128 bits > 128 bits, hence guaranteeing uniqueness.