-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Use atomic_polyfill on targets without atomics #707
Conversation
To clarify: things have changed since then, chiefly these work now: It works on -imac, but this PR will allow it to work on -imc also (preferred because it's not using a trap handler anymore) |
I will try to come back to you about this next Edit: lol, I thought "week" and wrote "year". Let's hope this wasn't an unconscious prophesy 😓 😆 |
Since all accesses are done within a critical section already, I think they could be replaced with UnsafeCell + write/read_volatile + fences. |
Thank you @Dirbaio. Could you elaborate how "UnsafeCell + write/read_volatile + fences" would roughly look like? |
Using It's an ugly workaround though. Ideally Rust should expose load/store atomics on riscv32-imc (what the esp32c3 is) like it does in thumbv6m. See relevant Rust issue: rust-lang/rust#99668 |
@TheButlah do you have bandwidth to change your PR to |
Is it really a good idea to add unsafe code when non-CAS atomics work fine? I think the issue was more of a lack of knowledge about the relevant
This is probably more the responsibility of the example code for HALs for chips using RISCV than it is a problem with |
Sooo ... there aren't changes to defmt necessary? I am slightly unsure about the status. |
they're not, I think this can be closed. It'll Just Work when rust-lang/rust#99668 gets fixed for riscv. Until then users can use these flags. |
Thank you for the summary @Dirbaio |
Most targets, even those without atomic instructions, support atomic load and stores. RISC-V is one of the few platforms that lacks this ability, and rustc is planning on solving that in the future (rust-lang/rust#99668).
However, in the meantime it is impossible to use
defmt-rtt
on the riscv non-atomic platform, such as the ESP32-C3.atomic-polyfill
is a useful crate that emulates the atomics viacritical_section
, but only on platforms without atomic support. On platforms with atomic support, it just re-exports the types fromcore::sync::atomic
.Would this PR be considered for inclusion in
defmt-rtt
? A prior PR was rejected here: #702