Skip to content

Commit a58e6c7

Browse files
committed
soc: st: stm32: stm32wbax pm enhancements
Power management enhancements to support suspend to ram with BLE activity. ST system clock module is no more used. Draft commit still to be refined. Signed-off-by: Alessandro Manganaro <[email protected]>
1 parent 96d062a commit a58e6c7

File tree

10 files changed

+313
-115
lines changed

10 files changed

+313
-115
lines changed

boards/st/nucleo_wba55cg/nucleo_wba55cg.dts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100

101101
&clk_hse {
102102
status = "okay";
103-
hse-div2;
104103
};
105104

106105
&clk_hsi {
@@ -109,9 +108,9 @@
109108

110109
&rcc {
111110
clocks = <&clk_hse>;
112-
clock-frequency = <DT_FREQ_M(16)>;
111+
clock-frequency = <DT_FREQ_M(32)>;
113112
ahb-prescaler = <1>;
114-
ahb5-prescaler = <2>;
113+
ahb5-prescaler = <1>;
115114
apb1-prescaler = <1>;
116115
apb2-prescaler = <2>;
117116
apb7-prescaler = <1>;

boards/st/nucleo_wba65ri/nucleo_wba65ri.dts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@
7979
};
8080
};
8181

82+
&clk_lsi {
83+
status = "okay";
84+
};
85+
8286
&clk_lse {
8387
status = "okay";
8488
};
8589

8690
&clk_hse {
87-
hse-div2;
8891
status = "okay";
8992
};
9093

@@ -94,9 +97,9 @@
9497

9598
&rcc {
9699
clocks = <&clk_hse>;
97-
clock-frequency = <DT_FREQ_M(16)>;
100+
clock-frequency = <DT_FREQ_M(32)>;
98101
ahb-prescaler = <1>;
99-
ahb5-prescaler = <2>;
102+
ahb5-prescaler = <1>;
100103
apb1-prescaler = <1>;
101104
apb2-prescaler = <2>;
102105
apb7-prescaler = <1>;

drivers/bluetooth/hci/hci_stm32wba.c

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
#include <zephyr/drivers/bluetooth.h>
1414
#include <zephyr/bluetooth/addr.h>
1515
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
16+
#include <zephyr/pm/policy.h>
17+
#include <zephyr/pm/device.h>
18+
#include <zephyr/pm/pm.h>
19+
#ifdef CONFIG_PM_DEVICE
20+
#include "linklayer_plat.h"
21+
#endif
1622
#include <linklayer_plat_local.h>
1723

1824
#include <zephyr/sys/byteorder.h>
@@ -454,6 +460,53 @@ static int bt_hci_stm32wba_setup(const struct device *dev,
454460
}
455461
#endif /* CONFIG_BT_HCI_SETUP */
456462

463+
#ifdef CONFIG_PM_DEVICE
464+
static int radio_pm_action(const struct device *dev, enum pm_device_action action)
465+
{
466+
switch (action) {
467+
case PM_DEVICE_ACTION_RESUME:
468+
LL_AHB5_GRP1_EnableClock(LL_AHB5_GRP1_PERIPH_RADIO);
469+
#if defined(CONFIG_PM_S2RAM)
470+
if (LL_PWR_IsActiveFlag_SB() == 1U) {
471+
/* Put the radio in active state */
472+
link_layer_register_isr();
473+
}
474+
#endif
475+
LINKLAYER_PLAT_NotifyWFIExit();
476+
ll_sys_dp_slp_exit();
477+
break;
478+
case PM_DEVICE_ACTION_SUSPEND:
479+
#if defined(CONFIG_PM_S2RAM)
480+
uint32_t radio_remaining_time = 0;
481+
enum pm_state state = pm_state_next_get(_current_cpu->id)->state;
482+
483+
if (state == PM_STATE_SUSPEND_TO_RAM) {
484+
/* */
485+
uint32_t cmd_status =
486+
ll_intf_le_get_remaining_time_for_next_event(&radio_remaining_time);
487+
UNUSED(cmd_status);
488+
assert_param(cmd_status == SUCCESS);
489+
490+
if (radio_remaining_time == LL_DP_SLP_NO_WAKEUP) {
491+
/* No next radio event scheduled */
492+
(void)ll_sys_dp_slp_enter(LL_DP_SLP_NO_WAKEUP);
493+
} else /* if (radio_remaining_time > RADIO_DEEPSLEEP_WAKEUP_TIME_US) */ {
494+
/* No event in a "near" futur */
495+
(void)ll_sys_dp_slp_enter(radio_remaining_time -
496+
CFG_LPM_STDBY_WAKEUP_TIME);
497+
}
498+
}
499+
#endif
500+
LINKLAYER_PLAT_NotifyWFIEnter();
501+
break;
502+
default:
503+
return -ENOTSUP;
504+
}
505+
506+
return 0;
507+
}
508+
#endif /* CONFIG_PM_DEVICE */
509+
457510
static DEVICE_API(bt_hci, drv) = {
458511
#if defined(CONFIG_BT_HCI_SETUP)
459512
.setup = bt_hci_stm32wba_setup,
@@ -463,10 +516,11 @@ static DEVICE_API(bt_hci, drv) = {
463516
};
464517

465518
#define HCI_DEVICE_INIT(inst) \
466-
static struct hci_data hci_data_##inst = { \
467-
}; \
468-
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &hci_data_##inst, NULL, \
469-
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv)
519+
static struct hci_data hci_data_##inst = {}; \
520+
PM_DEVICE_DT_INST_DEFINE(inst, radio_pm_action); \
521+
DEVICE_DT_INST_DEFINE(inst, NULL, PM_DEVICE_DT_INST_GET(inst), &hci_data_##inst, NULL, \
522+
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv);
470523

471524
/* Only one instance supported */
472525
HCI_DEVICE_INIT(0)
526+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2023 STMicroelectronics
5+
*/
6+
7+
/ {
8+
/* Change min residency time to ease power consumption measurement */
9+
cpus {
10+
cpu0: cpu@0 {
11+
cpu-power-states = <&stop0 &stop1 &standby>;
12+
};
13+
14+
power-states {
15+
standby: state2 {
16+
compatible = "zephyr,power-state";
17+
power-state-name = "suspend-to-ram";
18+
substate-id = <1>;
19+
min-residency-us = <10000>;
20+
exit-latency-us = <1000>;
21+
};
22+
};
23+
};
24+
25+
};
26+
27+
&lptim1 {
28+
status = "okay";
29+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2023 STMicroelectronics
5+
*/
6+
7+
/ {
8+
/* Change min residency time to ease power consumption measurement */
9+
cpus {
10+
cpu0: cpu@0 {
11+
cpu-power-states = <&stop0 &stop1 &standby>;
12+
};
13+
14+
power-states {
15+
standby: state2 {
16+
compatible = "zephyr,power-state";
17+
power-state-name = "suspend-to-ram";
18+
substate-id = <1>;
19+
min-residency-us = <10000>;
20+
exit-latency-us = <1000>;
21+
};
22+
};
23+
};
24+
};
25+
26+
&lptim1 {
27+
status = "okay";
28+
};

samples/bluetooth/peripheral_hr/prj.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ CONFIG_BT_BAS=y
88
CONFIG_BT_HRS=y
99
CONFIG_BT_DEVICE_NAME="Zephyr Heartrate Sensor"
1010
CONFIG_BT_DEVICE_APPEARANCE=833
11+
12+
CONFIG_PM=y
13+
CONFIG_PM_DEVICE=y
14+
CONFIG_PM_DEVICE_RUNTIME=y
15+
CONFIG_PM_DEVICE_SYSTEM_MANAGED=y
16+
CONFIG_PM_S2RAM=y

soc/st/stm32/stm32wbax/hci_if/linklayer_plat_adapt.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
#include <stm32_backup_domain.h>
1212

13-
#include "scm.h"
13+
#include "app_conf.h"
14+
#include "bsp.h"
1415

1516
#define LOG_LEVEL CONFIG_SOC_LOG_LEVEL
1617
LOG_MODULE_REGISTER(linklayer_plat_adapt);
@@ -245,17 +246,13 @@ void LINKLAYER_PLAT_StartRadioEvt(void)
245246
__HAL_RCC_RADIO_CLK_SLEEP_ENABLE();
246247

247248
NVIC_SetPriority((IRQn_Type)RADIO_INTR_NUM, RADIO_INTR_PRIO_HIGH_Z);
248-
249-
scm_notifyradiostate(SCM_RADIO_ACTIVE);
250249
}
251250

252251
void LINKLAYER_PLAT_StopRadioEvt(void)
253252
{
254253
__HAL_RCC_RADIO_CLK_SLEEP_DISABLE();
255254

256255
NVIC_SetPriority((IRQn_Type)RADIO_INTR_NUM, RADIO_INTR_PRIO_LOW_Z);
257-
258-
scm_notifyradiostate(SCM_RADIO_NOT_ACTIVE);
259256
}
260257

261258
/* Link Layer notification for RCO calibration start */

0 commit comments

Comments
 (0)