From 2369db3657ea924907b1e4e94ff0699775ab1b04 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 28 Dec 2019 15:37:37 -0800 Subject: [PATCH] Lots of debugging stuff: works, but sample rate is low enough that it's not super useful --- src/main.rs | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index f1aea66..310fde4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -112,7 +112,7 @@ extern crate panic_itm; // panic handler mod bsp; -use cortex_m::iprintln; +use cortex_m::{iprintln, itm}; use cortex_m::asm::{bkpt, delay}; use cortex_m_rt::entry; @@ -260,13 +260,50 @@ fn main() -> ! { bkpt(); + // We have 48 KBytes of ram + // But sizes >= 4096 seem to cause faults :s + let mut buffer = [0u8; 2048]; + loop { + for sample in buffer.iter_mut() { + *sample = (per.adc1.dr.read().bits() >> 4) as u8; + } + itm::write_all(&mut per.itm.stim[0], &buffer); + //let avg_sample = (buffer.iter().map(|x| *x as u32).sum::() / buffer.len() as u32) as u16; + //if buffer.iter().any(|&s| s as u32 * 4 > avg_sample as u32 * 5 || s as u32 * 5 < avg_sample as u32 * 4) { + // // Dump the buffer: + // itm::write_all(&mut per.itm.stim[0], &buffer); + // //for sample in buffer.iter() { + // ////for i in 0..2048 { + // // //let data = (buffer[i] >> 4) as u32; + // // let data = (sample >> 4) as u8; + // // while !per.itm.stim[0].is_fifo_ready() {} + // // per.itm.stim[0].write_u8(data); + // // //per.itm.stim[0].write_u32(data | (data << 8) | (data << 16) | (data << 24)); + // // //delay(10000); + // //} + //} + } + + loop { + iprintln!(&mut per.itm.stim[0], "hello!"); + } + loop { //let push_button = per.gpioa.idr.read().idr0().bit(); - let push_button = per.gpiod.idr.read().idr0().bit(); - per.gpioe.odr.modify(|_, w| { - w.odr8().bit(push_button) - }); - iprintln!(&mut per.itm.stim[0], "ADC: {:x}", per.adc1.dr.read().bits()); + //let push_button = per.gpiod.idr.read().idr0().bit(); + //per.gpioe.odr.modify(|_, w| { + // w.odr8().bit(push_button) + //}); + //iprintln!(&mut per.itm.stim[0], "ADC: {:x}", per.adc1.dr.read().bits()); + //per.itm.stim[0].write_u32(per.adc1.dr.read().bits()); + while !per.itm.stim[0].is_fifo_ready() {} + let adc = per.adc1.dr.read().bits(); + //let data = adc as u16; + //per.itm.stim[0].write_u16(data); + let data = (adc >> 4) as u32; + //per.itm.stim[0].write_u8(data); + per.itm.stim[0].write_u32(data | (data << 8) | (data << 16) | (data << 24)); + delay(1); } }