Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for ESP32-C3 #148

Closed
makepaddev opened this issue Jan 31, 2024 · 6 comments
Closed

Support for ESP32-C3 #148

makepaddev opened this issue Jan 31, 2024 · 6 comments
Labels
C-question Category: A question

Comments

@makepaddev
Copy link

Hi,

I'm trying to compile esp-wifi 0.3.0 which depends on portable-atomic (since 0.2.0). However portable atomic doesn't want to compile:
The CPU is the ESP32-C3 (32 bit RiscV afaik)

error: cfg(portable_atomic_unsafe_assume_single_core) does not compatible with this target;
if you need cfg(portable_atomic_unsafe_assume_single_core) support for this target,
please submit an issue at https://github.com/taiki-e/portable-atomic
--> /Users/admin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/portable-atomic-1.6.0/src/lib.rs:362:1
|
362 | / compile_error!(
363 | | "cfg(portable_atomic_unsafe_assume_single_core) does not compatible with this target;\n
364 | | if you need cfg(portable_atomic_unsafe_assume_single_core) support for this target,\n
365 | | please submit an issue at https://github.com/taiki-e/portable-atomic"
366 | | );
| |_^

Issue in esp-wifi:
esp-rs/esp-wifi-sys#426

@taiki-e
Copy link
Owner

taiki-e commented Jan 31, 2024

Currently, unsafe_assume_single_core cannot be enabled on targets that support atomic CAS.

I would expect to get this error if the v2 resolver is not enabled or if there are dependencies that have this feature enabled by mistake.

(We can loosen this check as it will be ignored even if you enable that feature, but I believe that if you get this error, it indicates that the dependency or build configuration may be incorrect.)

Could you tell me specifically how to reproduce this problem?

@makepaddev
Copy link
Author

I have uploaded my current little project here: https://github.com/makepaddev/rc_radio
You need this:
rustup toolchain install nightly --component rust-src
rustup target add riscv32imc-unknown-none-elf

then you should be able to call cargo build to see the errors

@taiki-e
Copy link
Owner

taiki-e commented Jan 31, 2024

Thanks.

CAS is enabled in your configuration, and the esp32c3 feature of the esp-hal enables unsafe_assume_single_core.

One way around the error here is to stop enabling CAS in the configuration. Like esp-rs/esp-wifi-sys#337 (comment).

Related: esp-rs/riscv-atomic-emulation-trap#11

@makepaddev
Copy link
Author

If i comment out the CAS flags in my configuration it gives the exact same compiler error
error: cfg(portable_atomic_unsafe_assume_single_core) does not compatible with this target;
if you need cfg(portable_atomic_unsafe_assume_single_core) support for this target,
please submit an issue at https://github.com/taiki-e/portable-atomic
--> /Users/admin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/portable-atomic-1.6.0/src/lib.rs:362:1
|
362 | / compile_error!(
363 | | "cfg(portable_atomic_unsafe_assume_single_core) does not compatible with this target;\n
364 | | if you need cfg(portable_atomic_unsafe_assume_single_core) support for this target,\n
365 | | please submit an issue at https://github.com/taiki-e/portable-atomic"
366 | | );
| |_^

@taiki-e
Copy link
Owner

taiki-e commented Jan 31, 2024

I cloned the reproduction and built it, but it seems that the line that enables the a feature also needs to be removed.

error: failed to run custom build command for `esp-hal-common v0.15.0`

Caused by:
  process didn't exit successfully: `/Users/taiki/projects/tmp/rc_radio/target/debug/build/esp-hal-common-6d7c78c82ede23cb/build-script-build` (exit status: 101)
  --- stderr
  thread 'main' panicked at /Users/taiki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-hal-common-0.15.0/build.rs:155:9:
  Atomic emulation flags detected in `.cargo/config.toml`, this is no longer supported!
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/ba7c7a301984967c8c13adb580ef9b86ba706a83/library/std/src/panicking.rs:645:5
     1: core::panicking::panic_fmt
               at /rustc/ba7c7a301984967c8c13adb580ef9b86ba706a83/library/core/src/panicking.rs:72:14
     2: build_script_build::main
               at ./build.rs:155:9
     3: core::ops::function::FnOnce::call_once
               at /rustc/ba7c7a301984967c8c13adb580ef9b86ba706a83/library/core/src/ops/function.rs:250:5
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
warning: build failed, waiting for other jobs to finish...

And, at least the following changes appear to have fixed the error from portable-atomic.

diff --git a/.cargo/config.toml b/.cargo/config.toml
index c23f0e2..ac3dcba 100644
--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -12,7 +12,7 @@ rustflags = [
 
   # comment the cfgs below if you do _not_ wish to emulate atomics.
   # enable the atomic codegen option for RISCV
-  "-C", "target-feature=+a",
+#  "-C", "target-feature=+a",
   # tell the core library have atomics even though it's not specified in the target definition
   "--cfg", "target_has_atomic_load_store",
   "--cfg", 'target_has_atomic_load_store="8"',
@@ -20,11 +20,11 @@ rustflags = [
   "--cfg", 'target_has_atomic_load_store="32"',
   "--cfg", 'target_has_atomic_load_store="ptr"',
   # enable cas
-  "--cfg", "target_has_atomic",
-  "--cfg", 'target_has_atomic="8"',
-  "--cfg", 'target_has_atomic="16"',
-  "--cfg", 'target_has_atomic="32"',
-  "--cfg", 'target_has_atomic="ptr"',
+#  "--cfg", "target_has_atomic",
+#  "--cfg", 'target_has_atomic="8"',
+#  "--cfg", 'target_has_atomic="16"',
+#  "--cfg", 'target_has_atomic="32"',
+#  "--cfg", 'target_has_atomic="ptr"',
 ]

If i comment out the CAS flags in my configuration it gives the exact same compiler error

I think you may encountered a cargo problem where the rustflags change in config does not trigger a rebuild, try cleaning build artifacts by cargo clean.

@makepaddev
Copy link
Author

Ah yea that fixed it, the atomic thing. Now i get an error with 'interrupt not found' but thats not your problem. Ok thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Category: A question
Projects
None yet
Development

No branches or pull requests

2 participants