mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-22 06:42:32 +00:00
Merge pull request #2677 from ExplodingWaffle/peri-clock
stm32/rcc: wait for peripheral clock to be active. also, hold the peripheral reset while enabling the clock.
This commit is contained in:
commit
6d9f87356b
@ -509,25 +509,20 @@ fn main() {
|
|||||||
if let Some(rcc) = &p.rcc {
|
if let Some(rcc) = &p.rcc {
|
||||||
let en = rcc.enable.as_ref().unwrap();
|
let en = rcc.enable.as_ref().unwrap();
|
||||||
|
|
||||||
let rst = match &rcc.reset {
|
let (start_rst, end_rst) = match &rcc.reset {
|
||||||
Some(rst) => {
|
Some(rst) => {
|
||||||
let rst_reg = format_ident!("{}", rst.register.to_ascii_lowercase());
|
let rst_reg = format_ident!("{}", rst.register.to_ascii_lowercase());
|
||||||
let set_rst_field = format_ident!("set_{}", rst.field.to_ascii_lowercase());
|
let set_rst_field = format_ident!("set_{}", rst.field.to_ascii_lowercase());
|
||||||
quote! {
|
(
|
||||||
crate::pac::RCC.#rst_reg().modify(|w| w.#set_rst_field(true));
|
quote! {
|
||||||
crate::pac::RCC.#rst_reg().modify(|w| w.#set_rst_field(false));
|
crate::pac::RCC.#rst_reg().modify(|w| w.#set_rst_field(true));
|
||||||
}
|
},
|
||||||
|
quote! {
|
||||||
|
crate::pac::RCC.#rst_reg().modify(|w| w.#set_rst_field(false));
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
None => TokenStream::new(),
|
None => (TokenStream::new(), TokenStream::new()),
|
||||||
};
|
|
||||||
|
|
||||||
let after_enable = if chip_name.starts_with("stm32f2") {
|
|
||||||
// Errata: ES0005 - 2.1.11 Delay after an RCC peripheral clock enabling
|
|
||||||
quote! {
|
|
||||||
cortex_m::asm::dsb();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
TokenStream::new()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let ptype = if let Some(reg) = &p.registers { reg.kind } else { "" };
|
let ptype = if let Some(reg) = &p.registers { reg.kind } else { "" };
|
||||||
@ -596,9 +591,22 @@ fn main() {
|
|||||||
fn enable_and_reset_with_cs(_cs: critical_section::CriticalSection) {
|
fn enable_and_reset_with_cs(_cs: critical_section::CriticalSection) {
|
||||||
#before_enable
|
#before_enable
|
||||||
#incr_stop_refcount
|
#incr_stop_refcount
|
||||||
|
|
||||||
|
#start_rst
|
||||||
|
|
||||||
crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(true));
|
crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(true));
|
||||||
#after_enable
|
|
||||||
#rst
|
// we must wait two peripheral clock cycles before the clock is active
|
||||||
|
// this seems to work, but might be incorrect
|
||||||
|
// see http://efton.sk/STM32/gotcha/g183.html
|
||||||
|
|
||||||
|
// dummy read (like in the ST HALs)
|
||||||
|
let _ = crate::pac::RCC.#en_reg().read();
|
||||||
|
|
||||||
|
// DSB for good measure
|
||||||
|
cortex_m::asm::dsb();
|
||||||
|
|
||||||
|
#end_rst
|
||||||
}
|
}
|
||||||
fn disable_with_cs(_cs: critical_section::CriticalSection) {
|
fn disable_with_cs(_cs: critical_section::CriticalSection) {
|
||||||
#before_disable
|
#before_disable
|
||||||
|
Loading…
Reference in New Issue
Block a user