diff --git a/src/bldc_motor_driver_stm32g4.rs b/src/bldc_motor_driver_stm32g4.rs index 10a2b8c..607042e 100644 --- a/src/bldc_motor_driver_stm32g4.rs +++ b/src/bldc_motor_driver_stm32g4.rs @@ -93,13 +93,11 @@ pub fn clock_init(perip: &Peripherals, core_perip: &mut CorePeripherals) { tim6.cr2.modify(|_, w| unsafe { w.mms().bits(0b010) }); } -pub fn dma_init(perip: &Peripherals, core_perip: &mut CorePeripherals, address: u32) { +pub fn dma_init(perip: &Peripherals) { let address = free(|cs| G_ADC_DATA.borrow(cs).borrow().as_ptr() as u32); // DMAの電源投入(クロックの有効化) - // perip.RCC.ahb1rstr.modify(|_, w| w.dmamux1rst().reset()); - // perip.RCC.ahb1rstr.modify(|_, w| w.dma1rst().reset()); perip.RCC.ahb1rstr.modify(|_, w| w.dmamux1rst().set_bit()); perip.RCC.ahb1rstr.modify(|_, w| w.dma1rst().set_bit()); perip.RCC.ahb1rstr.modify(|_, w| w.dmamux1rst().clear_bit()); @@ -137,15 +135,12 @@ pub fn dma_init(perip: &Peripherals, core_perip: &mut CorePeripherals, address: let adc = &perip.ADC2; let adc_data_register_addr = &adc.dr as *const _ as u32; - // let adc_dma_buf_addr : u32 = adc_dma_buf as *const [u16; 4] as u32; - // perip.DMA1.cpar1.modify(|_, w| unsafe { w.pa().bits(*adc.dr.as_ptr()) }); // peripheral address perip .DMA1 .cpar1 .modify(|_, w| unsafe { w.pa().bits(adc_data_register_addr) }); // peripheral address - // perip.DMA1.cndtr1.modify(|_, w| unsafe { w.ndt().bits(adc_dma_buf.len() as u16) }); // num perip.DMA1.cndtr1.modify(|_, w| unsafe { w.ndt().bits(7) }); // num - // perip.DMA1.cmar1.modify(|_, w| unsafe { w.ma().bits(adc_dma_buf_addr) }); // memory address + perip .DMA1 .cmar1 diff --git a/src/main.rs b/src/main.rs index 4ac3866..802752f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,6 +69,7 @@ fn TIM3() { } }); } + defmt::timestamp!("{=u32:us}", { // NOTE(interrupt-safe) single instruction volatile read operation free(|cs| { @@ -96,16 +97,8 @@ fn main() -> ! { bldc_motor_driver_stm32g4::clock_init(&perip, &mut core_perip); bldc_motor_driver_stm32g4::adc2_init(&perip); - // let adc_data: [u16; 7] = [77; 7]; - // let adcd = bldc_motor_driver_stm32g4::AdcData::new(); - - // let dma_buf_addr: u32 = adc_data.as_ptr() as u32; - // defmt::error!("addr {}", adc_data.as_ptr() as u32); - // let dma_buf_addr: u32 = adcd.data.as_ptr() as u32; - - // defmt::error!("addr {}", dma_buf_addr); - bldc_motor_driver_stm32g4::dma_init(&perip, &mut core_perip, 0); + bldc_motor_driver_stm32g4::dma_init(&perip); bldc_motor_driver_stm32g4::dma_adc2_start(&perip); bldc_motor_driver_stm32g4::init_g_peripheral(perip); @@ -176,11 +169,8 @@ fn main() -> ! { // uart.write_str("hello "); // write!(uart, "{} + {} = {}\r\n", 2, 4, 2+4); defmt::info!("hello from defmt"); - // defmt::error!("addr {}", adc_data.as_ptr() as u32); - // defmt::error!("addr {}", adcd.data.as_ptr() as u32); let adcd = free(|cs| bldc_motor_driver_stm32g4::G_ADC_DATA.borrow(cs).borrow().clone()); - write!( uart, "{{\"ADC\":[{:4}, {:4}, {:4}, {:4}, {:4}, {:4}, {:4}]}}\r\n",