duskmoon314/aw-pac

[d1-pac] `Peripherals::take()` cannot use without `critical-section`

youngday opened this issue · 3 comments

how to call it ? thanks

22   |     let p = pac::Peripherals::take().unwrap();
     |                               ^^^^ `Peripherals` is not an iterator
     |
    ::: /home/youngday/.cargo/registry/src/mirrors.ustc.edu.cn-12df342d903acd47/d1-pac-0.0.28/src/lib.rs:1751:1
     |
1751 | pub struct Peripherals {
     | ---------------------- doesn't satisfy `Peripherals: Iterator`

Can you provide more codes for your case? I haven't seen this before, and it seems like you are trying to call some methods of Iterator on Peripherals.

A straightforward usage of uart is like this: https://github.com/duskmoon314/rust-embedded-demo/blob/main/pac/d1/src/bin/uart.rs.

To find more use cases, you can check all dependents here: https://github.com/duskmoon314/aw-pac/network/dependents.

I just found out svd2rust put take inside #[cfg(feature = "critical-section")] and I believe this is the reason. How to use this is still under discovering.

After discovering, the answer is that you should have an implementation of critical-section. A straightforward example is like this:

# In your Cargo.toml
d1-pac = { version = "0.0.29", features = ["critical-section"] }
riscv = { git = "...", features = ["critical-section-single-hart"] }
// Somewhere in your rust code
use riscv as _;

This might be enough because d1 has only one core.

Close this issue for now. Feel free to reopen if you have further questions.