-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use HSI48 and clock recovery system to clock USB
- Loading branch information
Showing
4 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::stm32::CRS; | ||
|
||
use super::Rcc; | ||
|
||
use crate::rcc::Enable; | ||
|
||
pub struct CrsConfig {} | ||
|
||
pub struct Crs { | ||
rb: CRS, | ||
} | ||
|
||
impl Crs { | ||
/// Sets up the clock recovery system for the HSI48 oscillator. | ||
/// TODO: make this configurable for more than just USB applications. | ||
pub fn configure(self, crs_config: CrsConfig, rcc: &Rcc) -> Self { | ||
// TODO: This needs to ensure that the HSI48 is enabled | ||
// and then setup the CRS. For now this just needs to use | ||
// the USB sync as the trigger system. | ||
|
||
rcc.enable_hsi48(); | ||
|
||
// Enable the clock recovery system | ||
CRS::enable(&rcc.rb); | ||
|
||
// Set to b10 for USB SOF as source | ||
self.rb | ||
.cfgr | ||
.modify(|_, w| unsafe { w.syncsrc().bits(0b10) }); | ||
|
||
self.rb.cr.modify(|_, w| { | ||
// Set autotrim enabled. | ||
w.autotrimen().set_bit(); | ||
// Enable CRS | ||
w.cen().set_bit() | ||
}); | ||
|
||
self | ||
} | ||
} | ||
|
||
pub trait CrsExt { | ||
/// Constrains the `CRS` peripheral so that it can only be setup once. | ||
fn constrain(self) -> Crs; | ||
} | ||
|
||
impl CrsExt for CRS { | ||
fn constrain(self) -> Crs { | ||
Crs { rb: self } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters