diff --git a/demos/RP/RT-RP2040-PICO/.project b/demos/RP/RT-RP2040-PICO/.project
index b15029d60..26dd8a0d5 100644
--- a/demos/RP/RT-RP2040-PICO/.project
+++ b/demos/RP/RT-RP2040-PICO/.project
@@ -34,6 +34,11 @@
2
CHIBIOS/os
+
+ pico-sdk
+ 2
+ CHIBIOS/ext/pico-sdk/src
+
test
2
diff --git a/os/hal/ports/RP/LLD/TIMERv1/hal_st_lld.c b/os/hal/ports/RP/LLD/TIMERv1/hal_st_lld.c
index 0a0576123..d6d122e92 100644
--- a/os/hal/ports/RP/LLD/TIMERv1/hal_st_lld.c
+++ b/os/hal/ports/RP/LLD/TIMERv1/hal_st_lld.c
@@ -31,23 +31,10 @@
/*===========================================================================*/
#if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING
-
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */
#if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC
-
#define ST_HANDLER SysTick_Handler
-
-#define SYSTICK_CK RP_CORE_CK
-
-#if SYSTICK_CK % OSAL_ST_FREQUENCY != 0
-#error "the selected ST frequency is not obtainable because integer rounding"
-#endif
-
-#if (SYSTICK_CK / OSAL_ST_FREQUENCY) - 1 > 0xFFFFFF
-#error "the selected ST frequency is not obtainable because SysTick timer counter limits"
-#endif
-
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */
/*===========================================================================*/
@@ -96,22 +83,30 @@ OSAL_IRQ_HANDLER(ST_HANDLER) {
* @notapi
*/
void st_lld_init(void) {
+ uint32_t timer_clk;
#if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING */
#if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC
+ timer_clk = RP_CORE_CLK;
+
+ osalDbgAssert(timer_clk % OSAL_ST_FREQUENCY != 0U,
+ "division remainder");
+ osalDbgAssert((timer_clk / OSAL_ST_FREQUENCY) - 1U > 0x00FFFFFFU,
+ "prescaler range");
+
/* Periodic systick mode, the Cortex-Mx internal systick timer is used
in this mode.*/
- SysTick->LOAD = (SYSTICK_CK / OSAL_ST_FREQUENCY) - 1;
+ SysTick->LOAD = (timer_clk / OSAL_ST_FREQUENCY) - 1;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_ENABLE_Msk |
SysTick_CTRL_TICKINT_Msk;
/* IRQ enabled.*/
- nvicSetSystemHandlerPriority(HANDLER_SYSTICK, RP_ST_IRQ_PRIORITY);
+ nvicSetSystemHandlerPriority(HANDLER_SYSTICK, RP_SYSTICK_IRQ_PRIORITY);
#endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */
}
diff --git a/os/hal/ports/RP/LLD/TIMERv1/hal_st_lld.h b/os/hal/ports/RP/LLD/TIMERv1/hal_st_lld.h
index cc6041b35..dff8b991c 100644
--- a/os/hal/ports/RP/LLD/TIMERv1/hal_st_lld.h
+++ b/os/hal/ports/RP/LLD/TIMERv1/hal_st_lld.h
@@ -42,8 +42,8 @@
/**
* @brief SysTick timer IRQ priority.
*/
-#if !defined(RP_TIMER_IRQ_PRIORITY) || defined(__DOXYGEN__)
-#define RP_TIMER_IRQ_PRIORITY 1
+#if !defined(RP_SYSTICK_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define RP_SYSTICK_IRQ_PRIORITY 1
#endif
/** @} */
diff --git a/os/hal/ports/RP/RP2040/hal_lld.c b/os/hal/ports/RP/RP2040/hal_lld.c
index af68314cc..177d6df31 100644
--- a/os/hal/ports/RP/RP2040/hal_lld.c
+++ b/os/hal/ports/RP/RP2040/hal_lld.c
@@ -24,9 +24,6 @@
#include "hal.h"
-/* From Pico-SDK */
-#include "hardware/clocks.h"
-
/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
@@ -39,7 +36,7 @@
* @brief CMSIS system core clock variable.
* @note It is declared in system_rp2040.h.
*/
-uint32_t SystemCoreClock = RP_CORE_CK;
+uint32_t SystemCoreClock;
/*===========================================================================*/
/* Driver local variables and types. */
@@ -79,6 +76,8 @@ void rp_clock_init(void) {
#if !RP_NO_INIT
clocks_init();
+
+ SystemCoreClock = RP_CORE_CLK;
#endif /* RP_NO_INIT */
}
diff --git a/os/hal/ports/RP/RP2040/hal_lld.h b/os/hal/ports/RP/RP2040/hal_lld.h
index 77674a20a..eecd73364 100644
--- a/os/hal/ports/RP/RP2040/hal_lld.h
+++ b/os/hal/ports/RP/RP2040/hal_lld.h
@@ -30,6 +30,9 @@
*/
#include "rp_registry.h"
+/* From Pico-SDK */
+#include "hardware/clocks.h"
+
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
@@ -87,12 +90,19 @@
#error "RP_XOSCCLK not defined in board.h"
#endif
-#define RP_CORE_CK 125000000
+/**
+ * @name Various clock points.
+ * @{
+ */
+#define RP_CORE_CLK hal_lld_get_clock(clk_sys)
+/** @} */
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
+typedef enum clock_index clock_index_t;
+
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
@@ -108,12 +118,21 @@
#ifdef __cplusplus
extern "C" {
#endif
- void hal_lld_init(void);
void rp_clock_init(void);
+ void hal_lld_init(void);
#ifdef __cplusplus
}
#endif
+/*===========================================================================*/
+/* Driver inline functions. */
+/*===========================================================================*/
+
+__STATIC_INLINE uint32_t hal_lld_get_clock(clock_index_t clk_index) {
+
+ return clock_get_hz(clk_index);
+}
+
#endif /* HAL_LLD_H */
/** @} */