embassy-rs / static-cell

Statically allocated, runtime initialized cell.
Apache License 2.0
30 stars 15 forks source link

no method named `compare_exchange` found for struct `portable_atomic::AtomicBool` in the current scope (on thumbv6m-none-eabi) #11

Closed gauteh closed 8 months ago

gauteh commented 8 months ago

Trying to use StaticCell with this pi-pico example: https://github.com/gauteh/defmt-serial/blob/main/example-pi-pico/src/main.rs fails with:

❯ cargo build
   Compiling nb v1.1.0
   Compiling void v1.0.2
   Compiling vcell v0.1.3
   Compiling bare-metal v0.2.5
   Compiling bitfield v0.13.2
   Compiling critical-section v1.1.2
   Compiling num_enum v0.5.11
   Compiling cortex-m-rt v0.7.3
   Compiling nb v0.1.3
   Compiling volatile-register v0.2.1
   Compiling stable_deref_trait v1.2.0
   Compiling either v1.9.0
   Compiling gcd v2.3.0
   Compiling bitflags v1.3.2
   Compiling arrayvec v0.7.4
   Compiling embedded-hal v0.2.7
   Compiling embedded-dma v0.2.0
   Compiling defmt v0.3.5
   Compiling bare-metal v1.0.0
   Compiling fugit v0.3.7
   Compiling itertools v0.10.5
   Compiling usb-device v0.2.9
   Compiling rand_core v0.6.4
   Compiling critical-section v0.2.8
   Compiling cortex-m v0.7.7
   Compiling rp2040-boot2 v0.2.1
   Compiling pio v0.2.1
   Compiling portable-atomic v1.6.0
   Compiling panic-halt v0.2.0
   Compiling rp2040-pac v0.4.0
   Compiling defmt-serial v0.6.0
   Compiling static_cell v2.0.0
   Compiling panic-probe v0.3.1
error[E0599]: no method named `compare_exchange` found for struct `portable_atomic::AtomicBool` in the current scope
   --> /home/gauteh/.cargo/registry/src/index.crates.io-6f17d22bba15001f/static_cell-2.0.0/src/lib.rs:122:14
    |
120 |           if self
    |  ____________-
121 | |             .used
122 | |             .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
    | |             -^^^^^^^^^^^^^^^^ method not found in `AtomicBool`
    | |_____________|
    |

For more information about this error, try `rustc --explain E0599`.
error: could not compile `static_cell` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...
gauteh commented 8 months ago

See: https://github.com/gauteh/defmt-serial/pull/10 for example code (not really working yet).

Dirbaio commented 8 months ago

you need to add a dependency on portable_atomic and enable either the unsafe-assume-single-core feature (if you're ONLY using 1 core of the 2 cores in the rp2040!), or the critical-section feature (and then ensure you've enabled a multicore-safe critical-section implementation, such as feature critical-section-impl of embassy-rp)

gauteh commented 8 months ago

Ok, thanks!