diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-03-18 16:23:28 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-03-18 16:23:28 +0000 |
| commit | 6d9f87356bb523de6a17fc380f23c04ee66b38ce (patch) | |
| tree | 6e6f888d2359ed60d1db37124b1e2d22524c5e2e | |
| parent | bd4cb82945112ecb847456a3b0b04163341e44fd (diff) | |
| parent | 1f9ffbfb18efb1cdf6f6696b8a9339e72eea05f2 (diff) | |
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.
| -rw-r--r-- | embassy-stm32/build.rs | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 40641a506..fe5236ed6 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -509,25 +509,20 @@ fn main() { | |||
| 509 | if let Some(rcc) = &p.rcc { | 509 | if let Some(rcc) = &p.rcc { |
| 510 | let en = rcc.enable.as_ref().unwrap(); | 510 | let en = rcc.enable.as_ref().unwrap(); |
| 511 | 511 | ||
| 512 | let rst = match &rcc.reset { | 512 | let (start_rst, end_rst) = match &rcc.reset { |
| 513 | Some(rst) => { | 513 | Some(rst) => { |
| 514 | let rst_reg = format_ident!("{}", rst.register.to_ascii_lowercase()); | 514 | let rst_reg = format_ident!("{}", rst.register.to_ascii_lowercase()); |
| 515 | let set_rst_field = format_ident!("set_{}", rst.field.to_ascii_lowercase()); | 515 | let set_rst_field = format_ident!("set_{}", rst.field.to_ascii_lowercase()); |
| 516 | quote! { | 516 | ( |
| 517 | crate::pac::RCC.#rst_reg().modify(|w| w.#set_rst_field(true)); | 517 | quote! { |
| 518 | crate::pac::RCC.#rst_reg().modify(|w| w.#set_rst_field(false)); | 518 | crate::pac::RCC.#rst_reg().modify(|w| w.#set_rst_field(true)); |
| 519 | } | 519 | }, |
| 520 | quote! { | ||
| 521 | crate::pac::RCC.#rst_reg().modify(|w| w.#set_rst_field(false)); | ||
| 522 | }, | ||
| 523 | ) | ||
| 520 | } | 524 | } |
| 521 | None => TokenStream::new(), | 525 | None => (TokenStream::new(), TokenStream::new()), |
| 522 | }; | ||
| 523 | |||
| 524 | let after_enable = if chip_name.starts_with("stm32f2") { | ||
| 525 | // Errata: ES0005 - 2.1.11 Delay after an RCC peripheral clock enabling | ||
| 526 | quote! { | ||
| 527 | cortex_m::asm::dsb(); | ||
| 528 | } | ||
| 529 | } else { | ||
| 530 | TokenStream::new() | ||
| 531 | }; | 526 | }; |
| 532 | 527 | ||
| 533 | let ptype = if let Some(reg) = &p.registers { reg.kind } else { "" }; | 528 | let ptype = if let Some(reg) = &p.registers { reg.kind } else { "" }; |
| @@ -596,9 +591,22 @@ fn main() { | |||
| 596 | fn enable_and_reset_with_cs(_cs: critical_section::CriticalSection) { | 591 | fn enable_and_reset_with_cs(_cs: critical_section::CriticalSection) { |
| 597 | #before_enable | 592 | #before_enable |
| 598 | #incr_stop_refcount | 593 | #incr_stop_refcount |
| 594 | |||
| 595 | #start_rst | ||
| 596 | |||
| 599 | crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(true)); | 597 | crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(true)); |
| 600 | #after_enable | 598 | |
| 601 | #rst | 599 | // we must wait two peripheral clock cycles before the clock is active |
| 600 | // this seems to work, but might be incorrect | ||
| 601 | // see http://efton.sk/STM32/gotcha/g183.html | ||
| 602 | |||
| 603 | // dummy read (like in the ST HALs) | ||
| 604 | let _ = crate::pac::RCC.#en_reg().read(); | ||
| 605 | |||
| 606 | // DSB for good measure | ||
| 607 | cortex_m::asm::dsb(); | ||
| 608 | |||
| 609 | #end_rst | ||
| 602 | } | 610 | } |
| 603 | fn disable_with_cs(_cs: critical_section::CriticalSection) { | 611 | fn disable_with_cs(_cs: critical_section::CriticalSection) { |
| 604 | #before_disable | 612 | #before_disable |
