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

Embassy compatibility #49

Open
Serhii-the-Dev opened this issue Apr 18, 2024 · 4 comments · May be fixed by #53
Open

Embassy compatibility #49

Serhii-the-Dev opened this issue Apr 18, 2024 · 4 comments · May be fixed by #53

Comments

@Serhii-the-Dev
Copy link

Serhii-the-Dev commented Apr 18, 2024

The Embassy project imposes first-class async support in the Rust embedded world including wake-on-interrupt scenarios which may be extremely helpful in certain scenarios. Alas, this HAL crate is not compatible with embassy as it's not providing a generic timer driver.

My build.rs:

use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

fn main() {
    // Put `memory.x` in our output directory and ensure it's
    // on the linker search path.
    let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
    File::create(out.join("memory.x"))
        .unwrap()
        .write_all(include_bytes!("memory.x"))
        .unwrap();
    println!("cargo:rustc-link-search={}", out.display());

    // By default, Cargo will re-run a build script whenever
    // any file in the project changes. By specifying `memory.x`
    // here, we ensure the build script is only re-run when
    // `memory.x` is changed.
    println!("cargo:rerun-if-changed=memory.x");

    println!("cargo:rustc-link-arg-bins=--nmagic");
    println!("cargo:rustc-link-arg-bins=-Tlink.x");
    println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
}

and the main file:

#![no_std]
#![no_main]

use defmt::*;
use embassy_executor::Spawner;
use embassy_time::Timer;
use gd32f1x0_hal::{pac, prelude::*};
use {defmt_rtt as _, panic_probe as _};

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
    loop {
        Timer::after_millis(1000).await;
        info!("one more second")
    }
}

Error on cargo build:

  = note: rust-lld: error: undefined symbol: _embassy_time_now
          >>> referenced by lib.rs:146 (src/lib.rs:146)
          >>>               embassy_time_driver-faf69ddeeee7d3fa.embassy_time_driver.71181d876a0d80ab-cgu.0.rcgu.o:(embassy_time_driver::now::h00fe3dbe3ce1d7f3) in archive /home/serhii/work/rusty-gd32/target/thumbv7m-none-eabi/debug/deps/libembassy_time_driver-faf69ddeeee7d3fa.rlib
          
          rust-lld: error: undefined symbol: _embassy_time_allocate_alarm
          >>> referenced by lib.rs:153 (src/lib.rs:153)
          >>>               embassy_time_driver-faf69ddeeee7d3fa.embassy_time_driver.71181d876a0d80ab-cgu.0.rcgu.o:(embassy_time_driver::allocate_alarm::h65b3cb5669a83b80) in archive /home/serhii/work/rusty-gd32/target/thumbv7m-none-eabi/debug/deps/libembassy_time_driver-faf69ddeeee7d3fa.rlib
          
          rust-lld: error: undefined symbol: _embassy_time_set_alarm_callback
          >>> referenced by lib.rs:158 (src/lib.rs:158)
          >>>               embassy_time_driver-faf69ddeeee7d3fa.embassy_time_driver.71181d876a0d80ab-cgu.0.rcgu.o:(embassy_time_driver::set_alarm_callback::h61450a8a8b58bacf) in archive /home/serhii/work/rusty-gd32/target/thumbv7m-none-eabi/debug/deps/libembassy_time_driver-faf69ddeeee7d3fa.rlib
          
          rust-lld: error: undefined symbol: _embassy_time_set_alarm
          >>> referenced by lib.rs:163 (src/lib.rs:163)
          >>>               embassy_time_driver-faf69ddeeee7d3fa.embassy_time_driver.71181d876a0d80ab-cgu.0.rcgu.o:(embassy_time_driver::set_alarm::h3bb1783fe163909a) in archive /home/serhii/work/rusty-gd32/target/thumbv7m-none-eabi/debug/deps/libembassy_time_driver-faf69ddeeee7d3fa.rlib
@qwandor
Copy link
Collaborator

qwandor commented Apr 18, 2024

Hello! I'm really not familiar with Embassy as I haven't used it myself yet, but would you like to send a PR to add an appropriate Embassy timer driver behind a feature flag, or would it make more sense to have a separate HAL crate specifically for Embassy?

@Serhii-the-Dev
Copy link
Author

Serhii-the-Dev commented Apr 18, 2024

Hello! I'm really not familiar with Embassy as I haven't used it myself yet, but would you like to send a PR to add an appropriate Embassy timer driver behind a feature flag, or would it make more sense to have a separate HAL crate specifically for Embassy?

Hi! Sorry, I'm new to the Rust embedded solutions world and it's hard for me to tell what a proper architecture would be...I was using the esp-hal repository as a reference and they implemented embassy support within their own crate so I was thinking it's a right place to ask, sorry if I made a mistake.

@qwandor
Copy link
Collaborator

qwandor commented Apr 19, 2024

That sounds reasonable, please go ahead and send a PR to add it.

@Serhii-the-Dev
Copy link
Author

Serhii-the-Dev commented Sep 8, 2024

Sorry it took so long, it was hard to find some spare time to learn all the stuff required for the time driver implementation 😅
I've created a PR, please let me know if some clarification or changes are required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants