Skip to content
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

Baud rate of 2,000,000 #14

Open
deepcoder opened this issue Sep 20, 2022 · 12 comments
Open

Baud rate of 2,000,000 #14

deepcoder opened this issue Sep 20, 2022 · 12 comments

Comments

@deepcoder
Copy link

I have a microcontroller that wants to connect at 20000000 baud. I am using a SparkFun FTDI usb to UART 3.3 volt device. I can use the aging CoolTerm v1.7.0 build 825 to connect to this device via this USB/UART and see the output correctly. CoolTerm lets me select this 2000000 baud rate. When I try the same with bt 0.4.0 and the same USB device on Mac OS 12.6, it does not work and delivers the following:

dproffer@graymini hid_download_py % bt -b 2000000
No port specified, using cu.usbserial-A700eF7u (last registered). Use -l to list ports.
Trying port cu.usbserial-A700eF7u... Failed.
Failed to configure port: Invalid argument
Hint: maybe the baud rate is not supported by the port.
The following baud rates are known (not necessarily supported though):
           50       75      110      134      150
          200      300      600     1200     1800
         2400     4800     9600    19200    38400
        57600    76800   115200   230400
dproffer@graymini hid_download_py %

coolterm

Thank you for your work on this project!

@wtarreau
Copy link
Owner

Hello @deepcoder,

sorry for the delay, I don't receive notifications for newly opened issues, I don't know why.

Sadly, non-standard speed support is OS-specific. Your OS indeed reports up to 230400 bauds using the standard API. The extended API uses TCSETS2 that is present since Linux 2.6.20, but I have no idea what is used on MacOS.

Hmmm apparently avrdude faced the same problem and found the solution here: avrdudes/avrdude#771

I guess I should give it a try as well.

@wtarreau
Copy link
Owner

@deepcoder I would appreciate it if you could try to apply the two attached patches (not having a mac myself prevents me from testing). If they work, I'll merge them. Thanks!

0001-src-rearrange-the-standard-baud-rate-setting-block.patch.txt
0002-src-add-support-for-non-standard-baud-rates-on-MacOS.patch.txt

@wtarreau
Copy link
Owner

@deepcoder any news ?

@renard
Copy link

renard commented Jan 31, 2023

@wtarreau on MacOS without your patch(es) the supported bauds are:

No port specified, using cu.usbserial-14230 (last registered). Use -l to list ports.
Trying port cu.usbserial-14230... Failed.
Failed to configure port: Invalid argument
Hint: maybe the baud rate is not supported by the port.
The following baud rates are known (not necessarily supported though):
           50       75      110      134      150
          200      300      600     1200     1800
         2400     4800     9600    19200    38400
        57600    76800   115200   230400

After the 0002-src-add-support-for-non-standard-baud-rates-on-MacOS.patch.txt it does not build:

  CC      src/bt.o
src/bt.c:559:22: error: member reference type 'int' is not a pointer
                else if (ioctl(fd->ifd, IOSSIOSPEED, &baud) >= 0) {
                               ~~  ^

Fix is to remove the ->ifd and it builds.

Now an arbitrary baud rate can be passed to -b:

./bin/bt -b 460800
No port specified, using cu.usbserial-14230 (last registered). Use -l to list ports.
Trying port cu.usbserial-14230... Connected to cu.usbserial-14230 at 9600 bps.
Escape character is 'Ctrl-]'. Use escape followed by '?' for help.

But it falls back to 9600.

However a valid baud rate works correctly:

./bin/bt -b 230400
No port specified, using cu.usbserial-14230 (last registered). Use -l to list ports.
Trying port cu.usbserial-14230... Connected to cu.usbserial-14230 at 230400 bps.
Escape character is 'Ctrl-]'. Use escape followed by '?' for help.

Not sure MacOS allows arbitrary ports.

HTH.

@wtarreau
Copy link
Owner

Thanks for the fix, indeed, I don't know how I messed up, probably some mistyped vi commands inside an ifdef I couldn't build, but I obviously did.

It's not necessarily a bad thing that you're seeing actually. If it had failed to set the baud rate you'd have got an error. Here it reports the baud rate reported by the standard method, so it cannot report an extended one. It's common to see the default baud rate being mentioned on extended baud rates. I'll have a look in case we have an equivalent of IOSSIOSPEED to retrieve the baud rate. In the mean time I've fixed the build bug you reported. We're on a good track I think.

Thanks Seb!

@renard
Copy link

renard commented Jan 31, 2023

Just a copy / blast: the original uses a stuct, your code does not.

this comment (avrdudes/avrdude#771 (comment)) states the driver may deny the use of non standard baud rates.

@wtarreau
Copy link
Owner

I'm not seeing anything indicating that there could be an equivalent to retrieve the configured speed. We'll likely have to modify the code to state that if we've successfully forced the speed on this platform, then we need to save it and report the configured one instead of the reported one.

@wtarreau
Copy link
Owner

Yes indeed for the baud rate but we test for the error and you don't get one, which is what makes me say it's likely OK.

@renard
Copy link

renard commented Jan 31, 2023

fair enough I do not have such devices to test the effective speed. Maybe @deepcoder has.

@wtarreau
Copy link
Owner

Let me try again with this (I updated patch 2 to fix the stupid copy-paste and did patch 3 to try to copy the speed). In your case only the 3rd one is needed since you fixed the 2nd.

0001-src-rearrange-the-standard-baud-rate-setting-block.patch.txt
0002-src-add-support-for-non-standard-baud-rates-on-MacOS.patch.txt
0003-src-keep-a-copy-of-non-standard-baud-rates-for-repor.patch.txt

I do have some devices that work at these speeds, I just need to figure which one is transportable ;-)
Or we can also connect two adapters back-to-back with one PC at a known-working speed on one side.

@renard
Copy link

renard commented Jan 31, 2023

With the 3 new patches it still reports 9600:

 ./bin/bt -b 430800
No port specified, using cu.usbserial-14230 (last registered). Use -l to list ports.
Trying port cu.usbserial-14230... Connected to cu.usbserial-14230 at 9600 bps.
Escape character is 'Ctrl-]'. Use escape followed by '?' for help.

Looks like I need to commute on Thursday and a space docking is planned.

@wtarreau
Copy link
Owner

wtarreau commented Feb 1, 2023

OK we'll see, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants