Closed mcuee closed 9 months ago
@MCUdude and @askn37
Please help to check if you encounter similar issue with CH340 under your Mac Thanks.
libserialport example output. https://github.com/sigrokproject/libserialport/tree/master/examples
cuee@mcuees-Mac-mini examples % ./list_ports
Getting port list.
Found port: /dev/cu.wlan-debug
Found port: /dev/cu.Bluetooth-Incoming-Port
Found port: /dev/cu.usbserial-22420
Found port: /dev/cu.wchusbserial22420
Found 4 ports.
Freeing port list.
ch340 cannot be recognized by name. This is a macos genuine driver.
ft231x is similarly not recognized by name. This is a macos genuine driver.
@MCUdude
Please take a look if we can improve on the current behavior. If it is not easy, then I will still close this issue but update the Wiki.
This is just a nice-to-have feature and not a must.
Does it work if you use a different serial chip?Also, it looks like you're using the WCH driver, and not the default one that Macos provides, hence the name cu.wchusbserial
Does it work if you use a different serial chip?Also, it looks like you're using the WCH driver, and not the default one that Macos provides, hence the name cu.wchusbserial
No, it is the default driver from Apple now. I have not installed any driver from WCH in the Mac Mini.
Ok. And what was the previous macos version that it worked with?
Ok. Ans what was the previous macos version that it worked with?
@MCUdude I do not know. I only have one Mac Mini M1 and I always upgrade to the latest version.
But at least it works on your Mac. What is the macOS version you are using?
@mcuee I'm not at home right now, so can't look into it. But try other libserialport examples as well, and see if you can get it to print the USB vid/pid and SN. This is what Avrdude use to identify a port
@mcuee I'm not at home right now, so can't look into it. But try other libserialport examples as well, and see if you can get it to print the USB vid/pid and SN. This is what Avrdude use to identify a port
I will carry out tests tomorrow.
In any case, this is not a big issue and we may not want to do anything.
-P ch340
is just an abbreation which is nice to have but not really essential.
Ok. And what was the previous macos version that it worked with?
I do not know. I only have one Mac Mini M1 and I always upgrade to the latest version.
So you don't have the slightest idea what ran before you upgraded? Was it a major update, or just a minor/patch? I haven't updated the macOS version on my mac in ages, but I'm planning a clean install sometime this spring. I'm still on 10.14, which is ancient.
In any case, this is not a big issue and we may not want to do anything.
Well, that means that -Pusb:vid:pid
wouldn't work either, which mean that all features that libserialport provides are now broken. I'd consider this a big deal, as this may break -r
as well.
@mcuee can you try to run the port_info
libserialport example? That should print relevant information about the port attached.
This should be the output when reading a CH340 chip:
$ ./port_info /dev/cu.usbserial-1410
Looking for port /dev/cu.usbserial-1410.
Port name: /dev/cu.usbserial-1410
Description: USB Serial
Type: USB
Manufacturer: (null)
Product: USB Serial
Serial: (null)
VID: 1A86 PID: 7523
Bus: 0 Address: 0
Freeing port.
The macos conceptual code described here works fine in my environment. So it doesn't seem to be a driver issue. https://github.com/avrdudes/avrdude/issues/907#issuecomment-1077408655
And it's not just the naming that doesn't work. The -P usb:vid:pid
syntax also doesn't seem to work.
askn@alicia avrdude_main % ./build_darwin/src/avrdude -curclock -pavr128db32 -v -Pusb:0x1A86:0x7523
avrdude: Version 7.2-20240122 (2f89aece)
Copyright the AVRDUDE authors;
see https://github.com/avrdudes/avrdude/blob/main/AUTHORS
System wide configuration file is /Users/askn/Collaborator/avrdude_main/build_darwin/src/avrdude.conf
User configuration file is /Users/askn/.avrduderc
avrdude setport_from_vid_pid() warning: -P usb:0x1A86:0x7523 is not connected; consider
-P /dev/cu.Bluetooth-Incoming-Port
-P /dev/cu.usbserial-230
-P /dev/cu.usbserial-D306JCWB
-P /dev/cu.wlan-debug
Using port : usb:0x1A86:0x7523
Using programmer : urclock
avrdude ser_open() OS error: cannot open port usb:0x1A86:0x7523: No such file or directory
avrdude main() error: unable to open port usb:0x1A86:0x7523 for programmer urclock
avrdude done. Thank you.
In any case, this is not a big issue and we may not want to do anything.
Well, that means that
-Pusb:vid:pid
wouldn't work either, which mean that all features that libserialport provides are now broken. I'd consider this a big deal, as this may break-r
as well.
You are right that -Pusb:vid:pid
does not work for CH340 now.
@mcuee can you try to run the
port_info
libserialport example? That should print relevant information about the port attached.This should be the output when reading a CH340 chip:
$ ./port_info /dev/cu.usbserial-1410 Looking for port /dev/cu.usbserial-1410. Port name: /dev/cu.usbserial-1410 Description: USB Serial Type: USB Manufacturer: (null) Product: USB Serial Serial: (null) VID: 1A86 PID: 7523 Bus: 0 Address: 0 Freeing port.
Now it is listed as a native port...
mcuee@mcuees-Mac-mini examples % ./list_ports
Getting port list.
Found port: /dev/cu.wlan-debug
Found port: /dev/cu.Bluetooth-Incoming-Port
Found port: /dev/cu.usbserial-22420
Found port: /dev/cu.wchusbserial22420
Found 4 ports.
Freeing port list.
mcuee@mcuees-Mac-mini examples % ./port_info /dev/cu.usbserial-22420
Looking for port /dev/cu.usbserial-22420.
Port name: /dev/cu.usbserial-22420
Description: USB2.0-Ser!
Type: Native
Freeing port.
mcuee@mcuees-Mac-mini examples % ./port_info /dev/cu.wchusbserial22420
Looking for port /dev/cu.wchusbserial22420.
Port name: /dev/cu.wchusbserial22420
Description: USB2.0-Ser!
Type: Native
Freeing port.
I am not so sure if we can fix this using libserialport.
pyserial seems to work fine.
(py310venv) mcuee@mcuees-Mac-mini bin % ./pyserial-ports -v
/dev/cu.Bluetooth-Incoming-Port
desc: n/a
hwid: n/a
/dev/cu.usbserial-22420
desc: USB2.0-Ser!
hwid: USB VID:PID=1A86:7523 LOCATION=2-2.4.2
/dev/cu.wchusbserial22420
desc: USB2.0-Ser!
hwid: USB VID:PID=1A86:7523 LOCATION=2-2.4.2
/dev/cu.wlan-debug
desc: n/a
hwid: n/a
4 ports found
So you don't have the slightest idea what ran before you upgraded? Was it a major update, or just a minor/patch? I haven't updated the macOS version on my mac in ages, but I'm planning a clean install sometime this spring. I'm still on 10.14, which is ancient.
@MCUdude
Sorry I have not tested urclock under macOS for a while. I was doing a minor upgrade from macOS 14.2 to 14.3. But macOS 14 itself is a major upgrade.
My Mac Mini M1 (2020 version) came with macOS 11 Big Sur and now it is running macOS 14 Sonoma.
The macos conceptual code described here works fine in my environment. So it doesn't seem to be a driver issue. #907 (comment)
@askn37
The driver (and macOS version) is not the issue per se. But I think libserialport relies on certain driver behavior to be able to work for avrdude. So it is rather a libserialport limitation.
@MCUdude
As this is not a real avrdude issue, I will keep the label as enhancement
. We may need some extra codes out of libserialport.
@askn37 What is the macOS version you are using?
@dl8dtl Just wondering if you have the older version of macOS to check. Thanks.
I'd consider this a big deal, as this may break -r as well.
@MCUdude Since Arduino Nano Every does not use CH340, it is not affected.
mcuee@mcuees-Mac-mini avr % avrdude -cjtag2updi -patmega4809 -Pusb:2341:0058 -r
avrdude: touching serial port /dev/cu.usbmodem224301 at 1200 baud
avrdude: waiting for new port... using same port /dev/cu.usbmodem224301
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9651 (probably m4809)
avrdude done. Thank you.
Affected: CH340 or similar, FTDI USB to Serial may be affected (need to check).
@mcuee
iMac 24-inch, M1, 2021 macos Sonoma 14.2.1
% uname -a
Darwin alicia.local 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:34 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8103 arm64
I agree that this may be a limitation of libserialport (1.0.0). On CH340 and FT231X, -T <name>
does not map to native port.
I think -T <name>
is a shortcut for -T usb:vid:pid
. Therefore, it may not generally work if a native port already exists.
@MCUdude
I saw that you were involved in some discussions in the PRs for libserialport. I will try those PRs under macOS.
For Linux, the following PR may be useful. https://github.com/sigrokproject/libserialport/pull/7
Thanks for testing the port_info example. There is a compatibility issue with the latest macOS version and libserialport.
@mcuee can you try the suggested fix here libserialport#14 and try the port_info example again? Since there have been some changes to the driver, 16 characters isn't enough to hold the descriptor string, and a side effect of this is that the port is flagged as native.
@mcuee It would be great if you had time to test https://github.com/sigrokproject/libserialport/pull/14 asap. It looks like the libserialport has gotten another maintainer we can contact to get a potential fix merged ASAP.
@MCUdude
https://github.com/sigrokproject/libserialport/pull/14 works fine for CH340.
git clone https://github.com/sigrokproject/libserialport.git libserialport_test
cd libserialport_test
git fetch origin pull/14/head
git checkout -b pr14_rebase FETCH_HEAD
git rebase origin/master
./autogen.sh
./configure --prefix=/Users/mcuee/bin
make
cd examples
mcuee@mcuees-Mac-mini examples % make -f Makefile.new
gcc -g -Wall -I /Users/mcuee/bin/include await_events.c -L /Users/mcuee/bin/lib -lserialport -o await_events
gcc -g -Wall -I /Users/mcuee/bin/include handle_errors.c -L /Users/mcuee/bin/lib -lserialport -o handle_errors
gcc -g -Wall -I /Users/mcuee/bin/include list_ports.c -L /Users/mcuee/bin/lib -lserialport -o list_ports
gcc -g -Wall -I /Users/mcuee/bin/include port_config.c -L /Users/mcuee/bin/lib -lserialport -o port_config
gcc -g -Wall -I /Users/mcuee/bin/include port_info.c -L /Users/mcuee/bin/lib -lserialport -o port_info
gcc -g -Wall -I /Users/mcuee/bin/include send_receive.c -L /Users/mcuee/bin/lib -lserialport -o send_receive
mcuee@mcuees-Mac-mini examples % ./port_info /dev/cu.usbserial-22420
Looking for port /dev/cu.usbserial-22420.
Port name: /dev/cu.usbserial-22420
Description: USB2.0-Ser!
Type: USB
Manufacturer: Generic
Product: USB2.0-Ser!
Serial: (null)
VID: 1A86 PID: 7523
Bus: 1 Address: 11263320
Freeing port.
mcuee@mcuees-Mac-mini examples % ./port_info /dev/cu.wchusbserial22420
Looking for port /dev/cu.wchusbserial22420.
Port name: /dev/cu.wchusbserial22420
Description: USB2.0-Ser!
Type: USB
Manufacturer: Generic
Product: USB2.0-Ser!
Serial: (null)
VID: 1A86 PID: 7523
Bus: 1 Address: 72211800
Freeing port.
Original binary without your patch.
mcuee@mcuees-Mac-mini examples % cd bin_org
mcuee@mcuees-Mac-mini bin_org % ./list_ports
Getting port list.
Found port: /dev/cu.wlan-debug
Found port: /dev/cu.Bluetooth-Incoming-Port
Found port: /dev/cu.usbserial-22420
Found port: /dev/cu.wchusbserial22420
Found 4 ports.
Freeing port list.
mcuee@mcuees-Mac-mini bin_org % ./port_info /dev/cu.usbserial-22420
Looking for port /dev/cu.usbserial-22420.
Port name: /dev/cu.usbserial-22420
Description: USB2.0-Ser!
Type: Native
Freeing port.
mcuee@mcuees-Mac-mini bin_org % ./port_info /dev/cu.wchusbserial22420
Looking for port /dev/cu.wchusbserial22420.
Port name: /dev/cu.wchusbserial22420
Description: USB2.0-Ser!
Type: Native
Freeing port.
Personally I like https://github.com/sigrokproject/libserialport/pull/9 better. It works fine with CH340.
git clone https://github.com/sigrokproject/libserialport.git libserialport_pr9
cd libserialport_pr9
git fetch origin pull/9/head
git checkout -b pr9_rebase FETCH_HEAD
git rebase origin/master
./autogen.sh
./configure --prefix=/Users/mcuee/bin1
make
cd examples
mcuee@mcuees-Mac-mini examples % nano Makefile.new
mcuee@mcuees-Mac-mini examples % make -f Makefile.new
gcc -g -Wall -I /Users/mcuee/bin1/include await_events.c -L /Users/mcuee/bin1/lib -lserialport -o await_events
gcc -g -Wall -I /Users/mcuee/bin1/include handle_errors.c -L /Users/mcuee/bin1/lib -lserialport -o handle_errors
gcc -g -Wall -I /Users/mcuee/bin1/include list_ports.c -L /Users/mcuee/bin1/lib -lserialport -o list_ports
gcc -g -Wall -I /Users/mcuee/bin1/include port_config.c -L /Users/mcuee/bin1/lib -lserialport -o port_config
gcc -g -Wall -I /Users/mcuee/bin1/include port_info.c -L /Users/mcuee/bin1/lib -lserialport -o port_info
gcc -g -Wall -I /Users/mcuee/bin1/include send_receive.c -L /Users/mcuee/bin1/lib -lserialport -o send_receive
mcuee@mcuees-Mac-mini examples % ./list_ports
Getting port list.
Found port: /dev/cu.wlan-debug
Found port: /dev/cu.Bluetooth-Incoming-Port
Found port: /dev/cu.usbserial-22420
Found port: /dev/cu.wchusbserial22420
Found 4 ports.
Freeing port list.
mcuee@mcuees-Mac-mini examples % ./port_info /dev/cu.usbserial-22420
Looking for port /dev/cu.usbserial-22420.
Port name: /dev/cu.usbserial-22420
Description: USB2.0-Ser!
Type: USB
Manufacturer: Generic
Product: USB2.0-Ser!
Serial: (null)
VID: 1A86 PID: 7523
Bus: 1 Address: 8396120
Freeing port.
mcuee@mcuees-Mac-mini examples % ./port_info /dev/cu.wchusbserial22420
Looking for port /dev/cu.wchusbserial22420.
Port name: /dev/cu.wchusbserial22420
Description: USB2.0-Ser!
Type: USB
Manufacturer: Generic
Product: USB2.0-Ser!
Serial: (null)
VID: 1A86 PID: 7523
Bus: 1 Address: 15785304
Freeing port.
https://github.com/sigrokproject/libserialport/pull/14 works fine for CH340.
Excellent! This means that the bus is a new descriptor sting that's longer than 16 bytes. A simple fix.
Personally I like https://github.com/sigrokproject/libserialport/pull/9 better. It works fine with CH340.
Yes, https://github.com/sigrokproject/libserialport/pull/9 will resolve the issue too. But the intention for the PR was to fix the CP2102 issue that's been there for many, many years. The root cause for the issue is the buffer overflow. https://github.com/sigrokproject/libserialport/pull/9 doesn't check the descriptor string at all. I'm not qualified to tell whether this is safe or not. But https://github.com/sigrokproject/libserialport/pull/14 just resolves the actual bug without changing any behavior.
@MCUdude
I can also confirm that your PR works with FT232R and CP2102 where libserialport git does not work.
The following PR works fine with FT232R and CP2102 as well. But you are right that your PR is simpler and easier to be accepted by the maintainer.
@mcuee I think we can close this issue, now that we know that it's an isolated libserialport issue, and there already exist two PRs that will fix the issue.
But thank you for the extensive testing! I was worried for a second that the Avrdude implementation suddenly didn't work. And that's not the case. It's Apple that doing changes, and the libserialport source code that isn't hardened against things like this.
Just upgraded my Mac Mini M1 2020 to latest macOS 14.3 and it seems to me avrdude can not recognize
-P ch340
now.