Skip to content

Commit 36089c7

Browse files
stm32, rcc: enhanced his48 handling (#113)
hsi48 is not driven the same way according to soc family: - stm32u5 use RCC_RC register - stm32l496/4a6 use RCC_CRRCR register
2 parents 205ead8 + bd7d6b8 commit 36089c7

File tree

4 files changed

+41
-20
lines changed

4 files changed

+41
-20
lines changed

kernel/src/drivers/clk/stm32-rcc.c.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ __STATIC_INLINE kstatus_t rcc_enable_hse(void)
111111
return iopoll32_until_set(RCC_BASE_ADDR + RCC_CR_REG, RCC_CR_HSERDY, HSE_STARTUP_TIMEOUT);
112112
}
113113

114+
#if defined(HAS_HSI48_CLOCK)
115+
__STATIC_INLINE kstatus_t rcc_enable_hsi48(void)
116+
{
117+
kstatus_t status = K_STATUS_OKAY;
118+
uint32_t reg;
119+
120+
reg = ioread32(RCC_BASE_ADDR + RCC_HSI48_REG);
121+
reg |= RCC_HSI48ON;
122+
iowrite32(RCC_BASE_ADDR + RCC_HSI48_REG, reg);
123+
124+
return iopoll32_until_set(RCC_BASE_ADDR + RCC_HSI48_REG, RCC_HSI48RDY, 500);
125+
}
126+
#endif /* RCC_CR_HSI48ON */
127+
128+
129+
114130
/**
115131
* @brief Convert AHB divisor (power of 2) to register value
116132
*
@@ -222,6 +238,13 @@ __STATIC_INLINE kstatus_t rcc_init_system_clk(void)
222238
}
223239
{%- endif %}
224240

241+
{%- if dts.clocks.clk_hsi48 is defined and dts.clocks.clk_hsi48.status == "okay" %}
242+
status = rcc_enable_hsi48();
243+
if (unlikely(status != K_STATUS_OKAY)) {
244+
goto err;
245+
}
246+
{%- endif %}
247+
225248
{%- if dts.clocks.clk_hse.status == "okay" %}
226249
status = rcc_enable_hse();
227250
if (unlikely(status != K_STATUS_OKAY)) {

kernel/src/drivers/clk/stm32l4-rcc.h.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@
7171
*/
7272
#define RCC_CIR_REG RCC_CICR_REG
7373

74+
/*
75+
* For stm32l496/4a6 subfamily, HSI48 control is held by CRRCR register
76+
*/
77+
#if defined(CONFIG_SOC_SUBFAMILY_STM32L49_Ax)
78+
#define HAS_HSI48_CLOCK
79+
#define RCC_HSI48_REG RCC_CRRCR_REG
80+
#define RCC_HSI48ON RCC_CRRCR_HSI48ON
81+
#define RCC_HSI48RDY RCC_CRRCR_HSI48RDY
82+
#endif
83+
7484
{#- There is only one main PLL for stm32f4xx families #}
7585
{%- set pll = dts.get_compatible("st,stm32l4xx-pll")[0] %}
7686
{%- if pll is not none and pll.status == "okay"%}

kernel/src/drivers/clk/stm32u5-rcc.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,6 @@ kstatus_t rcc_enable_pll(void)
161161
stm32u5_enable_pll_p_output(PLL_ID_3);
162162
stm32u5_enable_pll_r_output(PLL_ID_3);
163163

164-
/*
165-
* Fixme:
166-
* Ugly hack, force HSI48 ON, this is used by RNG as clock source.
167-
* Remove this while outpost/sentry-kernel/issues/253 outpost/sentry-kernel/issues/254
168-
* are fixed/closed.
169-
*/
170-
rcc_enable_hsi48();
171-
172164
return K_STATUS_OKAY;
173165
}
174166

kernel/src/drivers/clk/stm32u5-rcc.h.in

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@
4949
#define RCC_APB2_BUS_FREQUENCY_MAX RCC_SYSCLOCK_FREQUENCY_MAX
5050
#define RCC_APB3_BUS_FREQUENCY_MAX RCC_SYSCLOCK_FREQUENCY_MAX
5151

52+
/*
53+
* For stm32u5 family, HSI48 control is held by CR register
54+
*/
55+
#define HAS_HSI48_CLOCK
56+
#define RCC_HSI48_REG RCC_CR_REG
57+
#define RCC_HSI48ON RCC_CR_HSI48ON
58+
#define RCC_HSI48RDY RCC_CR_HSI48RDY
59+
5260
typedef enum stm32u5_pll_id {
5361
PLL_ID_1 = 0,
5462
PLL_ID_2 = 1,
@@ -104,18 +112,6 @@ static inline void __stm32_rcc_set_peripheral_bus_div(
104112
iowrite32(RCC_BASE_ADDR + RCC_CFGR3_REG, cfgr3.raw);
105113
}
106114

107-
static inline kstatus_t rcc_enable_hsi48(void)
108-
{
109-
kstatus_t status = K_STATUS_OKAY;
110-
uint32_t rcc_cr;
111-
112-
rcc_cr = ioread32(RCC_BASE_ADDR + RCC_CR_REG);
113-
rcc_cr |= RCC_CR_HSI48ON;
114-
iowrite32(RCC_BASE_ADDR + RCC_CR_REG, rcc_cr);
115-
116-
return iopoll32_until_set(RCC_BASE_ADDR + RCC_CR_REG, RCC_CR_HSI48RDY, 500);
117-
}
118-
119115
kstatus_t rcc_select_system_clock(void);
120116

121117
kstatus_t rcc_enable_pll(void);

0 commit comments

Comments
 (0)