stm32/usb: ensure mux is configured in examples.

This commit is contained in:
Dario Nieuwenhuis 2024-03-19 21:49:47 +01:00
parent d90abb8ac9
commit 4858a53a39
12 changed files with 71 additions and 49 deletions

View File

@ -63,6 +63,7 @@ async fn main(spawner: Spawner) {
config.rcc.apb1_pre = APBPrescaler::DIV4; config.rcc.apb1_pre = APBPrescaler::DIV4;
config.rcc.apb2_pre = APBPrescaler::DIV2; config.rcc.apb2_pre = APBPrescaler::DIV2;
config.rcc.sys = Sysclk::PLL1_P; config.rcc.sys = Sysclk::PLL1_P;
config.rcc.mux.clk48sel = mux::Clk48sel::PLL1_Q;
} }
let p = embassy_stm32::init(config); let p = embassy_stm32::init(config);

View File

@ -42,6 +42,7 @@ async fn main(_spawner: Spawner) {
config.rcc.apb1_pre = APBPrescaler::DIV4; config.rcc.apb1_pre = APBPrescaler::DIV4;
config.rcc.apb2_pre = APBPrescaler::DIV2; config.rcc.apb2_pre = APBPrescaler::DIV2;
config.rcc.sys = Sysclk::PLL1_P; config.rcc.sys = Sysclk::PLL1_P;
config.rcc.mux.clk48sel = mux::Clk48sel::PLL1_Q;
} }
let p = embassy_stm32::init(config); let p = embassy_stm32::init(config);

View File

@ -39,6 +39,7 @@ async fn main(_spawner: Spawner) {
config.rcc.apb1_pre = APBPrescaler::DIV4; config.rcc.apb1_pre = APBPrescaler::DIV4;
config.rcc.apb2_pre = APBPrescaler::DIV2; config.rcc.apb2_pre = APBPrescaler::DIV2;
config.rcc.sys = Sysclk::PLL1_P; config.rcc.sys = Sysclk::PLL1_P;
config.rcc.mux.clk48sel = mux::Clk48sel::PLL1_Q;
} }
let p = embassy_stm32::init(config); let p = embassy_stm32::init(config);

View File

@ -92,6 +92,7 @@ async fn main(_spawner: Spawner) {
config.rcc.apb1_pre = APBPrescaler::DIV4; config.rcc.apb1_pre = APBPrescaler::DIV4;
config.rcc.apb2_pre = APBPrescaler::DIV2; config.rcc.apb2_pre = APBPrescaler::DIV2;
config.rcc.sys = Sysclk::PLL1_P; config.rcc.sys = Sysclk::PLL1_P;
config.rcc.mux.clk48sel = mux::Clk48sel::PLL1_Q;
} }
let p = embassy_stm32::init(config); let p = embassy_stm32::init(config);

View File

@ -39,6 +39,7 @@ async fn main(_spawner: Spawner) {
config.rcc.apb1_pre = APBPrescaler::DIV4; config.rcc.apb1_pre = APBPrescaler::DIV4;
config.rcc.apb2_pre = APBPrescaler::DIV2; config.rcc.apb2_pre = APBPrescaler::DIV2;
config.rcc.sys = Sysclk::PLL1_P; config.rcc.sys = Sysclk::PLL1_P;
config.rcc.mux.clk48sel = mux::Clk48sel::PLL1_Q;
} }
let p = embassy_stm32::init(config); let p = embassy_stm32::init(config);

View File

@ -39,6 +39,7 @@ async fn main(_spawner: Spawner) {
config.rcc.apb1_pre = APBPrescaler::DIV4; config.rcc.apb1_pre = APBPrescaler::DIV4;
config.rcc.apb2_pre = APBPrescaler::DIV2; config.rcc.apb2_pre = APBPrescaler::DIV2;
config.rcc.sys = Sysclk::PLL1_P; config.rcc.sys = Sysclk::PLL1_P;
config.rcc.mux.clk48sel = mux::Clk48sel::PLL1_Q;
} }
let p = embassy_stm32::init(config); let p = embassy_stm32::init(config);

View File

@ -40,6 +40,7 @@ async fn main(_spawner: Spawner) {
config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz
config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz
config.rcc.voltage_scale = VoltageScale::Scale1; config.rcc.voltage_scale = VoltageScale::Scale1;
config.rcc.mux.usbsel = mux::Usbsel::HSI48;
} }
let p = embassy_stm32::init(config); let p = embassy_stm32::init(config);

View File

@ -4,7 +4,6 @@
use defmt::{panic, *}; use defmt::{panic, *};
use defmt_rtt as _; // global logger use defmt_rtt as _; // global logger
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_stm32::rcc::*;
use embassy_stm32::usb::{Driver, Instance}; use embassy_stm32::usb::{Driver, Instance};
use embassy_stm32::{bind_interrupts, peripherals, usb, Config}; use embassy_stm32::{bind_interrupts, peripherals, usb, Config};
use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
@ -22,18 +21,21 @@ async fn main(_spawner: Spawner) {
info!("Hello World!"); info!("Hello World!");
let mut config = Config::default(); let mut config = Config::default();
config.rcc.hsi48 = Some(Hsi48Config { sync_from_usb: true }); // needed for USB {
config.rcc.sys = Sysclk::PLL1_R; use embassy_stm32::rcc::*;
config.rcc.hsi = true; config.rcc.hsi48 = Some(Hsi48Config { sync_from_usb: true }); // needed for USB
config.rcc.pll = Some(Pll { config.rcc.sys = Sysclk::PLL1_R;
source: PllSource::HSI, config.rcc.hsi = true;
prediv: PllPreDiv::DIV1, config.rcc.pll = Some(Pll {
mul: PllMul::MUL10, source: PllSource::HSI,
divp: None, prediv: PllPreDiv::DIV1,
divq: None, mul: PllMul::MUL10,
divr: Some(PllRDiv::DIV2), // sysclk 80Mhz (16 / 1 * 10 / 2) divp: None,
}); divq: None,
divr: Some(PllRDiv::DIV2), // sysclk 80Mhz (16 / 1 * 10 / 2)
});
config.rcc.mux.clk48sel = mux::Clk48sel::HSI48;
}
let p = embassy_stm32::init(config); let p = embassy_stm32::init(config);
// Create the driver, from the HAL. // Create the driver, from the HAL.

View File

@ -5,7 +5,6 @@ use defmt::*;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_net::tcp::TcpSocket; use embassy_net::tcp::TcpSocket;
use embassy_net::{Stack, StackResources}; use embassy_net::{Stack, StackResources};
use embassy_stm32::rcc::*;
use embassy_stm32::rng::Rng; use embassy_stm32::rng::Rng;
use embassy_stm32::usb::Driver; use embassy_stm32::usb::Driver;
use embassy_stm32::{bind_interrupts, peripherals, rng, usb, Config}; use embassy_stm32::{bind_interrupts, peripherals, rng, usb, Config};
@ -44,17 +43,22 @@ async fn net_task(stack: &'static Stack<Device<'static, MTU>>) -> ! {
#[embassy_executor::main] #[embassy_executor::main]
async fn main(spawner: Spawner) { async fn main(spawner: Spawner) {
let mut config = Config::default(); let mut config = Config::default();
config.rcc.hsi = true; {
config.rcc.sys = Sysclk::PLL1_R; use embassy_stm32::rcc::*;
config.rcc.pll = Some(Pll { config.rcc.hsi = true;
// 80Mhz clock (16 / 1 * 10 / 2) config.rcc.sys = Sysclk::PLL1_R;
source: PllSource::HSI, config.rcc.pll = Some(Pll {
prediv: PllPreDiv::DIV1, // 80Mhz clock (16 / 1 * 10 / 2)
mul: PllMul::MUL10, source: PllSource::HSI,
divp: None, prediv: PllPreDiv::DIV1,
divq: None, mul: PllMul::MUL10,
divr: Some(PllRDiv::DIV2), divp: None,
}); divq: None,
divr: Some(PllRDiv::DIV2),
});
config.rcc.hsi48 = Some(Hsi48Config { sync_from_usb: true }); // needed for USB
config.rcc.mux.clk48sel = mux::Clk48sel::HSI48;
}
let p = embassy_stm32::init(config); let p = embassy_stm32::init(config);
// Create the driver, from the HAL. // Create the driver, from the HAL.

View File

@ -4,7 +4,6 @@
use defmt::*; use defmt::*;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_futures::join::join; use embassy_futures::join::join;
use embassy_stm32::rcc::*;
use embassy_stm32::usb::Driver; use embassy_stm32::usb::Driver;
use embassy_stm32::{bind_interrupts, peripherals, usb, Config}; use embassy_stm32::{bind_interrupts, peripherals, usb, Config};
use embassy_time::Timer; use embassy_time::Timer;
@ -21,17 +20,22 @@ bind_interrupts!(struct Irqs {
#[embassy_executor::main] #[embassy_executor::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let mut config = Config::default(); let mut config = Config::default();
config.rcc.hsi = true; {
config.rcc.sys = Sysclk::PLL1_R; use embassy_stm32::rcc::*;
config.rcc.pll = Some(Pll { config.rcc.hsi = true;
// 80Mhz clock (16 / 1 * 10 / 2) config.rcc.sys = Sysclk::PLL1_R;
source: PllSource::HSI, config.rcc.pll = Some(Pll {
prediv: PllPreDiv::DIV1, // 80Mhz clock (16 / 1 * 10 / 2)
mul: PllMul::MUL10, source: PllSource::HSI,
divp: None, prediv: PllPreDiv::DIV1,
divq: None, mul: PllMul::MUL10,
divr: Some(PllRDiv::DIV2), divp: None,
}); divq: None,
divr: Some(PllRDiv::DIV2),
});
config.rcc.hsi48 = Some(Hsi48Config { sync_from_usb: true }); // needed for USB
config.rcc.mux.clk48sel = mux::Clk48sel::HSI48;
}
let p = embassy_stm32::init(config); let p = embassy_stm32::init(config);
// Create the driver, from the HAL. // Create the driver, from the HAL.

View File

@ -4,7 +4,6 @@
use defmt::{panic, *}; use defmt::{panic, *};
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_futures::join::join; use embassy_futures::join::join;
use embassy_stm32::rcc::*;
use embassy_stm32::usb::{Driver, Instance}; use embassy_stm32::usb::{Driver, Instance};
use embassy_stm32::{bind_interrupts, peripherals, usb, Config}; use embassy_stm32::{bind_interrupts, peripherals, usb, Config};
use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
@ -19,17 +18,22 @@ bind_interrupts!(struct Irqs {
#[embassy_executor::main] #[embassy_executor::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let mut config = Config::default(); let mut config = Config::default();
config.rcc.hsi = true; {
config.rcc.sys = Sysclk::PLL1_R; use embassy_stm32::rcc::*;
config.rcc.pll = Some(Pll { config.rcc.hsi = true;
// 80Mhz clock (16 / 1 * 10 / 2) config.rcc.sys = Sysclk::PLL1_R;
source: PllSource::HSI, config.rcc.pll = Some(Pll {
prediv: PllPreDiv::DIV1, // 80Mhz clock (16 / 1 * 10 / 2)
mul: PllMul::MUL10, source: PllSource::HSI,
divp: None, prediv: PllPreDiv::DIV1,
divq: None, mul: PllMul::MUL10,
divr: Some(PllRDiv::DIV2), divp: None,
}); divq: None,
divr: Some(PllRDiv::DIV2),
});
config.rcc.hsi48 = Some(Hsi48Config { sync_from_usb: true }); // needed for USB
config.rcc.mux.clk48sel = mux::Clk48sel::HSI48;
}
let p = embassy_stm32::init(config); let p = embassy_stm32::init(config);
info!("Hello World!"); info!("Hello World!");

View File

@ -35,6 +35,7 @@ async fn main(_spawner: Spawner) {
config.rcc.sys = Sysclk::PLL1_R; config.rcc.sys = Sysclk::PLL1_R;
config.rcc.voltage_range = VoltageScale::RANGE1; config.rcc.voltage_range = VoltageScale::RANGE1;
config.rcc.hsi48 = Some(Hsi48Config { sync_from_usb: true }); // needed for USB config.rcc.hsi48 = Some(Hsi48Config { sync_from_usb: true }); // needed for USB
config.rcc.mux.iclksel = mux::Iclksel::HSI48; // USB uses ICLK
} }
let p = embassy_stm32::init(config); let p = embassy_stm32::init(config);