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

more delay methods #65

Open
pdgilbert opened this issue Mar 31, 2023 · 0 comments
Open

more delay methods #65

pdgilbert opened this issue Mar 31, 2023 · 0 comments

Comments

@pdgilbert
Copy link

The delay function seems to be lacking some methods. It would be nice if this example worked for the commented out lines.

Click to expand
#![deny(warnings)]
#![deny(unsafe_code)]
#![no_main]
#![no_std]

#[cfg(debug_assertions)]
use panic_semihosting as _;

#[cfg(not(debug_assertions))]
use panic_halt as _;

use stm32g4xx_hal::{
   delay::DelayFromCountDownTimer,
   prelude::*,
   rcc::Config,
   stm32::Peripherals,
   timer::Timer,
};

use cortex_m_rt::entry;

#[entry]
fn main() -> ! {
    let dp = Peripherals::take().expect("cannot take peripherals");
    let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals");
    let mut rcc = dp.RCC.freeze(Config::hsi());

    let gpioa = dp.GPIOA.split(&mut rcc);
    let mut led = gpioa.pa5.into_push_pull_output();

    let mut delay_syst = cp.SYST.delay(&rcc.clocks);

    let timer2 = Timer::new(dp.TIM2, &rcc.clocks);
    let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.ms()));

    loop {
        led.toggle().unwrap();
        delay_syst.delay(1000.ms());
        delay_syst.delay_ms(1000);
        delay_syst.delay_ms(1000_u32); 
        //delay_syst.delay_ms(1000_u16);   //expected `u32`, found `u16`
        //delay_syst.delay_ms(100_u8);    //expected `u32`, found `u8`

        led.toggle().unwrap();
        //delay_tim2.delay(1000.ms());    //method not found 
        //delay_tim2.delay_ms(1000);      //trait `DelayMs<i32>` is not implemented
        delay_tim2.delay_ms(1000_u32);
        delay_tim2.delay_ms(1000_u16);
        delay_tim2.delay_ms(100_u8);
    }
}

Also, module stm32 should be called pac. Several hals are doing this by making pac an alias for stm32.

I am attempting several examples on stm32g4xx_hal that I have compiling on other hals. Differences with delay are causing the most problems at the moment . (See https://github.com/pdgilbert/rust-integration-testing/actions.)

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

No branches or pull requests

1 participant