Skip to content

Commit c757f36

Browse files
authored
add PICO_USE_FASTEST_SUPPORTED_CLOCK, and support vreg setting and SYS_CLOCK_MHZ=200 for rp2040 (#2285)
1 parent 7ce1ae8 commit c757f36

File tree

11 files changed

+82
-11
lines changed

11 files changed

+82
-11
lines changed

src/rp2040/hardware_regs/include/hardware/platform_defs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,25 @@
6161
#endif
6262
#endif
6363

64+
// PICO_CONFIG: PICO_USE_FASTEST_SUPPORTED_CLOCK, Use the fastest officially supported clock by default, type=bool, default=0, group=hardware_base
65+
#ifndef PICO_USE_FASTEST_SUPPORTED_CLOCK
66+
#define PICO_USE_FASTEST_SUPPORTED_CLOCK 0
67+
#endif
68+
6469
// PICO_CONFIG: SYS_CLK_HZ, System operating frequency in Hz, type=int, default=125000000, advanced=true, group=hardware_base
6570
#ifndef SYS_CLK_HZ
6671
#ifdef SYS_CLK_KHZ
6772
#define SYS_CLK_HZ ((SYS_CLK_KHZ) * _u(1000))
6873
#elif defined(SYS_CLK_MHZ)
6974
#define SYS_CLK_HZ ((SYS_CLK_MHZ) * _u(1000000))
7075
#else
76+
#if PICO_USE_FASTEST_SUPPORTED_CLOCK
77+
#define SYS_CLK_HZ _u(200000000)
78+
#else
7179
#define SYS_CLK_HZ _u(125000000)
7280
#endif
7381
#endif
82+
#endif
7483

7584
// PICO_CONFIG: USB_CLK_HZ, USB clock frequency. Must be 48MHz for the USB interface to operate correctly, type=int, default=48000000, advanced=true, group=hardware_base
7685
#ifndef USB_CLK_HZ

src/rp2350/hardware_regs/include/hardware/platform_defs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@
8989
#endif
9090
#endif
9191

92+
// PICO_CONFIG: PICO_USE_FASTEST_SUPPORTED_CLOCK, Use the fastest officially supported clock by default, type=bool, default=0, group=hardware_base
93+
#ifndef PICO_USE_FASTEST_SUPPORTED_CLOCK
94+
#define PICO_USE_FASTEST_SUPPORTED_CLOCK 0
95+
#endif
96+
9297
// PICO_CONFIG: SYS_CLK_HZ, System operating frequency in Hz, type=int, default=150000000, advanced=true, group=hardware_base
9398
#ifndef SYS_CLK_HZ
9499
#ifdef SYS_CLK_KHZ

src/rp2_common/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ alias(
7171
"//src/rp2_common/hardware_base:__pkg__",
7272
"//src/rp2_common/hardware_irq:__pkg__",
7373
"//src/rp2_common/hardware_pll:__pkg__",
74+
"//src/rp2_common/hardware_vreg:__pkg__",
7475
"//src/rp2_common/hardware_watchdog:__pkg__",
7576
"//src/rp2_common/hardware_xosc:__pkg__",
7677
"//src/rp2_common/pico_bit_ops:__pkg__",

src/rp2_common/hardware_clocks/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ pico_mirrored_target_link_libraries(hardware_clocks INTERFACE
1010
hardware_vreg
1111
hardware_watchdog
1212
hardware_xosc
13-
)
13+
)
14+
15+
if (PICO_USE_FASTEST_SUPPORTED_CLOCK)
16+
target_compile_definitions(hardware_clocks INTERFACE PICO_USE_FASTEST_SUPPORTED_CLOCK=1)
17+
endif()

src/rp2_common/hardware_clocks/include/hardware/clocks.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,36 @@ extern "C" {
206206
#endif
207207
#endif // SYS_CLK_KHZ == 125000 && XOSC_KHZ == 12000 && PLL_COMMON_REFDIV == 1
208208

209+
#if PICO_RP2040 && (SYS_CLK_HZ == 200 * MHZ) && (XOSC_HZ == 12 * MHZ) && (PLL_SYS_REFDIV == 1)
210+
// PICO_CONFIG: SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST, Should the regulator voltage be adjusted above SYS_CLK_VREG_VOLTAGE_MIN when initializing the clocks, type=bool, default=0, advanced=true, group=hardware_clocks
211+
#ifndef SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST
212+
#define SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST 1
213+
#endif
214+
// PICO_CONFIG: SYS_CLK_VREG_VOLTAGE_MIN, minimum voltage (see VREG_VOLTAGE_x_xx) for the voltage regulator to be ensured during clock initialization if SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST is 1, type=int, advanced=true, group=hardware_clocks
215+
#if SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST && !defined(SYS_CLK_VREG_VOLTAGE_MIN)
216+
#define SYS_CLK_VREG_VOLTAGE_MIN VREG_VOLTAGE_1_15
217+
#endif
218+
// PLL settings for fast 200 MHz system clock on RP2040
219+
#ifndef PLL_SYS_VCO_FREQ_HZ
220+
#define PLL_SYS_VCO_FREQ_HZ (1200 * MHZ)
221+
#endif
222+
#ifndef PLL_SYS_POSTDIV1
223+
#define PLL_SYS_POSTDIV1 6
224+
#endif
225+
#ifndef PLL_SYS_POSTDIV2
226+
#define PLL_SYS_POSTDIV2 1
227+
#endif
228+
#else
229+
#ifndef SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST
230+
#define SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST 0
231+
#endif
232+
#endif // PICO_RP2040 && SYS_CLK_KHZ == 200000 && XOSC_KHZ == 12000 && PLL_COMMON_REFDIV == 1
233+
234+
// PICO_CONFIG: SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US, Number of microseconds to wait after updating regulator voltage due to SYS_CLK_VREG_VOLTAGE_MIN to allow voltage to settle, type=bool, default=1, advanced=true, group=hardware_clocks
235+
#ifndef SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US
236+
#define SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US 1000
237+
#endif
238+
209239
#if !defined(PLL_SYS_VCO_FREQ_HZ) || !defined(PLL_SYS_POSTDIV1) || !defined(PLL_SYS_POSTDIV2)
210240
#error PLL_SYS_VCO_FREQ_HZ, PLL_SYS_POSTDIV1 and PLL_SYS_POSTDIV2 must all be specified when using custom clock setup
211241
#endif

src/rp2_common/hardware_vreg/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cc_library(
1010
target_compatible_with = compatible_with_rp2(),
1111
deps = [
1212
"//src/rp2_common:hardware_structs",
13-
"//src/rp2_common:pico_platform",
13+
"//src/rp2_common:pico_platform_internal",
1414
"//src/rp2_common/hardware_base",
1515
],
1616
)

src/rp2_common/hardware_vreg/include/hardware/vreg.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ enum vreg_voltage {
8282
void vreg_set_voltage(enum vreg_voltage voltage);
8383

8484

85+
/*! \brief Get voltage
86+
* \ingroup hardware_vreg
87+
*
88+
* \return The current voltage (from enumeration \ref vreg_voltage) of the voltage regulator
89+
**/
90+
enum vreg_voltage vreg_get_voltage(void);
91+
8592
/*! \brief Enable use of voltages beyond the safe range of operation
8693
* \ingroup hardware_vreg
8794
*

src/rp2_common/hardware_vreg/vreg.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void vreg_set_voltage(enum vreg_voltage voltage) {
1616
VREG_AND_CHIP_RESET_VREG_VSEL_BITS
1717
);
1818

19-
#elif PICO_RP2350
19+
#else
2020

2121
hw_set_bits(&powman_hw->vreg_ctrl, POWMAN_PASSWORD_BITS | POWMAN_VREG_CTRL_UNLOCK_BITS);
2222

@@ -32,19 +32,21 @@ void vreg_set_voltage(enum vreg_voltage voltage) {
3232
while (powman_hw->vreg & POWMAN_VREG_UPDATE_IN_PROGRESS_BITS)
3333
tight_loop_contents();
3434

35+
#endif
36+
}
37+
38+
enum vreg_voltage vreg_get_voltage(void) {
39+
#if PICO_RP2040
40+
return (vreg_and_chip_reset_hw->vreg & VREG_AND_CHIP_RESET_VREG_VSEL_BITS) >> VREG_AND_CHIP_RESET_VREG_VSEL_LSB;
3541
#else
36-
panic_unsupported();
42+
return (powman_hw->vreg & POWMAN_VREG_VSEL_BITS) >> POWMAN_VREG_VSEL_LSB;
3743
#endif
3844
}
3945

4046
void vreg_disable_voltage_limit(void) {
4147
#if PICO_RP2040
42-
// The voltage limit can't be disabled on RP2040 (was implemented by
43-
// hardwiring the LDO controls)
44-
return;
45-
#elif PICO_RP2350
46-
hw_set_bits(&powman_hw->vreg_ctrl, POWMAN_PASSWORD_BITS | POWMAN_VREG_CTRL_DISABLE_VOLTAGE_LIMIT_BITS);
48+
// The voltage limit can't be disabled on RP2040 (was implemented by hard-wiring the LDO controls)
4749
#else
48-
panic_unsupported();
50+
hw_set_bits(&powman_hw->vreg_ctrl, POWMAN_PASSWORD_BITS | POWMAN_VREG_CTRL_DISABLE_VOLTAGE_LIMIT_BITS);
4951
#endif
5052
}

src/rp2_common/pico_runtime_init/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ cc_library(
3434
"//src/rp2_common/hardware_base",
3535
"//src/rp2_common/hardware_clocks",
3636
"//src/rp2_common/hardware_ticks",
37+
"//src/rp2_common/hardware_timer",
38+
"//src/rp2_common/hardware_vreg",
3739
"//src/rp2_common/pico_bootrom",
3840
"//src/rp2_common/pico_runtime",
3941
],

src/rp2_common/pico_runtime_init/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE
1313
)
1414

1515
if (TARGET hardware_clocks)
16-
pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE hardware_clocks)
16+
pico_mirrored_target_link_libraries(pico_runtime_init INTERFACE hardware_clocks hardware_timer hardware_vreg)
1717
endif()
1818

1919
# pico/runtime_init.h includes pico/runtime.h

0 commit comments

Comments
 (0)