Compare commits

..

3 commits

Author SHA1 Message Date
Joe Ardent
1f9d4ae284 add thumbv7m target 2024-11-04 13:47:02 -08:00
Joe Ardent
86aa77175f can't seem to flash the board 2024-10-13 13:36:32 -07:00
Joe Ardent
842d8b26a6 checkpoint 2024-10-12 14:40:52 -07:00
4 changed files with 49 additions and 26 deletions

View file

@ -1,8 +1,9 @@
[target.thumbv7m-none-eabi]
runner = 'probe-rs run --chip STM32F302R8Tx'
# 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"
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
#[target.'cfg(all(target_arch = "arm", target_os = "none"))']
rustflags = []
[build]

4
.rustfmt.toml Normal file
View file

@ -0,0 +1,4 @@
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
wrap_comments = true
edition = "2021"

View file

@ -25,3 +25,7 @@ bench = false
codegen-units = 1 # better optimizations
debug = true # symbols are nice and they don't increase the size on Flash
lto = true # better optimizations
[profile.dev.package."*"]
opt-level = "z"
debug = true

View file

@ -1,45 +1,59 @@
#![no_std]
#![no_main]
use stm32f3xx_hal::{self as hal, adc, pac, prelude::*};
use {defmt_rtt as _, panic_halt as _};
use cortex_m::asm;
use defmt_rtt as _;
#[allow(deprecated)]
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;
mod motor;
//use motor::*;
#[cortex_m_rt::entry]
fn main() -> ! {
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);
let dp = pac::Peripherals::take().unwrap();
// 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 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 adc_common = adc::CommonAdc::new(dp.ADC1_2, &clocks, &mut rcc.ahb);
let mut padc = adc::Adc::new(
sp.ADC1,
dp.ADC1,
adc::config::Config::default(),
&clocks,
&adc_common,
);
loop {
let pot_out: u16 = padc.read(&mut pot).unwrap_or(0);
let pot_out = (POT_MAX - pot_out) as f32 / POT_MAX as f32;
let pot_out = (4000.0 * pot_out) as u32;
// 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
);
led.toggle().unwrap();
delay.delay_ms(pot_out);
let mut led_pwm = tim2_channels.0.output_to_pa5(led);
let max = led_pwm.get_max_duty();
loop {
asm::wfi();
let pot_out: u16 = padc.read(&mut pot).unwrap_or(0);
let pot_out = (pot_out as f32 / POT_MAX as f32) as u32;
led_pwm.set_duty(max * pot_out);
led_pwm.enable();
}
}