2.17. Ring Oscillator (ROSC)

2.17.1. Overview

The Ring Oscillator (ROSC) is an on-chip oscillator built from a ring of inverters. It requires no external components and is started automatically during RP2040 power up. It provides the clock to the cores during boot. The frequency of the

ROSC is programmable and it can directly provide a high speed clock to the cores, but the frequency varies with Process, Voltage and Temperature (PVT) so it cannot provide clocks for components which require an accurate frequency such as the RTC, USB and ADC. Methods for mitigating the frequency variation are discussed in Section 2.15 but these are only relevant to very low power design. For most applications requiring accurate clock frequencies it is recommended to switch to the XOSC and PLLs. During boot the ROSC runs at a nominal 6.5MHz and is guaranteed to be in the range 1.8MHz to 12MHz.

Once the chip has booted the programmer can choose to continue running from the ROSC and increase its frequency or start the Crystal Oscillator (XOSC) and PLLs. The ROSC can be disabled after the system clocks have been switched to the XOSC. Each oscillator has advantages and the programmer can switch between them to achieve the best solution for the application.

Figure 34. ROSC overview.

Figure 34: ROSC overview block diagram. The diagram shows a central 'control & status' block at the bottom. Above it are four main functional blocks: 'ROSC', 'divider', 'random bit', and 'counter'. The 'ROSC' block is connected to the 'divider' block. The 'divider' block is connected to the 'random bit' and 'counter' blocks. The 'random bit' block is connected to the 'counter' block. The 'counter' block is connected to a 'phase shift' block. The 'phase shift' block is connected to the 'divider' block. The 'divider' block has two output lines: 'rosc_clksrc' and 'rosc_clksrc_ph'.
graph TD
    ROSC[ROSC] --- divider[divider]
    divider --- random_bit[random bit]
    divider --- counter[counter]
    random_bit --- counter
    counter --- phase_shift[phase shift]
    phase_shift --- divider
    divider --- rosc_clksrc[rosc_clksrc]
    divider --- rosc_clksrc_ph[rosc_clksrc_ph]
    control_status[control & status]
    ROSC --- control_status
    divider --- control_status
    random_bit --- control_status
    counter --- control_status
    phase_shift --- control_status
  
Figure 34: ROSC overview block diagram. The diagram shows a central 'control & status' block at the bottom. Above it are four main functional blocks: 'ROSC', 'divider', 'random bit', and 'counter'. The 'ROSC' block is connected to the 'divider' block. The 'divider' block is connected to the 'random bit' and 'counter' blocks. The 'random bit' block is connected to the 'counter' block. The 'counter' block is connected to a 'phase shift' block. The 'phase shift' block is connected to the 'divider' block. The 'divider' block has two output lines: 'rosc_clksrc' and 'rosc_clksrc_ph'.

2.17.2. ROSC/XOSC trade-offs

The advantages of the ROSC are its flexibility and its low power. Also, there is no requirement for internal or external components when using the ROSC to provide clocks. Its frequency is programmable so it can be used to provide a fast core clock without starting the PLLs and can be divided by clock generators ( Section 2.15 ) to generate slower peripheral clocks. The ROSC starts immediately and responds immediately to the frequency controls. It will retain the frequency setting when entering and exiting the DORMANT state (see Section 2.11.3 ). However, the user must be aware that the frequency may have drifted when exiting the DORMANT state due to changes in the supply voltage and the chip temperature.

The disadvantage of the ROSC is its frequency variation with PVT (Process, Voltage & Temperature) which makes it unsuitable for generating precise clocks or for applications where software execution timing is important. However, the PVT frequency variation can be exploited to provide automatic frequency scaling to maximise performance. This is discussed in Section 2.15 .

The only advantage of the XOSC is its accurate frequency, but this is an overriding requirement in many applications.

The disadvantages of the XOSC are its requirement for external components (a crystal etc), its higher power consumption, slow startup time (>1ms) and fixed, low frequency. PLLs are required to produce higher frequency clocks. They consume more power and take significant time to start up and to change frequency. Exiting DORMANT mode is much slower than for ROSC because the XOSC must be restarted and the PLLs must be reconfigured.

2.17.3. Modifying the frequency

The ROSC is arranged as 8 stages, each with programmable drive. There are 2 methods of controlling the frequency. The frequency range controls the number of stages in the ROSC loop and the FREQA & FREQB registers control the drive strength of the stages.

The frequency range is changed by writing to the FREQ_RANGE register which controls the number of stages in the ROSC loop. The default LOW range has 8 (stages 0-7), MEDIUM has 6 (stages 2-7), HIGH has 4 (stages 4-7) and TOOHIGH has 2 (stages 6-7). It is recommended to change FREQ_RANGE one step at a time until the desired range is reached. The ROSC output will not glitch when increasing the frequency range, so the output clock can continue to be used. However, that is not true when going back down the frequency range. An alternate clock source must be selected for the modules clocked by ROSC, or they must be held in reset during the transition. The behaviour has not been fully characterised but the MEDIUM range will be approximately 1.33 times the LOW RANGE, the HIGH range will be 2 times

the LOW range and the TOOHIGH range will be 4 times the LOW range. The TOOHIGH range is aptly named. It should not be used because the internal logic of the ROSC will not run at that frequency.

The FREQA & FREQB registers control the drive strength of the stages in the ROSC loop. Increasing the drive strength reduces the delay through the stage and increases the oscillation frequency. Each stage has 3 drive strength control bits. Each bit turns on additional drive, therefore each stage has 4 drive strength settings equal to the number of bits set, with 0 being the default, 1 being double drive, 2 being triple drive and 3 being quadruple drive. Turning on extra drive will not have a linear effect on frequency, setting a second bit will have less impact than setting the first bit and so on. To ensure smooth transitions it is recommended to change one drive strength bit at a time. When FREQ_RANGE is used to shorten the ROSC loop, the bypassed stages still propagate the signal and therefore their drive strengths must be set to at least the same level as the lowest drive strength in the stages that are in the loop. This will not affect the oscillation frequency.

2.17.4. ROSC divider

The ROSC frequency is too fast to be used directly so is divided in an integer divider controlled by the DIV register. DIV can be changed while the ROSC is running, the output clock will change frequency without glitching. The default divisor is 16 which ensures the output clock is in the range 1.8 to 12MHz on chip startup.

The divider has 2 outputs, rosc_clksrc and rosc_clksrc_ph, the second being a phase shifted version of the first. This is primarily intended for use during product development and the outputs will be identical if the PHASE register is left in its default state.

2.17.5. Random Number Generator

If the system clocks are running from the XOSC and/or PLLs the ROSC can be used to generate random numbers. Simply enable the ROSC and read the RANDBIT register to get a 1-bit random number and read it n times to get an n -bit value. This does not meet the requirements of randomness for security systems because it can be compromised, but it may be useful in less critical applications. If the cores are running from the ROSC then the value will not be random because the timing of the register read will be correlated to the phase of the ROSC.

2.17.6. ROSC 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 ROSC 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.17.7. 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).

Pico Extras: https://github.com/raspberrypi/pico-extras/blob/master/src/rp2_common/hardware_rosc/rosc.c Lines 56 - 61

56 void rosc_set_dormant(void) {
57     // WARNING: This stops the rosc until woken up by an irq
58     rosc_write(&rosc_hw->dormant, ROSC_DORMANT_VALUE_DORMANT);
59     // Wait for it to become stable once woken up
60     while(!(rosc_hw->status & ROSC_STATUS_STABLE_BITS));
61 }

WARNING

If no IRQ is configured before going into dormant mode the ROSC will never restart.

See Section 2.11.5.2 for some examples of dormant mode.

2.17.8. List of Registers

The ROSC registers start at a base address of 0x40060000(defined as ROSC_BASE in SDK).

Table 264. List of ROSC registers

OffsetNameInfo
0x00CTRLRing Oscillator control
0x04FREQARing Oscillator frequency control A
0x08FREQBRing Oscillator frequency control B
0x0cDORMANTRing Oscillator pause control
0x10DIVControls the output divider
0x14PHASEControls the phase shifted output
0x18STATUSRing Oscillator Status
0x1cRANDOMBITReturns a 1 bit random value
0x20COUNTA down counter running at the ROSC frequency which counts to zero and stops.

ROSC: CTRL Register

Offset: 0x00

Description

Ring Oscillator control

Table 265. CTRL Register

BitsDescriptionTypeReset
31:24Reserved.--
23:12ENABLE: On power-up this field is initialised to ENABLE
The system clock must be switched to another source before setting this field to DISABLE otherwise the chip will lock up
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
BitsDescriptionTypeReset
11:0FREQ_RANGE : Controls the number of delay stages in the ROSC ring
LOW uses stages 0 to 7
MEDIUM uses stages 2 to 7
HIGH uses stages 4 to 7
TOOHIGH uses stages 6 to 7 and should not be used because its frequency exceeds design specifications
The clock output will not glitch when changing the range up one step at a time
The clock output will glitch when changing the range down
Note: the values here are gray coded which is why HIGH comes before TOOHIGH
RW0xaa0
Enumerated values:
0xfa4 → LOW
0xfa5 → MEDIUM
0xfa7 → HIGH
0xfa6 → TOOHIGH

ROSC: FREQA Register

Offset: 0x04

Description

The FREQA & FREQB registers control the frequency by controlling the drive strength of each stage
The drive strength has 4 levels determined by the number of bits set
Increasing the number of bits set increases the drive strength and increases the oscillation frequency
0 bits set is the default drive strength
1 bit set doubles the drive strength
2 bits set triples drive strength
3 bits set quadruples drive strength

Table 266. FREQA Register

BitsDescriptionTypeReset
31:16PASSWD : Set to 0x9696 to apply the settings
Any other value in this field will set all drive strengths to 0
RW0x0000
Enumerated values:
0x9696 → PASS
15Reserved.--
14:12DS3 : Stage 3 drive strengthRW0x0
11Reserved.--
10:8DS2 : Stage 2 drive strengthRW0x0
7Reserved.--
6:4DS1 : Stage 1 drive strengthRW0x0
3Reserved.--
2:0DS0 : Stage 0 drive strengthRW0x0

ROSC: FREQB Register

Offset: 0x08

Description

For a detailed description see freqa register

Table 267. FREQB Register

BitsDescriptionTypeReset
31:16PASSWD : Set to 0x9696 to apply the settings
Any other value in this field will set all drive strengths to 0
RW0x0000
Enumerated values:
0x9696 → PASS
15Reserved.--
14:12DS7 : Stage 7 drive strengthRW0x0
11Reserved.--
10:8DS6 : Stage 6 drive strengthRW0x0
7Reserved.--
6:4DS5 : Stage 5 drive strengthRW0x0
3Reserved.--
2:0DS4 : Stage 4 drive strengthRW0x0

ROSC: DORMANT Register

Offset: 0x0c

Description

Ring Oscillator pause control

Table 268. DORMANT Register

BitsDescriptionTypeReset
31:0This is used to save power by pausing the ROSC
On power-up this field is initialised to WAKE
An invalid write will also select WAKE
Warning: setup the irq before selecting dormant mode
RW-
Enumerated values:
0x636f6d61 → DORMANT
0x77616b65 → WAKE

ROSC: DIV Register

Offset: 0x10

Description

Controls the output divider

Table 269. DIV Register

BitsDescriptionTypeReset
31:12Reserved.--
11:0set to 0xaa0 + div where
div = 0 divides by 32
div = 1-31 divides by div
any other value sets div=31
this register resets to div=16
RW-
Enumerated values:
BitsDescriptionTypeReset
0xaa0 → PASS

ROSC: PHASE Register

Offset: 0x14

Description

Controls the phase shifted output

Table 270. PHASE Register

BitsDescriptionTypeReset
31:12Reserved.--
11:4PASSWD : set to 0xaa
any other value enables the output with shift=0
RW0x00
3ENABLE : enable the phase-shifted output
this can be changed on-the-fly
RW0x1
2FLIP : invert the phase-shifted output
this is ignored when div=1
RW0x0
1:0SHIFT : phase shift the phase-shifted output by SHIFT input clocks
this can be changed on-the-fly
must be set to 0 before setting div=1
RW0x0

ROSC: STATUS Register

Offset: 0x18

Description

Ring Oscillator Status

Table 271. STATUS Register

BitsDescriptionTypeReset
31STABLE : Oscillator is running and stableRO0x0
30:25Reserved.--
24BADWRITE : An invalid value has been written to CTRL_ENABLE or CTRL_FREQ_RANGE or FREQA or FREQB or DIV or PHASE or DORMANTWC0x0
23:17Reserved.--
16DIV_RUNNING : post-divider is running
this resets to 0 but transitions to 1 during chip startup
RO-
15:13Reserved.--
12ENABLED : Oscillator is enabled but not necessarily running and stable
this resets to 0 but transitions to 1 during chip startup
RO-
11:0Reserved.--

ROSC: RANDOMBIT Register

Offset: 0x1c

Table 272. RANDOMBIT Register

BitsDescriptionTypeReset
31:1Reserved.--
BitsDescriptionTypeReset
0This just reads the state of the oscillator output so randomness is compromised if the ring oscillator is stopped or run at a harmonic of the bus frequencyRO0x1

ROSC: COUNT Register

Offset: 0x20

Table 273. COUNT Register

BitsDescriptionTypeReset
31:8Reserved.--
7:0A down counter running at the ROSC 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.
RW0x00