aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32l4/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-05-04 01:00:38 +0200
committerDario Nieuwenhuis <[email protected]>2022-05-04 01:41:37 +0200
commitfc32b3750c448a81b7dd44cf9de98723b8eb4fcf (patch)
tree989562f5750d28ab11732633839db8f25a1ad773 /examples/stm32l4/src
parent85c0525e01c52bbb85c7b93600a60837ee7b87dc (diff)
Remove embassy_hal_common::usb.
The replacement is `embassy-usb`. There's a WIP driver for stm32 USBD in #709, there's no WIP driver for stm32 USB_OTG. This means we're left without USB_OTG support for now. Reason for removing is I'm going to soon remove `embassy::io`, and USB uses it. I don't want to spend time maintaining "dead" code that is going to be removed. Volunteers welcome, either to update old USB to the new IO, or write a USB_OTG driver fo the new USB.
Diffstat (limited to 'examples/stm32l4/src')
-rw-r--r--examples/stm32l4/src/bin/usb_uart.rs115
1 files changed, 0 insertions, 115 deletions
diff --git a/examples/stm32l4/src/bin/usb_uart.rs b/examples/stm32l4/src/bin/usb_uart.rs
deleted file mode 100644
index 878309550..000000000
--- a/examples/stm32l4/src/bin/usb_uart.rs
+++ /dev/null
@@ -1,115 +0,0 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt_rtt as _; // global logger
6use panic_probe as _;
7
8use defmt::{info, unwrap};
9use defmt_rtt as _; // global logger
10use embassy::interrupt::InterruptExt;
11use futures::pin_mut;
12use panic_probe as _; // print out panic messages
13
14use embassy::executor::Spawner;
15use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
16use embassy_stm32::pac::pwr::vals::Usv;
17use embassy_stm32::pac::{PWR, RCC};
18use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv};
19use embassy_stm32::usb_otg::{State, Usb, UsbBus, UsbOtg, UsbSerial};
20use embassy_stm32::{interrupt, Config, Peripherals};
21use usb_device::device::{UsbDeviceBuilder, UsbVidPid};
22
23static mut EP_MEMORY: [u32; 2048] = [0; 2048];
24
25// USB requires at least 48 MHz clock
26fn config() -> Config {
27 let mut config = Config::default();
28 // set up a 80Mhz clock
29 config.rcc.mux = ClockSrc::PLL(
30 PLLSource::HSI16,
31 PLLClkDiv::Div2,
32 PLLSrcDiv::Div2,
33 PLLMul::Mul20,
34 None,
35 );
36 // enable HSI48 clock for USB
37 config.rcc.hsi48 = true;
38 config
39}
40
41#[embassy::main(config = "config()")]
42async fn main(_spawner: Spawner, p: Peripherals) {
43 // Enable PWR peripheral
44 unsafe { RCC.apb1enr1().modify(|w| w.set_pwren(true)) };
45 unsafe { PWR.cr2().modify(|w| w.set_usv(Usv::VALID)) }
46
47 let mut rx_buffer = [0u8; 64];
48 // we send back input + cr + lf
49 let mut tx_buffer = [0u8; 66];
50
51 let peri = UsbOtg::new_fs(p.USB_OTG_FS, p.PA12, p.PA11);
52 let usb_bus = UsbBus::new(peri, unsafe { &mut EP_MEMORY });
53
54 let serial = UsbSerial::new(&usb_bus, &mut rx_buffer, &mut tx_buffer);
55
56 let device = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
57 .manufacturer("Fake company")
58 .product("Serial port")
59 .serial_number("TEST")
60 .device_class(0x02)
61 .build();
62
63 let irq = interrupt::take!(OTG_FS);
64 irq.set_priority(interrupt::Priority::P3);
65
66 let mut state = State::new();
67 let usb = unsafe { Usb::new(&mut state, device, serial, irq) };
68 pin_mut!(usb);
69
70 let (mut reader, mut writer) = usb.as_ref().take_serial_0();
71
72 info!("usb initialized!");
73
74 unwrap!(
75 writer
76 .write_all(b"\r\nInput returned upper cased on CR+LF\r\n")
77 .await
78 );
79
80 let mut buf = [0u8; 64];
81 loop {
82 let mut n = 0;
83
84 async {
85 loop {
86 let char = unwrap!(reader.read_byte().await);
87
88 if char == b'\r' || char == b'\n' {
89 break;
90 }
91
92 buf[n] = char;
93 n += 1;
94
95 // stop if we're out of room
96 if n == buf.len() {
97 break;
98 }
99 }
100 }
101 .await;
102
103 if n > 0 {
104 for char in buf[..n].iter_mut() {
105 // upper case
106 if 0x61 <= *char && *char <= 0x7a {
107 *char &= !0x20;
108 }
109 }
110 unwrap!(writer.write_all(&buf[..n]).await);
111 unwrap!(writer.write_all(b"\r\n").await);
112 unwrap!(writer.flush().await);
113 }
114 }
115}