Skip to content

more delay methods #65

@pdgilbert

Description

@pdgilbert

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions