Skip to content

Commit 16ef0ae

Browse files
committed
lib/stm32wba/hci Moving HAL based funcs into stm32wba hci part
Moving HAL based funcs from zephyr to hal stm32wba hci part. In this way we separate zephyr based adaptation from pure HAL code. Signed-off-by: Alessandro Manganaro <[email protected]>
1 parent dc6c138 commit 16ef0ae

File tree

5 files changed

+186
-0
lines changed

5 files changed

+186
-0
lines changed

lib/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ if(CONFIG_HAS_STM32LIB)
3939
zephyr_sources(stm32wba/hci/power_table.c)
4040
zephyr_sources(stm32wba/hci/scm.c)
4141
zephyr_sources(stm32wba/hci/log_module.c)
42+
zephyr_sources(stm32wba/hci/linklayer_plat.c)
43+
zephyr_sources(stm32wba/hci/ll_sys_if.c)
4244
if(CONFIG_FLASH)
4345
zephyr_sources(stm32wba/hci/flash_manager.c)
4446
zephyr_sources(stm32wba/hci/flash_driver.c)

lib/stm32wba/hci/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ Patch List:
117117
app_conf.h
118118
scm.c
119119
ll_intf_cmn.h
120+
ll_sys_if.c
121+
linklayer_plat.c
120122

121123
* Changes from official delivery:
122124
- dos2unix applied

lib/stm32wba/hci/linklayer_plat.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2023 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/logging/log.h>
8+
9+
#include "scm.h"
10+
11+
#define LOG_LEVEL CONFIG_SOC_LOG_LEVEL
12+
LOG_MODULE_REGISTER(linklayer_plat);
13+
14+
/* Radio bus clock control variables */
15+
uint8_t AHB5_SwitchedOff;
16+
uint32_t radio_sleep_timer_val;
17+
18+
void LINKLAYER_PLAT_ClockInit(void)
19+
{
20+
AHB5_SwitchedOff = 0;
21+
radio_sleep_timer_val = 0;
22+
23+
LL_PWR_EnableBkUpAccess();
24+
25+
/* Select LSE as Sleep CLK */
26+
__HAL_RCC_RADIOSLPTIM_CONFIG(RCC_RADIOSTCLKSOURCE_LSE);
27+
28+
LL_PWR_DisableBkUpAccess();
29+
30+
/* Enable AHB5ENR peripheral clock (bus CLK) */
31+
__HAL_RCC_RADIO_CLK_ENABLE();
32+
}
33+
34+
void LINKLAYER_PLAT_WaitHclkRdy(void)
35+
{
36+
while (HAL_RCCEx_GetRadioBusClockReadiness() != RCC_RADIO_BUS_CLOCK_READY) {
37+
}
38+
}
39+
40+
void LINKLAYER_PLAT_AclkCtrl(uint8_t enable)
41+
{
42+
LOG_DBG("enable: %d", enable);
43+
if (enable) {
44+
/* Enable RADIO baseband clock (active CLK) */
45+
HAL_RCCEx_EnableRadioBBClock();
46+
47+
/* Polling on HSE32 activation */
48+
while (LL_RCC_HSE_IsReady() == 0) {
49+
}
50+
} else {
51+
/* Disable RADIO baseband clock (active CLK) */
52+
HAL_RCCEx_DisableRadioBBClock();
53+
}
54+
}
55+
56+
void LINKLAYER_PLAT_NotifyWFIEnter(void)
57+
{
58+
/* Check if Radio state will allow the AHB5 clock to be cut */
59+
60+
/* AHB5 clock will be cut in the following cases:
61+
* - 2.4GHz radio is not in ACTIVE mode (in SLEEP or DEEPSLEEP mode).
62+
* - RADIOSMEN and STRADIOCLKON bits are at 0.
63+
*/
64+
if ((LL_PWR_GetRadioMode() != LL_PWR_RADIO_ACTIVE_MODE) ||
65+
((__HAL_RCC_RADIO_IS_CLK_SLEEP_ENABLED() == 0) &&
66+
(LL_RCC_RADIO_IsEnabledSleepTimerClock() == 0))) {
67+
AHB5_SwitchedOff = 1;
68+
}
69+
}
70+
71+
void LINKLAYER_PLAT_NotifyWFIExit(void)
72+
{
73+
/* Check if AHB5 clock has been turned of and needs resynchronisation */
74+
if (AHB5_SwitchedOff) {
75+
/* Read sleep register as earlier as possible */
76+
radio_sleep_timer_val = ll_intf_cmn_get_slptmr_value();
77+
}
78+
}

lib/stm32wba/hci/ll_sys_if.c

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) 2023 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/logging/log.h>
8+
#define LOG_LEVEL CONFIG_SOC_LOG_LEVEL
9+
LOG_MODULE_REGISTER(ll_sys_if);
10+
11+
#include "ll_intf.h"
12+
#include "ll_intf_cmn.h"
13+
#include "utilities_common.h"
14+
15+
static void ll_sys_sleep_clock_source_selection(void);
16+
17+
void ll_sys_reset(void);
18+
19+
void ll_sys_config_params(void)
20+
{
21+
ll_intf_config_ll_ctx_params(USE_RADIO_LOW_ISR, NEXT_EVENT_SCHEDULING_FROM_ISR);
22+
}
23+
24+
#if (CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE == 0)
25+
uint8_t ll_sys_BLE_sleep_clock_accuracy_selection(void)
26+
{
27+
uint8_t BLE_sleep_clock_accuracy = 0;
28+
uint32_t RevID = LL_DBGMCU_GetRevisionID();
29+
uint32_t linklayer_slp_clk_src = LL_RCC_RADIO_GetSleepTimerClockSource();
30+
31+
if (linklayer_slp_clk_src == LL_RCC_RADIOSLEEPSOURCE_LSE) {
32+
/* LSE selected as Link Layer sleep clock source. */
33+
/* Sleep clock accuracy is different regarding the WBA device ID and revision */
34+
#if defined(STM32WBA52xx) || defined(STM32WBA54xx) || defined(STM32WBA55xx)
35+
if (RevID == REV_ID_A) {
36+
BLE_sleep_clock_accuracy = STM32WBA5x_REV_ID_A_SCA_RANGE;
37+
} else if (RevID == REV_ID_B) {
38+
BLE_sleep_clock_accuracy = STM32WBA5x_REV_ID_B_SCA_RANGE;
39+
} else {
40+
/* Revision ID not supported, default value of 500ppm applied */
41+
BLE_sleep_clock_accuracy = STM32WBA5x_DEFAULT_SCA_RANGE;
42+
}
43+
#else
44+
UNUSED(RevID);
45+
#endif
46+
/* defined(STM32WBA52xx) || defined(STM32WBA54xx) || defined(STM32WBA55xx) */
47+
} else {
48+
/* LSE is not the Link Layer sleep clock source, */
49+
/* sleep clock accuracy default value is 500 ppm */
50+
BLE_sleep_clock_accuracy = STM32WBA5x_DEFAULT_SCA_RANGE;
51+
}
52+
53+
return BLE_sleep_clock_accuracy;
54+
}
55+
#endif /* CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE */
56+
57+
void ll_sys_sleep_clock_source_selection(void)
58+
{
59+
uint16_t freq_value = 0;
60+
uint32_t linklayer_slp_clk_src = LL_RCC_RADIOSLEEPSOURCE_NONE;
61+
62+
linklayer_slp_clk_src = LL_RCC_RADIO_GetSleepTimerClockSource();
63+
switch (linklayer_slp_clk_src) {
64+
case LL_RCC_RADIOSLEEPSOURCE_LSE:
65+
linklayer_slp_clk_src = RTC_SLPTMR;
66+
break;
67+
68+
case LL_RCC_RADIOSLEEPSOURCE_LSI:
69+
linklayer_slp_clk_src = RCO_SLPTMR;
70+
break;
71+
72+
case LL_RCC_RADIOSLEEPSOURCE_HSE_DIV1000:
73+
linklayer_slp_clk_src = CRYSTAL_OSCILLATOR_SLPTMR;
74+
break;
75+
76+
case LL_RCC_RADIOSLEEPSOURCE_NONE:
77+
/* No Link Layer sleep clock source selected */
78+
assert_param(0);
79+
break;
80+
}
81+
ll_intf_cmn_le_select_slp_clk_src((uint8_t)linklayer_slp_clk_src, &freq_value);
82+
}
83+
84+
void ll_sys_reset(void)
85+
{
86+
#if (CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE == 0)
87+
uint8_t bsca = 0;
88+
#endif /* CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE */
89+
90+
/* Apply the selected link layer sleep timer source */
91+
ll_sys_sleep_clock_source_selection();
92+
93+
/* Configure the link layer sleep clock accuracy if different from the default one */
94+
#if (CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE != 0)
95+
ll_intf_le_set_sleep_clock_accuracy(CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE);
96+
#else
97+
bsca = ll_sys_BLE_sleep_clock_accuracy_selection();
98+
if (bsca != STM32WBA5x_DEFAULT_SCA_RANGE) {
99+
ll_intf_le_set_sleep_clock_accuracy(bsca);
100+
}
101+
#endif /* CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE */
102+
}

scripts/ble_library.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
ble_heartrate_app_path + "/STM32_WPAN/Target/power_table.c",
108108
ble_heartrate_app_path + "/STM32_WPAN/Target/bpka.c",
109109
ble_heartrate_app_path + "/STM32_WPAN/Target/bpka.h",
110+
ble_heartrate_app_path + "/STM32_WPAN/Target/linklayer_plat.c",
111+
ble_heartrate_app_path + "/STM32_WPAN/Target/ll_sys_if.c",
110112
"Utilities/trace/adv_trace/stm32_adv_trace.h",
111113
"Utilities/misc/stm32_mem.h",
112114
"Utilities/tim_serv/stm32_timer.h",

0 commit comments

Comments
 (0)