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

Various Atomic issues #1055

Closed
David-OConnor opened this issue Dec 31, 2023 · 2 comments
Closed

Various Atomic issues #1055

David-OConnor opened this issue Dec 31, 2023 · 2 comments

Comments

@David-OConnor
Copy link

David-OConnor commented Dec 31, 2023

Hi! I'm attempting a hello world, and have hit several errors related to atomics and the linker. It seems related to this thread, which points to dependency conflicts. I've removed everything except the basics, but am still hitting errors.

C3 MCU (Risc-V)

Error:

   Compiling bitfield v0.14.0
error[E0599]: no method named `compare_exchange_weak` found for reference `&AtomicU8` in the current scope
   --> C:\Users\the_a\.cargo\registry\src\index.crates.io-6f17d22bba15001f\heapless-0.8.0\src\mpmc.rs:222:18    |
221 |               if dequeue_pos
    |  ________________-
222 | |                 .compare_exchange_weak(
    | |                 -^^^^^^^^^^^^^^^^^^^^^ method not found in `&AtomicU8`
    | |_________________|
    |

error[E0599]: no method named `compare_exchange_weak` found for reference `&AtomicU8` in the current scope
   --> C:\Users\the_a\.cargo\registry\src\index.crates.io-6f17d22bba15001f\heapless-0.8.0\src\mpmc.rs:262:18    |
261 |               if enqueue_pos
    |  ________________-
262 | |                 .compare_exchange_weak(
    | |                 -^^^^^^^^^^^^^^^^^^^^^ method not found in `&AtomicU8`
    | |_________________|
    |

rust-toolchain.toml:

[toolchain]
channel = "nightly"
components = ["rust-src"]
targets = ["riscv32imc-unknown-none-elf"]

config.toml:

[target.riscv32imc-unknown-none-elf]
#[target.'cfg(all(target_arch = "riscv", target_os = "none"))']
runner = "espflash flash --monitor"
#runner = "probe-rs run --chip esp32c3" # to list chips, run `probe-rs chip list.`


[build]
rustflags = [
  "-C", "link-arg=-Tlinkall.x",
  "-C", "link-arg=-Trom_functions.x",
  #  "-C", "linker=flip-link",
  #  "-C", "link-arg=-Tlink.x",
  #  "-C", "link-arg=-Tdefmt.x",
  #  # This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
  #  # See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
  #  "-C", "link-arg=--nmagic",

  # Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
  # NOTE: May negatively impact performance of produced code
  "-C", "force-frame-pointers",

  # comment the cfgs below if you do _not_ wish to emulate atomics.
  # enable the atomic codegen option for RISCV
  "-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"',
  "--cfg", 'target_has_atomic_load_store="16"',
  "--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"',
]

target = "riscv32imc-unknown-none-elf"

#[unstable]
#build-std = ["core"]

Relevant section of cargo.toml:

[dependencies]
#defmt = "^0.3.5"
#defmt-rtt = "^0.4.0"
#panic-probe = { version = "^0.3.1", features = ["print-defmt"] }

hal = { package = "esp32c3-hal", version = "0.14.0" }
esp-backtrace = { version = "0.9.0", features = ["esp32c3", "panic-handler", "exception-handler", "print-uart"] }
esp-println = { version = "0.8.0", features = ["esp32c3"] }
@David-OConnor
Copy link
Author

David-OConnor commented Dec 31, 2023

Update: If I switch hal to 0.13.0, I get linker errors instead:

error: linking with `rust-lld` failed: exit code: 1
  |
  = note: "rust-lld" "-flavor" "gnu" "C:\\Users\\the_a\\AppData\\Local\\Temp\\rustc4XgiDd\\symbols.o" "C:\\Users\\the_a\\strike\\airdome\\target\\riscv32imc-unknown-none-elf\\debug\\deps\\project_name-a033d8939de967da.project_name.41b8fd6340978067-cgu.0.rcgu.o" "--as-needed" "-L" "C:\\Users\\the_a\\strike\\airdome\\target\\riscv32imc-unknown-none-elf\\debug\\deps" "-L" "C:\\Users\\the_

  // ... (lots more)

  cstack" "-L" "C:\\Users\\the_a\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\riscv32imc-unknown-none-elf\\lib" "-o" "C:\\Users\\the_a\\strike\\airdome\\target\\riscv32imc-unknown-none-elf\\debug\\deps\\project_name-a033d8939de967da" "--gc-sections" "-O1" "-Tlinkall.x" "-Trom_functions.x"
  = note: rust-lld: error: cannot find linker script rom_functions.x

warning: `project_name` (bin "project_name") generated 9 warnings
error: could not compile `project_name` (bin "project_name") due to 1 previous error; 9 warnings emitted
PS C:\Users\the_a\strike\airdome>

@David-OConnor
Copy link
Author

Solved, thanks to danielb on Matrix. The varying errors I ran into were transient dependency and rustflags mismatches.

Fix. Cargo.toml

hal = { package = "esp32c3-hal", version = "^0.14.0" }
esp-backtrace = { version = "^0.9.0", features = ["esp32c3", "panic-handler", "exception-handler", "print-jtag-serial"] }
esp-println = { version = "^0.8.0", features = ["esp32c3"] }

esp-wifi  = { version = "0.1.1", features = ["esp32c3", "wifi"] }
embedded-svc = { version = "0.25.0", default-features = false, features = [] }
smoltcp = { version = "^0.11.0", default-features=false, features = ["proto-igmp", "proto-ipv4", "socket-tcp", "socket-icmp", "socket-udp", "medium-ethernet", "proto-dhcpv4", "socket-raw", "socket-dhcpv4"] }
embedded-io = "^0.6.1"

[patch.crates-io]
esp-wifi = { git = "https://github.com/esp-rs/esp-wifi", rev = "a69545d" }

rustsflags:

rustflags = [
  "-C", "link-arg=-Tlinkall.x",
  # This line is required to prevent link errors if using `esp-wifi`, but will cause link errors if not.
  "-C", "link-arg=-Trom_functions.x",
  # Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
  # NOTE: May negatively impact performance of produced code
  "-C", "force-frame-pointers",
]

@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

1 participant