Skip to content

Commit

Permalink
soc: st: stm32: stm32wbax: STM32WBA Cube 1.4.1 FW integration
Browse files Browse the repository at this point in the history
STM32WBA Cube FW 1.4.1 integration

Added new functions required by STM32WBA Cube FW 1.4.1 Link Layer
for WFI notification management and clock source selection

Signed-off-by: Alessandro Manganaro <alessandro.manganaro@st.com>
  • Loading branch information
Alessandro Manganaro committed Oct 21, 2024
1 parent 2f23313 commit b9fb0a9
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
31 changes: 31 additions & 0 deletions soc/st/stm32/stm32wbax/hci_if/linklayer_plat.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ typedef void (*radio_isr_cb_t) (void);
radio_isr_cb_t radio_callback;
radio_isr_cb_t low_isr_callback;

/* Radio bus clock control variables */
uint8_t AHB5_SwitchedOff;
uint32_t radio_sleep_timer_val;

extern const struct device *rng_dev;

/* Radio critical sections */
Expand All @@ -44,6 +48,9 @@ volatile uint8_t radio_sw_low_isr_is_running_high_prio;

void LINKLAYER_PLAT_ClockInit(void)
{
AHB5_SwitchedOff = 0;
radio_sleep_timer_val = 0;

LL_PWR_EnableBkUpAccess();

/* Select LSE as Sleep CLK */
Expand Down Expand Up @@ -314,3 +321,27 @@ void LINKLAYER_PLAT_SCHLDR_TIMING_UPDATE_NOT(Evnt_timing_t *p_evnt_timing) {}
void LINKLAYER_PLAT_EnableOSContextSwitch(void) {}

void LINKLAYER_PLAT_DisableOSContextSwitch(void) {}

void LINKLAYER_PLAT_NotifyWFIEnter(void)
{
/* Check if Radio state will allow the AHB5 clock to be cut */

/* AHB5 clock will be cut in the following cases:
* - 2.4GHz radio is not in ACTIVE mode (in SLEEP or DEEPSLEEP mode).
* - RADIOSMEN and STRADIOCLKON bits are at 0.
*/
if ((LL_PWR_GetRadioMode() != LL_PWR_RADIO_ACTIVE_MODE) ||
((__HAL_RCC_RADIO_IS_CLK_SLEEP_ENABLED() == 0) &&
(LL_RCC_RADIO_IsEnabledSleepTimerClock() == 0))) {
AHB5_SwitchedOff = 1;

Check notice on line 336 in soc/st/stm32/stm32wbax/hci_if/linklayer_plat.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

soc/st/stm32/stm32wbax/hci_if/linklayer_plat.c:336 - ((__HAL_RCC_RADIO_IS_CLK_SLEEP_ENABLED() == 0) && - (LL_RCC_RADIO_IsEnabledSleepTimerClock() == 0))) { + ((__HAL_RCC_RADIO_IS_CLK_SLEEP_ENABLED() == 0) && + (LL_RCC_RADIO_IsEnabledSleepTimerClock() == 0))) {
}
}

void LINKLAYER_PLAT_NotifyWFIExit(void)
{
/* Check if AHB5 clock has been turned of and needs resynchronisation */
if (AHB5_SwitchedOff) {
/* Read sleep register as earlier as possible */
radio_sleep_timer_val = ll_intf_cmn_get_slptmr_value();
}
}
86 changes: 86 additions & 0 deletions soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ LOG_MODULE_REGISTER(ll_sys_if);
#include "ll_sys.h"
#include "linklayer_plat.h"
#include "app_conf.h"
#include "ll_intf_cmn.h"
#include "utilities_common.h"

extern struct k_mutex ble_ctlr_stack_mutex;
extern struct k_work_q ll_work_q;
struct k_work ll_sys_work;

static void ll_sys_sleep_clock_source_selection(void);

void ll_sys_reset(void);

void ll_sys_schedule_bg_process(void)
{
k_work_submit_to_queue(&ll_work_q, &ll_sys_work);
Expand All @@ -45,3 +51,83 @@ void ll_sys_config_params(void)
{
ll_intf_config_ll_ctx_params(USE_RADIO_LOW_ISR, NEXT_EVENT_SCHEDULING_FROM_ISR);
}

#if (CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE == 0)
uint8_t ll_sys_BLE_sleep_clock_accuracy_selection(void)
{
uint8_t BLE_sleep_clock_accuracy = 0;
uint32_t RevID = LL_DBGMCU_GetRevisionID();
uint32_t linklayer_slp_clk_src = LL_RCC_RADIO_GetSleepTimerClockSource();

if (linklayer_slp_clk_src == LL_RCC_RADIOSLEEPSOURCE_LSE) {
/* LSE selected as Link Layer sleep clock source. */
/* Sleep clock accuracy is different regarding the WBA device ID and revision */
#if defined(STM32WBA52xx) || defined(STM32WBA54xx) || defined(STM32WBA55xx)
if (RevID == REV_ID_A) {

Check warning on line 66 in soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SUSPECT_CODE_INDENT

soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c:66 suspect code indent for conditional statements (16, 16)
BLE_sleep_clock_accuracy = STM32WBA5x_REV_ID_A_SCA_RANGE;
} else if (RevID == REV_ID_B) {

Check notice on line 68 in soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c:68 - BLE_sleep_clock_accuracy = STM32WBA5x_REV_ID_A_SCA_RANGE; + BLE_sleep_clock_accuracy = STM32WBA5x_REV_ID_A_SCA_RANGE;
BLE_sleep_clock_accuracy = STM32WBA5x_REV_ID_B_SCA_RANGE;
} else {
/* Revision ID not supported, default value of 500ppm applied */
BLE_sleep_clock_accuracy = STM32WBA5x_DEFAULT_SCA_RANGE;
}
#else
UNUSED(RevID);
#endif
/* defined(STM32WBA52xx) || defined(STM32WBA54xx) || defined(STM32WBA55xx) */
} else {

Check notice on line 78 in soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c:78 - UNUSED(RevID); + UNUSED(RevID); #endif - /* defined(STM32WBA52xx) || defined(STM32WBA54xx) || defined(STM32WBA55xx) */ + /* defined(STM32WBA52xx) || defined(STM32WBA54xx) || defined(STM32WBA55xx) */
/* LSE is not the Link Layer sleep clock source, sleep clock accurcay
* default value is 500 ppm */

Check warning on line 80 in soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

BLOCK_COMMENT_STYLE

soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c:80 Block comments use a trailing */ on a separate line
BLE_sleep_clock_accuracy = STM32WBA5x_DEFAULT_SCA_RANGE;
}

return BLE_sleep_clock_accuracy;
}
#endif /* CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE */

void ll_sys_sleep_clock_source_selection(void)
{
uint16_t freq_value = 0;
uint32_t linklayer_slp_clk_src = LL_RCC_RADIOSLEEPSOURCE_NONE;

linklayer_slp_clk_src = LL_RCC_RADIO_GetSleepTimerClockSource();
switch(linklayer_slp_clk_src) {

Check failure on line 94 in soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c:94 space required before the open parenthesis '('
case LL_RCC_RADIOSLEEPSOURCE_LSE:

Check notice on line 95 in soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

soc/st/stm32/stm32wbax/hci_if/ll_sys_if.c:95 - switch(linklayer_slp_clk_src) { + switch (linklayer_slp_clk_src) {
linklayer_slp_clk_src = RTC_SLPTMR;
break;

case LL_RCC_RADIOSLEEPSOURCE_LSI:
linklayer_slp_clk_src = RCO_SLPTMR;
break;

case LL_RCC_RADIOSLEEPSOURCE_HSE_DIV1000:
linklayer_slp_clk_src = CRYSTAL_OSCILLATOR_SLPTMR;
break;

case LL_RCC_RADIOSLEEPSOURCE_NONE:
/* No Link Layer sleep clock source selected */
assert_param(0);
break;
}
ll_intf_cmn_le_select_slp_clk_src((uint8_t)linklayer_slp_clk_src, &freq_value);
}

void ll_sys_reset(void)
{
#if (CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE == 0)
uint8_t bsca = 0;
#endif /* CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE */

/* Apply the selected link layer sleep timer source */
ll_sys_sleep_clock_source_selection();

/* Configure the link layer sleep clock accuracy if different from the default one */
#if (CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE != 0)
ll_intf_le_set_sleep_clock_accuracy(CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE);
#else
bsca = ll_sys_BLE_sleep_clock_accuracy_selection();
if (bsca != STM32WBA5x_DEFAULT_SCA_RANGE) {
ll_intf_le_set_sleep_clock_accuracy(bsca);
}
#endif /* CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE */
}
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ manifest:
groups:
- hal
- name: hal_stm32
revision: 6f0e5f70cb540c487e3e3678af2e95d0937f9863
revision: pull/237/head
path: modules/hal/stm32
groups:
- hal
Expand Down

0 comments on commit b9fb0a9

Please sign in to comment.