Compare commits
No commits in common. "1f9d4ae2845cc9feb8e55efa0f38ac934f2f106d" and "8069017df05ead17109b1c9ee4840f948709cd7c" have entirely different histories.
1f9d4ae284
...
8069017df0
4 changed files with 25 additions and 48 deletions
|
|
@ -1,9 +1,8 @@
|
||||||
[target.thumbv7m-none-eabi]
|
[target.thumbv7m-none-eabi]
|
||||||
runner = 'probe-rs run --chip STM32F302R8Tx'
|
|
||||||
# uncomment this to make `cargo run` execute programs on QEMU
|
# uncomment this to make `cargo run` execute programs on QEMU
|
||||||
# runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
|
# runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
|
||||||
|
|
||||||
#[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||||
rustflags = []
|
rustflags = []
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
imports_granularity = "Crate"
|
|
||||||
group_imports = "StdExternalCrate"
|
|
||||||
wrap_comments = true
|
|
||||||
edition = "2021"
|
|
||||||
|
|
@ -25,7 +25,3 @@ bench = false
|
||||||
codegen-units = 1 # better optimizations
|
codegen-units = 1 # better optimizations
|
||||||
debug = true # symbols are nice and they don't increase the size on Flash
|
debug = true # symbols are nice and they don't increase the size on Flash
|
||||||
lto = true # better optimizations
|
lto = true # better optimizations
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
|
||||||
opt-level = "z"
|
|
||||||
debug = true
|
|
||||||
|
|
|
||||||
62
src/main.rs
62
src/main.rs
|
|
@ -1,59 +1,45 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use cortex_m::asm;
|
use stm32f3xx_hal::{self as hal, adc, pac, prelude::*};
|
||||||
use defmt_rtt as _;
|
|
||||||
#[allow(deprecated)]
|
use {defmt_rtt as _, panic_halt as _};
|
||||||
use hal::pwm::tim2;
|
|
||||||
use hal::{adc, flash::FlashExt, gpio::GpioExt, hal::PwmPin, pac, prelude::*, rcc::RccExt};
|
|
||||||
use panic_halt as _;
|
|
||||||
use stm32f3xx_hal as hal;
|
|
||||||
|
|
||||||
static POT_MAX: u16 = 4095;
|
static POT_MAX: u16 = 4095;
|
||||||
|
|
||||||
|
mod motor;
|
||||||
|
//use motor::*;
|
||||||
|
|
||||||
#[cortex_m_rt::entry]
|
#[cortex_m_rt::entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let dp = pac::Peripherals::take().unwrap();
|
let sp = pac::Peripherals::take().unwrap();
|
||||||
|
let mut rcc = sp.RCC.constrain();
|
||||||
|
let mut gpiob = sp.GPIOB.split(&mut rcc.ahb);
|
||||||
|
let mut led = gpiob
|
||||||
|
.pb2
|
||||||
|
.into_push_pull_output(&mut gpiob.moder, &mut gpiob.otyper);
|
||||||
|
|
||||||
// Configure our clocks
|
|
||||||
let mut flash = dp.FLASH.constrain();
|
|
||||||
let mut rcc = dp.RCC.constrain();
|
|
||||||
let clocks = rcc.cfgr.sysclk(16.MHz()).freeze(&mut flash.acr);
|
|
||||||
|
|
||||||
let mut gpiob = dp.GPIOB.split(&mut rcc.ahb);
|
|
||||||
let mut gpioa = dp.GPIOA.split(&mut rcc.ahb);
|
|
||||||
let led = gpioa
|
|
||||||
.pa5
|
|
||||||
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);
|
|
||||||
let mut pot = gpiob.pb1.into_analog(&mut gpiob.moder, &mut gpiob.pupdr);
|
let mut pot = gpiob.pb1.into_analog(&mut gpiob.moder, &mut gpiob.pupdr);
|
||||||
|
|
||||||
let adc_common = adc::CommonAdc::new(dp.ADC1_2, &clocks, &mut rcc.ahb);
|
let mut flash = sp.FLASH.constrain();
|
||||||
|
let clocks = rcc.cfgr.freeze(&mut flash.acr);
|
||||||
|
let cp = cortex_m::Peripherals::take().unwrap();
|
||||||
|
let mut delay = hal::delay::Delay::new(cp.SYST, clocks);
|
||||||
|
|
||||||
|
let adc_common = adc::CommonAdc::new(sp.ADC1_2, &clocks, &mut rcc.ahb);
|
||||||
let mut padc = adc::Adc::new(
|
let mut padc = adc::Adc::new(
|
||||||
dp.ADC1,
|
sp.ADC1,
|
||||||
adc::config::Config::default(),
|
adc::config::Config::default(),
|
||||||
&clocks,
|
&clocks,
|
||||||
&adc_common,
|
&adc_common,
|
||||||
);
|
);
|
||||||
|
|
||||||
// TIM2
|
|
||||||
//
|
|
||||||
// A 32-bit timer, so we can set a larger resolution
|
|
||||||
#[allow(deprecated)]
|
|
||||||
let tim2_channels = tim2(
|
|
||||||
dp.TIM2,
|
|
||||||
160000, // resolution of duty cycle
|
|
||||||
50.Hz(), // frequency of period
|
|
||||||
&clocks, // To get the timer's clock speed
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut led_pwm = tim2_channels.0.output_to_pa5(led);
|
|
||||||
let max = led_pwm.get_max_duty();
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
asm::wfi();
|
|
||||||
let pot_out: u16 = padc.read(&mut pot).unwrap_or(0);
|
let pot_out: u16 = padc.read(&mut pot).unwrap_or(0);
|
||||||
let pot_out = (pot_out as f32 / POT_MAX as f32) as u32;
|
let pot_out = (POT_MAX - pot_out) as f32 / POT_MAX as f32;
|
||||||
led_pwm.set_duty(max * pot_out);
|
let pot_out = (4000.0 * pot_out) as u32;
|
||||||
led_pwm.enable();
|
|
||||||
|
led.toggle().unwrap();
|
||||||
|
delay.delay_ms(pot_out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue