stm32/test: add stm32f446 (board not in HIL rig yet)

This commit is contained in:
Dario Nieuwenhuis
2023-11-27 00:36:04 +01:00
parent 6bdacb4f69
commit cf13f70ea9
6 changed files with 72 additions and 39 deletions

View File

@ -6,6 +6,8 @@
#[path = "../common.rs"]
mod common;
use core::f32::consts::PI;
use common::*;
use defmt::assert;
use embassy_executor::Spawner;
@ -13,6 +15,7 @@ use embassy_stm32::adc::Adc;
use embassy_stm32::dac::{DacCh1, Value};
use embassy_stm32::dma::NoDma;
use embassy_time::{Delay, Timer};
use micromath::F32Ext;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
@ -20,24 +23,22 @@ async fn main(_spawner: Spawner) {
// Initialize the board and obtain a Peripherals instance
let p: embassy_stm32::Peripherals = embassy_stm32::init(config());
#[cfg(feature = "stm32f429zi")]
let dac_peripheral = p.DAC;
let dac = peri!(p, DAC);
let dac_pin = peri!(p, DAC_PIN);
let mut adc_pin = unsafe { core::ptr::read(&dac_pin) };
#[cfg(any(feature = "stm32h755zi", feature = "stm32g071rb"))]
let dac_peripheral = p.DAC1;
let mut dac = DacCh1::new(dac_peripheral, NoDma, p.PA4);
let mut dac = DacCh1::new(dac, NoDma, dac_pin);
let mut adc = Adc::new(p.ADC1, &mut Delay);
#[cfg(feature = "stm32h755zi")]
let normalization_factor = 256;
#[cfg(any(feature = "stm32f429zi", feature = "stm32g071rb"))]
#[cfg(any(feature = "stm32f429zi", feature = "stm32f446re", feature = "stm32g071rb"))]
let normalization_factor: i32 = 16;
dac.set(Value::Bit8(0));
// Now wait a little to obtain a stable value
Timer::after_millis(30).await;
let offset = adc.read(&mut unsafe { embassy_stm32::Peripherals::steal() }.PA4);
let offset = adc.read(&mut adc_pin);
for v in 0..=255 {
// First set the DAC output value
@ -62,10 +63,6 @@ async fn main(_spawner: Spawner) {
cortex_m::asm::bkpt();
}
use core::f32::consts::PI;
use micromath::F32Ext;
fn to_sine_wave(v: u8) -> u8 {
if v >= 128 {
// top half