Compilation Error with portable-atomic on ESP32-C3 Target

Hi All,
I'm trying to compile my Rust project for the ESP32-C3, but keep encountering the following error related to the portable-atomic crate.

 / compile_error!(
  "`portable_atomic_unsafe_assume_single_core` cfg (`unsafe-ass...
    does not compatible with target that supports atomic CAS;\n\
    see also <https://github.com/taiki-e/portable-atomic/issues/...
 );

It seems that the esp-hal and other dependencies are enabling the unsafe_assume_single_core feature, which is incompatible with my target.

I would appreciate any insights on how to resolve this issue. Do I need to adjust any dependencies in my Cargo.toml or change any feature flags?

Here is my Cargo.toml for reference:

[package]
name = "esp32-mqtt"
version = "0.1.0"
authors = [""]

[dependencies]
logger = { path = "../logger" }
esp-backtrace = { version = "0.14.2", features = [
    "esp32c3",
    "exception-handler",
    "panic-handler",
    "println",
] }
esp-hal = { version = "0.18.0", features = [ "esp32c3","async" ] }
esp-hal-embassy = { version = "0.1.0", features = [
    "time-timg0",            # Compatible with all chips
    "esp32c3"
] }
embassy-time = "0.3"
embassy-executor = { version = "0.5", features = ["integrated-timers","executor-thread","task-arena-size-10240"] }


esp-println = { version = "0.12.0", features = ["esp32c3", "log"] }
log = { version = "0.4.21" }
esp-alloc = { version = "0.4.0" }
embedded-svc = { version = "0.26.1", default-features = false, features = [] }
embedded-io = "0.6.1"
esp-wifi = { version = "0.6.0", features = [
    "esp32c3",
    "phy-enable-usb",
    "utils",
    "wifi",
    "embassy-net",
] }
heapless = { version = "0.8.0", default-features = false }
smoltcp = { version = "0.11.0", default-features = false, features = [
    "medium-ethernet",
    "proto-dhcpv4",
    "proto-igmp",
    "proto-ipv4",
    "socket-dhcpv4",
    "socket-icmp",
    "socket-raw",
    "socket-tcp",
    "socket-udp",
] }
embassy-net = { version = "0.4.0", features = ["dns", "tcp", "medium-ethernet", "dhcpv4-hostname"] }
embassy-futures = "0.1.1"
embassy-sync = "0.6.0"
embedded-nal-async = "0.7.1"
rust-mqtt = {version="0.3.0", default-features = false}

[profile.dev]
# Rust debug is too slow.
# For debug builds always builds with some optimization
opt-level = "s"


[profile.release]
codegen-units = 1 # LLVM can perform better optimizations using a single thread
debug = 2
debug-assertions = false
incremental = false
lto = 'fat'
opt-level = 's'
overflow-checks = false


it's not likely the hal crate would enable the wrong feature flag, you need to figure out which dependency actually does that. you can see the features dependency graph by running:

$ cargo tree --edges features

Hi, Thank You for your response

Yes, I have tried the dependency graph. It appears that the esp-hal feature "esp32c3" enables the unsafe-assume-single-core feature in portable-atomic. Also esp-wifi v0.6.0 "default" feature, which indirectly pulls in portable-atomic v1.9.0

if that is the case, I suspect you might be compiling for the wrong target. what's the content of your .cargo/config.toml file or the cargo command line arguments you run to build the app?

if I recall correctly, the esp32-c3 is risc-v based, but I don't know exactly which target is the right one, you'll have to check the manual. (experts can correct me, but I think binaries built for the base riscv32i- target should be compatible for chips with more extensions like riscv32imac-, though you get bad performance)

Hi, Here is the config.toml file. Please have a look at it. Here have been using 'riscv32imc-unknown-none-elf' as the target for ESP32C3.

[target.riscv32imc-unknown-none-elf]
runner = "espflash flash --monitor"

[env]
ESP_LOGLEVEL="INFO"

[build]
rustflags = [
  "-C", "force-frame-pointers",
]
target = "riscv32imc-unknown-none-elf"

[unstable]
build-std = ["alloc", "core"]

I don't think riscv32imc- is a target with atomic instructions. maybe the target detection logic of the portable-atomic crate is incorrect for your target?

I would suggest you ask the maintainer or open an issue on "portable-atomic"'s github repo, since this crate needs to support so many target platforms, I'm afraid the there's might be some edge cases.

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.