Skip to content

Commit ea5d389

Browse files
committed
[rp2040] bugfix
1 parent dc5910c commit ea5d389

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

ext/hathach/tusb_port.cpp.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ tusb_get_device_serial(uint16_t *serial_str)
4040
(uint32_t *)0x0080A00C, (uint32_t *)0x0080A040,
4141
(uint32_t *)0x0080A044, (uint32_t *)0x0080A048
4242
%% endif
43+
%% elif target.platform in ["rp"]
44+
/* sysinfo CHIP_ID and GIT_REV */
45+
((uint32_t *)0x40000000),((uint32_t *)0x40000040),
46+
((uint32_t *)0x40000000),((uint32_t *)0x40000040),
4347
%% endif
4448
};
4549

ext/rp/pico.cpp.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern "C" void panic(const char *fmt, ...) {
2121
%% if with_debug
2222
va_list va;
2323
va_start(va, fmt);
24-
modm::log::debug.vprintf(fmt, va);
24+
modm::log::info.vprintf(fmt, va);
2525
va_end(va);
2626
%% endif
2727
modm_assert(0, "pico", "Pico-SDK panic!");

src/modm/board/rp_pico/board.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ struct SystemClock
4141
{
4242
ClockControl::disableResus();
4343
ClockControl::enableExternalCrystal(XOSCFrequency);
44-
ClockControl::disableAux(ClockControl::Clock::Sys);
45-
ClockControl::disableAux(ClockControl::Clock::Ref);
44+
ClockControl::disableAux<ClockControl::Clock::Sys>();
45+
ClockControl::disableAux<ClockControl::Clock::Ref>();
4646
// PLL SYS: 12MHz / 1 = 12MHz * 125 = 1500MHZ / 6 / 2 = 125MHz
4747
ClockControl::init_pll<ClockControl::Pll::Sys,1,SysPLLMul,6,2>();
4848
// PLL USB: 12MHz / 1 = 12MHz * 40 = 480 MHz / 5 / 2 = 48MHz
@@ -70,6 +70,7 @@ struct SystemClock
7070
CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLK_SYS,
7171
1 << 8);
7272

73+
ClockControl::updateCoreFrequency<Frequency>();
7374
return true;
7475
}
7576
};

src/modm/platform/clock/rp/clocks.cpp.in

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 1
1919
#endif
2020

21+
// CMSIS Core compliance
22+
constinit uint32_t modm_fastdata SystemCoreClock(modm::platform::ClockControl::BootFrequency);
23+
2124
namespace modm::platform
2225
{
2326
constinit uint16_t modm_fastdata delay_fcpu_MHz(computeDelayMhz(ClockControl::BootFrequency));
2427
constinit uint16_t modm_fastdata delay_ns_per_loop(computeDelayNsPerLoop(ClockControl::BootFrequency));
2528

2629

27-
2830
void ClockControl::enableExternalCrystal(uint32_t freq) {
2931
// Assumes 1-15 MHz input, checked above.
3032
xosc_hw->ctrl = XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ;
@@ -45,12 +47,6 @@ static inline bool has_glitchless_mux(ClockControl::Clock clk_index) {
4547
return clk_index == ClockControl::Clock::Sys || clk_index == ClockControl::Clock::Ref;
4648
}
4749

48-
void ClockControl::disableAux(Clock clk) {
49-
hw_clear_bits(&clocks_hw->clk[uint32_t(clk)].ctrl, CLOCKS_CLK_SYS_CTRL_SRC_BITS);
50-
while (clocks_hw->clk[uint32_t(clk)].selected != 0x1)
51-
__NOP();
52-
}
53-
5450
void ClockControl::configure(Clock clk,uint32_t src, uint32_t auxsrc, uint32_t div) {
5551

5652
clock_hw_t *clock = &clocks_hw->clk[uint32_t(clk)];
@@ -112,6 +108,5 @@ void ClockControl::configure(Clock clk,uint32_t src, uint32_t auxsrc, uint32_t d
112108
// Now that the source is configured, we can trust that the user-supplied
113109
// divisor is a safe value.
114110
clock->div = div;
115-
116111
}
117112
}

src/modm/platform/clock/rp/clocks.hpp.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ namespace modm::platform
5353
clocks_hw->resus.ctrl = 0;
5454
}
5555
static void enableExternalCrystal(uint32_t freq);
56+
template <Clock clk>
57+
static void disableAux() {
58+
static_assert(clk == Clock::Ref or clk == Clock::Sys,"Only Sys and Ref clocks has aux");
59+
if constexpr(clk == Clock::Sys) {
60+
hw_clear_bits(&clocks_hw->clk[uint32_t(clk)].ctrl, CLOCKS_CLK_SYS_CTRL_SRC_BITS);
61+
} else if constexpr(clk == Clock::Ref) {
62+
hw_clear_bits(&clocks_hw->clk[uint32_t(clk)].ctrl, CLOCKS_CLK_REF_CTRL_SRC_BITS);
63+
}
64+
while (clocks_hw->clk[uint32_t(clk)].selected != 0x1)
65+
__NOP();
66+
}
67+
5668
static void disableAux(Clock clk);
5769
template <Pll pll_name,uint32_t refdiv,uint32_t pll_mul, uint32_t post_div1, uint32_t post_div2>
5870
static void init_pll() {
@@ -98,5 +110,12 @@ namespace modm::platform
98110
hw_clear_bits(&pll->pwr, PLL_PWR_POSTDIVPD_BITS);
99111
}
100112
static void configure(Clock clk,uint32_t src, uint32_t auxsrc,uint32_t div8);
113+
template< uint32_t Core_Hz >
114+
static void updateCoreFrequency()
115+
{
116+
SystemCoreClock = Core_Hz;
117+
delay_fcpu_MHz = computeDelayMhz(Core_Hz);
118+
delay_ns_per_loop = computeDelayNsPerLoop(Core_Hz);
119+
}
101120
};
102121
}

0 commit comments

Comments
 (0)