Skip to content

Commit 684b90e

Browse files
rjaylesdanieldegrasse
authored andcommitted
bluetooth: stm32wbax: add temperature calibration of linklayer
This patch allows to link the request of the linklayer for a temperature calibration to the temperature driver. The linklayer will then adapt and trigger its calibration related to the current temperature. Signed-off-by: Romain Jayles <romain.jayles@st.com>
1 parent 94b8265 commit 684b90e

File tree

4 files changed

+85
-11
lines changed

4 files changed

+85
-11
lines changed

drivers/bluetooth/hci/Kconfig.stm32

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
menu "STM32WBA Bluetooth configuration"
6-
depends on BT_STM32WBA
6+
depends on BT_STM32WBA
77

8-
config BT_STM32WBA_USE_TEMPERATURE_BASED_RADIO_CALIBRATION
8+
config BT_STM32WBA_USE_TEMP_BASED_CALIB
99
bool "STM32WBA Radio calibration based on temperature sensor"
1010
default y
1111
select SENSOR
1212
select STM32_TEMP
1313
help
14-
Allows the linklayer to calibrate itself on the current temperature read on the ADC4
14+
Allows the linklayer to calibrate itself on the current temperature read on the ADC4
1515
endmenu

drivers/bluetooth/hci/hci_stm32wba.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,6 @@ static int bt_hci_stm32wba_open(const struct device *dev, bt_hci_recv_t recv)
361361

362362
link_layer_register_isr();
363363

364-
ll_sys_config_params();
365-
366364
ret = bt_ble_ctlr_init();
367365
if (ret == 0) {
368366
data->recv = recv;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,6 @@ void LINKLAYER_PLAT_RCOStopClbr(void)
270270
/* Required only for RCO module usage in the context of LSI2 calibration */
271271
}
272272

273-
/* TODO: To do when porting the temperature measurement function and thread */
274-
void LINKLAYER_PLAT_RequestTemperature(void) {}
275-
276273
void LINKLAYER_PLAT_SCHLDR_TIMING_UPDATE_NOT(Evnt_timing_t *p_evnt_timing) {}
277274

278275
void LINKLAYER_PLAT_EnableOSContextSwitch(void)

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

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@
1111
LOG_MODULE_REGISTER(ll_sys_if_adapt);
1212

1313
#include "ll_sys.h"
14+
#include "ll_intf_cmn.h"
15+
#if defined(CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB)
16+
#include <zephyr/drivers/sensor.h>
17+
#endif /* defined(CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB) */
1418

1519
extern struct k_mutex ble_ctrl_stack_mutex;
1620
extern struct k_work_q ll_work_q;
1721
struct k_work ll_sys_work;
1822

23+
#if defined(CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB)
24+
static const struct device *dev_temp_sensor = DEVICE_DT_GET(DT_ALIAS(die_temp0));
25+
static struct k_work temp_calibration_work;
26+
#endif /* defined(CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB) */
27+
1928
static void ll_sys_bg_process_handler(struct k_work *work)
2029
{
2130
k_mutex_lock(&ble_ctrl_stack_mutex, K_FOREVER);
@@ -38,6 +47,76 @@ void ll_sys_bg_process_init(void)
3847
k_work_init(&ll_sys_work, &ll_sys_bg_process_handler);
3948
}
4049

41-
/* TODO: Implement temperature measurement thread after
42-
* implementing temperature measurement request function
43-
**/
50+
#if defined(CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB)
51+
52+
/**
53+
* @brief Link Layer temperature calibration function
54+
* @param None
55+
* @retval None
56+
*/
57+
static void ll_sys_temperature_calibration_measurement(void)
58+
{
59+
struct sensor_value val;
60+
61+
int rc = sensor_sample_fetch(dev_temp_sensor);
62+
63+
if (rc) {
64+
LOG_ERR("Failed to fetch sample (%d)", rc);
65+
return;
66+
}
67+
68+
rc = sensor_channel_get(dev_temp_sensor, SENSOR_CHAN_DIE_TEMP, &val);
69+
if (rc) {
70+
LOG_ERR("Failed to get data (%d)", rc);
71+
return;
72+
}
73+
74+
LOG_DBG("Radio calibration, temperature : %u °C", val.val1);
75+
ll_intf_cmn_set_temperature_value(val.val1);
76+
}
77+
78+
/**
79+
* @brief Link Layer temperature calibration work handler task
80+
* @param work
81+
* @retval None
82+
*/
83+
void ll_sys_temperature_calibration_measurement_work_handler(struct k_work *work)
84+
{
85+
ll_sys_temperature_calibration_measurement();
86+
}
87+
88+
/**
89+
* @brief Link Layer temperature request background process initialization
90+
* @param None
91+
* @retval None
92+
*/
93+
void ll_sys_bg_temperature_measurement_init(void)
94+
{
95+
if (!device_is_ready(dev_temp_sensor)) {
96+
LOG_ERR("dev_temp_sensor: device %s not ready", dev_temp_sensor->name);
97+
k_panic();
98+
} else {
99+
/* Register Temperature Measurement task */
100+
k_work_init(&temp_calibration_work,
101+
ll_sys_temperature_calibration_measurement_work_handler);
102+
}
103+
}
104+
105+
/**
106+
* @brief Request background task processing for temperature measurement
107+
* @param None
108+
* @retval None
109+
*/
110+
void ll_sys_bg_temperature_measurement(void)
111+
{
112+
static uint8_t initial_temperature_acquisition;
113+
114+
if (initial_temperature_acquisition == 0) {
115+
ll_sys_temperature_calibration_measurement();
116+
initial_temperature_acquisition = 1;
117+
} else {
118+
k_work_submit_to_queue(&ll_work_q, &temp_calibration_work);
119+
}
120+
}
121+
122+
#endif /* defined(CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB) */

0 commit comments

Comments
 (0)