-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use non-standard baud rates for uploading on MacOS #771
Comments
I'm afraid there is not much we can do about this. This appears to be a limitation of MacOS. I just tried with a standard FTDI adapter, and the system-supplied
|
Even though they encode the baudrates as full numbers (as opposed to bitmapping them as it used to be in historic Unices), they appear to restrict the applicable baudrates to a pre-known set of numbers, even for hardware (like the FTDI) that can support almost arbitrary baudrates. |
|
Thanks for taking the time to find the root cause. It's a real bummer though... |
Well, if you find out what they are doing, I'll happily integrate it. Remember: it's the call to |
Yeah, I know that, I already faced and played with tc for an old Serial App and this issue on mac os, but as now we can read at 250K with other, was hoping it was solved. |
Just for reference, the MiniTerm (based on Pyserial) works with "odd" baud rates on mac as well. EDIT: https://github.com/pyserial/pyserial/blob/master/serial/serialposix.py |
That probably means we could look what pyserial does, in order to find out how to enable them on MacOS. |
Excellent! It's been a while since I've used anything pyserial based on my mac, but I'm 99% sure it works with custom baud rates. I'll give it an extra try tonight just to be sure. Let me know if you need help with testing this! |
Can confirm that pyserial works 250000, 500000, and 1M baud on MacOS and a CH340C USB to serial chip. It probably works with more baud rates too! |
Here's an update. I got Avrdude working with custom baud rates by tweaking some code I found online.
// ser_setparams() {
// ...
rc = tcsetattr(fd->ifd, TCSANOW, &termios);
if (rc < 0) {
// Try custom baudrate (MacOS only)
#define IOSSIOSPEED 0x80045402
speed = baud;
if(ioctl(fd->ifd, IOSSIOSPEED, &speed) < 0) {
avrdude_message(MSG_INFO, "%s: ser_setparams(): tcsetattr()/ioctrl() failed\n",
progname);
return -errno;
}
}
tcflush(fd->ifd, TCIFLUSH);
return 0;
}
I've pushed the fix here: References: |
I'm a bit embarrassed why they introduced that hack. Nothing would have prevented them from simply accepting those non-standard baud rates in a simple I'm not a friend of local hacks like |
This is perhaps a better way. Tested and works: #ifndef IOSSIOSPEED
#define IOSSIOSPEED _IOW('T', 2, speed_t)
#endif |
I also added rc = tcsetattr(fd->ifd, TCSANOW, &termios);
if (rc < 0) {
// Try custom baudrate (MacOS only)
#ifdef __APPLE__
#ifndef IOSSIOSPEED
#define IOSSIOSPEED _IOW('T', 2, speed_t)
#endif
speed = baud;
if(ioctl(fd->ifd, IOSSIOSPEED, &speed) < 0) {
avrdude_message(MSG_INFO, "%s: ser_setparams(): tcsetattr()/ioctrl() failed\n",
progname);
return -errno;
}
#else
avrdude_message(MSG_INFO, "%s: ser_setparams(): tcsetattr() failed\n",
progname);
return -errno;
#endif
}
tcflush(fd->ifd, TCIFLUSH);
return 0;
} |
It looks like IOSSOISPEED is defined in
But I'm not sure if we can rely on this file being present on every MacOS machine set up to build Avrdude. |
Except that the path is even longer here (full XCode package): |
I'm able to include ioss.h by adding the following code: #ifdef __APPLE__
#include <IOKit/serial/ioss.h>
#endif
Agreed. I just created a simple proof-of-concept code to help out point in the right direction. It looks like pyserial is just using a flag to indicate this. |
Awesome guys, II already faced this issue two years ago, and running an old project with custom moteino boards setup to 250K today I was unable to flash them. I flashed back all the board with standard baud rate toda) so it's awesome it's fixed. If one could attach the compiled file fixed, I can give a try on my side (and I'm really interested) Anyway, thank for your investigation and this prompt fix. |
Takk, Hans. I didn't immediately figure out how that complicated path in the filesystem is supposed to be written in sourcecode. I assumed it must be way simpler. (Alas dtruss doesn't work anymore out of the box, as the system by default runs in a pretty secure mode now.) Give PR #898 a try (and feel free to add review comments). I could only test the |
Check out the Wiki. Marius mentioned there how you can fetch the build artifacts from the CI process. |
I'll try that, I'm trying to build with instruction with no luck, each time I need to build something with libusb and libftdi it's a mess :-) |
I think the Wiki describes the prerequisites pretty well now. It almost doesn't matter whether you obtain the prerequisites using brew (Hans uses it) or Mac ports (I use them when testing on MacOS here). Then, just use the new |
Thanks for your help, but does not works either include files (I remember I needed to fix lot of stuff compiling airspy) changed build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/usr/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/local/Cellar" by build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/usr/local/include -D CMAKE_C_FLAGS=-I/opt/homebrew/include -D CMAKE_EXE_LINKER_FLAGS=-L/opt/homebrew/Cellar" Now it goes further but fail later, charles@mini-m1:avrdude$ ./build.sh
-- Configuration summary:
-- ----------------------
-- DO HAVE libelf
-- DO HAVE libusb
-- DO HAVE libusb_1_0
-- DO HAVE libhidapi
-- DO HAVE libftdi (but prefer to use libftdi1)
-- DO HAVE libftdi1
-- DISABLED doc
-- DISABLED parport
-- DISABLED linuxgpio
-- DISABLED linuxspi
-- ----------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/charles/devt/avrdude/build_darwin
Consolidate compiler generated dependencies of target libavrdude
[ 1%] Building C object src/CMakeFiles/libavrdude.dir/dfu.c.o
In file included from /Users/charles/devt/avrdude/src/dfu.c:33:
/Users/charles/devt/avrdude/src/dfu.h:32:4: error: "libusb needs either <usb.h> or <lusb0_usb.h>"
# error "libusb needs either <usb.h> or <lusb0_usb.h>"
^
/Users/charles/devt/avrdude/src/dfu.h:52:3: error: unknown type name 'usb_dev_handle'
usb_dev_handle *dev_handle;
^
/Users/charles/devt/avrdude/src/dfu.h:53:32: error: field has incomplete type 'struct usb_device_descriptor'
struct usb_device_descriptor dev_desc;
^
/Users/charles/devt/avrdude/src/dfu.h:53:10: note: forward declaration of 'struct usb_device_descriptor'
struct usb_device_descriptor dev_desc;
^
/Users/charles/devt/avrdude/src/dfu.h:54:32: error: field has incomplete type 'struct usb_config_descriptor'
struct usb_config_descriptor conf_desc;
^
/Users/charles/devt/avrdude/src/dfu.h:54:10: note: forward declaration of 'struct usb_config_descriptor'
struct usb_config_descriptor conf_desc;
^
/Users/charles/devt/avrdude/src/dfu.h:55:35: error: field has incomplete type 'struct usb_interface_descriptor'
struct usb_interface_descriptor intf_desc;
^
/Users/charles/devt/avrdude/src/dfu.h:55:10: note: forward declaration of 'struct usb_interface_descriptor'
struct usb_interface_descriptor intf_desc;
^
/Users/charles/devt/avrdude/src/dfu.h:56:34: error: field has incomplete type 'struct usb_endpoint_descriptor'
struct usb_endpoint_descriptor endp_desc;
^
/Users/charles/devt/avrdude/src/dfu.h:56:10: note: forward declaration of 'struct usb_endpoint_descriptor'
struct usb_endpoint_descriptor endp_desc;
^
/Users/charles/devt/avrdude/src/dfu.c:97:30: error: unknown type name 'usb_dev_handle'
static char * get_usb_string(usb_dev_handle * dev_handle, int index);
^
/Users/charles/devt/avrdude/src/dfu.c:152:3: error: implicit declaration of function 'usb_init' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
usb_init();
^
/Users/charles/devt/avrdude/src/dfu.c:153:3: error: implicit declaration of function 'usb_find_busses' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
usb_find_busses();
^
/Users/charles/devt/avrdude/src/dfu.c:154:3: error: implicit declaration of function 'usb_find_devices' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
usb_find_devices();
^
/Users/charles/devt/avrdude/src/dfu.c:154:3: note: did you mean 'usb_find_busses'?
/Users/charles/devt/avrdude/src/dfu.c:153:3: note: 'usb_find_busses' declared here
usb_find_busses();
^
/Users/charles/devt/avrdude/src/dfu.c:191:14: error: use of undeclared identifier 'usb_busses'
for (bus = usb_busses; !found && bus != NULL; bus = bus->next) {
^
/Users/charles/devt/avrdude/src/dfu.c:191:58: error: incomplete definition of type 'struct usb_bus'
for (bus = usb_busses; !found && bus != NULL; bus = bus->next) {
~~~^
/Users/charles/devt/avrdude/src/dfu.c:163:10: note: forward declaration of 'struct usb_bus'
struct usb_bus *bus;
^
/Users/charles/devt/avrdude/src/dfu.c:192:19: error: incomplete definition of type 'struct usb_bus'
for (dev = bus->devices; !found && dev != NULL; dev = dev->next) {
~~~^
/Users/charles/devt/avrdude/src/dfu.c:163:10: note: forward declaration of 'struct usb_bus'
struct usb_bus *bus;
^
/Users/charles/devt/avrdude/src/dfu.c:192:62: error: incomplete definition of type 'struct usb_device'
for (dev = bus->devices; !found && dev != NULL; dev = dev->next) {
~~~^
/Users/charles/devt/avrdude/src/dfu.c:161:10: note: forward declaration of 'struct usb_device'
struct usb_device *found = NULL;
^
/Users/charles/devt/avrdude/src/dfu.c:193:46: error: incomplete definition of type 'struct usb_bus'
if (dfu->bus_name != NULL && strcmp(bus->dirname, dfu->bus_name))
~~~^
/Users/charles/devt/avrdude/src/dfu.c:163:10: note: forward declaration of 'struct usb_bus'
struct usb_bus *bus;
^
/Users/charles/devt/avrdude/src/dfu.c:196:23: error: incomplete definition of type 'struct usb_device'
if (strcmp(dev->filename, dfu->dev_name))
~~~^
/Users/charles/devt/avrdude/src/dfu.c:161:10: note: forward declaration of 'struct usb_device'
struct usb_device *found = NULL;
^
/Users/charles/devt/avrdude/src/dfu.c:198:28: error: incomplete definition of type 'struct usb_device'
} else if (vid != dev->descriptor.idVendor)
~~~^
/Users/charles/devt/avrdude/src/dfu.c:161:10: note: forward declaration of 'struct usb_device'
struct usb_device *found = NULL;
^
/Users/charles/devt/avrdude/src/dfu.c:200:38: error: incomplete definition of type 'struct usb_device'
else if (pid != 0 && pid != dev->descriptor.idProduct)
~~~^
/Users/charles/devt/avrdude/src/dfu.c:161:10: note: forward declaration of 'struct usb_device'
struct usb_device *found = NULL;
^
/Users/charles/devt/avrdude/src/dfu.c:218:36: error: incomplete definition of type 'struct usb_device'
progname, found->descriptor.idVendor, found->descriptor.idProduct,
~~~~~^
/Users/charles/devt/avrdude/src/dfu.c:161:10: note: forward declaration of 'struct usb_device'
struct usb_device *found = NULL;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [src/CMakeFiles/libavrdude.dir/dfu.c.o] Error 1
make[1]: *** [src/CMakeFiles/libavrdude.dir/all] Error 2
make: *** [all] Error 2
Build failed.
I need to focus on other urgent task so I'm leaving here, may be give a try tomorrow on my office's Mac Thanks for your time |
Fixed in #898 |
Hi!
It seems like I can't upload a program to a target when a non-standard baud rate is used. I'm running a version of the Optiboot bootloader (-c arduino) that runs at 250000 baud. I'm able to upload to this using a Windows computer, but not on my mac.
115200 and 230400 baud works fine.
The text was updated successfully, but these errors were encountered: