embassy-rs / embassy

Modern embedded framework, using Rust and async.
https://embassy.dev
Apache License 2.0
5.51k stars 767 forks source link

RP2040: embassy-usb-logger does not work outside of embassy #3466

Open jdswensen opened 1 week ago

jdswensen commented 1 week ago

If you copy/paste the code from the RP2040 USB logger example into a new project, it will not compile.

Here is the cargo manifest I used:

[package]
edition = "2021"
name = "usb-logger"
version = "0.1.0"
resolver = "2"

[dependencies]
defmt = "0.3"
defmt-rtt = "0.4"
panic-probe = { version = "0.3", features = ["print-defmt"] }

embedded-hal = "1.0.0"
embedded-hal-async = "1.0.0"
embedded-io = "0.6.1"
embedded-io-async = "0.6.1"
embedded-storage = "0.3.1"

cortex-m = { version = "0.7.6" }
cortex-m-rt = "0.7.3"

embassy-executor = { version = "0.5.0", features = ["task-arena-size-1024", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers", "executor-interrupt"] }
embassy-futures = "0.1.1"
embassy-rp = { version = "0.1.0", features = ["defmt", "unstable-pac", "time-driver", "critical-section-impl"] }
embassy-sync = { version = "0.6.0" }
embassy-time = { version = "0.3.0", features = ["defmt", "defmt-timestamp-uptime"] }
embassy-usb = "0.3.0"

# usbd-hid = "0.8.2"
# usbd-hid-macros = "0.8.2"
embassy-usb-logger = "0.2.0"
# embassy-usb-logger = { git = "https://github.com/embassy-rs/embassy.git" }
log = "0.4.22"

and the compile error:

error: failed to select a version for `byteorder`.
    ... required by package `usbd-hid-macros v0.6.0`
    ... which satisfies dependency `usbd-hid-macros = "^0.6.0"` of package `usbd-hid v0.7.0`
    ... which satisfies dependency `usbd-hid = "^0.7.0"` of package `embassy-usb v0.2.0`
    ... which satisfies dependency `embassy-usb = "^0.2.0"` of package `embassy-usb-logger v0.2.0`
    ... which satisfies dependency `embassy-usb-logger = "^0.2.0"` of package `usb-logger v0.1.0 (/Users/jake/projects/tests/usb-logger)`
versions that meet the requirements `~1.4` are: 1.4.3, 1.4.2, 1.4.1, 1.4.0

all possible versions conflict with previously selected packages.

  previously selected package `byteorder v1.5.0`
    ... which satisfies dependency `byteorder = "^1.5"` of package `usbd-hid-macros v0.8.1`
    ... which satisfies dependency `usbd-hid-macros = "^0.8.1"` of package `usbd-hid v0.8.1`
    ... which satisfies dependency `usbd-hid = "^0.8.1"` of package `embassy-usb v0.3.0`
    ... which satisfies dependency `embassy-usb = "^0.3.0"` of package `usb-logger v0.1.0 (/Users/jake/projects/tests/usb-logger)`

failed to select a version for `byteorder` which could resolve this conflict

I suspect that this is due to some build error in the tagged version. I tried pointing just the embassy-usb-logger crate to the upstream but got a compile error about two different versions of a trait (understandable).

error[E0277]: the trait bound `Driver<'_, USB>: embassy_usb_driver::Driver<'_>` is not satisfied
   --> src/main.rs:21:5
    |
21  |     embassy_usb_logger::run!(1024, log::LevelFilter::Info, driver);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |     |
    |     the trait `embassy_usb_driver::Driver<'_>` is not implemented for `Driver<'_, USB>`
    |     required by a bound introduced by this call
    |
help: trait impl with same name found
   --> /Users/jake/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-rp-0.1.0/src/usb.rs:294:1
    |
294 | impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: perhaps two different versions of crate `embassy_usb_driver` are being used?
note: required by a bound in `UsbLogger::<N>::run`
   --> /Users/jake/.cargo/git/checkouts/embassy-9312dcb0ed774b29/b31648f/embassy-usb-logger/src/lib.rs:67:12
    |
65  |     pub async fn run<'d, D>(&'d self, state: &'d mut LoggerState<'d>, driver: D) -> !
    |                  --- required by a bound in this associated function
66  |     where
67  |         D: Driver<'d>,
    |            ^^^^^^^^^^ required by this bound in `UsbLogger::<N>::run`
    = note: this error originates in the macro `embassy_usb_logger::run` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Driver<'_, USB>: embassy_usb_driver::Driver<'_>` is not satisfied
   --> src/main.rs:21:5
    |
21  |     embassy_usb_logger::run!(1024, log::LevelFilter::Info, driver);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `embassy_usb_driver::Driver<'_>` is not implemented for `Driver<'_, USB>`
    |
help: trait impl with same name found
   --> /Users/jake/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-rp-0.1.0/src/usb.rs:294:1
    |
294 | impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: perhaps two different versions of crate `embassy_usb_driver` are being used?
note: required by a bound in `UsbLogger::<N>::run`
   --> /Users/jake/.cargo/git/checkouts/embassy-9312dcb0ed774b29/b31648f/embassy-usb-logger/src/lib.rs:67:12
    |
65  |     pub async fn run<'d, D>(&'d self, state: &'d mut LoggerState<'d>, driver: D) -> !
    |                  --- required by a bound in this associated function
66  |     where
67  |         D: Driver<'d>,
    |            ^^^^^^^^^^ required by this bound in `UsbLogger::<N>::run`
    = note: this error originates in the macro `embassy_usb_logger::run` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `usb-logger` (bin "usb-logger") due to 3 previous errors

So I updated all of the embassy crates to point at the upstream and that seemed to work. It's a good enough work around for me to continue but figured you would like to know!

danya02 commented 1 week ago

I'd like to confirm a similar issue: I was trying to start with the ethernet_w5500_tcp_server demo, but when I used what I thought was the correct manifest, it failed to compile.

I went into the repo and deleted all path references, then deleted things until Cargo stopped complaining (in particular on things like how embassy-net == 0.4.0 does not have features multicast and raw, and embassy-rp == 0.2.0 doesn't have rp2040, but the manifest in the repo does successfully mention them.

It seems as though the repo contains some breaking changes which were not published to crates.io, but which were fixed in the examples, so the examples no longer work with the released versions.

After that was done, my manifest looked like:

[package]
edition = "2021"
name = "embassy-rp-examples"
version = "0.1.0"
license = "MIT OR Apache-2.0"

[dependencies]
embassy-embedded-hal = { version = "0.2.0", features = ["defmt"] }
embassy-sync = { version = "0.6.0", features = ["defmt"] }
embassy-executor = { version = "0.6.1", features = ["task-arena-size-98304", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
embassy-time = { version = "0.3.2", features = ["defmt", "defmt-timestamp-uptime"] }
embassy-rp = { version = "0.2.0", features = ["defmt", "unstable-pac", "time-driver", "critical-section-impl"] }
embassy-net = { version = "0.4.0", features = ["defmt", "tcp", "udp", "dhcpv4", "dhcpv4-hostname", "medium-ethernet", "dns", "proto-ipv4", "proto-ipv6"] }
embassy-net-wiznet = { version = "0.1.0", features = ["defmt"] }
embassy-futures = { version = "0.1.0" }

defmt = "0.3"
defmt-rtt = "0.4"
fixed = "1.23.1"
fixed-macro = "1.2"

# for web request example
reqwless = { version = "0.13.0", features = ["defmt"] }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde-json-core = "0.5.1"

#cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m = { version = "0.7.6", features = ["inline-asm"] }
cortex-m-rt = "0.7.0"
critical-section = "1.1"
panic-probe = { version = "0.3", features = ["print-defmt"] }
st7789 = "0.6.1"
byte-slice-cast = { version = "1.2.0", default-features = false }
smart-leds = "0.4.0"
heapless = "0.8"
usbd-hid = "0.8.1"

embedded-hal-1 = { package = "embedded-hal", version = "1.0" }
embedded-hal-async = "1.0"
embedded-hal-bus = { version = "0.1", features = ["async"] }
embedded-io-async = { version = "0.6.1", features = ["defmt-03"] }
embedded-storage = { version = "0.3" }
static_cell = "2.1"
portable-atomic = { version = "1.5", features = ["critical-section"] }
log = "0.4"
pio-proc = "0.2"
pio = "0.2.1"
rand = { version = "0.8.5", default-features = false }
[profile.release]
debug = 2
lto = true
opt-level = 'z'

[profile.dev]
debug = 2
lto = true
opt-level = "z"

And here's the errors I got:

$ cargo embed --bin ethernet_w5500_tcp_server
   Compiling embassy-rp-examples v0.1.0 (/home/danya/Projects/embassy/examples/rp)
error: could not compile `embassy-rp-examples` (bin "ethernet_w5500_tcp_server") due to 6 previous errors
error[E0412]: cannot find type `Runner` in crate `embassy_net`
   --> src/bin/ethernet_w5500_tcp_server.rs:40:44
    |
40  | async fn net_task(mut runner: embassy_net::Runner<'static, Device<'static>>) -> ! {
    |                                            ^^^^^^
    |
   ::: /home/danya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-net-0.4.0/src/lib.rs:246:1
    |
246 | struct Inner<D: Driver> {
    | ----------------------- similarly named struct `Inner` defined here
    |
help: a struct with a similar name exists
    |
40  | async fn net_task(mut runner: embassy_net::Inner<'static, Device<'static>>) -> ! {
    |                                            ~~~~~
help: consider importing this struct
    |
9   + use embassy_net_wiznet::Runner;
    |
help: if you import `Runner`, refer to it directly
    |
40  - async fn net_task(mut runner: embassy_net::Runner<'static, Device<'static>>) -> ! {
40  + async fn net_task(mut runner: Runner<'static, Device<'static>>) -> ! {
    |

error[E0425]: cannot find function `new` in crate `embassy_net`
  --> src/bin/ethernet_w5500_tcp_server.rs:77:40
   |
77 |     let (stack, runner) = embassy_net::new(
   |                                        ^^^ not found in `embassy_net`
   |
help: consider importing one of these functions
   |
9  + use crate::new;
   |
9  + use embassy_net_wiznet::new;
   |
help: if you import `new`, refer to it directly
   |
77 -     let (stack, runner) = embassy_net::new(
77 +     let (stack, runner) = new(
   |

error[E0599]: no method named `unwrap` found for tuple `(Device<'_, 1514>, Runner<'_, _, ExclusiveDevice<Spi<'_, SPI0, Async>, Output<'_>, Delay>, Input<'_>, Output<'_>>)` in the current scope
  --> src/bin/ethernet_w5500_tcp_server.rs:69:6
   |
61 |       let (device, runner) = embassy_net_wiznet::new(
   |  ____________________________-
62 | |         mac_addr,
63 | |         state,
64 | |         ExclusiveDevice::new(spi, cs, Delay),
...  |
68 | |     .await
69 | |     .unwrap();
   | |_____-^^^^^^
   |
   = note: the full type name has been written to '/home/danya/Projects/embassy/examples/rp/target/thumbv6m-none-eabi/debug/deps/ethernet_w5500_tcp_server-a8bde0bd203a2227.long-type-18356303867768005353.txt'
   = note: consider using `--verbose` to print the full type name to the console
help: there is a method `unwrapped_as` with a similar name
   |
69 |     .unwrapped_as();
   |      ~~~~~~~~~~~~

error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied
   --> src/bin/ethernet_w5500_tcp_server.rs:130:33
    |
130 | async fn wait_for_config(stack: Stack<'static>) -> embassy_net::StaticConfigV4 {
    |                                 ^^^^^--------- help: remove the unnecessary generics
    |                                 |
    |                                 expected 0 lifetime arguments
    |
note: struct defined here, with 0 lifetime parameters
   --> /home/danya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-net-0.4.0/src/lib.rs:241:12
    |
241 | pub struct Stack<D: Driver> {
    |            ^^^^^

error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied
   --> src/bin/ethernet_w5500_tcp_server.rs:130:33
    |
130 | async fn wait_for_config(stack: Stack<'static>) -> embassy_net::StaticConfigV4 {
    |                                 ^^^^^ expected 1 generic argument
    |
note: struct defined here, with 1 generic parameter: `D`
   --> /home/danya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-net-0.4.0/src/lib.rs:241:12
    |
241 | pub struct Stack<D: Driver> {
    |            ^^^^^ -
help: add missing generic argument
    |
130 | async fn wait_for_config(stack: Stack<'static, D>) -> embassy_net::StaticConfigV4 {
    |                                              +++

error: aborting due to 5 previous errors

Some errors have detailed explanations: E0107, E0412, E0425, E0599.
For more information about an error, try `rustc --explain E0107`.
       Error Failed to run cargo build: exit code = Some(101).