pwm_input is working on F446

This commit is contained in:
Bruno Bousquet
2024-05-29 00:28:26 -04:00
parent a6c419d096
commit 521332bdd1
10 changed files with 265 additions and 29 deletions

View File

@@ -15,7 +15,7 @@
"cwd": "${workspaceRoot}",
"preLaunchTask": "Cargo Build (debug)",
"runToEntryPoint": "main",
"executable": "./target/thumbv7m-none-eabi/debug/input_capture",
"executable": "./target/thumbv7m-none-eabi/debug/pwm_input",
/* Run `cargo build --example itm` and uncomment this line to run itm example */
// "executable": "./target/thumbv7em-none-eabihf/debug/examples/itm",
"device": "STM32F103TB",

View File

@@ -9,7 +9,7 @@
],
"args": [
"--bin",
"input_capture"
"pwm_input"
],
"group": {
"kind": "build",

View File

@@ -0,0 +1,50 @@
#![no_std]
#![no_main]
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Pull, Speed};
use embassy_stm32::time::khz;
use embassy_stm32::timer::{self, pwm_input::PwmInput};
use embassy_stm32::{bind_interrupts, peripherals};
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
/// Connect PB2 and PB10 with a 1k Ohm resistor
#[embassy_executor::task]
async fn blinky(led: peripherals::PC13) {
let mut led = Output::new(led, Level::High, Speed::Low);
loop {
info!("high");
led.set_high();
Timer::after_millis(300).await;
info!("low");
led.set_low();
Timer::after_millis(300).await;
}
}
bind_interrupts!(struct Irqs {
TIM2 => timer::CaptureCompareInterruptHandler<peripherals::TIM2>;
});
#[embassy_executor::main]
async fn main(spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
info!("Hello World!");
unwrap!(spawner.spawn(blinky(p.PC13)));
let pwm_input = PwmInput::new(p.TIM2, p.PA0, Pull::None, khz(1000));
loop {
Timer::after_millis(500).await;
let _per = pwm_input.get_period_ticks();
let _dc = pwm_input.get_duty_ticks();
let _pc = pwm_input.get_duty_cycle();
asm::nop();
}
}