L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
radio_board_if.c
Go to the documentation of this file.
1/* USER CODE BEGIN Header */
2/**
3 ******************************************************************************
4 * @file radio_board_if.c
5 * @author MCD Application Team
6 * @brief This file provides an interface layer between MW and Radio Board
7 ******************************************************************************
8 * @attention
9 *
10 * Copyright (c) 2026 STMicroelectronics.
11 * All rights reserved.
12 *
13 * This software is licensed under terms that can be found in the LICENSE file
14 * in the root directory of this software component.
15 * If no LICENSE file comes with this software, it is provided AS-IS.
16 *
17 ******************************************************************************
18 */
19/* USER CODE END Header */
20
21/* Includes ------------------------------------------------------------------*/
22#include "radio_board_if.h"
23
24/* USER CODE BEGIN Includes */
25
26#include "radio_driver.h"
27/* USER CODE END Includes */
28
29/* External variables ---------------------------------------------------------*/
30/* USER CODE BEGIN EV */
31
32/* USER CODE END EV */
33
34/* Private typedef -----------------------------------------------------------*/
35/* USER CODE BEGIN PTD */
36
37/* USER CODE END PTD */
38
39/* Private define ------------------------------------------------------------*/
40/* USER CODE BEGIN PD */
41
42/* USER CODE END PD */
43
44/* Private macro -------------------------------------------------------------*/
45/* USER CODE BEGIN PM */
46
47/* USER CODE END PM */
48
49/* Private variables ---------------------------------------------------------*/
50/* USER CODE BEGIN PV */
51
52/* USER CODE END PV */
53
54/* Private function prototypes -----------------------------------------------*/
55/* USER CODE BEGIN PFP */
56
57/* USER CODE END PFP */
58
59/* Exported functions --------------------------------------------------------*/
60int32_t RBI_Init(void)
61{
62 /* USER CODE BEGIN RBI_Init_1 */
63
64 /* USER CODE END RBI_Init_1 */
65#if defined(USE_BSP_DRIVER)
66 /* Important note: BSP code is board dependent
67 * STM32WL_Nucleo code can be found
68 * either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
69 * or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
70 * 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
71 * on board RF switch configuration (pin control, number of port etc)
72 * on TCXO configuration
73 * on DC/DC configuration
74 * on maximum output power that the board can deliver*/
75 return BSP_RADIO_Init();
76#else
77 /* 2/ Or implement RBI_Init here */
78 int32_t retcode = 0;
79 /* USER CODE BEGIN RBI_Init_2 */
80 GPIO_InitTypeDef gpio_init_structure = {0};
81
82 /*
83 * XXX: does not appear to be a way to over-ride XTAL_DEFAULT_CAP_VALUE
84 * This function is called shortly after setting this to the wrong value,
85 * so correct it here
86 */
87 SUBGRF_WriteRegister( REG_XTA_TRIM, 0x14 );
88 SUBGRF_WriteRegister( REG_XTB_TRIM, 0x14 );
89
92
93 /* Configure the Radio Switch pin */
94 gpio_init_structure.Pin = RF_SW_CTRL1_PIN;
95 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
96 gpio_init_structure.Pull = GPIO_NOPULL;
97 gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
98 HAL_GPIO_Init(RF_SW_CTRL1_GPIO_PORT, &gpio_init_structure);
99 gpio_init_structure.Pin = RF_SW_CTRL2_PIN;
100 HAL_GPIO_Init(RF_SW_CTRL2_GPIO_PORT, &gpio_init_structure);
101
102 HAL_GPIO_WritePin(RF_SW_CTRL2_GPIO_PORT, RF_SW_CTRL2_PIN, GPIO_PIN_RESET);
103 HAL_GPIO_WritePin(RF_SW_CTRL1_GPIO_PORT, RF_SW_CTRL1_PIN, GPIO_PIN_RESET);
104
105 /* USER CODE END RBI_Init_2 */
106 return retcode;
107#endif /* USE_BSP_DRIVER */
108}
109
110int32_t RBI_DeInit(void)
111{
112 /* USER CODE BEGIN RBI_DeInit_1 */
113
114 /* USER CODE END RBI_DeInit_1 */
115#if defined(USE_BSP_DRIVER)
116 /* Important note: BSP code is board dependent
117 * STM32WL_Nucleo code can be found
118 * either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
119 * or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
120 * 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
121 * on board RF switch configuration (pin control, number of port etc)
122 * on TCXO configuration
123 * on DC/DC configuration
124 * on maximum output power that the board can deliver*/
125 return BSP_RADIO_DeInit();
126#else
127 /* 2/ Or implement RBI_DeInit here */
128 int32_t retcode = 0;
129 /* USER CODE BEGIN RBI_DeInit_2 */
130 /* Turn off switch */
131 HAL_GPIO_WritePin(RF_SW_CTRL1_GPIO_PORT, RF_SW_CTRL1_PIN, GPIO_PIN_RESET);
132 HAL_GPIO_WritePin(RF_SW_CTRL2_GPIO_PORT, RF_SW_CTRL2_PIN, GPIO_PIN_RESET);
133
134 /* DeInit the Radio Switch pin */
135 HAL_GPIO_DeInit(RF_SW_CTRL1_GPIO_PORT, RF_SW_CTRL1_PIN);
136 HAL_GPIO_DeInit(RF_SW_CTRL2_GPIO_PORT, RF_SW_CTRL2_PIN);
137
138 /* USER CODE END RBI_DeInit_2 */
139 return retcode;
140#endif /* USE_BSP_DRIVER */
141}
142
144{
145 /* USER CODE BEGIN RBI_ConfigRFSwitch_1 */
146
147 /* USER CODE END RBI_ConfigRFSwitch_1 */
148#if defined(USE_BSP_DRIVER)
149
150 /* Important note: BSP code is board dependent
151 * STM32WL_Nucleo code can be found
152 * either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
153 * or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
154 * 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
155 * on board RF switch configuration (pin control, number of port etc)
156 * on TCXO configuration
157 * on DC/DC configuration
158 * on maximum output power that the board can deliver*/
159 return BSP_RADIO_ConfigRFSwitch((BSP_RADIO_Switch_TypeDef) Config);
160#else
161 /* 2/ Or implement RBI_ConfigRFSwitch here */
162 int32_t retcode = 0;
163 /* USER CODE BEGIN RBI_ConfigRFSwitch_2 */
164 switch (Config)
165 {
166 case RBI_SWITCH_OFF:
167 /* Turn off switch */
168 HAL_GPIO_WritePin(RF_SW_CTRL1_GPIO_PORT, RF_SW_CTRL1_PIN, GPIO_PIN_RESET);
169 HAL_GPIO_WritePin(RF_SW_CTRL2_GPIO_PORT, RF_SW_CTRL2_PIN, GPIO_PIN_RESET);
170 break;
171
172 case RBI_SWITCH_RX:
173 /*Turns On in Rx Mode the RF Switch */
174 HAL_GPIO_WritePin(RF_SW_CTRL1_GPIO_PORT, RF_SW_CTRL1_PIN, GPIO_PIN_SET);
175 HAL_GPIO_WritePin(RF_SW_CTRL2_GPIO_PORT, RF_SW_CTRL2_PIN, GPIO_PIN_RESET);
176 break;
177
179 /*Turns On in Tx Low Power the RF Switch */
180 HAL_GPIO_WritePin(RF_SW_CTRL1_GPIO_PORT, RF_SW_CTRL1_PIN, GPIO_PIN_SET);
181 HAL_GPIO_WritePin(RF_SW_CTRL2_GPIO_PORT, RF_SW_CTRL2_PIN, GPIO_PIN_SET);
182 break;
183
185 /*Turns On in Tx High Power the RF Switch */
186 HAL_GPIO_WritePin(RF_SW_CTRL1_GPIO_PORT, RF_SW_CTRL1_PIN, GPIO_PIN_RESET);
187 HAL_GPIO_WritePin(RF_SW_CTRL2_GPIO_PORT, RF_SW_CTRL2_PIN, GPIO_PIN_SET);
188 break;
189
190 default:
191 break;
192 }
193 /* USER CODE END RBI_ConfigRFSwitch_2 */
194 return retcode;
195#endif /* USE_BSP_DRIVER */
196}
197
198int32_t RBI_GetTxConfig(void)
199{
200 /* USER CODE BEGIN RBI_GetTxConfig_1 */
201
202 /* USER CODE END RBI_GetTxConfig_1 */
203#if defined(USE_BSP_DRIVER)
204 /* Important note: BSP code is board dependent
205 * STM32WL_Nucleo code can be found
206 * either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
207 * or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
208 * 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
209 * on board RF switch configuration (pin control, number of port etc)
210 * on TCXO configuration
211 * on DC/DC configuration
212 * on maximum output power that the board can deliver*/
213 return BSP_RADIO_GetTxConfig();
214#else
215 /* 2/ Or implement RBI_GetTxConfig here */
216 int32_t retcode = RBI_CONF_RFO;
217 /* USER CODE BEGIN RBI_GetTxConfig_2 */
218 // MT - toto som sem dal podla Gemini: https://gemini.google.com/share/f0bdb0e5fc24
219 //retcode = RBI_CONF_RFO_HP; // high-power, other not works !!! this is very important !!! cez MX
220 /* USER CODE END RBI_GetTxConfig_2 */
221 return retcode;
222#endif /* USE_BSP_DRIVER */
223}
224
225int32_t RBI_IsTCXO(void)
226{
227 /* USER CODE BEGIN RBI_IsTCXO_1 */
228
229 /* USER CODE END RBI_IsTCXO_1 */
230#if defined(USE_BSP_DRIVER)
231 /* Important note: BSP code is board dependent
232 * STM32WL_Nucleo code can be found
233 * either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
234 * or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
235 * 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
236 * on board RF switch configuration (pin control, number of port etc)
237 * on TCXO configuration
238 * on DC/DC configuration
239 * on maximum output power that the board can deliver*/
240 return BSP_RADIO_IsTCXO();
241#else
242 /* 2/ Or implement RBI_IsTCXO here */
243 int32_t retcode = IS_TCXO_SUPPORTED;
244 /* USER CODE BEGIN RBI_IsTCXO_2 */
245 //retcode=1;
246 /* USER CODE END RBI_IsTCXO_2 */
247 return retcode;
248#endif /* USE_BSP_DRIVER */
249}
250
251int32_t RBI_IsDCDC(void)
252{
253 /* USER CODE BEGIN RBI_IsDCDC_1 */
254
255 /* USER CODE END RBI_IsDCDC_1 */
256#if defined(USE_BSP_DRIVER)
257 /* Important note: BSP code is board dependent
258 * STM32WL_Nucleo code can be found
259 * either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
260 * or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
261 * 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
262 * on board RF switch configuration (pin control, number of port etc)
263 * on TCXO configuration
264 * on DC/DC configuration
265 * on maximum output power that the board can deliver*/
266 return BSP_RADIO_IsDCDC();
267#else
268 /* 2/ Or implement RBI_IsDCDC here */
269 int32_t retcode = IS_DCDC_SUPPORTED;
270 /* USER CODE BEGIN RBI_IsDCDC_2 */
271
272 /* USER CODE END RBI_IsDCDC_2 */
273 return retcode;
274#endif /* USE_BSP_DRIVER */
275}
276
278{
279 /* USER CODE BEGIN RBI_GetRFOMaxPowerConfig_1 */
280
281 /* USER CODE END RBI_GetRFOMaxPowerConfig_1 */
282#if defined(USE_BSP_DRIVER)
283 /* Important note: BSP code is board dependent
284 * STM32WL_Nucleo code can be found
285 * either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
286 * or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
287 * 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
288 * on board RF switch configuration (pin control, number of port etc)
289 * on TCXO configuration
290 * on DC/DC configuration
291 * on maximum output power that the board can deliver*/
292 return BSP_RADIO_GetRFOMaxPowerConfig((BSP_RADIO_RFOMaxPowerConfig_TypeDef) Config);
293#else
294 /* 2/ Or implement RBI_RBI_GetRFOMaxPowerConfig here */
295 int32_t ret = 0;
296 /* USER CODE BEGIN RBI_GetRFOMaxPowerConfig_2 */
297 if (Config == RBI_RFO_LP_MAXPOWER) {
298 ret = 15; /*dBm*/
299 } else {
300 ret = 22; /*dBm*/
301 }
302 /* USER CODE END RBI_GetRFOMaxPowerConfig_2 */
303 return ret;
304#endif /* USE_BSP_DRIVER */
305}
306/* USER CODE BEGIN EF */
307
308/* USER CODE END EF */
309
310/* Private Functions Definition -----------------------------------------------*/
311/* USER CODE BEGIN PrFD */
312
313/* USER CODE END PrFD */
int32_t RBI_GetTxConfig(void)
Return Board Configuration.
int32_t RBI_DeInit(void)
DeInit Radio Switch.
int32_t RBI_IsDCDC(void)
Get If DCDC is to be present on board.
int32_t RBI_ConfigRFSwitch(RBI_Switch_TypeDef Config)
Configure Radio Switch.
int32_t RBI_IsTCXO(void)
Get If TCXO is to be present on board.
int32_t RBI_GetRFOMaxPowerConfig(RBI_RFOMaxPowerConfig_TypeDef Config)
Return RF Output Max Power Configuration of matching circuit.
int32_t RBI_Init(void)
Init Radio Switch.
Header for Radio interface configuration.
#define RF_SW_CTRL1_GPIO_CLK_ENABLE()
#define RF_SW_CTRL2_GPIO_CLK_ENABLE()
RBI_RFOMaxPowerConfig_TypeDef
@ RBI_RFO_LP_MAXPOWER
#define RBI_CONF_RFO
#define IS_TCXO_SUPPORTED
#define RF_SW_CTRL1_PIN
#define IS_DCDC_SUPPORTED
RBI_Switch_TypeDef
@ RBI_SWITCH_RFO_HP
@ RBI_SWITCH_RX
@ RBI_SWITCH_OFF
@ RBI_SWITCH_RFO_LP
#define RF_SW_CTRL2_GPIO_PORT
#define RF_SW_CTRL1_GPIO_PORT
#define RF_SW_CTRL2_PIN