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

fix: musl list ports handle /dev/* from available_ports #635

Merged
merged 4 commits into from
May 14, 2024

Conversation

TheEdward162
Copy link
Contributor

Hi, I've been trying to use espflash from Alpine linux and on my system serialport::available_ports() returns something like [SerialPortInfo { port_name: "/dev/ttyS0", port_type: Unknown }, SerialPortInfo { port_name: "/dev/ttyUSB0", port_type: Unknown }]. The function that handles this expects port_name to be in the form of /sys/class/tty/* and this makes espflash not work on my system due to being unable to detect any serial ports.

In this PR I've added a branch which checks if the path returned from available_ports starts with /dev/ and if it does it replaces it with /sys/class/tty/ and proceeds as before. I can confirm this works for flashing esp32c3 board I'm working with.

I'm not sure this is the best approach but at least it works now. Let me know if you think this can be improved in an obvious way.

Copy link
Member

@SergioGasquez SergioGasquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for your contribution! Changes LGTM, sadly I can't test it because I don't have any musl machine.

Mind solving the conflicts so we can merge it?

Copy link
Member

@SergioGasquez SergioGasquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@SergioGasquez SergioGasquez merged commit 890f17a into esp-rs:main May 14, 2024
28 checks passed
@contra-bit
Copy link

@TheEdward162 could you please share how you enabled running espflash without root on alpine linux?

My user account is in the dialout group. I have eudev setup. I can read the port ttyACM0.

~/esp % cargo run --release --  --list-all-ports
    Finished `release` profile [optimized + debuginfo] target(s) in 0.24s
     Running `espflash flash --monitor target/riscv32imc-unknown-none-elf/release/esp-first-try --list-all-ports`
[2024-05-16T13:39:48Z INFO ] Serial port: '/dev/ttyACM0'
[2024-05-16T13:39:48Z INFO ] Connecting...
Error: espflash::serial_error

  × Failed to open serial port /dev/ttyACM0
  ├─▶ Error while connecting to device
  ├─▶ IO error while using serial port: Permission denied
  ╰─▶ Permission denied

1 ~/esp % file /dev/ttyACM0
/dev/ttyACM0: character special (166/0)
~/esp % ls /dev/ttyACM0
/dev/ttyACM0
~/esp % ls /dev/ttyACM0 -lah
crw-rw----    1 root     dialout   166,   0 May 16 15:44 /dev/ttyACM0

Running the command espflash flash --monitor target/riscv32imc-unknown-none-elf/release/esp-first-try --list-all-ports --before usb-reset as root solves the issue for me.

--before usb-reset is currently required for me, due to issue #636

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

Successfully merging this pull request may close these issues.

None yet

3 participants