2.16. Crystal Oscillator (XOSC)
2.16.1. Overview
The Crystal Oscillator (XOSC) uses an external crystal to produce an accurate reference clock. The RP2040 supports 1MHz to 15MHz crystals and the RP2040 reference design (see the Minimal Design Example in Hardware design with RP2040 ) uses a 12MHz crystal. The reference clock is distributed to the PLLs, which can be used to multiply the XOSC frequency to provide accurate high speed clocks. For example, they can generate a 48MHz clock which meets the frequency accuracy requirement of the USB interface and a 133MHz maximum speed system clock. The XOSC clock is also a clock source for the clock generators, so can be used directly if required.
If the user already has an accurate clock source then it is possible to drive an external clock directly into XIN (aka XI), and disable the oscillator circuit. In this mode XIN can be driven at up to 50MHz.
If the user wants to use the XOSC clock outside the RP2040 then it must be routed out to a GPIO via a clk_gpout clock generator. It is not recommended to take it directly from XIN (aka XI) or XOUT (aka XO).
Figure 33. XOSC overview

graph LR
Crystal[Crystal] --- XIN[XIN]
XOSC[XOSC] --- XOUT[XOUT]
XOSC --- Startup[Startup delay]
Startup --- Counter[counter]
Counter --> xosc_clkrc[xosc_clkrc]
CS[control & status] --- XOSC
CS --- Counter2.16.1.1. Recommended Crystals
For the best performance and stability across typical operating temperature ranges, it is recommended to use the Abracon ABM8-272-T3. You can source the ABM8-272-T3 directly from Abracon or from an authorised reseller. The Abracon ABM8-272-T3 has the following specifications:
Table 257. Key Crystal Specifications.
| Parameters | Minimum | Typical | Maximum | Units | Notes |
|---|---|---|---|---|---|
| Center Frequency | 12.000 | 12.000 | 12.000 | MHz | |
| Operation Mode | Fundamental-AT | Fundamental-AT | Fundamental-AT | ||
| Operating Temperature | -40 | +85 | °C | ||
| Storage Temperature | -55 | +125 | °C | ||
| Frequency Tolerance (25°C) | -30 | +30 | ppm | ||
| Frequency Stability (25°C) | -30 | +30 | ppm | ||
| Equivalent Series Resistance (R1) | 50 | Ω | |||
| Shunt Capacitance (C0) | 3.0 | pF | |||
| Load Capacitance (CL) | 10 | 10 | 10 | pF | |
| Drive Level | 10 | 200 | μW | ||
| Aging | -5 | +5 | ppm | @25±3°C, 1st year |
| Parameters | Minimum | Typical | Maximum | Units | Notes |
|---|---|---|---|---|---|
| Insulation Resistance | 500 | MΩ | @100Vdc±15V |
Even if you use a crystal with similar specifications, you will need to test the circuit over a range of temperatures to ensure stability.
The crystal oscillator is powered from the VDDIO voltage. As a result, the Abracon crystal and that particular damping resistor are tuned for 3.3V operation. If you use a different IO voltage, you will need to re-tune.
Any changes to crystal parameters risk instability across any components connected to the crystal circuit.
If you can't source the recommended crystal directly from Abracon or a reseller, contact applications@raspberrypi.com .
Raspberry Pi Pico has been specifically tuned for the specifications of the Abracon ABM8-272-T3 crystal. For an example of how to use a crystal with RP2040, see the Raspberry Pi Pico board schematic in Appendix B of the Raspberry Pi Pico Datasheet and the Raspberry Pi Pico design files .
2.16.2. Usage
The XOSC is disabled on chip startup and the RP2040 boots using the Ring Oscillator (ROSC). To start the XOSC, the programmer must set the CTRL_ENABLE register. The XOSC is not immediately usable because it takes time for the oscillations to build to sufficient amplitude. This time will be dependent on the chosen crystal but will be of the order of a few milliseconds. The XOSC incorporates a timer controlled by the STARTUP_DELAY register for automatically managing this and setting a flag (STATUS_STABLE) when the XOSC clock is usable.
2.16.3. Startup Delay
The STARTUP_DELAY register specifies how many clock cycles must be seen from the crystal before it can be used. This is specified in multiples of 256. The SDK
xosc_init function sets this value. The 1ms default is sufficient for the RP2040 reference design (see the Minimal Design Example in
Hardware design with RP2040
) which runs the XOSC at 12MHz. When the timer expires, the STATUS_STABLE flag will be set to indicate the XOSC output can be used.
Before starting the XOSC the programmer must ensure the STARTUP_DELAY register is correctly configured. The required value can be calculated by:
So with a 12MHz crystal and a 1ms wait time, the calculation is:
NOTE
The value is rounded up to the nearest integer so the wait time will be just over 1ms
2.16.4. XOSC Counter
The COUNT register provides a method of managing short software delays. Writing a value to the COUNT register automatically triggers it to start counting down to zero at the XOSC frequency. The programmer then simply polls the register until it reaches zero. This is preferable to using NOPs in software loops because it is independent of the core clock frequency, the compiler and the execution time of the compiled code.
2.16.5. DORMANT mode
In DORMANT mode (see Section 2.11.3 ) all of the on-chip clocks can be paused to save power. This is particularly useful in battery-powered applications. The RP2040 is woken from DORMANT mode by an interrupt either from an external event such as an edge on a GPIO pin or from the on-chip RTC. This must be configured before entering DORMANT mode. If the RTC is being used to trigger wake-up then it must be clocked from an external source. To enter DORMANT mode the programmer must then switch all internal clocks to be driven from XOSC or ROSC and stop the PLLs. Then a specific 32-bit value must be written to the DORMANT register in the chosen oscillator (XOSC or ROSC) to stop it oscillating. When exiting DORMANT mode the chosen oscillator will restart. If XOSC is chosen then the frequency will be more precise but the restart time is longer due to the startup delay (>1ms on the RP2040 reference design (see the Minimal Design Example in Hardware design with RP2040 )). If ROSC is chosen then the frequency is less precise but the start-up time is very short (approximately 1µs).
NOTE
The PLLs must be stopped before entering DORMANT mode
SDK: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_xosc/xosc.c Lines 56 - 63
56 void xosc_dormant(void) {
57 // WARNING: This stops the xosc until woken up by an irq
58 xosc_hw->dormant = XOSC_DORMANT_VALUE_DORMANT;
59 // Wait for it to become stable once woken up
60 while(!(xosc_hw->status & XOSC_STATUS_STABLE_BITS)) {
61 tight_loop_contents();
62 }
63 }
WARNING
If no IRQ is configured before going into DORMANT mode the XOSC or ROSC will never restart.
See Section 2.11.5.2 for a complete example of DORMANT mode using the XOSC.
2.16.6. Programmer's Model
SDK: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2040/hardware_structs/include/hardware/structs/xosc.h Lines 27 - 59
27 typedef struct {
28 _REG_(XOSC_CTRL_OFFSET) // XOSC_CTRL
29 // Crystal Oscillator Control
30 // 0x00fff000 [23:12] ENABLE (-) On power-up this field is initialised to DISABLE and
the...
31 // 0x0000fff [11:0] FREQ_RANGE (-) Frequency range
32 io_rw_32 ctrl;
33
34 _REG_(XOSC_STATUS_OFFSET) // XOSC_STATUS
35 // Crystal Oscillator Status
36 // 0x8000000 [31] STABLE (0) Oscillator is running and stable
37 // 0x0100000 [24] BADWRITE (0) An invalid value has been written to CTRL_ENABLE
or...
38 // 0x0001000 [12] ENABLED (-) Oscillator is enabled but not necessarily running
and...
39 // 0x0000003 [1:0] FREQ_RANGE (-) The current frequency range setting, always reads 0
40 io_rw_32 status;
41 }42 _REG_(XOSC_DORMANT_OFFSET) // XOSC_DORMANT 43 // Crystal Oscillator pause control 44 // 0xffffffff [31:0] DORMANT (-) This is used to save power by pausing the XOSC + 45 io_rw_32 dormant; 46 47 _REG_(XOSC_STARTUP_OFFSET) // XOSC_STARTUP 48 // Controls the startup delay 49 // 0x00100000 [20] X4 (-) Multiplies the startup_delay by 4 50 // 0x00003fff [13:0] DELAY (-) in multiples of 256*xtal_period 51 io_rw_32 startup; 52 53 uint32_t _pad0[3]; 54 55 _REG_(XOSC_COUNT_OFFSET) // XOSC_COUNT 56 // A down counter running at the XOSC frequency which counts to zero and stops. 57 // 0x000000ff [7:0] COUNT (0x00) 58 io_rw_32 count; 59 } xosc_hw_t;
SDK: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_xosc/xosc.c Lines 29 - 43
29 void xosc_init(void) {
30 // Assumes 1-15 MHz input, checked above.
31 xosc_hw->ctrl = XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ;
32
33 // Set xosc startup delay
34 xosc_hw->startup = STARTUP_DELAY;
35
36 // Set the enable bit now that we have set freq range and startup delay
37 hw_set_bits(&xosc_hw->ctrl, XOSC_CTRL_ENABLE_VALUE_ENABLE << XOSC_CTRL_ENABLE_LSB);
38
39 // Wait for XOSC to be stable
40 while(!(xosc_hw->status & XOSC_STATUS_STABLE_BITS)) {
41 tight_loop_contents();
42 }
43 }2.16.7. List of Registers
The XOSC registers start at a base address of 0x40024000 (defined as XOSC_BASE in SDK).
Table 258. List of XOSC registers
| Offset | Name | Info |
|---|---|---|
| 0x00 | CTRL | Crystal Oscillator Control |
| 0x04 | STATUS | Crystal Oscillator Status |
| 0x08 | DORMANT | Crystal Oscillator pause control |
| 0x0c | STARTUP | Controls the startup delay |
| 0x1c | COUNT | A down counter running at the XOSC frequency which counts to zero and stops. |
XOSC: CTRL Register
Offset: 0x00
DescriptionCrystal Oscillator Control
Table 259. CTRL Register
| Bits | Description | Type | Reset |
|---|---|---|---|
| 31:24 | Reserved. | - | - |
| 23:12 | ENABLE:
On power-up this field is initialised to DISABLE and the chip runs from the ROSC. If the chip has subsequently been programmed to run from the XOSC then setting this field to DISABLE may lock-up the chip. If this is a concern then run the clk_ref from the ROSC and enable the clk_sys RESUS feature. The 12-bit code is intended to give some protection against accidental writes. An invalid setting will enable the oscillator. | RW | - |
| Enumerated values: | |||
| 0xd1e → DISABLE | |||
| 0xfab → ENABLE | |||
| 11:0 | FREQ_RANGE: Frequency range. This resets to 0xAA0 and cannot be changed. | RW | - |
| Enumerated values: | |||
| 0xaa0 → 1_15MHZ | |||
| 0xaa1 → RESERVED_1 | |||
| 0xaa2 → RESERVED_2 | |||
| 0xaa3 → RESERVED_3 |
Offset: 0x04
DescriptionCrystal Oscillator Status
Table 260. STATUS Register
| Bits | Description | Type | Reset |
|---|---|---|---|
| 31 | STABLE: Oscillator is running and stable | RO | 0x0 |
| 30:25 | Reserved. | - | - |
| 24 | BADWRITE: An invalid value has been written to CTRL_ENABLE or CTRL_FREQ_RANGE or DORMANT | WC | 0x0 |
| 23:13 | Reserved. | - | - |
| 12 | ENABLED: Oscillator is enabled but not necessarily running and stable, resets to 0 | RO | - |
| 11:2 | Reserved. | - | - |
| 1:0 | FREQ_RANGE: The current frequency range setting, always reads 0 | RO | - |
| Enumerated values: | |||
| 0x0 → 1_15MHZ | |||
| 0x1 → RESERVED_1 | |||
| 0x2 → RESERVED_2 | |||
| 0x3 → RESERVED_3 |
XOSC: DORMANT Register
Offset: 0x08
Description
Crystal Oscillator pause control
Table 261. DORMANT Register
| Bits | Description | Type | Reset |
|---|---|---|---|
| 31:0 | This is used to save power by pausing the XOSC On power-up this field is initialised to WAKE An invalid write will also select WAKE WARNING: stop the PLLs before selecting dormant mode WARNING: setup the irq before selecting dormant mode | RW | - |
| Enumerated values: | |||
| 0x63f6d61 → DORMANT | |||
| 0x77616b65 → WAKE |
XOSC: STARTUP Register
Offset: 0x0c
Description
Controls the startup delay
Table 262. STARTUP Register
| Bits | Description | Type | Reset |
|---|---|---|---|
| 31:21 | Reserved. | - | - |
| 20 | X4 : Multiplies the startup_delay by 4. This is of little value to the user given that the delay can be programmed directly. | RW | 0x0 |
| 19:14 | Reserved. | - | - |
| 13:0 | DELAY : in multiples of 256*xtal_period. The reset value of 0xc4 corresponds to approx 50 000 cycles. | RW | 0x00c4 |
XOSC: COUNT Register
Offset: 0x1c
Table 263. COUNT Register
| Bits | Description | Type | Reset |
|---|---|---|---|
| 31:8 | Reserved. | - | - |
| 7:0 | A down counter running at the xosc frequency which counts to zero and stops. To start the counter write a non-zero value. Can be used for short software pauses when setting up time sensitive hardware. | RW | 0x00 |