diff options
| author | Mick Chanthaseth <[email protected]> | 2024-02-16 22:27:06 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-02-16 22:27:06 -0800 |
| commit | 7609313a75fee51613535eb8ea5dac4cdb193d3e (patch) | |
| tree | 696777d9e54a88a77cf5ac0066f90ad559f2a84e /examples | |
| parent | 0097cbcfe3311ca89f52284a4a1187e19666a330 (diff) | |
| parent | 377e58e408f830f79171a470ba602b7d8bc525e4 (diff) | |
Merge branch 'embassy-rs:main' into main
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/rp/src/bin/i2c_slave.rs | 2 | ||||
| -rw-r--r-- | examples/rp/src/bin/pio_ws2812.rs | 7 | ||||
| -rw-r--r-- | examples/rp/src/bin/usb_serial_with_logger.rs | 117 | ||||
| -rw-r--r-- | examples/stm32f0/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32f1/src/bin/hello.rs | 4 | ||||
| -rw-r--r-- | examples/stm32f1/src/bin/usb_serial.rs | 20 | ||||
| -rw-r--r-- | examples/stm32f3/src/bin/hello.rs | 5 | ||||
| -rw-r--r-- | examples/stm32f3/src/bin/usb_serial.rs | 21 | ||||
| -rw-r--r-- | examples/stm32f334/src/bin/adc.rs | 24 | ||||
| -rw-r--r-- | examples/stm32f334/src/bin/hello.rs | 5 | ||||
| -rw-r--r-- | examples/stm32f334/src/bin/opamp.rs | 24 | ||||
| -rw-r--r-- | examples/stm32f334/src/bin/pwm.rs | 27 | ||||
| -rw-r--r-- | examples/stm32f7/.cargo/config.toml | 2 | ||||
| -rw-r--r-- | examples/stm32f7/Cargo.toml | 6 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/eth.rs | 2 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/hash.rs | 78 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/adc.rs | 16 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/pll.rs | 16 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/usb_serial.rs | 31 |
19 files changed, 333 insertions, 76 deletions
diff --git a/examples/rp/src/bin/i2c_slave.rs b/examples/rp/src/bin/i2c_slave.rs index ac470d2be..9fffb4646 100644 --- a/examples/rp/src/bin/i2c_slave.rs +++ b/examples/rp/src/bin/i2c_slave.rs | |||
| @@ -110,7 +110,7 @@ async fn main(spawner: Spawner) { | |||
| 110 | let c_sda = p.PIN_1; | 110 | let c_sda = p.PIN_1; |
| 111 | let c_scl = p.PIN_0; | 111 | let c_scl = p.PIN_0; |
| 112 | let mut config = i2c::Config::default(); | 112 | let mut config = i2c::Config::default(); |
| 113 | config.frequency = 5_000; | 113 | config.frequency = 1_000_000; |
| 114 | let controller = i2c::I2c::new_async(p.I2C0, c_sda, c_scl, Irqs, config); | 114 | let controller = i2c::I2c::new_async(p.I2C0, c_sda, c_scl, Irqs, config); |
| 115 | 115 | ||
| 116 | unwrap!(spawner.spawn(controller_task(controller))); | 116 | unwrap!(spawner.spawn(controller_task(controller))); |
diff --git a/examples/rp/src/bin/pio_ws2812.rs b/examples/rp/src/bin/pio_ws2812.rs index 9a97cb8a7..ac145933c 100644 --- a/examples/rp/src/bin/pio_ws2812.rs +++ b/examples/rp/src/bin/pio_ws2812.rs | |||
| @@ -12,7 +12,7 @@ use embassy_rp::pio::{ | |||
| 12 | Common, Config, FifoJoin, Instance, InterruptHandler, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine, | 12 | Common, Config, FifoJoin, Instance, InterruptHandler, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine, |
| 13 | }; | 13 | }; |
| 14 | use embassy_rp::{bind_interrupts, clocks, into_ref, Peripheral, PeripheralRef}; | 14 | use embassy_rp::{bind_interrupts, clocks, into_ref, Peripheral, PeripheralRef}; |
| 15 | use embassy_time::Timer; | 15 | use embassy_time::{Duration, Ticker, Timer}; |
| 16 | use fixed::types::U24F8; | 16 | use fixed::types::U24F8; |
| 17 | use fixed_macro::fixed; | 17 | use fixed_macro::fixed; |
| 18 | use smart_leds::RGB8; | 18 | use smart_leds::RGB8; |
| @@ -107,6 +107,8 @@ impl<'d, P: Instance, const S: usize, const N: usize> Ws2812<'d, P, S, N> { | |||
| 107 | 107 | ||
| 108 | // DMA transfer | 108 | // DMA transfer |
| 109 | self.sm.tx().dma_push(self.dma.reborrow(), &words).await; | 109 | self.sm.tx().dma_push(self.dma.reborrow(), &words).await; |
| 110 | |||
| 111 | Timer::after_micros(55).await; | ||
| 110 | } | 112 | } |
| 111 | } | 113 | } |
| 112 | 114 | ||
| @@ -143,6 +145,7 @@ async fn main(_spawner: Spawner) { | |||
| 143 | let mut ws2812 = Ws2812::new(&mut common, sm0, p.DMA_CH0, p.PIN_16); | 145 | let mut ws2812 = Ws2812::new(&mut common, sm0, p.DMA_CH0, p.PIN_16); |
| 144 | 146 | ||
| 145 | // Loop forever making RGB values and pushing them out to the WS2812. | 147 | // Loop forever making RGB values and pushing them out to the WS2812. |
| 148 | let mut ticker = Ticker::every(Duration::from_millis(10)); | ||
| 146 | loop { | 149 | loop { |
| 147 | for j in 0..(256 * 5) { | 150 | for j in 0..(256 * 5) { |
| 148 | debug!("New Colors:"); | 151 | debug!("New Colors:"); |
| @@ -152,7 +155,7 @@ async fn main(_spawner: Spawner) { | |||
| 152 | } | 155 | } |
| 153 | ws2812.write(&data).await; | 156 | ws2812.write(&data).await; |
| 154 | 157 | ||
| 155 | Timer::after_millis(10).await; | 158 | ticker.next().await; |
| 156 | } | 159 | } |
| 157 | } | 160 | } |
| 158 | } | 161 | } |
diff --git a/examples/rp/src/bin/usb_serial_with_logger.rs b/examples/rp/src/bin/usb_serial_with_logger.rs new file mode 100644 index 000000000..4ba4fc25c --- /dev/null +++ b/examples/rp/src/bin/usb_serial_with_logger.rs | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | //! This example shows how to use USB (Universal Serial Bus) in the RP2040 chip as well as how to create multiple usb classes for one device | ||
| 2 | //! | ||
| 3 | //! This creates a USB serial port that echos. It will also print out logging information on a separate serial device | ||
| 4 | |||
| 5 | #![no_std] | ||
| 6 | #![no_main] | ||
| 7 | |||
| 8 | use defmt::{info, panic}; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_futures::join::join; | ||
| 11 | use embassy_rp::bind_interrupts; | ||
| 12 | use embassy_rp::peripherals::USB; | ||
| 13 | use embassy_rp::usb::{Driver, Instance, InterruptHandler}; | ||
| 14 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | ||
| 15 | use embassy_usb::driver::EndpointError; | ||
| 16 | use embassy_usb::{Builder, Config}; | ||
| 17 | use {defmt_rtt as _, panic_probe as _}; | ||
| 18 | |||
| 19 | bind_interrupts!(struct Irqs { | ||
| 20 | USBCTRL_IRQ => InterruptHandler<USB>; | ||
| 21 | }); | ||
| 22 | |||
| 23 | #[embassy_executor::main] | ||
| 24 | async fn main(_spawner: Spawner) { | ||
| 25 | info!("Hello there!"); | ||
| 26 | |||
| 27 | let p = embassy_rp::init(Default::default()); | ||
| 28 | |||
| 29 | // Create the driver, from the HAL. | ||
| 30 | let driver = Driver::new(p.USB, Irqs); | ||
| 31 | |||
| 32 | // Create embassy-usb Config | ||
| 33 | let mut config = Config::new(0xc0de, 0xcafe); | ||
| 34 | config.manufacturer = Some("Embassy"); | ||
| 35 | config.product = Some("USB-serial example"); | ||
| 36 | config.serial_number = Some("12345678"); | ||
| 37 | config.max_power = 100; | ||
| 38 | config.max_packet_size_0 = 64; | ||
| 39 | |||
| 40 | // Required for windows compatibility. | ||
| 41 | // https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/kconfig/CONFIG_CDC_ACM_IAD.html#help | ||
| 42 | config.device_class = 0xEF; | ||
| 43 | config.device_sub_class = 0x02; | ||
| 44 | config.device_protocol = 0x01; | ||
| 45 | config.composite_with_iads = true; | ||
| 46 | |||
| 47 | // Create embassy-usb DeviceBuilder using the driver and config. | ||
| 48 | // It needs some buffers for building the descriptors. | ||
| 49 | let mut device_descriptor = [0; 256]; | ||
| 50 | let mut config_descriptor = [0; 256]; | ||
| 51 | let mut bos_descriptor = [0; 256]; | ||
| 52 | let mut control_buf = [0; 64]; | ||
| 53 | |||
| 54 | let mut state = State::new(); | ||
| 55 | let mut logger_state = State::new(); | ||
| 56 | |||
| 57 | let mut builder = Builder::new( | ||
| 58 | driver, | ||
| 59 | config, | ||
| 60 | &mut device_descriptor, | ||
| 61 | &mut config_descriptor, | ||
| 62 | &mut bos_descriptor, | ||
| 63 | &mut [], // no msos descriptors | ||
| 64 | &mut control_buf, | ||
| 65 | ); | ||
| 66 | |||
| 67 | // Create classes on the builder. | ||
| 68 | let mut class = CdcAcmClass::new(&mut builder, &mut state, 64); | ||
| 69 | |||
| 70 | // Create a class for the logger | ||
| 71 | let logger_class = CdcAcmClass::new(&mut builder, &mut logger_state, 64); | ||
| 72 | |||
| 73 | // Creates the logger and returns the logger future | ||
| 74 | // Note: You'll need to use log::info! afterwards instead of info! for this to work (this also applies to all the other log::* macros) | ||
| 75 | let log_fut = embassy_usb_logger::with_class!(1024, log::LevelFilter::Info, logger_class); | ||
| 76 | |||
| 77 | // Build the builder. | ||
| 78 | let mut usb = builder.build(); | ||
| 79 | |||
| 80 | // Run the USB device. | ||
| 81 | let usb_fut = usb.run(); | ||
| 82 | |||
| 83 | // Do stuff with the class! | ||
| 84 | let echo_fut = async { | ||
| 85 | loop { | ||
| 86 | class.wait_connection().await; | ||
| 87 | log::info!("Connected"); | ||
| 88 | let _ = echo(&mut class).await; | ||
| 89 | log::info!("Disconnected"); | ||
| 90 | } | ||
| 91 | }; | ||
| 92 | |||
| 93 | // Run everything concurrently. | ||
| 94 | // If we had made everything `'static` above instead, we could do this using separate tasks instead. | ||
| 95 | join(usb_fut, join(echo_fut, log_fut)).await; | ||
| 96 | } | ||
| 97 | |||
| 98 | struct Disconnected {} | ||
| 99 | |||
| 100 | impl From<EndpointError> for Disconnected { | ||
| 101 | fn from(val: EndpointError) -> Self { | ||
| 102 | match val { | ||
| 103 | EndpointError::BufferOverflow => panic!("Buffer overflow"), | ||
| 104 | EndpointError::Disabled => Disconnected {}, | ||
| 105 | } | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> { | ||
| 110 | let mut buf = [0; 64]; | ||
| 111 | loop { | ||
| 112 | let n = class.read_packet(&mut buf).await?; | ||
| 113 | let data = &buf[..n]; | ||
| 114 | info!("data: {:x}", data); | ||
| 115 | class.write_packet(data).await?; | ||
| 116 | } | ||
| 117 | } | ||
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml index 71b0eb683..c74980dc4 100644 --- a/examples/stm32f0/Cargo.toml +++ b/examples/stm32f0/Cargo.toml | |||
| @@ -13,7 +13,7 @@ cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-sing | |||
| 13 | cortex-m-rt = "0.7.0" | 13 | cortex-m-rt = "0.7.0" |
| 14 | defmt = "0.3" | 14 | defmt = "0.3" |
| 15 | defmt-rtt = "0.4" | 15 | defmt-rtt = "0.4" |
| 16 | panic-probe = "0.3" | 16 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 17 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } | 17 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } |
| 18 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } | 18 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } |
| 19 | embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 19 | embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
diff --git a/examples/stm32f1/src/bin/hello.rs b/examples/stm32f1/src/bin/hello.rs index 7b761ecc1..3c295612c 100644 --- a/examples/stm32f1/src/bin/hello.rs +++ b/examples/stm32f1/src/bin/hello.rs | |||
| @@ -3,15 +3,13 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::info; | 4 | use defmt::info; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::time::Hertz; | ||
| 7 | use embassy_stm32::Config; | 6 | use embassy_stm32::Config; |
| 8 | use embassy_time::Timer; | 7 | use embassy_time::Timer; |
| 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] |
| 12 | async fn main(_spawner: Spawner) -> ! { | 11 | async fn main(_spawner: Spawner) -> ! { |
| 13 | let mut config = Config::default(); | 12 | let config = Config::default(); |
| 14 | config.rcc.sys_ck = Some(Hertz(36_000_000)); | ||
| 15 | let _p = embassy_stm32::init(config); | 13 | let _p = embassy_stm32::init(config); |
| 16 | 14 | ||
| 17 | loop { | 15 | loop { |
diff --git a/examples/stm32f1/src/bin/usb_serial.rs b/examples/stm32f1/src/bin/usb_serial.rs index e28381893..1ae6c1dee 100644 --- a/examples/stm32f1/src/bin/usb_serial.rs +++ b/examples/stm32f1/src/bin/usb_serial.rs | |||
| @@ -21,9 +21,23 @@ bind_interrupts!(struct Irqs { | |||
| 21 | #[embassy_executor::main] | 21 | #[embassy_executor::main] |
| 22 | async fn main(_spawner: Spawner) { | 22 | async fn main(_spawner: Spawner) { |
| 23 | let mut config = Config::default(); | 23 | let mut config = Config::default(); |
| 24 | config.rcc.hse = Some(Hertz(8_000_000)); | 24 | { |
| 25 | config.rcc.sys_ck = Some(Hertz(48_000_000)); | 25 | use embassy_stm32::rcc::*; |
| 26 | config.rcc.pclk1 = Some(Hertz(24_000_000)); | 26 | config.rcc.hse = Some(Hse { |
| 27 | freq: Hertz(8_000_000), | ||
| 28 | // Oscillator for bluepill, Bypass for nucleos. | ||
| 29 | mode: HseMode::Oscillator, | ||
| 30 | }); | ||
| 31 | config.rcc.pll = Some(Pll { | ||
| 32 | src: PllSource::HSE, | ||
| 33 | prediv: PllPreDiv::DIV1, | ||
| 34 | mul: PllMul::MUL9, | ||
| 35 | }); | ||
| 36 | config.rcc.sys = Sysclk::PLL1_P; | ||
| 37 | config.rcc.ahb_pre = AHBPrescaler::DIV1; | ||
| 38 | config.rcc.apb1_pre = APBPrescaler::DIV2; | ||
| 39 | config.rcc.apb2_pre = APBPrescaler::DIV1; | ||
| 40 | } | ||
| 27 | let mut p = embassy_stm32::init(config); | 41 | let mut p = embassy_stm32::init(config); |
| 28 | 42 | ||
| 29 | info!("Hello World!"); | 43 | info!("Hello World!"); |
diff --git a/examples/stm32f3/src/bin/hello.rs b/examples/stm32f3/src/bin/hello.rs index fd54da53d..3c295612c 100644 --- a/examples/stm32f3/src/bin/hello.rs +++ b/examples/stm32f3/src/bin/hello.rs | |||
| @@ -3,16 +3,13 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::info; | 4 | use defmt::info; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::time::Hertz; | ||
| 7 | use embassy_stm32::Config; | 6 | use embassy_stm32::Config; |
| 8 | use embassy_time::Timer; | 7 | use embassy_time::Timer; |
| 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] |
| 12 | async fn main(_spawner: Spawner) -> ! { | 11 | async fn main(_spawner: Spawner) -> ! { |
| 13 | let mut config = Config::default(); | 12 | let config = Config::default(); |
| 14 | config.rcc.hse = Some(Hertz(8_000_000)); | ||
| 15 | config.rcc.sysclk = Some(Hertz(16_000_000)); | ||
| 16 | let _p = embassy_stm32::init(config); | 13 | let _p = embassy_stm32::init(config); |
| 17 | 14 | ||
| 18 | loop { | 15 | loop { |
diff --git a/examples/stm32f3/src/bin/usb_serial.rs b/examples/stm32f3/src/bin/usb_serial.rs index cf9ecedfa..ee1c43afd 100644 --- a/examples/stm32f3/src/bin/usb_serial.rs +++ b/examples/stm32f3/src/bin/usb_serial.rs | |||
| @@ -21,11 +21,22 @@ bind_interrupts!(struct Irqs { | |||
| 21 | #[embassy_executor::main] | 21 | #[embassy_executor::main] |
| 22 | async fn main(_spawner: Spawner) { | 22 | async fn main(_spawner: Spawner) { |
| 23 | let mut config = Config::default(); | 23 | let mut config = Config::default(); |
| 24 | config.rcc.hse = Some(mhz(8)); | 24 | { |
| 25 | config.rcc.sysclk = Some(mhz(48)); | 25 | use embassy_stm32::rcc::*; |
| 26 | config.rcc.pclk1 = Some(mhz(24)); | 26 | config.rcc.hse = Some(Hse { |
| 27 | config.rcc.pclk2 = Some(mhz(24)); | 27 | freq: mhz(8), |
| 28 | config.rcc.pll48 = true; | 28 | mode: HseMode::Bypass, |
| 29 | }); | ||
| 30 | config.rcc.pll = Some(Pll { | ||
| 31 | src: PllSource::HSE, | ||
| 32 | prediv: PllPreDiv::DIV1, | ||
| 33 | mul: PllMul::MUL9, | ||
| 34 | }); | ||
| 35 | config.rcc.sys = Sysclk::PLL1_P; | ||
| 36 | config.rcc.ahb_pre = AHBPrescaler::DIV1; | ||
| 37 | config.rcc.apb1_pre = APBPrescaler::DIV2; | ||
| 38 | config.rcc.apb2_pre = APBPrescaler::DIV1; | ||
| 39 | } | ||
| 29 | let p = embassy_stm32::init(config); | 40 | let p = embassy_stm32::init(config); |
| 30 | 41 | ||
| 31 | info!("Hello World!"); | 42 | info!("Hello World!"); |
diff --git a/examples/stm32f334/src/bin/adc.rs b/examples/stm32f334/src/bin/adc.rs index 063ee9dac..a9fb7f1a6 100644 --- a/examples/stm32f334/src/bin/adc.rs +++ b/examples/stm32f334/src/bin/adc.rs | |||
| @@ -5,7 +5,6 @@ use defmt::info; | |||
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::adc::{Adc, SampleTime}; | 6 | use embassy_stm32::adc::{Adc, SampleTime}; |
| 7 | use embassy_stm32::peripherals::ADC1; | 7 | use embassy_stm32::peripherals::ADC1; |
| 8 | use embassy_stm32::rcc::{AdcClockSource, Adcpres}; | ||
| 9 | use embassy_stm32::time::mhz; | 8 | use embassy_stm32::time::mhz; |
| 10 | use embassy_stm32::{adc, bind_interrupts, Config}; | 9 | use embassy_stm32::{adc, bind_interrupts, Config}; |
| 11 | use embassy_time::{Delay, Timer}; | 10 | use embassy_time::{Delay, Timer}; |
| @@ -18,12 +17,23 @@ bind_interrupts!(struct Irqs { | |||
| 18 | #[embassy_executor::main] | 17 | #[embassy_executor::main] |
| 19 | async fn main(_spawner: Spawner) -> ! { | 18 | async fn main(_spawner: Spawner) -> ! { |
| 20 | let mut config = Config::default(); | 19 | let mut config = Config::default(); |
| 21 | config.rcc.sysclk = Some(mhz(64)); | 20 | { |
| 22 | config.rcc.hclk = Some(mhz(64)); | 21 | use embassy_stm32::rcc::*; |
| 23 | config.rcc.pclk1 = Some(mhz(32)); | 22 | config.rcc.hse = Some(Hse { |
| 24 | config.rcc.pclk2 = Some(mhz(64)); | 23 | freq: mhz(8), |
| 25 | config.rcc.adc = Some(AdcClockSource::Pll(Adcpres::DIV1)); | 24 | mode: HseMode::Bypass, |
| 26 | 25 | }); | |
| 26 | config.rcc.pll = Some(Pll { | ||
| 27 | src: PllSource::HSE, | ||
| 28 | prediv: PllPreDiv::DIV1, | ||
| 29 | mul: PllMul::MUL9, | ||
| 30 | }); | ||
| 31 | config.rcc.sys = Sysclk::PLL1_P; | ||
| 32 | config.rcc.ahb_pre = AHBPrescaler::DIV1; | ||
| 33 | config.rcc.apb1_pre = APBPrescaler::DIV2; | ||
| 34 | config.rcc.apb2_pre = APBPrescaler::DIV1; | ||
| 35 | config.rcc.adc = AdcClockSource::Pll(AdcPllPrescaler::DIV1); | ||
| 36 | } | ||
| 27 | let mut p = embassy_stm32::init(config); | 37 | let mut p = embassy_stm32::init(config); |
| 28 | 38 | ||
| 29 | info!("create adc..."); | 39 | info!("create adc..."); |
diff --git a/examples/stm32f334/src/bin/hello.rs b/examples/stm32f334/src/bin/hello.rs index fd54da53d..3c295612c 100644 --- a/examples/stm32f334/src/bin/hello.rs +++ b/examples/stm32f334/src/bin/hello.rs | |||
| @@ -3,16 +3,13 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::info; | 4 | use defmt::info; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::time::Hertz; | ||
| 7 | use embassy_stm32::Config; | 6 | use embassy_stm32::Config; |
| 8 | use embassy_time::Timer; | 7 | use embassy_time::Timer; |
| 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] |
| 12 | async fn main(_spawner: Spawner) -> ! { | 11 | async fn main(_spawner: Spawner) -> ! { |
| 13 | let mut config = Config::default(); | 12 | let config = Config::default(); |
| 14 | config.rcc.hse = Some(Hertz(8_000_000)); | ||
| 15 | config.rcc.sysclk = Some(Hertz(16_000_000)); | ||
| 16 | let _p = embassy_stm32::init(config); | 13 | let _p = embassy_stm32::init(config); |
| 17 | 14 | ||
| 18 | loop { | 15 | loop { |
diff --git a/examples/stm32f334/src/bin/opamp.rs b/examples/stm32f334/src/bin/opamp.rs index 850a0e335..6f25191be 100644 --- a/examples/stm32f334/src/bin/opamp.rs +++ b/examples/stm32f334/src/bin/opamp.rs | |||
| @@ -6,7 +6,6 @@ use embassy_executor::Spawner; | |||
| 6 | use embassy_stm32::adc::{Adc, SampleTime}; | 6 | use embassy_stm32::adc::{Adc, SampleTime}; |
| 7 | use embassy_stm32::opamp::{OpAmp, OpAmpGain}; | 7 | use embassy_stm32::opamp::{OpAmp, OpAmpGain}; |
| 8 | use embassy_stm32::peripherals::ADC2; | 8 | use embassy_stm32::peripherals::ADC2; |
| 9 | use embassy_stm32::rcc::{AdcClockSource, Adcpres}; | ||
| 10 | use embassy_stm32::time::mhz; | 9 | use embassy_stm32::time::mhz; |
| 11 | use embassy_stm32::{adc, bind_interrupts, Config}; | 10 | use embassy_stm32::{adc, bind_interrupts, Config}; |
| 12 | use embassy_time::{Delay, Timer}; | 11 | use embassy_time::{Delay, Timer}; |
| @@ -19,12 +18,23 @@ bind_interrupts!(struct Irqs { | |||
| 19 | #[embassy_executor::main] | 18 | #[embassy_executor::main] |
| 20 | async fn main(_spawner: Spawner) -> ! { | 19 | async fn main(_spawner: Spawner) -> ! { |
| 21 | let mut config = Config::default(); | 20 | let mut config = Config::default(); |
| 22 | config.rcc.sysclk = Some(mhz(64)); | 21 | { |
| 23 | config.rcc.hclk = Some(mhz(64)); | 22 | use embassy_stm32::rcc::*; |
| 24 | config.rcc.pclk1 = Some(mhz(32)); | 23 | config.rcc.hse = Some(Hse { |
| 25 | config.rcc.pclk2 = Some(mhz(64)); | 24 | freq: mhz(8), |
| 26 | config.rcc.adc = Some(AdcClockSource::Pll(Adcpres::DIV1)); | 25 | mode: HseMode::Bypass, |
| 27 | 26 | }); | |
| 27 | config.rcc.pll = Some(Pll { | ||
| 28 | src: PllSource::HSE, | ||
| 29 | prediv: PllPreDiv::DIV1, | ||
| 30 | mul: PllMul::MUL9, | ||
| 31 | }); | ||
| 32 | config.rcc.sys = Sysclk::PLL1_P; | ||
| 33 | config.rcc.ahb_pre = AHBPrescaler::DIV1; | ||
| 34 | config.rcc.apb1_pre = APBPrescaler::DIV2; | ||
| 35 | config.rcc.apb2_pre = APBPrescaler::DIV1; | ||
| 36 | config.rcc.adc = AdcClockSource::Pll(AdcPllPrescaler::DIV1); | ||
| 37 | } | ||
| 28 | let mut p = embassy_stm32::init(config); | 38 | let mut p = embassy_stm32::init(config); |
| 29 | 39 | ||
| 30 | info!("create adc..."); | 40 | info!("create adc..."); |
diff --git a/examples/stm32f334/src/bin/pwm.rs b/examples/stm32f334/src/bin/pwm.rs index c149cad92..7fc1ea926 100644 --- a/examples/stm32f334/src/bin/pwm.rs +++ b/examples/stm32f334/src/bin/pwm.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::hrtim::*; | 6 | use embassy_stm32::hrtim::*; |
| 7 | use embassy_stm32::rcc::HrtimClockSource; | ||
| 8 | use embassy_stm32::time::{khz, mhz}; | 7 | use embassy_stm32::time::{khz, mhz}; |
| 9 | use embassy_stm32::Config; | 8 | use embassy_stm32::Config; |
| 10 | use embassy_time::Timer; | 9 | use embassy_time::Timer; |
| @@ -12,14 +11,26 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 12 | 11 | ||
| 13 | #[embassy_executor::main] | 12 | #[embassy_executor::main] |
| 14 | async fn main(_spawner: Spawner) { | 13 | async fn main(_spawner: Spawner) { |
| 15 | let mut config: Config = Default::default(); | 14 | let mut config = Config::default(); |
| 16 | config.rcc.sysclk = Some(mhz(64)); | 15 | { |
| 17 | config.rcc.hclk = Some(mhz(64)); | 16 | use embassy_stm32::rcc::*; |
| 18 | config.rcc.pclk1 = Some(mhz(32)); | 17 | config.rcc.hse = Some(Hse { |
| 19 | config.rcc.pclk2 = Some(mhz(64)); | 18 | freq: mhz(8), |
| 20 | config.rcc.hrtim = HrtimClockSource::PllClk; | 19 | mode: HseMode::Bypass, |
| 21 | 20 | }); | |
| 21 | config.rcc.pll = Some(Pll { | ||
| 22 | src: PllSource::HSE, | ||
| 23 | prediv: PllPreDiv::DIV1, | ||
| 24 | mul: PllMul::MUL9, | ||
| 25 | }); | ||
| 26 | config.rcc.sys = Sysclk::PLL1_P; | ||
| 27 | config.rcc.ahb_pre = AHBPrescaler::DIV1; | ||
| 28 | config.rcc.apb1_pre = APBPrescaler::DIV2; | ||
| 29 | config.rcc.apb2_pre = APBPrescaler::DIV1; | ||
| 30 | config.rcc.hrtim = HrtimClockSource::PllClk; | ||
| 31 | } | ||
| 22 | let p = embassy_stm32::init(config); | 32 | let p = embassy_stm32::init(config); |
| 33 | |||
| 23 | info!("Hello World!"); | 34 | info!("Hello World!"); |
| 24 | 35 | ||
| 25 | let ch1 = PwmPin::new_cha(p.PA8); | 36 | let ch1 = PwmPin::new_cha(p.PA8); |
diff --git a/examples/stm32f7/.cargo/config.toml b/examples/stm32f7/.cargo/config.toml index 9088eea6e..086da2d78 100644 --- a/examples/stm32f7/.cargo/config.toml +++ b/examples/stm32f7/.cargo/config.toml | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] |
| 2 | # replace STM32F429ZITx with your chip as listed in `probe-rs chip list` | 2 | # replace STM32F429ZITx with your chip as listed in `probe-rs chip list` |
| 3 | runner = "probe-rs run --chip STM32F767ZITx" | 3 | runner = "probe-rs run --chip STM32F777ZITx" |
| 4 | 4 | ||
| 5 | [build] | 5 | [build] |
| 6 | target = "thumbv7em-none-eabihf" | 6 | target = "thumbv7em-none-eabihf" |
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index 941ba38cd..736e81723 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml | |||
| @@ -5,8 +5,8 @@ version = "0.1.0" | |||
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | # Change stm32f767zi to your chip name, if necessary. | 8 | # Change stm32f777zi to your chip name, if necessary. |
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f767zi", "memory-x", "unstable-pac", "time-driver-any", "exti"] } | 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f777zi", "memory-x", "unstable-pac", "time-driver-any", "exti"] } |
| 10 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } |
| 11 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 12 | embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| @@ -28,6 +28,8 @@ rand_core = "0.6.3" | |||
| 28 | critical-section = "1.1" | 28 | critical-section = "1.1" |
| 29 | embedded-storage = "0.3.1" | 29 | embedded-storage = "0.3.1" |
| 30 | static_cell = "2" | 30 | static_cell = "2" |
| 31 | sha2 = { version = "0.10.8", default-features = false } | ||
| 32 | hmac = "0.12.1" | ||
| 31 | 33 | ||
| 32 | [profile.release] | 34 | [profile.release] |
| 33 | debug = 2 | 35 | debug = 2 |
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index 5bff48197..9a608e909 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs | |||
| @@ -19,7 +19,7 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 19 | 19 | ||
| 20 | bind_interrupts!(struct Irqs { | 20 | bind_interrupts!(struct Irqs { |
| 21 | ETH => eth::InterruptHandler; | 21 | ETH => eth::InterruptHandler; |
| 22 | RNG => rng::InterruptHandler<peripherals::RNG>; | 22 | HASH_RNG => rng::InterruptHandler<peripherals::RNG>; |
| 23 | }); | 23 | }); |
| 24 | 24 | ||
| 25 | type Device = Ethernet<'static, ETH, GenericSMI>; | 25 | type Device = Ethernet<'static, ETH, GenericSMI>; |
diff --git a/examples/stm32f7/src/bin/hash.rs b/examples/stm32f7/src/bin/hash.rs new file mode 100644 index 000000000..c2d1a7158 --- /dev/null +++ b/examples/stm32f7/src/bin/hash.rs | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::info; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_stm32::hash::*; | ||
| 7 | use embassy_stm32::{bind_interrupts, hash, peripherals, Config}; | ||
| 8 | use embassy_time::Instant; | ||
| 9 | use hmac::{Hmac, Mac}; | ||
| 10 | use sha2::{Digest, Sha256}; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | type HmacSha256 = Hmac<Sha256>; | ||
| 14 | |||
| 15 | bind_interrupts!(struct Irqs { | ||
| 16 | HASH_RNG => hash::InterruptHandler<peripherals::HASH>; | ||
| 17 | }); | ||
| 18 | |||
| 19 | #[embassy_executor::main] | ||
| 20 | async fn main(_spawner: Spawner) -> ! { | ||
| 21 | let config = Config::default(); | ||
| 22 | let p = embassy_stm32::init(config); | ||
| 23 | |||
| 24 | let test_1: &[u8] = b"as;dfhaslfhas;oifvnasd;nifvnhasd;nifvhndlkfghsd;nvfnahssdfgsdafgsasdfasdfasdfasdfasdfghjklmnbvcalskdjghalskdjgfbaslkdjfgbalskdjgbalskdjbdfhsdfhsfghsfghfgh"; | ||
| 25 | let test_2: &[u8] = b"fdhalksdjfhlasdjkfhalskdjfhgal;skdjfgalskdhfjgalskdjfglafgadfgdfgdafgaadsfgfgdfgadrgsyfthxfgjfhklhjkfgukhulkvhlvhukgfhfsrghzdhxyfufynufyuszeradrtydyytserr"; | ||
| 26 | |||
| 27 | let mut hw_hasher = Hash::new(p.HASH, p.DMA2_CH7, Irqs); | ||
| 28 | |||
| 29 | let hw_start_time = Instant::now(); | ||
| 30 | |||
| 31 | // Compute a digest in hardware. | ||
| 32 | let mut context = hw_hasher.start(Algorithm::SHA256, DataType::Width8, None); | ||
| 33 | hw_hasher.update(&mut context, test_1).await; | ||
| 34 | hw_hasher.update(&mut context, test_2).await; | ||
| 35 | let mut hw_digest: [u8; 32] = [0; 32]; | ||
| 36 | hw_hasher.finish(context, &mut hw_digest).await; | ||
| 37 | |||
| 38 | let hw_end_time = Instant::now(); | ||
| 39 | let hw_execution_time = hw_end_time - hw_start_time; | ||
| 40 | |||
| 41 | let sw_start_time = Instant::now(); | ||
| 42 | |||
| 43 | // Compute a digest in software. | ||
| 44 | let mut sw_hasher = Sha256::new(); | ||
| 45 | sw_hasher.update(test_1); | ||
| 46 | sw_hasher.update(test_2); | ||
| 47 | let sw_digest = sw_hasher.finalize(); | ||
| 48 | |||
| 49 | let sw_end_time = Instant::now(); | ||
| 50 | let sw_execution_time = sw_end_time - sw_start_time; | ||
| 51 | |||
| 52 | info!("Hardware Digest: {:?}", hw_digest); | ||
| 53 | info!("Software Digest: {:?}", sw_digest[..]); | ||
| 54 | info!("Hardware Execution Time: {:?}", hw_execution_time); | ||
| 55 | info!("Software Execution Time: {:?}", sw_execution_time); | ||
| 56 | assert_eq!(hw_digest, sw_digest[..]); | ||
| 57 | |||
| 58 | let hmac_key: [u8; 64] = [0x55; 64]; | ||
| 59 | |||
| 60 | // Compute HMAC in hardware. | ||
| 61 | let mut sha256hmac_context = hw_hasher.start(Algorithm::SHA256, DataType::Width8, Some(&hmac_key)); | ||
| 62 | hw_hasher.update(&mut sha256hmac_context, test_1).await; | ||
| 63 | hw_hasher.update(&mut sha256hmac_context, test_2).await; | ||
| 64 | let mut hw_hmac: [u8; 32] = [0; 32]; | ||
| 65 | hw_hasher.finish(sha256hmac_context, &mut hw_hmac).await; | ||
| 66 | |||
| 67 | // Compute HMAC in software. | ||
| 68 | let mut sw_mac = HmacSha256::new_from_slice(&hmac_key).unwrap(); | ||
| 69 | sw_mac.update(test_1); | ||
| 70 | sw_mac.update(test_2); | ||
| 71 | let sw_hmac = sw_mac.finalize().into_bytes(); | ||
| 72 | |||
| 73 | info!("Hardware HMAC: {:?}", hw_hmac); | ||
| 74 | info!("Software HMAC: {:?}", sw_hmac[..]); | ||
| 75 | assert_eq!(hw_hmac, sw_hmac[..]); | ||
| 76 | |||
| 77 | loop {} | ||
| 78 | } | ||
diff --git a/examples/stm32g4/src/bin/adc.rs b/examples/stm32g4/src/bin/adc.rs index 35324d931..99e3ef63b 100644 --- a/examples/stm32g4/src/bin/adc.rs +++ b/examples/stm32g4/src/bin/adc.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::adc::{Adc, SampleTime}; | 6 | use embassy_stm32::adc::{Adc, SampleTime}; |
| 7 | use embassy_stm32::rcc::{AdcClockSource, ClockSrc, Pll, PllM, PllN, PllR, PllSource}; | 7 | use embassy_stm32::rcc::{AdcClockSource, Pll, PllMul, PllPreDiv, PllRDiv, Pllsrc, Sysclk}; |
| 8 | use embassy_stm32::Config; | 8 | use embassy_stm32::Config; |
| 9 | use embassy_time::{Delay, Timer}; | 9 | use embassy_time::{Delay, Timer}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -14,17 +14,17 @@ async fn main(_spawner: Spawner) { | |||
| 14 | let mut config = Config::default(); | 14 | let mut config = Config::default(); |
| 15 | 15 | ||
| 16 | config.rcc.pll = Some(Pll { | 16 | config.rcc.pll = Some(Pll { |
| 17 | source: PllSource::HSI, | 17 | source: Pllsrc::HSI, |
| 18 | prediv_m: PllM::DIV4, | 18 | prediv: PllPreDiv::DIV4, |
| 19 | mul_n: PllN::MUL85, | 19 | mul: PllMul::MUL85, |
| 20 | div_p: None, | 20 | divp: None, |
| 21 | div_q: None, | 21 | divq: None, |
| 22 | // Main system clock at 170 MHz | 22 | // Main system clock at 170 MHz |
| 23 | div_r: Some(PllR::DIV2), | 23 | divr: Some(PllRDiv::DIV2), |
| 24 | }); | 24 | }); |
| 25 | 25 | ||
| 26 | config.rcc.adc12_clock_source = AdcClockSource::SYS; | 26 | config.rcc.adc12_clock_source = AdcClockSource::SYS; |
| 27 | config.rcc.mux = ClockSrc::PLL; | 27 | config.rcc.sys = Sysclk::PLL1_R; |
| 28 | 28 | ||
| 29 | let mut p = embassy_stm32::init(config); | 29 | let mut p = embassy_stm32::init(config); |
| 30 | info!("Hello World!"); | 30 | info!("Hello World!"); |
diff --git a/examples/stm32g4/src/bin/pll.rs b/examples/stm32g4/src/bin/pll.rs index 46ebe0b0d..5274de79d 100644 --- a/examples/stm32g4/src/bin/pll.rs +++ b/examples/stm32g4/src/bin/pll.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::rcc::{ClockSrc, Pll, PllM, PllN, PllR, PllSource}; | 6 | use embassy_stm32::rcc::{Pll, PllMul, PllPreDiv, PllRDiv, Pllsrc, Sysclk}; |
| 7 | use embassy_stm32::Config; | 7 | use embassy_stm32::Config; |
| 8 | use embassy_time::Timer; | 8 | use embassy_time::Timer; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -13,16 +13,16 @@ async fn main(_spawner: Spawner) { | |||
| 13 | let mut config = Config::default(); | 13 | let mut config = Config::default(); |
| 14 | 14 | ||
| 15 | config.rcc.pll = Some(Pll { | 15 | config.rcc.pll = Some(Pll { |
| 16 | source: PllSource::HSI, | 16 | source: Pllsrc::HSI, |
| 17 | prediv_m: PllM::DIV4, | 17 | prediv: PllPreDiv::DIV4, |
| 18 | mul_n: PllN::MUL85, | 18 | mul: PllMul::MUL85, |
| 19 | div_p: None, | 19 | divp: None, |
| 20 | div_q: None, | 20 | divq: None, |
| 21 | // Main system clock at 170 MHz | 21 | // Main system clock at 170 MHz |
| 22 | div_r: Some(PllR::DIV2), | 22 | divr: Some(PllRDiv::DIV2), |
| 23 | }); | 23 | }); |
| 24 | 24 | ||
| 25 | config.rcc.mux = ClockSrc::PLL; | 25 | config.rcc.sys = Sysclk::PLL1_R; |
| 26 | 26 | ||
| 27 | let _p = embassy_stm32::init(config); | 27 | let _p = embassy_stm32::init(config); |
| 28 | info!("Hello World!"); | 28 | info!("Hello World!"); |
diff --git a/examples/stm32g4/src/bin/usb_serial.rs b/examples/stm32g4/src/bin/usb_serial.rs index c26fa76b7..989fef5b0 100644 --- a/examples/stm32g4/src/bin/usb_serial.rs +++ b/examples/stm32g4/src/bin/usb_serial.rs | |||
| @@ -3,7 +3,9 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::{panic, *}; | 4 | use defmt::{panic, *}; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::rcc::{Clock48MhzSrc, ClockSrc, Hsi48Config, Pll, PllM, PllN, PllQ, PllR, PllSource}; | 6 | use embassy_stm32::rcc::{ |
| 7 | Clk48Src, Hse, HseMode, Hsi48Config, Pll, PllMul, PllPreDiv, PllQDiv, PllRDiv, Pllsrc, Sysclk, | ||
| 8 | }; | ||
| 7 | use embassy_stm32::time::Hertz; | 9 | use embassy_stm32::time::Hertz; |
| 8 | use embassy_stm32::usb::{self, Driver, Instance}; | 10 | use embassy_stm32::usb::{self, Driver, Instance}; |
| 9 | use embassy_stm32::{bind_interrupts, peripherals, Config}; | 11 | use embassy_stm32::{bind_interrupts, peripherals, Config}; |
| @@ -24,25 +26,32 @@ async fn main(_spawner: Spawner) { | |||
| 24 | // Change this to `false` to use the HSE clock source for the USB. This example assumes an 8MHz HSE. | 26 | // Change this to `false` to use the HSE clock source for the USB. This example assumes an 8MHz HSE. |
| 25 | const USE_HSI48: bool = true; | 27 | const USE_HSI48: bool = true; |
| 26 | 28 | ||
| 27 | let plldivq = if USE_HSI48 { None } else { Some(PllQ::DIV6) }; | 29 | let plldivq = if USE_HSI48 { None } else { Some(PllQDiv::DIV6) }; |
| 30 | |||
| 31 | config.rcc.hse = Some(Hse { | ||
| 32 | freq: Hertz(8_000_000), | ||
| 33 | mode: HseMode::Oscillator, | ||
| 34 | }); | ||
| 28 | 35 | ||
| 29 | config.rcc.pll = Some(Pll { | 36 | config.rcc.pll = Some(Pll { |
| 30 | source: PllSource::HSE(Hertz(8_000_000)), | 37 | source: Pllsrc::HSE, |
| 31 | prediv_m: PllM::DIV2, | 38 | prediv: PllPreDiv::DIV2, |
| 32 | mul_n: PllN::MUL72, | 39 | mul: PllMul::MUL72, |
| 33 | div_p: None, | 40 | divp: None, |
| 34 | div_q: plldivq, | 41 | divq: plldivq, |
| 35 | // Main system clock at 144 MHz | 42 | // Main system clock at 144 MHz |
| 36 | div_r: Some(PllR::DIV2), | 43 | divr: Some(PllRDiv::DIV2), |
| 37 | }); | 44 | }); |
| 38 | 45 | ||
| 39 | config.rcc.mux = ClockSrc::PLL; | 46 | config.rcc.sys = Sysclk::PLL1_R; |
| 47 | config.rcc.boost = true; // BOOST! | ||
| 40 | 48 | ||
| 41 | if USE_HSI48 { | 49 | if USE_HSI48 { |
| 42 | // Sets up the Clock Recovery System (CRS) to use the USB SOF to trim the HSI48 oscillator. | 50 | // Sets up the Clock Recovery System (CRS) to use the USB SOF to trim the HSI48 oscillator. |
| 43 | config.rcc.clock_48mhz_src = Some(Clock48MhzSrc::Hsi48(Hsi48Config { sync_from_usb: true })); | 51 | config.rcc.hsi48 = Some(Hsi48Config { sync_from_usb: true }); |
| 52 | config.rcc.clk48_src = Clk48Src::HSI48; | ||
| 44 | } else { | 53 | } else { |
| 45 | config.rcc.clock_48mhz_src = Some(Clock48MhzSrc::PllQ); | 54 | config.rcc.clk48_src = Clk48Src::PLL1_Q; |
| 46 | } | 55 | } |
| 47 | 56 | ||
| 48 | let p = embassy_stm32::init(config); | 57 | let p = embassy_stm32::init(config); |
