rust-embedded/rust-raspberrypi-OS-tutorials

Unexpected Error: #<Errno::EINVAL: Invalid argument - tcsetattr>

sachaos opened this issue · 8 comments

I have a problem when trying 06_drivers_gpio_uart.
I got following error.

$ DEV_SERIAL=/dev/tty.usbserial-1420 make miniterm

Miniterm 1.0


[MT] ⚡ Unexpected Error: #<Errno::EINVAL: Invalid argument - tcsetattr>

[MT] Bye 👋

I think the cause of the error is baud.
The baud is depending on the platform according to the documentation.
I'm using Mac OS.

Integer from 50 to 256000, depending on platform)
https://rubydoc.info/gems/serialport/SerialPort:set_modem_params

The current value is 576000

@target_serial = SerialPort.new(@target_serial_name, 576_000, 8, 1, SerialPort::NONE)

Reproduce process

  1. Use Mac OS.
  2. Compile source.
  3. Write binary to SD card.
  4. Power on.
  5. Run miniterm.

Ah, I didn’t know macOS was more restrictive.
That’s a pity.

Does Miniterm start if you set it to 256000? (You wouldn’t see sane output though, because the Kerne binary is hardcoded to 576000.

I read up a bit on it. Seems macOS usually doesn’t allow more than 230400 when opening the device, but it seems there is a way to circumvent it using stty.

Can you do a test for me?

  1. change the baudrate in miniterm.rb back to 230400.
  2. Start the Miniterm.
  3. In a different console, execute stty -f /dev/USB_SERIAL_NAME 576000
  4. Only now power the RPi and check if you can see the console output.

For reference: https://stackoverflow.com/a/32083512

@andre-richter

Does Miniterm start if you set it to 256000? (You wouldn’t see sane output though, because the Kerne binary is hardcoded to 576000.

Yes. It works fine when I revert ee52e8e288ef6f00416eed94921c2b0e1acfab73

❯ DEV_SERIAL=/dev/tty.usbserial-1420 make miniterm
Miniterm 1.0

[MT] ✅ Serial connected
[0] Booting on: Raspberry Pi 4
[1] Drivers loaded:
      1. BCM GPIO
      2. BCM PL011 UART
[2] Chars written: 93
[3] Echoing input now
kjkdsafdsa

[MT] Bye 👋

I'll try the test using stty.

@andre-richter It seems 576000 is invalid value on macOS.

stty -f /dev/tty.usbserial-1420 576000
stty: tcsetattr: Invalid argument

The value 460800 which is mentioned in the stackoverflow was valid.

$ stty -f /dev/tty.usbserial-1420 460800

$ echo $?
0

Thanks!

Then I might need to make the whole tutorials use 460800 to solve this issue and adapt miniterm.rb to spawn the stty when on macOS.

@andre-richter I've created PR to fix this problem.
I've checked it works on my macOS.

Please review & merge it If it looks good. #96

Hi @sachaos,

could you please try out #97 on your Mac and tell me if it works?
I bumped to 921_600 baud + some more fixes.

I added you as co-author of this new PR to credit your findings.

@andre-richter Thank you! I'll try the PR.