diff options
| author | xoviat <[email protected]> | 2023-06-19 21:18:46 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-06-19 21:18:46 -0500 |
| commit | 0d67ef795e4dfecef90690bce51f2820f77fc4bc (patch) | |
| tree | fa6b8a092652a9d0af9f67576b1b99063c3aa184 /examples | |
| parent | 978e7b5e77f86dc82c393442702defa38b516f4b (diff) | |
| parent | 37a1e9f971214c11a614b06b230be27c688fff1d (diff) | |
Merge branch 'main' of https://github.com/embassy-rs/embassy into tl-mbox-2
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f0/src/bin/wdg.rs | 4 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/wdt.rs | 8 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/usb_serial.rs | 4 | ||||
| -rw-r--r-- | examples/stm32h5/src/bin/usb_serial.rs | 8 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/low_level_timer_api.rs | 54 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/wdg.rs | 4 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/adc.rs | 10 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/dac.rs | 8 | ||||
| -rw-r--r-- | examples/stm32wl/src/bin/lora_lorawan.rs | 2 | ||||
| -rw-r--r-- | examples/stm32wl/src/bin/random.rs | 8 |
10 files changed, 43 insertions, 67 deletions
diff --git a/examples/stm32f0/src/bin/wdg.rs b/examples/stm32f0/src/bin/wdg.rs index 80e76f901..a44b17528 100644 --- a/examples/stm32f0/src/bin/wdg.rs +++ b/examples/stm32f0/src/bin/wdg.rs | |||
| @@ -16,10 +16,10 @@ async fn main(_spawner: Spawner) { | |||
| 16 | let mut wdg = IndependentWatchdog::new(p.IWDG, 20_000_00); | 16 | let mut wdg = IndependentWatchdog::new(p.IWDG, 20_000_00); |
| 17 | 17 | ||
| 18 | info!("Watchdog start"); | 18 | info!("Watchdog start"); |
| 19 | unsafe { wdg.unleash() }; | 19 | wdg.unleash(); |
| 20 | 20 | ||
| 21 | loop { | 21 | loop { |
| 22 | Timer::after(Duration::from_secs(1)).await; | 22 | Timer::after(Duration::from_secs(1)).await; |
| 23 | unsafe { wdg.pet() }; | 23 | wdg.pet(); |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
diff --git a/examples/stm32f4/src/bin/wdt.rs b/examples/stm32f4/src/bin/wdt.rs index b2c587fa1..e5d122af7 100644 --- a/examples/stm32f4/src/bin/wdt.rs +++ b/examples/stm32f4/src/bin/wdt.rs | |||
| @@ -17,9 +17,7 @@ async fn main(_spawner: Spawner) { | |||
| 17 | let mut led = Output::new(p.PB7, Level::High, Speed::Low); | 17 | let mut led = Output::new(p.PB7, Level::High, Speed::Low); |
| 18 | 18 | ||
| 19 | let mut wdt = IndependentWatchdog::new(p.IWDG, 1_000_000); | 19 | let mut wdt = IndependentWatchdog::new(p.IWDG, 1_000_000); |
| 20 | unsafe { | 20 | wdt.unleash(); |
| 21 | wdt.unleash(); | ||
| 22 | } | ||
| 23 | 21 | ||
| 24 | let mut i = 0; | 22 | let mut i = 0; |
| 25 | 23 | ||
| @@ -36,9 +34,7 @@ async fn main(_spawner: Spawner) { | |||
| 36 | // MCU should restart in 1 second after the last pet. | 34 | // MCU should restart in 1 second after the last pet. |
| 37 | if i < 5 { | 35 | if i < 5 { |
| 38 | info!("Petting watchdog"); | 36 | info!("Petting watchdog"); |
| 39 | unsafe { | 37 | wdt.pet(); |
| 40 | wdt.pet(); | ||
| 41 | } | ||
| 42 | } | 38 | } |
| 43 | 39 | ||
| 44 | i += 1; | 40 | i += 1; |
diff --git a/examples/stm32g4/src/bin/usb_serial.rs b/examples/stm32g4/src/bin/usb_serial.rs index ecbe3a6e6..c111a9787 100644 --- a/examples/stm32g4/src/bin/usb_serial.rs +++ b/examples/stm32g4/src/bin/usb_serial.rs | |||
| @@ -38,9 +38,7 @@ async fn main(_spawner: Spawner) { | |||
| 38 | let p = embassy_stm32::init(config); | 38 | let p = embassy_stm32::init(config); |
| 39 | info!("Hello World!"); | 39 | info!("Hello World!"); |
| 40 | 40 | ||
| 41 | unsafe { | 41 | pac::RCC.ccipr().write(|w| w.set_clk48sel(0b10)); |
| 42 | pac::RCC.ccipr().write(|w| w.set_clk48sel(0b10)); | ||
| 43 | } | ||
| 44 | 42 | ||
| 45 | let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); | 43 | let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); |
| 46 | 44 | ||
diff --git a/examples/stm32h5/src/bin/usb_serial.rs b/examples/stm32h5/src/bin/usb_serial.rs index 3912327e2..336eed644 100644 --- a/examples/stm32h5/src/bin/usb_serial.rs +++ b/examples/stm32h5/src/bin/usb_serial.rs | |||
| @@ -45,11 +45,9 @@ async fn main(_spawner: Spawner) { | |||
| 45 | 45 | ||
| 46 | info!("Hello World!"); | 46 | info!("Hello World!"); |
| 47 | 47 | ||
| 48 | unsafe { | 48 | pac::RCC.ccipr4().write(|w| { |
| 49 | pac::RCC.ccipr4().write(|w| { | 49 | w.set_usbsel(pac::rcc::vals::Usbsel::HSI48); |
| 50 | w.set_usbsel(pac::rcc::vals::Usbsel::HSI48); | 50 | }); |
| 51 | }); | ||
| 52 | } | ||
| 53 | 51 | ||
| 54 | // Create the driver, from the HAL. | 52 | // Create the driver, from the HAL. |
| 55 | let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); | 53 | let driver = Driver::new(p.USB, Irqs, p.PA12, p.PA11); |
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index 1972f8ff2..d360df085 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs | |||
| @@ -62,49 +62,39 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | |||
| 62 | T::enable(); | 62 | T::enable(); |
| 63 | <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset(); | 63 | <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset(); |
| 64 | 64 | ||
| 65 | unsafe { | 65 | ch1.set_speed(Speed::VeryHigh); |
| 66 | ch1.set_speed(Speed::VeryHigh); | 66 | ch1.set_as_af(ch1.af_num(), AFType::OutputPushPull); |
| 67 | ch1.set_as_af(ch1.af_num(), AFType::OutputPushPull); | 67 | ch2.set_speed(Speed::VeryHigh); |
| 68 | ch2.set_speed(Speed::VeryHigh); | 68 | ch2.set_as_af(ch1.af_num(), AFType::OutputPushPull); |
| 69 | ch2.set_as_af(ch1.af_num(), AFType::OutputPushPull); | 69 | ch3.set_speed(Speed::VeryHigh); |
| 70 | ch3.set_speed(Speed::VeryHigh); | 70 | ch3.set_as_af(ch1.af_num(), AFType::OutputPushPull); |
| 71 | ch3.set_as_af(ch1.af_num(), AFType::OutputPushPull); | 71 | ch4.set_speed(Speed::VeryHigh); |
| 72 | ch4.set_speed(Speed::VeryHigh); | 72 | ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull); |
| 73 | ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull); | ||
| 74 | } | ||
| 75 | 73 | ||
| 76 | let mut this = Self { inner: tim }; | 74 | let mut this = Self { inner: tim }; |
| 77 | 75 | ||
| 78 | this.set_freq(freq); | 76 | this.set_freq(freq); |
| 79 | this.inner.start(); | 77 | this.inner.start(); |
| 80 | 78 | ||
| 81 | unsafe { | 79 | let r = T::regs_gp32(); |
| 82 | T::regs_gp32() | 80 | r.ccmr_output(0) |
| 83 | .ccmr_output(0) | 81 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); |
| 84 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); | 82 | r.ccmr_output(0) |
| 85 | T::regs_gp32() | 83 | .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); |
| 86 | .ccmr_output(0) | 84 | r.ccmr_output(1) |
| 87 | .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); | 85 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); |
| 88 | T::regs_gp32() | 86 | r.ccmr_output(1) |
| 89 | .ccmr_output(1) | 87 | .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); |
| 90 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); | 88 | |
| 91 | T::regs_gp32() | ||
| 92 | .ccmr_output(1) | ||
| 93 | .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); | ||
| 94 | } | ||
| 95 | this | 89 | this |
| 96 | } | 90 | } |
| 97 | 91 | ||
| 98 | pub fn enable(&mut self, channel: Channel) { | 92 | pub fn enable(&mut self, channel: Channel) { |
| 99 | unsafe { | 93 | T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true)); |
| 100 | T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true)); | ||
| 101 | } | ||
| 102 | } | 94 | } |
| 103 | 95 | ||
| 104 | pub fn disable(&mut self, channel: Channel) { | 96 | pub fn disable(&mut self, channel: Channel) { |
| 105 | unsafe { | 97 | T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false)); |
| 106 | T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false)); | ||
| 107 | } | ||
| 108 | } | 98 | } |
| 109 | 99 | ||
| 110 | pub fn set_freq(&mut self, freq: Hertz) { | 100 | pub fn set_freq(&mut self, freq: Hertz) { |
| @@ -112,11 +102,11 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | |||
| 112 | } | 102 | } |
| 113 | 103 | ||
| 114 | pub fn get_max_duty(&self) -> u32 { | 104 | pub fn get_max_duty(&self) -> u32 { |
| 115 | unsafe { T::regs_gp32().arr().read().arr() } | 105 | T::regs_gp32().arr().read().arr() |
| 116 | } | 106 | } |
| 117 | 107 | ||
| 118 | pub fn set_duty(&mut self, channel: Channel, duty: u32) { | 108 | pub fn set_duty(&mut self, channel: Channel, duty: u32) { |
| 119 | defmt::assert!(duty < self.get_max_duty()); | 109 | defmt::assert!(duty < self.get_max_duty()); |
| 120 | unsafe { T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty)) } | 110 | T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty)) |
| 121 | } | 111 | } |
| 122 | } | 112 | } |
diff --git a/examples/stm32h7/src/bin/wdg.rs b/examples/stm32h7/src/bin/wdg.rs index 2b0301aad..9181dfd67 100644 --- a/examples/stm32h7/src/bin/wdg.rs +++ b/examples/stm32h7/src/bin/wdg.rs | |||
| @@ -15,10 +15,10 @@ async fn main(_spawner: Spawner) { | |||
| 15 | 15 | ||
| 16 | let mut wdg = IndependentWatchdog::new(p.IWDG1, 20_000_000); | 16 | let mut wdg = IndependentWatchdog::new(p.IWDG1, 20_000_000); |
| 17 | 17 | ||
| 18 | unsafe { wdg.unleash() }; | 18 | wdg.unleash(); |
| 19 | 19 | ||
| 20 | loop { | 20 | loop { |
| 21 | Timer::after(Duration::from_secs(1)).await; | 21 | Timer::after(Duration::from_secs(1)).await; |
| 22 | unsafe { wdg.pet() }; | 22 | wdg.pet(); |
| 23 | } | 23 | } |
| 24 | } | 24 | } |
diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs index 281346e5f..1771e5202 100644 --- a/examples/stm32l4/src/bin/adc.rs +++ b/examples/stm32l4/src/bin/adc.rs | |||
| @@ -12,12 +12,10 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 12 | fn main() -> ! { | 12 | fn main() -> ! { |
| 13 | info!("Hello World!"); | 13 | info!("Hello World!"); |
| 14 | 14 | ||
| 15 | unsafe { | 15 | pac::RCC.ccipr().modify(|w| { |
| 16 | pac::RCC.ccipr().modify(|w| { | 16 | w.set_adcsel(0b11); |
| 17 | w.set_adcsel(0b11); | 17 | }); |
| 18 | }); | 18 | pac::RCC.ahb2enr().modify(|w| w.set_adcen(true)); |
| 19 | pac::RCC.ahb2enr().modify(|w| w.set_adcen(true)); | ||
| 20 | } | ||
| 21 | 19 | ||
| 22 | let p = embassy_stm32::init(Default::default()); | 20 | let p = embassy_stm32::init(Default::default()); |
| 23 | 21 | ||
diff --git a/examples/stm32l4/src/bin/dac.rs b/examples/stm32l4/src/bin/dac.rs index d6e744aa6..a36ed5d90 100644 --- a/examples/stm32l4/src/bin/dac.rs +++ b/examples/stm32l4/src/bin/dac.rs | |||
| @@ -11,11 +11,9 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 11 | fn main() -> ! { | 11 | fn main() -> ! { |
| 12 | info!("Hello World!"); | 12 | info!("Hello World!"); |
| 13 | 13 | ||
| 14 | unsafe { | 14 | pac::RCC.apb1enr1().modify(|w| { |
| 15 | pac::RCC.apb1enr1().modify(|w| { | 15 | w.set_dac1en(true); |
| 16 | w.set_dac1en(true); | 16 | }); |
| 17 | }); | ||
| 18 | } | ||
| 19 | 17 | ||
| 20 | let p = embassy_stm32::init(Default::default()); | 18 | let p = embassy_stm32::init(Default::default()); |
| 21 | 19 | ||
diff --git a/examples/stm32wl/src/bin/lora_lorawan.rs b/examples/stm32wl/src/bin/lora_lorawan.rs index e179c5ca1..805d21418 100644 --- a/examples/stm32wl/src/bin/lora_lorawan.rs +++ b/examples/stm32wl/src/bin/lora_lorawan.rs | |||
| @@ -35,7 +35,7 @@ async fn main(_spawner: Spawner) { | |||
| 35 | config.rcc.enable_lsi = true; // enable RNG | 35 | config.rcc.enable_lsi = true; // enable RNG |
| 36 | let p = embassy_stm32::init(config); | 36 | let p = embassy_stm32::init(config); |
| 37 | 37 | ||
| 38 | unsafe { pac::RCC.ccipr().modify(|w| w.set_rngsel(0b01)) } | 38 | pac::RCC.ccipr().modify(|w| w.set_rngsel(0b01)); |
| 39 | 39 | ||
| 40 | let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); | 40 | let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); |
| 41 | 41 | ||
diff --git a/examples/stm32wl/src/bin/random.rs b/examples/stm32wl/src/bin/random.rs index 182c607f9..d8562fca5 100644 --- a/examples/stm32wl/src/bin/random.rs +++ b/examples/stm32wl/src/bin/random.rs | |||
| @@ -15,11 +15,9 @@ async fn main(_spawner: Spawner) { | |||
| 15 | config.rcc.enable_lsi = true; //Needed for RNG to work | 15 | config.rcc.enable_lsi = true; //Needed for RNG to work |
| 16 | 16 | ||
| 17 | let p = embassy_stm32::init(config); | 17 | let p = embassy_stm32::init(config); |
| 18 | unsafe { | 18 | pac::RCC.ccipr().modify(|w| { |
| 19 | pac::RCC.ccipr().modify(|w| { | 19 | w.set_rngsel(0b01); |
| 20 | w.set_rngsel(0b01); | 20 | }); |
| 21 | }); | ||
| 22 | } | ||
| 23 | 21 | ||
| 24 | info!("Hello World!"); | 22 | info!("Hello World!"); |
| 25 | 23 | ||
