diff options
| author | Frostie314159 <[email protected]> | 2024-03-31 20:48:05 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-03-31 20:48:05 +0200 |
| commit | 67c9cc2c4b886e6962ecdd6eff8794b14c1accdc (patch) | |
| tree | f176ab269949d26f48e04c950cebc5489bae8c56 /examples/stm32h7/src | |
| parent | a2f9aa592ec61beb247065003016515f0d423c13 (diff) | |
| parent | 6634cc90bcd3eb25b64712688920f383584b2964 (diff) | |
Merge branch 'embassy-rs:main' into ticker_send_sync
Diffstat (limited to 'examples/stm32h7/src')
27 files changed, 353 insertions, 116 deletions
diff --git a/examples/stm32h7/src/bin/adc.rs b/examples/stm32h7/src/bin/adc.rs index e367827e9..a5594d10c 100644 --- a/examples/stm32h7/src/bin/adc.rs +++ b/examples/stm32h7/src/bin/adc.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| @@ -39,7 +38,7 @@ async fn main(_spawner: Spawner) { | |||
| 39 | config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz | 38 | config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz |
| 40 | config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz | 39 | config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz |
| 41 | config.rcc.voltage_scale = VoltageScale::Scale1; | 40 | config.rcc.voltage_scale = VoltageScale::Scale1; |
| 42 | config.rcc.adc_clock_source = AdcClockSource::PLL2_P; | 41 | config.rcc.mux.adcsel = mux::Adcsel::PLL2_P; |
| 43 | } | 42 | } |
| 44 | let mut p = embassy_stm32::init(config); | 43 | let mut p = embassy_stm32::init(config); |
| 45 | 44 | ||
| @@ -47,7 +46,7 @@ async fn main(_spawner: Spawner) { | |||
| 47 | 46 | ||
| 48 | let mut adc = Adc::new(p.ADC3, &mut Delay); | 47 | let mut adc = Adc::new(p.ADC3, &mut Delay); |
| 49 | 48 | ||
| 50 | adc.set_sample_time(SampleTime::Cycles32_5); | 49 | adc.set_sample_time(SampleTime::CYCLES32_5); |
| 51 | 50 | ||
| 52 | let mut vrefint_channel = adc.enable_vrefint(); | 51 | let mut vrefint_channel = adc.enable_vrefint(); |
| 53 | 52 | ||
diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs index a9cab1ff4..1ee90a870 100644 --- a/examples/stm32h7/src/bin/blinky.rs +++ b/examples/stm32h7/src/bin/blinky.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32h7/src/bin/button_exti.rs b/examples/stm32h7/src/bin/button_exti.rs index dfe587d41..2a546dac5 100644 --- a/examples/stm32h7/src/bin/button_exti.rs +++ b/examples/stm32h7/src/bin/button_exti.rs | |||
| @@ -1,11 +1,10 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::exti::ExtiInput; |
| 8 | use embassy_stm32::gpio::{Input, Pull}; | 7 | use embassy_stm32::gpio::Pull; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 9 | ||
| 11 | #[embassy_executor::main] | 10 | #[embassy_executor::main] |
| @@ -13,8 +12,7 @@ async fn main(_spawner: Spawner) { | |||
| 13 | let p = embassy_stm32::init(Default::default()); | 12 | let p = embassy_stm32::init(Default::default()); |
| 14 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 15 | 14 | ||
| 16 | let button = Input::new(p.PC13, Pull::Down); | 15 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); |
| 17 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 18 | 16 | ||
| 19 | info!("Press the USER button..."); | 17 | info!("Press the USER button..."); |
| 20 | 18 | ||
diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs index 489fb03dd..170a5aa28 100644 --- a/examples/stm32h7/src/bin/camera.rs +++ b/examples/stm32h7/src/bin/camera.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::dcmi::{self, *}; | 5 | use embassy_stm32::dcmi::{self, *}; |
| @@ -79,9 +78,9 @@ async fn main(_spawner: Spawner) { | |||
| 79 | ); | 78 | ); |
| 80 | 79 | ||
| 81 | defmt::info!("attempting capture"); | 80 | defmt::info!("attempting capture"); |
| 82 | defmt::unwrap!(dcmi.capture(unsafe { &mut FRAME }).await); | 81 | defmt::unwrap!(dcmi.capture(unsafe { &mut *core::ptr::addr_of_mut!(FRAME) }).await); |
| 83 | 82 | ||
| 84 | defmt::info!("captured frame: {:x}", unsafe { &FRAME }); | 83 | defmt::info!("captured frame: {:x}", unsafe { &*core::ptr::addr_of!(FRAME) }); |
| 85 | 84 | ||
| 86 | defmt::info!("main loop running"); | 85 | defmt::info!("main loop running"); |
| 87 | loop { | 86 | loop { |
diff --git a/examples/stm32h7/src/bin/can.rs b/examples/stm32h7/src/bin/can.rs new file mode 100644 index 000000000..22cb27481 --- /dev/null +++ b/examples/stm32h7/src/bin/can.rs | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_stm32::peripherals::*; | ||
| 7 | use embassy_stm32::{bind_interrupts, can, rcc, Config}; | ||
| 8 | use embassy_time::Timer; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 10 | |||
| 11 | bind_interrupts!(struct Irqs { | ||
| 12 | FDCAN1_IT0 => can::IT0InterruptHandler<FDCAN1>; | ||
| 13 | FDCAN1_IT1 => can::IT1InterruptHandler<FDCAN1>; | ||
| 14 | }); | ||
| 15 | |||
| 16 | #[embassy_executor::main] | ||
| 17 | async fn main(_spawner: Spawner) { | ||
| 18 | let mut config = Config::default(); | ||
| 19 | config.rcc.hse = Some(rcc::Hse { | ||
| 20 | freq: embassy_stm32::time::Hertz(25_000_000), | ||
| 21 | mode: rcc::HseMode::Oscillator, | ||
| 22 | }); | ||
| 23 | config.rcc.mux.fdcansel = rcc::mux::Fdcansel::HSE; | ||
| 24 | |||
| 25 | let peripherals = embassy_stm32::init(config); | ||
| 26 | |||
| 27 | let mut can = can::CanConfigurator::new(peripherals.FDCAN1, peripherals.PA11, peripherals.PA12, Irqs); | ||
| 28 | |||
| 29 | // 250k bps | ||
| 30 | can.set_bitrate(250_000); | ||
| 31 | |||
| 32 | //let mut can = can.into_internal_loopback_mode(); | ||
| 33 | let mut can = can.into_normal_mode(); | ||
| 34 | |||
| 35 | info!("CAN Configured"); | ||
| 36 | |||
| 37 | let mut i = 0; | ||
| 38 | let mut last_read_ts = embassy_time::Instant::now(); | ||
| 39 | |||
| 40 | loop { | ||
| 41 | let frame = can::frame::Frame::new_extended(0x123456F, &[i; 8]).unwrap(); | ||
| 42 | info!("Writing frame"); | ||
| 43 | _ = can.write(&frame).await; | ||
| 44 | |||
| 45 | match can.read().await { | ||
| 46 | Ok(envelope) => { | ||
| 47 | let (rx_frame, ts) = envelope.parts(); | ||
| 48 | let delta = (ts - last_read_ts).as_millis(); | ||
| 49 | last_read_ts = ts; | ||
| 50 | info!( | ||
| 51 | "Rx: {:x} {:x} {:x} {:x} --- NEW {}", | ||
| 52 | rx_frame.data()[0], | ||
| 53 | rx_frame.data()[1], | ||
| 54 | rx_frame.data()[2], | ||
| 55 | rx_frame.data()[3], | ||
| 56 | delta, | ||
| 57 | ) | ||
| 58 | } | ||
| 59 | Err(_err) => error!("Error in frame"), | ||
| 60 | } | ||
| 61 | |||
| 62 | Timer::after_millis(250).await; | ||
| 63 | |||
| 64 | i += 1; | ||
| 65 | if i > 3 { | ||
| 66 | break; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | let (mut tx, mut rx) = can.split(); | ||
| 71 | // With split | ||
| 72 | loop { | ||
| 73 | let frame = can::frame::Frame::new_extended(0x123456F, &[i; 8]).unwrap(); | ||
| 74 | info!("Writing frame"); | ||
| 75 | _ = tx.write(&frame).await; | ||
| 76 | |||
| 77 | match rx.read().await { | ||
| 78 | Ok(envelope) => { | ||
| 79 | let (rx_frame, ts) = envelope.parts(); | ||
| 80 | let delta = (ts - last_read_ts).as_millis(); | ||
| 81 | last_read_ts = ts; | ||
| 82 | info!( | ||
| 83 | "Rx: {:x} {:x} {:x} {:x} --- NEW {}", | ||
| 84 | rx_frame.data()[0], | ||
| 85 | rx_frame.data()[1], | ||
| 86 | rx_frame.data()[2], | ||
| 87 | rx_frame.data()[3], | ||
| 88 | delta, | ||
| 89 | ) | ||
| 90 | } | ||
| 91 | Err(_err) => error!("Error in frame"), | ||
| 92 | } | ||
| 93 | |||
| 94 | Timer::after_millis(250).await; | ||
| 95 | |||
| 96 | i += 1; | ||
| 97 | } | ||
| 98 | } | ||
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs index f66268151..a6f969aba 100644 --- a/examples/stm32h7/src/bin/dac.rs +++ b/examples/stm32h7/src/bin/dac.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use cortex_m_rt::entry; | 4 | use cortex_m_rt::entry; |
| 6 | use defmt::*; | 5 | use defmt::*; |
| @@ -41,7 +40,7 @@ fn main() -> ! { | |||
| 41 | config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz | 40 | config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz |
| 42 | config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz | 41 | config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz |
| 43 | config.rcc.voltage_scale = VoltageScale::Scale1; | 42 | config.rcc.voltage_scale = VoltageScale::Scale1; |
| 44 | config.rcc.adc_clock_source = AdcClockSource::PLL2_P; | 43 | config.rcc.mux.adcsel = mux::Adcsel::PLL2_P; |
| 45 | } | 44 | } |
| 46 | let p = embassy_stm32::init(config); | 45 | let p = embassy_stm32::init(config); |
| 47 | 46 | ||
diff --git a/examples/stm32h7/src/bin/dac_dma.rs b/examples/stm32h7/src/bin/dac_dma.rs index c19fdd623..3a9887e3c 100644 --- a/examples/stm32h7/src/bin/dac_dma.rs +++ b/examples/stm32h7/src/bin/dac_dma.rs | |||
| @@ -1,15 +1,14 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::dac::{DacCh1, DacCh2, ValueArray}; | 6 | use embassy_stm32::dac::{DacCh1, DacCh2, ValueArray}; |
| 8 | use embassy_stm32::pac::timer::vals::{Mms, Opm}; | 7 | use embassy_stm32::pac::timer::vals::Mms; |
| 9 | use embassy_stm32::peripherals::{DAC1, DMA1_CH3, DMA1_CH4, TIM6, TIM7}; | 8 | use embassy_stm32::peripherals::{DAC1, DMA1_CH3, DMA1_CH4, TIM6, TIM7}; |
| 10 | use embassy_stm32::rcc::low_level::RccPeripheral; | 9 | use embassy_stm32::rcc::frequency; |
| 11 | use embassy_stm32::time::Hertz; | 10 | use embassy_stm32::time::Hertz; |
| 12 | use embassy_stm32::timer::low_level::Basic16bitInstance; | 11 | use embassy_stm32::timer::low_level::Timer; |
| 13 | use micromath::F32Ext; | 12 | use micromath::F32Ext; |
| 14 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | 14 | ||
| @@ -43,7 +42,7 @@ async fn main(spawner: Spawner) { | |||
| 43 | config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz | 42 | config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz |
| 44 | config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz | 43 | config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz |
| 45 | config.rcc.voltage_scale = VoltageScale::Scale1; | 44 | config.rcc.voltage_scale = VoltageScale::Scale1; |
| 46 | config.rcc.adc_clock_source = AdcClockSource::PLL2_P; | 45 | config.rcc.mux.adcsel = mux::Adcsel::PLL2_P; |
| 47 | } | 46 | } |
| 48 | 47 | ||
| 49 | // Initialize the board and obtain a Peripherals instance | 48 | // Initialize the board and obtain a Peripherals instance |
| @@ -52,19 +51,19 @@ async fn main(spawner: Spawner) { | |||
| 52 | // Obtain two independent channels (p.DAC1 can only be consumed once, though!) | 51 | // Obtain two independent channels (p.DAC1 can only be consumed once, though!) |
| 53 | let (dac_ch1, dac_ch2) = embassy_stm32::dac::Dac::new(p.DAC1, p.DMA1_CH3, p.DMA1_CH4, p.PA4, p.PA5).split(); | 52 | let (dac_ch1, dac_ch2) = embassy_stm32::dac::Dac::new(p.DAC1, p.DMA1_CH3, p.DMA1_CH4, p.PA4, p.PA5).split(); |
| 54 | 53 | ||
| 55 | spawner.spawn(dac_task1(dac_ch1)).ok(); | 54 | spawner.spawn(dac_task1(p.TIM6, dac_ch1)).ok(); |
| 56 | spawner.spawn(dac_task2(dac_ch2)).ok(); | 55 | spawner.spawn(dac_task2(p.TIM7, dac_ch2)).ok(); |
| 57 | } | 56 | } |
| 58 | 57 | ||
| 59 | #[embassy_executor::task] | 58 | #[embassy_executor::task] |
| 60 | async fn dac_task1(mut dac: DacCh1<'static, DAC1, DMA1_CH3>) { | 59 | async fn dac_task1(tim: TIM6, mut dac: DacCh1<'static, DAC1, DMA1_CH3>) { |
| 61 | let data: &[u8; 256] = &calculate_array::<256>(); | 60 | let data: &[u8; 256] = &calculate_array::<256>(); |
| 62 | 61 | ||
| 63 | info!("TIM6 frequency is {}", TIM6::frequency()); | 62 | info!("TIM6 frequency is {}", frequency::<TIM6>()); |
| 64 | const FREQUENCY: Hertz = Hertz::hz(200); | 63 | const FREQUENCY: Hertz = Hertz::hz(200); |
| 65 | 64 | ||
| 66 | // Compute the reload value such that we obtain the FREQUENCY for the sine | 65 | // Compute the reload value such that we obtain the FREQUENCY for the sine |
| 67 | let reload: u32 = (TIM6::frequency().0 / FREQUENCY.0) / data.len() as u32; | 66 | let reload: u32 = (frequency::<TIM6>().0 / FREQUENCY.0) / data.len() as u32; |
| 68 | 67 | ||
| 69 | // Depends on your clock and on the specific chip used, you may need higher or lower values here | 68 | // Depends on your clock and on the specific chip used, you may need higher or lower values here |
| 70 | if reload < 10 { | 69 | if reload < 10 { |
| @@ -75,17 +74,17 @@ async fn dac_task1(mut dac: DacCh1<'static, DAC1, DMA1_CH3>) { | |||
| 75 | dac.set_triggering(true); | 74 | dac.set_triggering(true); |
| 76 | dac.enable(); | 75 | dac.enable(); |
| 77 | 76 | ||
| 78 | TIM6::enable_and_reset(); | 77 | let tim = Timer::new(tim); |
| 79 | TIM6::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); | 78 | tim.regs_basic().arr().modify(|w| w.set_arr(reload as u16 - 1)); |
| 80 | TIM6::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); | 79 | tim.regs_basic().cr2().modify(|w| w.set_mms(Mms::UPDATE)); |
| 81 | TIM6::regs().cr1().modify(|w| { | 80 | tim.regs_basic().cr1().modify(|w| { |
| 82 | w.set_opm(Opm::DISABLED); | 81 | w.set_opm(false); |
| 83 | w.set_cen(true); | 82 | w.set_cen(true); |
| 84 | }); | 83 | }); |
| 85 | 84 | ||
| 86 | debug!( | 85 | debug!( |
| 87 | "TIM6 Frequency {}, Target Frequency {}, Reload {}, Reload as u16 {}, Samples {}", | 86 | "TIM6 Frequency {}, Target Frequency {}, Reload {}, Reload as u16 {}, Samples {}", |
| 88 | TIM6::frequency(), | 87 | frequency::<TIM6>(), |
| 89 | FREQUENCY, | 88 | FREQUENCY, |
| 90 | reload, | 89 | reload, |
| 91 | reload as u16, | 90 | reload as u16, |
| @@ -100,23 +99,23 @@ async fn dac_task1(mut dac: DacCh1<'static, DAC1, DMA1_CH3>) { | |||
| 100 | } | 99 | } |
| 101 | 100 | ||
| 102 | #[embassy_executor::task] | 101 | #[embassy_executor::task] |
| 103 | async fn dac_task2(mut dac: DacCh2<'static, DAC1, DMA1_CH4>) { | 102 | async fn dac_task2(tim: TIM7, mut dac: DacCh2<'static, DAC1, DMA1_CH4>) { |
| 104 | let data: &[u8; 256] = &calculate_array::<256>(); | 103 | let data: &[u8; 256] = &calculate_array::<256>(); |
| 105 | 104 | ||
| 106 | info!("TIM7 frequency is {}", TIM7::frequency()); | 105 | info!("TIM7 frequency is {}", frequency::<TIM6>()); |
| 107 | 106 | ||
| 108 | const FREQUENCY: Hertz = Hertz::hz(600); | 107 | const FREQUENCY: Hertz = Hertz::hz(600); |
| 109 | let reload: u32 = (TIM7::frequency().0 / FREQUENCY.0) / data.len() as u32; | 108 | let reload: u32 = (frequency::<TIM7>().0 / FREQUENCY.0) / data.len() as u32; |
| 110 | 109 | ||
| 111 | if reload < 10 { | 110 | if reload < 10 { |
| 112 | error!("Reload value {} below threshold!", reload); | 111 | error!("Reload value {} below threshold!", reload); |
| 113 | } | 112 | } |
| 114 | 113 | ||
| 115 | TIM7::enable_and_reset(); | 114 | let tim = Timer::new(tim); |
| 116 | TIM7::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); | 115 | tim.regs_basic().arr().modify(|w| w.set_arr(reload as u16 - 1)); |
| 117 | TIM7::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); | 116 | tim.regs_basic().cr2().modify(|w| w.set_mms(Mms::UPDATE)); |
| 118 | TIM7::regs().cr1().modify(|w| { | 117 | tim.regs_basic().cr1().modify(|w| { |
| 119 | w.set_opm(Opm::DISABLED); | 118 | w.set_opm(false); |
| 120 | w.set_cen(true); | 119 | w.set_cen(true); |
| 121 | }); | 120 | }); |
| 122 | 121 | ||
| @@ -126,7 +125,7 @@ async fn dac_task2(mut dac: DacCh2<'static, DAC1, DMA1_CH4>) { | |||
| 126 | 125 | ||
| 127 | debug!( | 126 | debug!( |
| 128 | "TIM7 Frequency {}, Target Frequency {}, Reload {}, Reload as u16 {}, Samples {}", | 127 | "TIM7 Frequency {}, Target Frequency {}, Reload {}, Reload as u16 {}, Samples {}", |
| 129 | TIM7::frequency(), | 128 | frequency::<TIM7>(), |
| 130 | FREQUENCY, | 129 | FREQUENCY, |
| 131 | reload, | 130 | reload, |
| 132 | reload as u16, | 131 | reload as u16, |
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index dbddfc22f..7c7964ecd 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| @@ -14,7 +13,7 @@ use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; | |||
| 14 | use embassy_time::Timer; | 13 | use embassy_time::Timer; |
| 15 | use embedded_io_async::Write; | 14 | use embedded_io_async::Write; |
| 16 | use rand_core::RngCore; | 15 | use rand_core::RngCore; |
| 17 | use static_cell::make_static; | 16 | use static_cell::StaticCell; |
| 18 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {defmt_rtt as _, panic_probe as _}; |
| 19 | 18 | ||
| 20 | bind_interrupts!(struct Irqs { | 19 | bind_interrupts!(struct Irqs { |
| @@ -64,19 +63,22 @@ async fn main(spawner: Spawner) -> ! { | |||
| 64 | 63 | ||
| 65 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; | 64 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; |
| 66 | 65 | ||
| 66 | static PACKETS: StaticCell<PacketQueue<4, 4>> = StaticCell::new(); | ||
| 67 | // warning: Not all STM32H7 devices have the exact same pins here | ||
| 68 | // for STM32H747XIH, replace p.PB13 for PG12 | ||
| 67 | let device = Ethernet::new( | 69 | let device = Ethernet::new( |
| 68 | make_static!(PacketQueue::<16, 16>::new()), | 70 | PACKETS.init(PacketQueue::<4, 4>::new()), |
| 69 | p.ETH, | 71 | p.ETH, |
| 70 | Irqs, | 72 | Irqs, |
| 71 | p.PA1, | 73 | p.PA1, // ref_clk |
| 72 | p.PA2, | 74 | p.PA2, // mdio |
| 73 | p.PC1, | 75 | p.PC1, // eth_mdc |
| 74 | p.PA7, | 76 | p.PA7, // CRS_DV: Carrier Sense |
| 75 | p.PC4, | 77 | p.PC4, // RX_D0: Received Bit 0 |
| 76 | p.PC5, | 78 | p.PC5, // RX_D1: Received Bit 1 |
| 77 | p.PG13, | 79 | p.PG13, // TX_D0: Transmit Bit 0 |
| 78 | p.PB13, | 80 | p.PB13, // TX_D1: Transmit Bit 1 |
| 79 | p.PG11, | 81 | p.PG11, // TX_EN: Transmit Enable |
| 80 | GenericSMI::new(0), | 82 | GenericSMI::new(0), |
| 81 | mac_addr, | 83 | mac_addr, |
| 82 | ); | 84 | ); |
| @@ -89,11 +91,13 @@ async fn main(spawner: Spawner) -> ! { | |||
| 89 | //}); | 91 | //}); |
| 90 | 92 | ||
| 91 | // Init network stack | 93 | // Init network stack |
| 92 | let stack = &*make_static!(Stack::new( | 94 | static STACK: StaticCell<Stack<Device>> = StaticCell::new(); |
| 95 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); | ||
| 96 | let stack = &*STACK.init(Stack::new( | ||
| 93 | device, | 97 | device, |
| 94 | config, | 98 | config, |
| 95 | make_static!(StackResources::<3>::new()), | 99 | RESOURCES.init(StackResources::<3>::new()), |
| 96 | seed | 100 | seed, |
| 97 | )); | 101 | )); |
| 98 | 102 | ||
| 99 | // Launch network task | 103 | // Launch network task |
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs index 17e1d9fb7..aeb169e19 100644 --- a/examples/stm32h7/src/bin/eth_client.rs +++ b/examples/stm32h7/src/bin/eth_client.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| @@ -15,7 +14,7 @@ use embassy_time::Timer; | |||
| 15 | use embedded_io_async::Write; | 14 | use embedded_io_async::Write; |
| 16 | use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; | 15 | use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; |
| 17 | use rand_core::RngCore; | 16 | use rand_core::RngCore; |
| 18 | use static_cell::make_static; | 17 | use static_cell::StaticCell; |
| 19 | use {defmt_rtt as _, panic_probe as _}; | 18 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | 19 | ||
| 21 | bind_interrupts!(struct Irqs { | 20 | bind_interrupts!(struct Irqs { |
| @@ -65,8 +64,10 @@ async fn main(spawner: Spawner) -> ! { | |||
| 65 | 64 | ||
| 66 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; | 65 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; |
| 67 | 66 | ||
| 67 | static PACKETS: StaticCell<PacketQueue<16, 16>> = StaticCell::new(); | ||
| 68 | |||
| 68 | let device = Ethernet::new( | 69 | let device = Ethernet::new( |
| 69 | make_static!(PacketQueue::<16, 16>::new()), | 70 | PACKETS.init(PacketQueue::<16, 16>::new()), |
| 70 | p.ETH, | 71 | p.ETH, |
| 71 | Irqs, | 72 | Irqs, |
| 72 | p.PA1, | 73 | p.PA1, |
| @@ -90,11 +91,13 @@ async fn main(spawner: Spawner) -> ! { | |||
| 90 | //}); | 91 | //}); |
| 91 | 92 | ||
| 92 | // Init network stack | 93 | // Init network stack |
| 93 | let stack = &*make_static!(Stack::new( | 94 | static STACK: StaticCell<Stack<Device>> = StaticCell::new(); |
| 95 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); | ||
| 96 | let stack = &*STACK.init(Stack::new( | ||
| 94 | device, | 97 | device, |
| 95 | config, | 98 | config, |
| 96 | make_static!(StackResources::<3>::new()), | 99 | RESOURCES.init(StackResources::<3>::new()), |
| 97 | seed | 100 | seed, |
| 98 | )); | 101 | )); |
| 99 | 102 | ||
| 100 | // Launch network task | 103 | // Launch network task |
diff --git a/examples/stm32h7/src/bin/eth_client_mii.rs b/examples/stm32h7/src/bin/eth_client_mii.rs new file mode 100644 index 000000000..de6ea522a --- /dev/null +++ b/examples/stm32h7/src/bin/eth_client_mii.rs | |||
| @@ -0,0 +1,142 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_net::tcp::client::{TcpClient, TcpClientState}; | ||
| 7 | use embassy_net::{Stack, StackResources}; | ||
| 8 | use embassy_stm32::eth::generic_smi::GenericSMI; | ||
| 9 | use embassy_stm32::eth::{Ethernet, PacketQueue}; | ||
| 10 | use embassy_stm32::peripherals::ETH; | ||
| 11 | use embassy_stm32::rng::Rng; | ||
| 12 | use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; | ||
| 13 | use embassy_time::Timer; | ||
| 14 | use embedded_io_async::Write; | ||
| 15 | use embedded_nal_async::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpConnect}; | ||
| 16 | use rand_core::RngCore; | ||
| 17 | use static_cell::StaticCell; | ||
| 18 | use {defmt_rtt as _, panic_probe as _}; | ||
| 19 | |||
| 20 | bind_interrupts!(struct Irqs { | ||
| 21 | ETH => eth::InterruptHandler; | ||
| 22 | RNG => rng::InterruptHandler<peripherals::RNG>; | ||
| 23 | }); | ||
| 24 | |||
| 25 | type Device = Ethernet<'static, ETH, GenericSMI>; | ||
| 26 | |||
| 27 | #[embassy_executor::task] | ||
| 28 | async fn net_task(stack: &'static Stack<Device>) -> ! { | ||
| 29 | stack.run().await | ||
| 30 | } | ||
| 31 | |||
| 32 | #[embassy_executor::main] | ||
| 33 | async fn main(spawner: Spawner) -> ! { | ||
| 34 | let mut config = Config::default(); | ||
| 35 | { | ||
| 36 | use embassy_stm32::rcc::*; | ||
| 37 | config.rcc.hsi = Some(HSIPrescaler::DIV1); | ||
| 38 | config.rcc.csi = true; | ||
| 39 | config.rcc.hsi48 = Some(Default::default()); // needed for RNG | ||
| 40 | config.rcc.pll1 = Some(Pll { | ||
| 41 | source: PllSource::HSI, | ||
| 42 | prediv: PllPreDiv::DIV4, | ||
| 43 | mul: PllMul::MUL50, | ||
| 44 | divp: Some(PllDiv::DIV2), | ||
| 45 | divq: None, | ||
| 46 | divr: None, | ||
| 47 | }); | ||
| 48 | config.rcc.sys = Sysclk::PLL1_P; // 400 Mhz | ||
| 49 | config.rcc.ahb_pre = AHBPrescaler::DIV2; // 200 Mhz | ||
| 50 | config.rcc.apb1_pre = APBPrescaler::DIV2; // 100 Mhz | ||
| 51 | config.rcc.apb2_pre = APBPrescaler::DIV2; // 100 Mhz | ||
| 52 | config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz | ||
| 53 | config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz | ||
| 54 | config.rcc.voltage_scale = VoltageScale::Scale1; | ||
| 55 | } | ||
| 56 | let p = embassy_stm32::init(config); | ||
| 57 | info!("Hello World!"); | ||
| 58 | |||
| 59 | // Generate random seed. | ||
| 60 | let mut rng = Rng::new(p.RNG, Irqs); | ||
| 61 | let mut seed = [0; 8]; | ||
| 62 | rng.fill_bytes(&mut seed); | ||
| 63 | let seed = u64::from_le_bytes(seed); | ||
| 64 | |||
| 65 | let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; | ||
| 66 | |||
| 67 | static PACKETS: StaticCell<PacketQueue<16, 16>> = StaticCell::new(); | ||
| 68 | |||
| 69 | let device = Ethernet::new_mii( | ||
| 70 | PACKETS.init(PacketQueue::<16, 16>::new()), | ||
| 71 | p.ETH, | ||
| 72 | Irqs, | ||
| 73 | p.PA1, | ||
| 74 | p.PC3, | ||
| 75 | p.PA2, | ||
| 76 | p.PC1, | ||
| 77 | p.PA7, | ||
| 78 | p.PC4, | ||
| 79 | p.PC5, | ||
| 80 | p.PB0, | ||
| 81 | p.PB1, | ||
| 82 | p.PG13, | ||
| 83 | p.PG12, | ||
| 84 | p.PC2, | ||
| 85 | p.PE2, | ||
| 86 | p.PG11, | ||
| 87 | GenericSMI::new(1), | ||
| 88 | mac_addr, | ||
| 89 | ); | ||
| 90 | info!("Device created"); | ||
| 91 | |||
| 92 | let config = embassy_net::Config::dhcpv4(Default::default()); | ||
| 93 | //let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { | ||
| 94 | // address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | ||
| 95 | // dns_servers: Vec::new(), | ||
| 96 | // gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | ||
| 97 | //}); | ||
| 98 | |||
| 99 | // Init network stack | ||
| 100 | static STACK: StaticCell<Stack<Device>> = StaticCell::new(); | ||
| 101 | static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new(); | ||
| 102 | let stack = &*STACK.init(Stack::new( | ||
| 103 | device, | ||
| 104 | config, | ||
| 105 | RESOURCES.init(StackResources::<3>::new()), | ||
| 106 | seed, | ||
| 107 | )); | ||
| 108 | |||
| 109 | // Launch network task | ||
| 110 | unwrap!(spawner.spawn(net_task(stack))); | ||
| 111 | |||
| 112 | // Ensure DHCP configuration is up before trying connect | ||
| 113 | stack.wait_config_up().await; | ||
| 114 | |||
| 115 | info!("Network task initialized"); | ||
| 116 | |||
| 117 | let state: TcpClientState<1, 1024, 1024> = TcpClientState::new(); | ||
| 118 | let client = TcpClient::new(&stack, &state); | ||
| 119 | |||
| 120 | loop { | ||
| 121 | // You need to start a server on the host machine, for example: `nc -l 8000` | ||
| 122 | let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 100, 1), 8000)); | ||
| 123 | |||
| 124 | info!("connecting..."); | ||
| 125 | let r = client.connect(addr).await; | ||
| 126 | if let Err(e) = r { | ||
| 127 | info!("connect error: {:?}", e); | ||
| 128 | Timer::after_secs(1).await; | ||
| 129 | continue; | ||
| 130 | } | ||
| 131 | let mut connection = r.unwrap(); | ||
| 132 | info!("connected!"); | ||
| 133 | loop { | ||
| 134 | let r = connection.write_all(b"Hello\n").await; | ||
| 135 | if let Err(e) = r { | ||
| 136 | info!("write error: {:?}", e); | ||
| 137 | break; | ||
| 138 | } | ||
| 139 | Timer::after_secs(1).await; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | } | ||
diff --git a/examples/stm32h7/src/bin/flash.rs b/examples/stm32h7/src/bin/flash.rs index 89c0c8a66..4f9f6bb0a 100644 --- a/examples/stm32h7/src/bin/flash.rs +++ b/examples/stm32h7/src/bin/flash.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::{info, unwrap}; | 4 | use defmt::{info, unwrap}; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32h7/src/bin/fmc.rs b/examples/stm32h7/src/bin/fmc.rs index 54e2c3629..5e5e6ccc8 100644 --- a/examples/stm32h7/src/bin/fmc.rs +++ b/examples/stm32h7/src/bin/fmc.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32h7/src/bin/i2c.rs b/examples/stm32h7/src/bin/i2c.rs index aea21ec6f..3bf39eb44 100644 --- a/examples/stm32h7/src/bin/i2c.rs +++ b/examples/stm32h7/src/bin/i2c.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index e0be495d1..a95b44b74 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs | |||
| @@ -1,14 +1,13 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::gpio::low_level::AFType; | 6 | use embassy_stm32::gpio::{AFType, Flex, Pull, Speed}; |
| 8 | use embassy_stm32::gpio::Speed; | ||
| 9 | use embassy_stm32::time::{khz, Hertz}; | 7 | use embassy_stm32::time::{khz, Hertz}; |
| 10 | use embassy_stm32::timer::*; | 8 | use embassy_stm32::timer::low_level::{OutputCompareMode, Timer as LLTimer}; |
| 11 | use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef}; | 9 | use embassy_stm32::timer::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance32bit4Channel}; |
| 10 | use embassy_stm32::{into_ref, Config, Peripheral}; | ||
| 12 | use embassy_time::Timer; | 11 | use embassy_time::Timer; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 13 | ||
| @@ -57,11 +56,15 @@ async fn main(_spawner: Spawner) { | |||
| 57 | Timer::after_millis(300).await; | 56 | Timer::after_millis(300).await; |
| 58 | } | 57 | } |
| 59 | } | 58 | } |
| 60 | pub struct SimplePwm32<'d, T: CaptureCompare32bitInstance> { | 59 | pub struct SimplePwm32<'d, T: GeneralInstance32bit4Channel> { |
| 61 | inner: PeripheralRef<'d, T>, | 60 | tim: LLTimer<'d, T>, |
| 61 | _ch1: Flex<'d>, | ||
| 62 | _ch2: Flex<'d>, | ||
| 63 | _ch3: Flex<'d>, | ||
| 64 | _ch4: Flex<'d>, | ||
| 62 | } | 65 | } |
| 63 | 66 | ||
| 64 | impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | 67 | impl<'d, T: GeneralInstance32bit4Channel> SimplePwm32<'d, T> { |
| 65 | pub fn new( | 68 | pub fn new( |
| 66 | tim: impl Peripheral<P = T> + 'd, | 69 | tim: impl Peripheral<P = T> + 'd, |
| 67 | ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd, | 70 | ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd, |
| @@ -70,25 +73,33 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | |||
| 70 | ch4: impl Peripheral<P = impl Channel4Pin<T>> + 'd, | 73 | ch4: impl Peripheral<P = impl Channel4Pin<T>> + 'd, |
| 71 | freq: Hertz, | 74 | freq: Hertz, |
| 72 | ) -> Self { | 75 | ) -> Self { |
| 73 | into_ref!(tim, ch1, ch2, ch3, ch4); | 76 | into_ref!(ch1, ch2, ch3, ch4); |
| 74 | 77 | ||
| 75 | T::enable_and_reset(); | 78 | let af1 = ch1.af_num(); |
| 76 | 79 | let af2 = ch2.af_num(); | |
| 77 | ch1.set_speed(Speed::VeryHigh); | 80 | let af3 = ch3.af_num(); |
| 78 | ch1.set_as_af(ch1.af_num(), AFType::OutputPushPull); | 81 | let af4 = ch4.af_num(); |
| 79 | ch2.set_speed(Speed::VeryHigh); | 82 | let mut ch1 = Flex::new(ch1); |
| 80 | ch2.set_as_af(ch1.af_num(), AFType::OutputPushPull); | 83 | let mut ch2 = Flex::new(ch2); |
| 81 | ch3.set_speed(Speed::VeryHigh); | 84 | let mut ch3 = Flex::new(ch3); |
| 82 | ch3.set_as_af(ch1.af_num(), AFType::OutputPushPull); | 85 | let mut ch4 = Flex::new(ch4); |
| 83 | ch4.set_speed(Speed::VeryHigh); | 86 | ch1.set_as_af_unchecked(af1, AFType::OutputPushPull, Pull::None, Speed::VeryHigh); |
| 84 | ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull); | 87 | ch2.set_as_af_unchecked(af2, AFType::OutputPushPull, Pull::None, Speed::VeryHigh); |
| 85 | 88 | ch3.set_as_af_unchecked(af3, AFType::OutputPushPull, Pull::None, Speed::VeryHigh); | |
| 86 | let mut this = Self { inner: tim }; | 89 | ch4.set_as_af_unchecked(af4, AFType::OutputPushPull, Pull::None, Speed::VeryHigh); |
| 87 | 90 | ||
| 88 | this.set_freq(freq); | 91 | let mut this = Self { |
| 89 | this.inner.start(); | 92 | tim: LLTimer::new(tim), |
| 90 | 93 | _ch1: ch1, | |
| 91 | let r = T::regs_gp32(); | 94 | _ch2: ch2, |
| 95 | _ch3: ch3, | ||
| 96 | _ch4: ch4, | ||
| 97 | }; | ||
| 98 | |||
| 99 | this.set_frequency(freq); | ||
| 100 | this.tim.start(); | ||
| 101 | |||
| 102 | let r = this.tim.regs_gp32(); | ||
| 92 | r.ccmr_output(0) | 103 | r.ccmr_output(0) |
| 93 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); | 104 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); |
| 94 | r.ccmr_output(0) | 105 | r.ccmr_output(0) |
| @@ -102,23 +113,26 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | |||
| 102 | } | 113 | } |
| 103 | 114 | ||
| 104 | pub fn enable(&mut self, channel: Channel) { | 115 | pub fn enable(&mut self, channel: Channel) { |
| 105 | T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true)); | 116 | self.tim.regs_gp32().ccer().modify(|w| w.set_cce(channel.index(), true)); |
| 106 | } | 117 | } |
| 107 | 118 | ||
| 108 | pub fn disable(&mut self, channel: Channel) { | 119 | pub fn disable(&mut self, channel: Channel) { |
| 109 | T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false)); | 120 | self.tim |
| 121 | .regs_gp32() | ||
| 122 | .ccer() | ||
| 123 | .modify(|w| w.set_cce(channel.index(), false)); | ||
| 110 | } | 124 | } |
| 111 | 125 | ||
| 112 | pub fn set_freq(&mut self, freq: Hertz) { | 126 | pub fn set_frequency(&mut self, freq: Hertz) { |
| 113 | <T as embassy_stm32::timer::low_level::GeneralPurpose32bitInstance>::set_frequency(&mut self.inner, freq); | 127 | self.tim.set_frequency(freq); |
| 114 | } | 128 | } |
| 115 | 129 | ||
| 116 | pub fn get_max_duty(&self) -> u32 { | 130 | pub fn get_max_duty(&self) -> u32 { |
| 117 | T::regs_gp32().arr().read().arr() | 131 | self.tim.regs_gp32().arr().read() |
| 118 | } | 132 | } |
| 119 | 133 | ||
| 120 | pub fn set_duty(&mut self, channel: Channel, duty: u32) { | 134 | pub fn set_duty(&mut self, channel: Channel, duty: u32) { |
| 121 | defmt::assert!(duty < self.get_max_duty()); | 135 | defmt::assert!(duty < self.get_max_duty()); |
| 122 | T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty)) | 136 | self.tim.regs_gp32().ccr(channel.index()).write_value(duty) |
| 123 | } | 137 | } |
| 124 | } | 138 | } |
diff --git a/examples/stm32h7/src/bin/mco.rs b/examples/stm32h7/src/bin/mco.rs index c023f4584..a6ee27625 100644 --- a/examples/stm32h7/src/bin/mco.rs +++ b/examples/stm32h7/src/bin/mco.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs index c55d780a0..1e48ba67b 100644 --- a/examples/stm32h7/src/bin/pwm.rs +++ b/examples/stm32h7/src/bin/pwm.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs index 1fb4cfec0..a9ef7200d 100644 --- a/examples/stm32h7/src/bin/rng.rs +++ b/examples/stm32h7/src/bin/rng.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32h7/src/bin/rtc.rs b/examples/stm32h7/src/bin/rtc.rs index 78cea9c89..0adb48877 100644 --- a/examples/stm32h7/src/bin/rtc.rs +++ b/examples/stm32h7/src/bin/rtc.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use chrono::{NaiveDate, NaiveDateTime}; | 4 | use chrono::{NaiveDate, NaiveDateTime}; |
| 6 | use defmt::*; | 5 | use defmt::*; |
| @@ -25,7 +24,7 @@ async fn main(_spawner: Spawner) { | |||
| 25 | .unwrap(); | 24 | .unwrap(); |
| 26 | 25 | ||
| 27 | let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); | 26 | let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); |
| 28 | info!("Got RTC! {:?}", now.timestamp()); | 27 | info!("Got RTC! {:?}", now.and_utc().timestamp()); |
| 29 | 28 | ||
| 30 | rtc.set_datetime(now.into()).expect("datetime not set"); | 29 | rtc.set_datetime(now.into()).expect("datetime not set"); |
| 31 | 30 | ||
| @@ -33,5 +32,5 @@ async fn main(_spawner: Spawner) { | |||
| 33 | Timer::after_millis(20000).await; | 32 | Timer::after_millis(20000).await; |
| 34 | 33 | ||
| 35 | let then: NaiveDateTime = rtc.now().unwrap().into(); | 34 | let then: NaiveDateTime = rtc.now().unwrap().into(); |
| 36 | info!("Got RTC! {:?}", then.timestamp()); | 35 | info!("Got RTC! {:?}", then.and_utc().timestamp()); |
| 37 | } | 36 | } |
diff --git a/examples/stm32h7/src/bin/sdmmc.rs b/examples/stm32h7/src/bin/sdmmc.rs index be968ff77..abe2d4ba7 100644 --- a/examples/stm32h7/src/bin/sdmmc.rs +++ b/examples/stm32h7/src/bin/sdmmc.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32h7/src/bin/signal.rs b/examples/stm32h7/src/bin/signal.rs index b5f583289..b73360f32 100644 --- a/examples/stm32h7/src/bin/signal.rs +++ b/examples/stm32h7/src/bin/signal.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::{info, unwrap}; | 4 | use defmt::{info, unwrap}; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs index a8db0ff77..aed27723a 100644 --- a/examples/stm32h7/src/bin/spi.rs +++ b/examples/stm32h7/src/bin/spi.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use core::fmt::Write; | 4 | use core::fmt::Write; |
| 6 | use core::str::from_utf8; | 5 | use core::str::from_utf8; |
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs index 561052e48..54d4d7656 100644 --- a/examples/stm32h7/src/bin/spi_dma.rs +++ b/examples/stm32h7/src/bin/spi_dma.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use core::fmt::Write; | 4 | use core::fmt::Write; |
| 6 | use core::str::from_utf8; | 5 | use core::str::from_utf8; |
diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs index db04d4e55..f9cbad6af 100644 --- a/examples/stm32h7/src/bin/usart.rs +++ b/examples/stm32h7/src/bin/usart.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use cortex_m_rt::entry; | 4 | use cortex_m_rt::entry; |
| 6 | use defmt::*; | 5 | use defmt::*; |
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs index 249050fd1..ae1f3a2e9 100644 --- a/examples/stm32h7/src/bin/usart_dma.rs +++ b/examples/stm32h7/src/bin/usart_dma.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use core::fmt::Write; | 4 | use core::fmt::Write; |
| 6 | 5 | ||
diff --git a/examples/stm32h7/src/bin/usart_split.rs b/examples/stm32h7/src/bin/usart_split.rs index 61c9f1954..b98c40877 100644 --- a/examples/stm32h7/src/bin/usart_split.rs +++ b/examples/stm32h7/src/bin/usart_split.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
diff --git a/examples/stm32h7/src/bin/usb_serial.rs b/examples/stm32h7/src/bin/usb_serial.rs index f80cf63ec..576506ad3 100644 --- a/examples/stm32h7/src/bin/usb_serial.rs +++ b/examples/stm32h7/src/bin/usb_serial.rs | |||
| @@ -1,11 +1,10 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::{panic, *}; | 4 | use defmt::{panic, *}; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::usb_otg::{Driver, Instance}; | 6 | use embassy_stm32::usb::{Driver, Instance}; |
| 8 | use embassy_stm32::{bind_interrupts, peripherals, usb_otg, Config}; | 7 | use embassy_stm32::{bind_interrupts, peripherals, usb, Config}; |
| 9 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | 8 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; |
| 10 | use embassy_usb::driver::EndpointError; | 9 | use embassy_usb::driver::EndpointError; |
| 11 | use embassy_usb::Builder; | 10 | use embassy_usb::Builder; |
| @@ -13,7 +12,7 @@ use futures::future::join; | |||
| 13 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 13 | ||
| 15 | bind_interrupts!(struct Irqs { | 14 | bind_interrupts!(struct Irqs { |
| 16 | OTG_FS => usb_otg::InterruptHandler<peripherals::USB_OTG_FS>; | 15 | OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>; |
| 17 | }); | 16 | }); |
| 18 | 17 | ||
| 19 | #[embassy_executor::main] | 18 | #[embassy_executor::main] |
| @@ -41,12 +40,13 @@ async fn main(_spawner: Spawner) { | |||
| 41 | config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz | 40 | config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz |
| 42 | config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz | 41 | config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz |
| 43 | config.rcc.voltage_scale = VoltageScale::Scale1; | 42 | config.rcc.voltage_scale = VoltageScale::Scale1; |
| 43 | config.rcc.mux.usbsel = mux::Usbsel::HSI48; | ||
| 44 | } | 44 | } |
| 45 | let p = embassy_stm32::init(config); | 45 | let p = embassy_stm32::init(config); |
| 46 | 46 | ||
| 47 | // Create the driver, from the HAL. | 47 | // Create the driver, from the HAL. |
| 48 | let mut ep_out_buffer = [0u8; 256]; | 48 | let mut ep_out_buffer = [0u8; 256]; |
| 49 | let mut config = embassy_stm32::usb_otg::Config::default(); | 49 | let mut config = embassy_stm32::usb::Config::default(); |
| 50 | config.vbus_detection = true; | 50 | config.vbus_detection = true; |
| 51 | let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config); | 51 | let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config); |
| 52 | 52 | ||
| @@ -65,7 +65,6 @@ async fn main(_spawner: Spawner) { | |||
| 65 | 65 | ||
| 66 | // Create embassy-usb DeviceBuilder using the driver and config. | 66 | // Create embassy-usb DeviceBuilder using the driver and config. |
| 67 | // It needs some buffers for building the descriptors. | 67 | // It needs some buffers for building the descriptors. |
| 68 | let mut device_descriptor = [0; 256]; | ||
| 69 | let mut config_descriptor = [0; 256]; | 68 | let mut config_descriptor = [0; 256]; |
| 70 | let mut bos_descriptor = [0; 256]; | 69 | let mut bos_descriptor = [0; 256]; |
| 71 | let mut control_buf = [0; 64]; | 70 | let mut control_buf = [0; 64]; |
| @@ -75,7 +74,6 @@ async fn main(_spawner: Spawner) { | |||
| 75 | let mut builder = Builder::new( | 74 | let mut builder = Builder::new( |
| 76 | driver, | 75 | driver, |
| 77 | config, | 76 | config, |
| 78 | &mut device_descriptor, | ||
| 79 | &mut config_descriptor, | 77 | &mut config_descriptor, |
| 80 | &mut bos_descriptor, | 78 | &mut bos_descriptor, |
| 81 | &mut [], // no msos descriptors | 79 | &mut [], // no msos descriptors |
diff --git a/examples/stm32h7/src/bin/wdg.rs b/examples/stm32h7/src/bin/wdg.rs index 76fd9dfc0..a4184aa96 100644 --- a/examples/stm32h7/src/bin/wdg.rs +++ b/examples/stm32h7/src/bin/wdg.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | 3 | ||
| 5 | use defmt::*; | 4 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
