Issue with AtomicBool when trying to build project for v6m

Hello

I'm trying to build a project for the M0+ of the RP2040 (thumbv6m-none-eabi ), I copy-pasted some code I got working for the stm32f4discovery (thumbv7em-none-eabihf), and this message shows up:

$ xargo build --target thumbv6m-none-eabi
   Compiling spin v0.5.2
   Compiling num-integer v0.1.44
error[E0599]: no method named `compare_and_swap` found for struct `AtomicBool` in the current scope
   --> /home/debuti/.cargo/registry/src/github.com-1ecc6299db9ec823/spin-0.5.2/src/mutex.rs:131:25
    |
131 |         while self.lock.compare_and_swap(false, true, Ordering::Acquire) != false
    |                         ^^^^^^^^^^^^^^^^ method not found in `AtomicBool`

error[E0599]: no method named `compare_and_swap` found for struct `AtomicBool` in the current scope
   --> /home/debuti/.cargo/registry/src/github.com-1ecc6299db9ec823/spin-0.5.2/src/mutex.rs:181:22
    |
181 |         if self.lock.compare_and_swap(false, true, Ordering::Acquire) == false
    |                      ^^^^^^^^^^^^^^^^ method not found in `AtomicBool`
...

I tried all combinations for stable and nightly, xargo and cargo, and (just in case although it seems to have nothing to do) spin 0.5.2 and 0.9.0

The issue is easily reproducible

rustup target add thumbv6m-none-eabi
mkdir repr_issue
cd repr_issue/
cargo init
echo "spin = \"0.5.2\"" >> Cargo.toml 
cargo build --target thumbv6m-none-eabi

Thanks in advance!

The std::sync::atomic documentation describes this limitation:

ARM targets with thumbv6m only provide load and store operations, and do not support Compare and Swap (CAS) operations, such as swap , fetch_add , etc.

https://doc.rust-lang.org/std/sync/atomic/index.html#portability

I guess this means that the spin crate is not usable on this platform.

1 Like

I missed that section completely. Thanks for pointing me the right direction!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.