From 018c48cf1ce54effe73f2287cb78fabbdede215c Mon Sep 17 00:00:00 2001
From: shufps <shufps80@gmail.com>
Date: Sun, 14 Jan 2024 22:43:22 +0100
Subject: [PATCH] changes to get usb working on a L1. Adds a usb_serial example
 too

---
 embassy-stm32/src/usb/usb.rs | 6 ++++++
 examples/stm32l1/Cargo.toml  | 1 +
 2 files changed, 7 insertions(+)

diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs
index 04b1b35e8..364076739 100644
--- a/embassy-stm32/src/usb/usb.rs
+++ b/embassy-stm32/src/usb/usb.rs
@@ -286,7 +286,10 @@ impl<'d, T: Instance> Driver<'d, T> {
         #[cfg(not(usb_v4))]
         regs.btable().write(|w| w.set_btable(0));
 
+        #[cfg(not(stm32l1))]
         dp.set_as_af(dp.af_num(), AFType::OutputPushPull);
+
+        #[cfg(not(stm32l1))]
         dm.set_as_af(dm.af_num(), AFType::OutputPushPull);
 
         // Initialize the bus so that it signals that power is available
@@ -444,6 +447,9 @@ impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> {
         #[cfg(any(usb_v3, usb_v4))]
         regs.bcdr().write(|w| w.set_dppu(true));
 
+        #[cfg(stm32l1)]
+        crate::pac::SYSCFG.pmc().modify(|w| w.set_usb_pu(true));
+
         trace!("enabled");
 
         let mut ep_types = [EpType::BULK; EP_COUNT - 1];
diff --git a/examples/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml
index c0b35b716..322c41262 100644
--- a/examples/stm32l1/Cargo.toml
+++ b/examples/stm32l1/Cargo.toml
@@ -9,6 +9,7 @@ embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["de
 embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
 embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
 embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = [ "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"]  }
+embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
 
 defmt = "0.3"
 defmt-rtt = "0.4"