diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-05-17 01:04:13 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-05-17 01:04:13 +0200 |
| commit | 35d05a4214e035bbb6da380c38c0a90b285887f2 (patch) | |
| tree | de9f18e1f858e62b03c0c465135bea3f57d926ac /embassy-rp/src | |
| parent | cd4111736c0384b1ef957df7f6aa51e3727c29b2 (diff) | |
| parent | a5ad79927ecaa9d6cd7bd96e015b66afa9201d84 (diff) | |
Merge pull request #174 from embassy-rs/nrf-neo
nRF-neo
Diffstat (limited to 'embassy-rp/src')
| -rw-r--r-- | embassy-rp/src/lib.rs | 103 | ||||
| -rw-r--r-- | embassy-rp/src/system.rs | 94 |
2 files changed, 102 insertions, 95 deletions
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index f64464d13..f1a045987 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs | |||
| @@ -15,7 +15,6 @@ pub mod dma; | |||
| 15 | pub mod gpio; | 15 | pub mod gpio; |
| 16 | pub mod pll; | 16 | pub mod pll; |
| 17 | pub mod resets; | 17 | pub mod resets; |
| 18 | pub mod system; | ||
| 19 | pub mod uart; | 18 | pub mod uart; |
| 20 | 19 | ||
| 21 | embassy_extras::peripherals! { | 20 | embassy_extras::peripherals! { |
| @@ -72,3 +71,105 @@ embassy_extras::peripherals! { | |||
| 72 | DMA_CH10, | 71 | DMA_CH10, |
| 73 | DMA_CH11, | 72 | DMA_CH11, |
| 74 | } | 73 | } |
| 74 | |||
| 75 | #[link_section = ".boot2"] | ||
| 76 | #[used] | ||
| 77 | static BOOT2: [u8; 256] = *include_bytes!("boot2.bin"); | ||
| 78 | |||
| 79 | pub mod config { | ||
| 80 | #[non_exhaustive] | ||
| 81 | pub struct Config {} | ||
| 82 | |||
| 83 | impl Default for Config { | ||
| 84 | fn default() -> Self { | ||
| 85 | Self {} | ||
| 86 | } | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | pub fn init(config: config::Config) -> Peripherals { | ||
| 91 | // Do this first, so that it panics if user is calling `init` a second time | ||
| 92 | // before doing anything important. | ||
| 93 | let peripherals = Peripherals::take(); | ||
| 94 | |||
| 95 | // Now reset all the peripherals, except QSPI and XIP (we're using those | ||
| 96 | // to execute from external flash!) | ||
| 97 | |||
| 98 | let resets = resets::Resets::new(); | ||
| 99 | |||
| 100 | // Reset everything except: | ||
| 101 | // - QSPI (we're using it to run this code!) | ||
| 102 | // - PLLs (it may be suicide if that's what's clocking us) | ||
| 103 | let mut peris = resets::ALL_PERIPHERALS; | ||
| 104 | peris.set_io_qspi(false); | ||
| 105 | peris.set_pads_qspi(false); | ||
| 106 | peris.set_pll_sys(false); | ||
| 107 | peris.set_pll_usb(false); | ||
| 108 | resets.reset(peris); | ||
| 109 | |||
| 110 | let mut peris = resets::ALL_PERIPHERALS; | ||
| 111 | peris.set_adc(false); | ||
| 112 | peris.set_rtc(false); | ||
| 113 | peris.set_spi0(false); | ||
| 114 | peris.set_spi1(false); | ||
| 115 | peris.set_uart0(false); | ||
| 116 | peris.set_uart1(false); | ||
| 117 | peris.set_usbctrl(false); | ||
| 118 | resets.unreset_wait(peris); | ||
| 119 | |||
| 120 | unsafe { | ||
| 121 | // xosc 12 mhz | ||
| 122 | pac::WATCHDOG.tick().write(|w| { | ||
| 123 | w.set_cycles(XOSC_MHZ as u16); | ||
| 124 | w.set_enable(true); | ||
| 125 | }); | ||
| 126 | |||
| 127 | pac::CLOCKS | ||
| 128 | .clk_sys_resus_ctrl() | ||
| 129 | .write_value(pac::clocks::regs::ClkSysResusCtrl(0)); | ||
| 130 | |||
| 131 | // Enable XOSC | ||
| 132 | // TODO extract to HAL module | ||
| 133 | const XOSC_MHZ: u32 = 12; | ||
| 134 | pac::XOSC | ||
| 135 | .ctrl() | ||
| 136 | .write(|w| w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ)); | ||
| 137 | |||
| 138 | let startup_delay = (((XOSC_MHZ * 1_000_000) / 1000) + 128) / 256; | ||
| 139 | pac::XOSC | ||
| 140 | .startup() | ||
| 141 | .write(|w| w.set_delay(startup_delay as u16)); | ||
| 142 | pac::XOSC.ctrl().write(|w| { | ||
| 143 | w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ); | ||
| 144 | w.set_enable(pac::xosc::vals::CtrlEnable::ENABLE); | ||
| 145 | }); | ||
| 146 | while !pac::XOSC.status().read().stable() {} | ||
| 147 | |||
| 148 | // Before we touch PLLs, switch sys and ref cleanly away from their aux sources. | ||
| 149 | pac::CLOCKS | ||
| 150 | .clk_sys_ctrl() | ||
| 151 | .modify(|w| w.set_src(pac::clocks::vals::ClkSysCtrlSrc::CLK_REF)); | ||
| 152 | while pac::CLOCKS.clk_sys_selected().read() != 1 {} | ||
| 153 | pac::CLOCKS | ||
| 154 | .clk_ref_ctrl() | ||
| 155 | .modify(|w| w.set_src(pac::clocks::vals::ClkRefCtrlSrc::ROSC_CLKSRC_PH)); | ||
| 156 | while pac::CLOCKS.clk_ref_selected().read() != 1 {} | ||
| 157 | |||
| 158 | let mut peris = resets::Peripherals(0); | ||
| 159 | peris.set_pll_sys(true); | ||
| 160 | peris.set_pll_usb(true); | ||
| 161 | resets.reset(peris); | ||
| 162 | resets.unreset_wait(peris); | ||
| 163 | |||
| 164 | pll::PLL::new(pll::PllSys).configure(1, 1500_000_000, 6, 2); | ||
| 165 | pll::PLL::new(pll::PllUsb).configure(1, 480_000_000, 5, 2); | ||
| 166 | |||
| 167 | // Activate peripheral clock and take external oscillator as input | ||
| 168 | pac::CLOCKS.clk_peri_ctrl().write(|w| { | ||
| 169 | w.set_enable(true); | ||
| 170 | w.set_auxsrc(pac::clocks::vals::ClkPeriCtrlAuxsrc::XOSC_CLKSRC); | ||
| 171 | }); | ||
| 172 | } | ||
| 173 | |||
| 174 | peripherals | ||
| 175 | } | ||
diff --git a/embassy-rp/src/system.rs b/embassy-rp/src/system.rs deleted file mode 100644 index ba1396433..000000000 --- a/embassy-rp/src/system.rs +++ /dev/null | |||
| @@ -1,94 +0,0 @@ | |||
| 1 | use crate::{pac, pll, resets}; | ||
| 2 | |||
| 3 | #[link_section = ".boot2"] | ||
| 4 | #[used] | ||
| 5 | pub static BOOT2: [u8; 256] = *include_bytes!("boot2.bin"); | ||
| 6 | |||
| 7 | #[non_exhaustive] | ||
| 8 | pub struct Config {} | ||
| 9 | |||
| 10 | impl Default for Config { | ||
| 11 | fn default() -> Self { | ||
| 12 | Self {} | ||
| 13 | } | ||
| 14 | } | ||
| 15 | |||
| 16 | /// safety: must only call once. | ||
| 17 | pub unsafe fn configure(_config: Config) { | ||
| 18 | // Now reset all the peripherals, except QSPI and XIP (we're using those | ||
| 19 | // to execute from external flash!) | ||
| 20 | |||
| 21 | let resets = resets::Resets::new(); | ||
| 22 | |||
| 23 | // Reset everything except: | ||
| 24 | // - QSPI (we're using it to run this code!) | ||
| 25 | // - PLLs (it may be suicide if that's what's clocking us) | ||
| 26 | let mut peris = resets::ALL_PERIPHERALS; | ||
| 27 | peris.set_io_qspi(false); | ||
| 28 | peris.set_pads_qspi(false); | ||
| 29 | peris.set_pll_sys(false); | ||
| 30 | peris.set_pll_usb(false); | ||
| 31 | resets.reset(peris); | ||
| 32 | |||
| 33 | let mut peris = resets::ALL_PERIPHERALS; | ||
| 34 | peris.set_adc(false); | ||
| 35 | peris.set_rtc(false); | ||
| 36 | peris.set_spi0(false); | ||
| 37 | peris.set_spi1(false); | ||
| 38 | peris.set_uart0(false); | ||
| 39 | peris.set_uart1(false); | ||
| 40 | peris.set_usbctrl(false); | ||
| 41 | resets.unreset_wait(peris); | ||
| 42 | |||
| 43 | // xosc 12 mhz | ||
| 44 | pac::WATCHDOG.tick().write(|w| { | ||
| 45 | w.set_cycles(XOSC_MHZ as u16); | ||
| 46 | w.set_enable(true); | ||
| 47 | }); | ||
| 48 | |||
| 49 | pac::CLOCKS | ||
| 50 | .clk_sys_resus_ctrl() | ||
| 51 | .write_value(pac::clocks::regs::ClkSysResusCtrl(0)); | ||
| 52 | |||
| 53 | // Enable XOSC | ||
| 54 | // TODO extract to HAL module | ||
| 55 | const XOSC_MHZ: u32 = 12; | ||
| 56 | pac::XOSC | ||
| 57 | .ctrl() | ||
| 58 | .write(|w| w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ)); | ||
| 59 | |||
| 60 | let startup_delay = (((XOSC_MHZ * 1_000_000) / 1000) + 128) / 256; | ||
| 61 | pac::XOSC | ||
| 62 | .startup() | ||
| 63 | .write(|w| w.set_delay(startup_delay as u16)); | ||
| 64 | pac::XOSC.ctrl().write(|w| { | ||
| 65 | w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ); | ||
| 66 | w.set_enable(pac::xosc::vals::CtrlEnable::ENABLE); | ||
| 67 | }); | ||
| 68 | while !pac::XOSC.status().read().stable() {} | ||
| 69 | |||
| 70 | // Before we touch PLLs, switch sys and ref cleanly away from their aux sources. | ||
| 71 | pac::CLOCKS | ||
| 72 | .clk_sys_ctrl() | ||
| 73 | .modify(|w| w.set_src(pac::clocks::vals::ClkSysCtrlSrc::CLK_REF)); | ||
| 74 | while pac::CLOCKS.clk_sys_selected().read() != 1 {} | ||
| 75 | pac::CLOCKS | ||
| 76 | .clk_ref_ctrl() | ||
| 77 | .modify(|w| w.set_src(pac::clocks::vals::ClkRefCtrlSrc::ROSC_CLKSRC_PH)); | ||
| 78 | while pac::CLOCKS.clk_ref_selected().read() != 1 {} | ||
| 79 | |||
| 80 | let mut peris = resets::Peripherals(0); | ||
| 81 | peris.set_pll_sys(true); | ||
| 82 | peris.set_pll_usb(true); | ||
| 83 | resets.reset(peris); | ||
| 84 | resets.unreset_wait(peris); | ||
| 85 | |||
| 86 | pll::PLL::new(pll::PllSys).configure(1, 1500_000_000, 6, 2); | ||
| 87 | pll::PLL::new(pll::PllUsb).configure(1, 480_000_000, 5, 2); | ||
| 88 | |||
| 89 | // Activate peripheral clock and take external oscillator as input | ||
| 90 | pac::CLOCKS.clk_peri_ctrl().write(|w| { | ||
| 91 | w.set_enable(true); | ||
| 92 | w.set_auxsrc(pac::clocks::vals::ClkPeriCtrlAuxsrc::XOSC_CLKSRC); | ||
| 93 | }); | ||
| 94 | } | ||
