aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGerzain Mata <[email protected]>2025-07-27 13:49:39 -0700
committerGerzain Mata <[email protected]>2025-07-27 14:02:47 -0700
commit1d3c48cf4539fe1959f25918a6fa3521a5678837 (patch)
treee18b0919f5285ce9221b60fbd95bc022a8bd705b /examples
parent0545353ec10e1debb998f6fff9a3e3dd46ad32a9 (diff)
Working USB_OTG_HS example
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32wba/Cargo.toml3
-rw-r--r--examples/stm32wba/src/bin/usb_hs_serial.rs68
2 files changed, 37 insertions, 34 deletions
diff --git a/examples/stm32wba/Cargo.toml b/examples/stm32wba/Cargo.toml
index 1ddae5fee..336ea1e2e 100644
--- a/examples/stm32wba/Cargo.toml
+++ b/examples/stm32wba/Cargo.toml
@@ -9,7 +9,6 @@ embassy-stm32 = { version = "0.2.0", path = "../../embassy-stm32", features = [
9embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] } 9embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = ["defmt"] }
10embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] } 10embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt"] }
11embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 11embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
12embassy-net = { version = "0.7.0", path = "../../embassy-net", features = ["defmt", "udp", "proto-ipv6", "medium-ieee802154", ], optional = true }
13embassy-usb = { version = "0.5.0", path = "../../embassy-usb", features = ["defmt"] } 12embassy-usb = { version = "0.5.0", path = "../../embassy-usb", features = ["defmt"] }
14embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } 13embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
15 14
@@ -18,7 +17,7 @@ defmt-rtt = "1.0.0"
18 17
19cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } 18cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
20cortex-m-rt = "0.7.0" 19cortex-m-rt = "0.7.0"
21embedded-hal = "1.0.0" 20embedded-hal = "0.2.6"
22panic-probe = { version = "1.0.0", features = ["print-defmt"] } 21panic-probe = { version = "1.0.0", features = ["print-defmt"] }
23heapless = { version = "0.8", default-features = false } 22heapless = { version = "0.8", default-features = false }
24static_cell = "2" 23static_cell = "2"
diff --git a/examples/stm32wba/src/bin/usb_hs_serial.rs b/examples/stm32wba/src/bin/usb_hs_serial.rs
index 41440a940..2e17e52d1 100644
--- a/examples/stm32wba/src/bin/usb_hs_serial.rs
+++ b/examples/stm32wba/src/bin/usb_hs_serial.rs
@@ -2,17 +2,14 @@
2#![no_main] 2#![no_main]
3 3
4use defmt::{panic, *}; 4use defmt::{panic, *};
5use defmt_rtt as _; // global logger
6use embassy_executor::Spawner; 5use embassy_executor::Spawner;
7use embassy_futures::join::join; 6use embassy_futures::join::join;
8use embassy_stm32::rcc::{mux, AHB5Prescaler, AHBPrescaler, APBPrescaler, Hse, HsePrescaler, Sysclk, VoltageScale};
9use embassy_stm32::rcc::{PllDiv, PllMul, PllPreDiv, PllSource};
10use embassy_stm32::usb::{Driver, Instance}; 7use embassy_stm32::usb::{Driver, Instance};
11use embassy_stm32::{bind_interrupts, peripherals, usb, Config}; 8use embassy_stm32::{bind_interrupts, peripherals, usb, Config};
12use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; 9use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
13use embassy_usb::driver::EndpointError; 10use embassy_usb::driver::EndpointError;
14use embassy_usb::Builder; 11use embassy_usb::Builder;
15use panic_probe as _; 12use {defmt_rtt as _, panic_probe as _};
16 13
17bind_interrupts!(struct Irqs { 14bind_interrupts!(struct Irqs {
18 USB_OTG_HS => usb::InterruptHandler<peripherals::USB_OTG_HS>; 15 USB_OTG_HS => usb::InterruptHandler<peripherals::USB_OTG_HS>;
@@ -24,37 +21,44 @@ async fn main(_spawner: Spawner) {
24 21
25 let mut config = Config::default(); 22 let mut config = Config::default();
26 23
27 // External HSE (32 MHz) setup 24
28 // config.rcc.hse = Some(Hse { 25 {
29 // prescaler: HsePrescaler::DIV2, 26 use embassy_stm32::rcc::*;
30 // }); 27 // External HSE (32 MHz) setup
31 28 // config.rcc.hse = Some(Hse {
32 // Fine-tune PLL1 dividers/multipliers 29 // prescaler: HsePrescaler::DIV2,
33 config.rcc.pll1 = Some(embassy_stm32::rcc::Pll { 30 // });
34 source: PllSource::HSI, 31
35 prediv: PllPreDiv::DIV1, // PLLM = 1 → HSI / 1 = 16 MHz 32 // Fine-tune PLL1 dividers/multipliers
36 mul: PllMul::MUL30, // PLLN = 30 → 16 MHz * 30 = 480 MHz VCO 33 config.rcc.pll1 = Some(Pll {
37 divr: Some(PllDiv::DIV5), // PLLR = 5 → 96 MHz (Sysclk) 34 source: PllSource::HSI,
38 // divq: Some(PllDiv::DIV10), // PLLQ = 10 → 48 MHz (NOT USED) 35 prediv: PllPreDiv::DIV1, // PLLM = 1 → HSI / 1 = 16 MHz
39 divq: None, 36 mul: PllMul::MUL30, // PLLN = 30 → 16 MHz * 30 = 480 MHz VCO
40 divp: Some(PllDiv::DIV30), // PLLP = 30 → 16 MHz (USBOTG) 37 divr: Some(PllDiv::DIV5), // PLLR = 5 → 96 MHz (Sysclk)
41 frac: Some(0), // Fractional part (enabled) 38 divq: Some(PllDiv::DIV10), // PLLQ = 10 → 48 MHz (NOT USED)
42 }); 39 // divq: None,
43 40 divp: Some(PllDiv::DIV30), // PLLP = 30 → 16 MHz (USBOTG)
44 config.rcc.ahb_pre = AHBPrescaler::DIV1; 41 frac: Some(0), // Fractional part (enabled)
45 config.rcc.apb1_pre = APBPrescaler::DIV1; 42 });
46 config.rcc.apb2_pre = APBPrescaler::DIV1; 43
47 config.rcc.apb7_pre = APBPrescaler::DIV1; 44 config.rcc.ahb_pre = AHBPrescaler::DIV1;
48 config.rcc.ahb5_pre = AHB5Prescaler::DIV4; 45 config.rcc.apb1_pre = APBPrescaler::DIV1;
49 46 config.rcc.apb2_pre = APBPrescaler::DIV1;
50 // voltage scale for max performance 47 config.rcc.apb7_pre = APBPrescaler::DIV1;
51 config.rcc.voltage_scale = VoltageScale::RANGE1; 48 config.rcc.ahb5_pre = AHB5Prescaler::DIV4;
52 // route PLL1_P into the USB‐OTG‐HS block 49
53 config.rcc.mux.otghssel = mux::Otghssel::PLL1_P; 50 config.rcc.voltage_scale = VoltageScale::RANGE1;
54 config.rcc.sys = Sysclk::PLL1_R; 51 config.rcc.mux.otghssel = mux::Otghssel::PLL1_P;
52 config.rcc.sys = Sysclk::PLL1_R;
53 }
55 54
56 let p = embassy_stm32::init(config); 55 let p = embassy_stm32::init(config);
57 56
57 // TRDT set to 5
58 // ASVLD set to 1
59 // BSVLD set to 1
60
61
58 // Create the driver, from the HAL. 62 // Create the driver, from the HAL.
59 let mut ep_out_buffer = [0u8; 256]; 63 let mut ep_out_buffer = [0u8; 256];
60 let mut config = embassy_stm32::usb::Config::default(); 64 let mut config = embassy_stm32::usb::Config::default();