aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/modules/ROOT/pages/faq.adoc20
-rw-r--r--embassy-stm32/src/usb/otg.rs4
-rw-r--r--examples/stm32f4/src/bin/usb_ethernet.rs13
-rw-r--r--examples/stm32f4/src/bin/usb_hid_keyboard.rs14
-rw-r--r--examples/stm32f4/src/bin/usb_hid_mouse.rs13
-rw-r--r--examples/stm32f4/src/bin/usb_raw.rs13
-rw-r--r--examples/stm32f4/src/bin/usb_serial.rs13
-rw-r--r--examples/stm32f7/src/bin/usb_serial.rs13
-rw-r--r--examples/stm32h7/src/bin/usb_serial.rs13
-rw-r--r--examples/stm32l4/src/bin/usb_serial.rs13
10 files changed, 126 insertions, 3 deletions
diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc
index 0944127a5..6cb7233c1 100644
--- a/docs/modules/ROOT/pages/faq.adoc
+++ b/docs/modules/ROOT/pages/faq.adoc
@@ -232,6 +232,26 @@ Look for the `MEMORY` section and try to determine the FLASH and RAM sizes and s
232 232
233If you find a case where the memory.x is wrong, please report it on [this Github issue](https://github.com/embassy-rs/stm32-data/issues/301) so other users are not caught by surprise. 233If you find a case where the memory.x is wrong, please report it on [this Github issue](https://github.com/embassy-rs/stm32-data/issues/301) so other users are not caught by surprise.
234 234
235== The USB examples are not working on my board, is there anything else I need to configure?
236
237If you are trying out the USB examples and your device doesn not connect, the most common issues are listed below.
238
239=== Incorrect RCC config
240
241Check your board and crystal/oscillator, in particular make sure that `HSE` is set to the correct value, e.g. `8_000_000` Hertz if your board does indeed run on a 8 MHz oscillator.
242
243=== VBUS detection on STM32 platform
244
245The USB specification requires that all USB devices monitor the bus for detection of plugging/unplugging actions. The devices must pull-up the D+ or D- lane as soon as the host supplies VBUS.
246
247See the docs, for example at link:https://docs.embassy.dev/embassy-stm32/git/stm32f401vc/usb/struct.Config.html[`usb/struct.Config.html`] for information on how to enable/disable `vbus_detection`.
248
249When the device is powered only from the USB bus that simultaneously serves as the data connection, this is optional. (If there's no power in VBUS the device would be off anyway, so it's safe to always assume there's power in VBUS, i.e. the USB cable is always plugged in). If your device doesn't have the required connections in place to allow VBUS sensing (see below), then this option needs to be set to `false` to work.
250
251When the device is powered from another power source and therefore can stay powered through USB cable plug/unplug events, then this must be implemented and `vbus_detection` MUST be set to `true`.
252
253If your board is powered from the USB and you are unsure whether it supports `vbus_detection`, consult the schematics of your board to see if VBUS is connected to PA9 for USB Full Speed or PB13 for USB High Speed, vice versa, possibly with a voltage divider. When designing your own hardware, see ST application note AN4879 (in particular section 2.6) and the reference manual of your specific chip for more details.
254
235== Known issues (details and/or mitigations) 255== Known issues (details and/or mitigations)
236 256
237These are issues that are commonly reported. Help wanted fixing them, or improving the UX when possible! 257These are issues that are commonly reported. Help wanted fixing them, or improving the UX when possible!
diff --git a/embassy-stm32/src/usb/otg.rs b/embassy-stm32/src/usb/otg.rs
index b386c6977..29572d3c6 100644
--- a/embassy-stm32/src/usb/otg.rs
+++ b/embassy-stm32/src/usb/otg.rs
@@ -281,10 +281,10 @@ pub struct Config {
281 /// Enable VBUS detection. 281 /// Enable VBUS detection.
282 /// 282 ///
283 /// The USB spec requires USB devices monitor for USB cable plug/unplug and react accordingly. 283 /// The USB spec requires USB devices monitor for USB cable plug/unplug and react accordingly.
284 /// This is done by checkihg whether there is 5V on the VBUS pin or not. 284 /// This is done by checking whether there is 5V on the VBUS pin or not.
285 /// 285 ///
286 /// If your device is bus-powered (powers itself from the USB host via VBUS), then this is optional. 286 /// If your device is bus-powered (powers itself from the USB host via VBUS), then this is optional.
287 /// (if there's no power in VBUS your device would be off anyway, so it's fine to always assume 287 /// (If there's no power in VBUS your device would be off anyway, so it's fine to always assume
288 /// there's power in VBUS, i.e. the USB cable is always plugged in.) 288 /// there's power in VBUS, i.e. the USB cable is always plugged in.)
289 /// 289 ///
290 /// If your device is self-powered (i.e. it gets power from a source other than the USB cable, and 290 /// If your device is self-powered (i.e. it gets power from a source other than the USB cable, and
diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs
index d2cbeea1b..34e58f282 100644
--- a/examples/stm32f4/src/bin/usb_ethernet.rs
+++ b/examples/stm32f4/src/bin/usb_ethernet.rs
@@ -40,6 +40,11 @@ bind_interrupts!(struct Irqs {
40 HASH_RNG => rng::InterruptHandler<peripherals::RNG>; 40 HASH_RNG => rng::InterruptHandler<peripherals::RNG>;
41}); 41});
42 42
43// If you are trying this and your USB device doesn't connect, the most
44// common issues are the RCC config and vbus_detection
45//
46// See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
47// for more information.
43#[embassy_executor::main] 48#[embassy_executor::main]
44async fn main(spawner: Spawner) { 49async fn main(spawner: Spawner) {
45 info!("Hello World!"); 50 info!("Hello World!");
@@ -71,7 +76,15 @@ async fn main(spawner: Spawner) {
71 static OUTPUT_BUFFER: StaticCell<[u8; 256]> = StaticCell::new(); 76 static OUTPUT_BUFFER: StaticCell<[u8; 256]> = StaticCell::new();
72 let ep_out_buffer = &mut OUTPUT_BUFFER.init([0; 256])[..]; 77 let ep_out_buffer = &mut OUTPUT_BUFFER.init([0; 256])[..];
73 let mut config = embassy_stm32::usb::Config::default(); 78 let mut config = embassy_stm32::usb::Config::default();
79
80 // Enable vbus_detection
81 // Note: some boards don't have this wired up and might not require it,
82 // as they are powered through usb!
83 // If you hang on boot, try setting this to "false"!
84 // See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
85 // for more information
74 config.vbus_detection = true; 86 config.vbus_detection = true;
87
75 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer, config); 88 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer, config);
76 89
77 // Create embassy-usb Config 90 // Create embassy-usb Config
diff --git a/examples/stm32f4/src/bin/usb_hid_keyboard.rs b/examples/stm32f4/src/bin/usb_hid_keyboard.rs
index d6e0be5ea..7067d15a3 100644
--- a/examples/stm32f4/src/bin/usb_hid_keyboard.rs
+++ b/examples/stm32f4/src/bin/usb_hid_keyboard.rs
@@ -21,6 +21,11 @@ bind_interrupts!(struct Irqs {
21 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>; 21 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>;
22}); 22});
23 23
24// If you are trying this and your USB device doesn't connect, the most
25// common issues are the RCC config and vbus_detection
26//
27// See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
28// for more information.
24#[embassy_executor::main] 29#[embassy_executor::main]
25async fn main(_spawner: Spawner) { 30async fn main(_spawner: Spawner) {
26 let mut config = Config::default(); 31 let mut config = Config::default();
@@ -49,8 +54,15 @@ async fn main(_spawner: Spawner) {
49 // Create the driver, from the HAL. 54 // Create the driver, from the HAL.
50 let mut ep_out_buffer = [0u8; 256]; 55 let mut ep_out_buffer = [0u8; 256];
51 let mut config = embassy_stm32::usb::Config::default(); 56 let mut config = embassy_stm32::usb::Config::default();
52 // If the board you’re using doesn’t have the VBUS pin wired up correctly for detecting the USB bus voltage (e.g. on the f4 blackpill board), set this to false 57
58 // Enable vbus_detection
59 // Note: some boards don't have this wired up and might not require it,
60 // as they are powered through usb!
61 // If you hang on boot, try setting this to "false"!
62 // See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
63 // for more information
53 config.vbus_detection = true; 64 config.vbus_detection = true;
65
54 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config); 66 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config);
55 67
56 // Create embassy-usb Config 68 // Create embassy-usb Config
diff --git a/examples/stm32f4/src/bin/usb_hid_mouse.rs b/examples/stm32f4/src/bin/usb_hid_mouse.rs
index 0bc236119..0d04d2a9c 100644
--- a/examples/stm32f4/src/bin/usb_hid_mouse.rs
+++ b/examples/stm32f4/src/bin/usb_hid_mouse.rs
@@ -18,6 +18,11 @@ bind_interrupts!(struct Irqs {
18 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>; 18 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>;
19}); 19});
20 20
21// If you are trying this and your USB device doesn't connect, the most
22// common issues are the RCC config and vbus_detection
23//
24// See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
25// for more information.
21#[embassy_executor::main] 26#[embassy_executor::main]
22async fn main(_spawner: Spawner) { 27async fn main(_spawner: Spawner) {
23 let mut config = Config::default(); 28 let mut config = Config::default();
@@ -46,7 +51,15 @@ async fn main(_spawner: Spawner) {
46 // Create the driver, from the HAL. 51 // Create the driver, from the HAL.
47 let mut ep_out_buffer = [0u8; 256]; 52 let mut ep_out_buffer = [0u8; 256];
48 let mut config = embassy_stm32::usb::Config::default(); 53 let mut config = embassy_stm32::usb::Config::default();
54
55 // Enable vbus_detection
56 // Note: some boards don't have this wired up and might not require it,
57 // as they are powered through usb!
58 // If you hang on boot, try setting this to "false"!
59 // See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
60 // for more information
49 config.vbus_detection = true; 61 config.vbus_detection = true;
62
50 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config); 63 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config);
51 64
52 // Create embassy-usb Config 65 // Create embassy-usb Config
diff --git a/examples/stm32f4/src/bin/usb_raw.rs b/examples/stm32f4/src/bin/usb_raw.rs
index 4e583aeb8..d058abdd0 100644
--- a/examples/stm32f4/src/bin/usb_raw.rs
+++ b/examples/stm32f4/src/bin/usb_raw.rs
@@ -69,6 +69,11 @@ bind_interrupts!(struct Irqs {
69 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>; 69 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>;
70}); 70});
71 71
72// If you are trying this and your USB device doesn't connect, the most
73// common issues are the RCC config and vbus_detection
74//
75// See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
76// for more information.
72#[embassy_executor::main] 77#[embassy_executor::main]
73async fn main(_spawner: Spawner) { 78async fn main(_spawner: Spawner) {
74 info!("Hello World!"); 79 info!("Hello World!");
@@ -99,7 +104,15 @@ async fn main(_spawner: Spawner) {
99 // Create the driver, from the HAL. 104 // Create the driver, from the HAL.
100 let mut ep_out_buffer = [0u8; 256]; 105 let mut ep_out_buffer = [0u8; 256];
101 let mut config = embassy_stm32::usb::Config::default(); 106 let mut config = embassy_stm32::usb::Config::default();
107
108 // Enable vbus_detection
109 // Note: some boards don't have this wired up and might not require it,
110 // as they are powered through usb!
111 // If you hang on boot, try setting this to "false"!
112 // See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
113 // for more information
102 config.vbus_detection = true; 114 config.vbus_detection = true;
115
103 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config); 116 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config);
104 117
105 // Create embassy-usb Config 118 // Create embassy-usb Config
diff --git a/examples/stm32f4/src/bin/usb_serial.rs b/examples/stm32f4/src/bin/usb_serial.rs
index f3a375d31..25806dd85 100644
--- a/examples/stm32f4/src/bin/usb_serial.rs
+++ b/examples/stm32f4/src/bin/usb_serial.rs
@@ -16,6 +16,11 @@ bind_interrupts!(struct Irqs {
16 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>; 16 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>;
17}); 17});
18 18
19// If you are trying this and your USB device doesn't connect, the most
20// common issues are the RCC config and vbus_detection
21//
22// See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
23// for more information.
19#[embassy_executor::main] 24#[embassy_executor::main]
20async fn main(_spawner: Spawner) { 25async fn main(_spawner: Spawner) {
21 info!("Hello World!"); 26 info!("Hello World!");
@@ -46,7 +51,15 @@ async fn main(_spawner: Spawner) {
46 // Create the driver, from the HAL. 51 // Create the driver, from the HAL.
47 let mut ep_out_buffer = [0u8; 256]; 52 let mut ep_out_buffer = [0u8; 256];
48 let mut config = embassy_stm32::usb::Config::default(); 53 let mut config = embassy_stm32::usb::Config::default();
54
55 // Enable vbus_detection
56 // Note: some boards don't have this wired up and might not require it,
57 // as they are powered through usb!
58 // If you hang on boot, try setting this to "false"!
59 // See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
60 // for more information
49 config.vbus_detection = true; 61 config.vbus_detection = true;
62
50 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config); 63 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config);
51 64
52 // Create embassy-usb Config 65 // Create embassy-usb Config
diff --git a/examples/stm32f7/src/bin/usb_serial.rs b/examples/stm32f7/src/bin/usb_serial.rs
index 39a5512f4..2fee561c7 100644
--- a/examples/stm32f7/src/bin/usb_serial.rs
+++ b/examples/stm32f7/src/bin/usb_serial.rs
@@ -16,6 +16,11 @@ bind_interrupts!(struct Irqs {
16 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>; 16 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>;
17}); 17});
18 18
19// If you are trying this and your USB device doesn't connect, the most
20// common issues are the RCC config and vbus_detection
21//
22// See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
23// for more information.
19#[embassy_executor::main] 24#[embassy_executor::main]
20async fn main(_spawner: Spawner) { 25async fn main(_spawner: Spawner) {
21 info!("Hello World!"); 26 info!("Hello World!");
@@ -46,7 +51,15 @@ async fn main(_spawner: Spawner) {
46 // Create the driver, from the HAL. 51 // Create the driver, from the HAL.
47 let mut ep_out_buffer = [0u8; 256]; 52 let mut ep_out_buffer = [0u8; 256];
48 let mut config = embassy_stm32::usb::Config::default(); 53 let mut config = embassy_stm32::usb::Config::default();
54
55 // Enable vbus_detection
56 // Note: some boards don't have this wired up and might not require it,
57 // as they are powered through usb!
58 // If you hang on boot, try setting this to "false"!
59 // See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
60 // for more information
49 config.vbus_detection = true; 61 config.vbus_detection = true;
62
50 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config); 63 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config);
51 64
52 // Create embassy-usb Config 65 // Create embassy-usb Config
diff --git a/examples/stm32h7/src/bin/usb_serial.rs b/examples/stm32h7/src/bin/usb_serial.rs
index 576506ad3..872ff815c 100644
--- a/examples/stm32h7/src/bin/usb_serial.rs
+++ b/examples/stm32h7/src/bin/usb_serial.rs
@@ -15,6 +15,11 @@ bind_interrupts!(struct Irqs {
15 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>; 15 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>;
16}); 16});
17 17
18// If you are trying this and your USB device doesn't connect, the most
19// common issues are the RCC config and vbus_detection
20//
21// See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
22// for more information.
18#[embassy_executor::main] 23#[embassy_executor::main]
19async fn main(_spawner: Spawner) { 24async fn main(_spawner: Spawner) {
20 info!("Hello World!"); 25 info!("Hello World!");
@@ -47,7 +52,15 @@ async fn main(_spawner: Spawner) {
47 // Create the driver, from the HAL. 52 // Create the driver, from the HAL.
48 let mut ep_out_buffer = [0u8; 256]; 53 let mut ep_out_buffer = [0u8; 256];
49 let mut config = embassy_stm32::usb::Config::default(); 54 let mut config = embassy_stm32::usb::Config::default();
55
56 // Enable vbus_detection
57 // Note: some boards don't have this wired up and might not require it,
58 // as they are powered through usb!
59 // If you hang on boot, try setting this to "false"!
60 // See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
61 // for more information
50 config.vbus_detection = true; 62 config.vbus_detection = true;
63
51 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config); 64 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config);
52 65
53 // Create embassy-usb Config 66 // Create embassy-usb Config
diff --git a/examples/stm32l4/src/bin/usb_serial.rs b/examples/stm32l4/src/bin/usb_serial.rs
index 198504b59..b905fc66f 100644
--- a/examples/stm32l4/src/bin/usb_serial.rs
+++ b/examples/stm32l4/src/bin/usb_serial.rs
@@ -16,6 +16,11 @@ bind_interrupts!(struct Irqs {
16 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>; 16 OTG_FS => usb::InterruptHandler<peripherals::USB_OTG_FS>;
17}); 17});
18 18
19// If you are trying this and your USB device doesn't connect, the most
20// common issues are the RCC config and vbus_detection
21//
22// See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
23// for more information.
19#[embassy_executor::main] 24#[embassy_executor::main]
20async fn main(_spawner: Spawner) { 25async fn main(_spawner: Spawner) {
21 info!("Hello World!"); 26 info!("Hello World!");
@@ -41,7 +46,15 @@ async fn main(_spawner: Spawner) {
41 // Create the driver, from the HAL. 46 // Create the driver, from the HAL.
42 let mut ep_out_buffer = [0u8; 256]; 47 let mut ep_out_buffer = [0u8; 256];
43 let mut config = embassy_stm32::usb::Config::default(); 48 let mut config = embassy_stm32::usb::Config::default();
49
50 // Enable vbus_detection
51 // Note: some boards don't have this wired up and might not require it,
52 // as they are powered through usb!
53 // If you hang on boot, try setting this to "false"!
54 // See https://embassy.dev/book/dev/faq.html#_the_usb_examples_are_not_working_on_my_board_is_there_anything_else_i_need_to_configure
55 // for more information
44 config.vbus_detection = true; 56 config.vbus_detection = true;
57
45 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config); 58 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, &mut ep_out_buffer, config);
46 59
47 // Create embassy-usb Config 60 // Create embassy-usb Config