Skip to content

Commit

Permalink
codeを整理
Browse files Browse the repository at this point in the history
  • Loading branch information
chama1176 committed Aug 29, 2024
1 parent 25cd990 commit 85c2218
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
9 changes: 2 additions & 7 deletions src/bldc_motor_driver_stm32g4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fn TIM3() {
}
});
}

defmt::timestamp!("{=u32:us}", {
// NOTE(interrupt-safe) single instruction volatile read operation
free(|cs| {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 85c2218

Please sign in to comment.