-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HAL: Add PMC, EFC configuration APIs #16
Closed
Closed
Changes from 2 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
4addd5d
manifest: increase internal feature flag granularity
tmplt c552e47
add pmc, efc modules from @jamesmunns's work
jamesmunns 1c8fcd2
move feature checking to a build.rs instead
tmplt d7e0f57
efc: find FWS via TryFrom impls
tmplt 7c5d8b6
hal: apply fmt
tmplt ecb51b5
features: separate device-selected master feature from MCU info
tmplt d77f43e
Add Voltage Level Checks To build.rs
martinmortsell 83de611
Fix Return Types
martinmortsell 3f1f25f
Add get_ Methods For All The Clocks (Except SLCK)
martinmortsell 762e919
efc: set VDDIO level via ctor instead of feature
tmplt be19501
build: ensure a chip feature is enabled
tmplt e42837e
pmc: Add Methods For Configuring Plla And Mck
martinmortsell 5d2dd11
Merge branch 'feat/pmc' of https://github.com/GrepitAB/atsams70-rust …
martinmortsell d8edfe1
pmc: Add Non-functional External Oscillator Support
martinmortsell daa8a2c
pmc: Fix Main Clock Selection
martinmortsell 9faca53
pmc: Add PCK Configuration
martinmortsell 14660e7
Update Documentation
martinmortsell 4ce66d6
pmc: Change Clock Source From Enum To Trait
martinmortsell 745c86a
Add get_slck() Method
martinmortsell 3d8af21
pmc: apply formatting
tmplt 41c83aa
boards/atsame70_xpro: init example skeleton
tmplt 6a614a8
boards/atsame70_xpro: doc how to erase fauly firmware
tmplt 465f7d7
pmc: improve get_mainck
tmplt c08d50f
hal/pmc: refer to PMC as pmc, instead of periph
tmplt 672c168
hal/pmc: add main crystal osc in normal mode back
tmplt d213282
hal/pmc: get_pllack: deconstruct PllaConfig
tmplt fef7e49
hal/pmc: refactor get_hclk
tmplt 0b5694b
hal/pmc: record clock freq for MAINCK, PLLACK, and HCLK
tmplt c47096b
hal/pmc: get_hclk: set EFC wait states before switching clocks
tmplt 451e3c1
hal/pmc: correctly configure UPLLCK and record its freq
tmplt 22c9964
hal/pmc: implement get_upllckdiv
tmplt e035fae
hal/pmc: use Hertz instead of Megahertz when logical
tmplt 2d4389c
hal/pmc: record SLCK freq
tmplt 5adcf9f
hal/pmc: remove unnecessary Results
tmplt dbe39b1
hal/pmc: handle unused_variables/dead_code warnings
tmplt b88ffd6
atsame70_xpro: apply example clock hierarchy configuration
tmplt 27f5bc0
hal/pmc: improve struct/enum docs
tmplt 0e6a9c5
hal/pmc: remove unused enum
tmplt dd1a9dc
hal/pmc: get_slck: remove impl details from docs
tmplt 009d478
hal/pmc: improve top-level docs
tmplt f74507d
atsame70_xpro: expose UPLLCKDIV on PCK2, @ 2.4MHz
tmplt 82a87de
hal/pmc: globalize magic values
tmplt 828299f
hal/pmc: apply formatting
tmplt b89177d
hal/pmc: refactor SCLK configuration to match MAINCK
tmplt d249979
hal/pmc: remove outdated comment
tmplt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,68 @@ | ||
//! Flash block configuration | ||
|
||
use crate::target_device::EFC; | ||
use crate::pmc::PmcError; | ||
|
||
pub struct Efc { | ||
pub(crate) periph: EFC, | ||
} | ||
|
||
impl Efc { | ||
pub fn new(periph: EFC) -> Self { | ||
periph.eefc_wpmr.modify(|_r, w| { | ||
w.wpkey().passwd(); | ||
w.wpen().clear_bit(); | ||
w | ||
}); | ||
|
||
Self { periph } | ||
} | ||
|
||
pub fn set_wait_states(&mut self, fws: FlashWaitStates) { | ||
let fws_bits = fws as u8; | ||
|
||
self.periph | ||
.eefc_fmr | ||
.modify(|_r, w| unsafe { w.fws().bits(fws_bits) }); | ||
} | ||
} | ||
|
||
/// The number of flash wait states for a read operation. | ||
/// | ||
/// Note: The number of cycles a read takes is 1 + FWS. | ||
#[derive(Debug, PartialEq, Copy, Clone)] | ||
#[repr(u8)] | ||
pub enum FlashWaitStates { | ||
Zero, | ||
One, | ||
Two, | ||
Three, | ||
Four, | ||
Five, | ||
Six, | ||
} | ||
|
||
impl FlashWaitStates { | ||
/// Calculate the lowest possible number of flash wait states from a given | ||
/// master clock frequency in MHz. | ||
/// | ||
/// The max mck frequency supported is 150MHz. This is *not* the CPU frequency, | ||
/// which may go up to 300MHz. | ||
/// | ||
/// Note: This is probably only valid at VDDIO = 3.0V | ||
pub fn from_mck_mhz(freq: u8) -> Result<Self, PmcError> { | ||
// Reference: Table 58-51 Embedded Flash Wait States for Worst-Case Conditions | ||
let fws = match freq { | ||
0..=23 => Self::Zero, | ||
24..=46 => Self::One, | ||
47..=69 => Self::Two, | ||
70..=92 => Self::Three, | ||
93..=115 => Self::Four, | ||
116..=138 => Self::Five, | ||
139..=150 => Self::Six, | ||
_ => return Err(PmcError::InvalidConfiguration), | ||
}; | ||
|
||
Ok(fws) | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you haven't seen the
cfg-if
crate, it's pretty handy for avoiding wordy cfgs like this.