wtarreau / bootterm

The terminal written for its users by its users
MIT License
215 stars 11 forks source link

Baud rate of 2,000,000 #14

Open deepcoder opened 1 year ago

deepcoder commented 1 year ago

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 commented 1 year ago

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: https://github.com/avrdudes/avrdude/issues/771

I guess I should give it a try as well.

wtarreau commented 1 year ago

@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 commented 1 year ago

@deepcoder any news ?

renard commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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

this comment (https://github.com/avrdudes/avrdude/issues/771#issuecomment-1061060824) states the driver may deny the use of non standard baud rates.

wtarreau commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

wtarreau commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

OK we'll see, thank you.