Compile example sketch for Feather M0 board

Total beginners question:

I have an Adafruit Feather M0 board and I'm trying to compile and upload the blinky_basic example from this repository:

https://github.com/atsamd-rs/atsamd/tree/master/boards/feather_m0/

I'm following the steps described, however when compiling I get the following error:

error[E0277]: compare_exchange requires atomic CAS but not available on this target by default

The error also guides me to this page, but since I have no experience with Rust I'm not sure how to maneuver:
https://docs.rs/portable-atomic/latest/portable_atomic/#optional-features

I was hoping to get a basic example running to get me started, and was hoping that these examples would work out of the box for this specific board. Is there perhaps an easy solution or something obvious that I'm missing?

can you describe the procedure how you built the project? I cannot reproduce the error. I cloned the repository and cargo build works out of the box.

whoopsie, speak too soon. first glance seems to indicate the rtic crate might be incompatible version, I'm gonna do some investigating.

ok, found it.

TLDR:

either one of the following should successfully build:

  • enable the "optional" portable-atomic feature of the dependency atsamd-hal:
    • cargo build --example blinky_basic --features atsamd-hal/portable-atomic
  • enable the critical-section feature of the (transitive) dependency portable-atomic
    • cargo add --dev portable-atomic --features critical-section
    • cargo build --example blinky_basic

long answer:

the cause is a little hard to explain, it's a wierd interaction between dev-dependencies and optional features.

dev-dependencies are NOT used when building the lib crate, but they are enabled when building examples. however, it is NOT supported to mark dev-dependencies as optional, which means even not every example uses every crates of dev-dependencies, when you build any example, all the dev-dependencies are enabled.

specifically, the blinky_basic example doesn't depends on rtic, so it didn't have any required-features, but since rtic is listed in dev-dependencies, it will be enabled anyway. the problem is, the feature flags required by rtic are not enabled by default, but controlled by the rtic optional feature flag.

so you are facing a really peculiar situation, where the "simple" example blinky_basic gives unhelpful error message, but if you build the more "advanced" example blinky_rtic, you'll be instructed to enable the rtic feature, and it builds successfully when you enable that feature.

IMO, it's better to move the examples (at least those needs non-trivial configurations) into separate packages, because of the limitation of dev-dependencies.

This works for me, many thanks for the help and thorough explanation!

I had no luck trying to upload with the hf2 bootloader, but had success with bossac after getting some hints from this older thread:
https://users.rust-lang.org/t/getting-started-with-feather-m0-solved/38962

I also swapped arm-none-eabi-objcopy with rust-objcopy as described here:
https://github.com/atsamd-rs/atsamd/wiki/Loading-code-onto-the-device#bossac

So now my board seems to blink as expected.