Appiko
SDK_BasicGeneric_B.c
Go to the documentation of this file.
1 
24 /* Includes ------------------------------------------------------------------*/
25 #include "SDK_EVAL_Config.h"
26 #include "S2LP_Config.h"
28 #include "S2LP_SDK_Util.h"
29 
30 
31 #define USE_VCOM
32 
33 
34 
35 
36 
68  BASE_FREQUENCY,
69  MODULATION_SELECT,
70  DATARATE,
71  FREQ_DEVIATION,
72  BANDWIDTH
73 };
74 
75 
80  PREAMBLE_LENGTH,
81  SYNC_LENGTH,
82  SYNC_WORD,
83  VARIABLE_LENGTH,
84  EXTENDED_LENGTH_FIELD,
85  CRC_MODE,
86  EN_ADDRESS,
87  EN_FEC,
88  EN_WHITENING
89 };
90 
91 
92 
100 };
101 
102 
107 
108 
112 uint8_t vectcRxBuff[128], cRxData;
113 
117 #define IRQ_PREEMPTION_PRIORITY 0x03
118 
135 static uint16_t M2S_GPIO_PIN_IRQ;
136 
137 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
138 {
139  if(GPIO_Pin==M2S_GPIO_PIN_IRQ)
140  {
141 
142  /* Get the IRQ status */
144 
145  /* Check the S2LP RX_DATA_DISC IRQ flag */
147  /* toggle LED1 */
148  SdkEvalLedToggle(LED1);
149 
150 #ifdef USE_VCOM
151  printf("DATA DISCARDED\n\r");
152 #endif
153 
154  /* RX command - to ensure the device will be ready for the next reception */
155  S2LPCmdStrobeRx();
156  }
157 
158  /* Check the S2LP RX_DATA_READY IRQ flag */
160  /* Get the RX FIFO size */
161  cRxData = S2LPFifoReadNumberBytesRxFifo();
162 
163  /* Read the RX FIFO */
164  S2LPSpiReadFifo(cRxData, vectcRxBuff);
165 
166  /* Flush the RX FIFO */
167  S2LPCmdStrobeFlushRxFifo();
168 
169  /* A simple way to check if the received data sequence is correct (in this case LED5 will toggle) */
170  {
171  SBool xCorrect=S_TRUE;
172 
173  for(uint8_t i=0 ; i<cRxData ; i++)
174  if(vectcRxBuff[i] != i+1)
175  xCorrect=S_FALSE;
176 
177  if(xCorrect) {
178  /* toggle LED2 */
179  SdkEvalLedToggle(LED2);
180 #ifdef USE_VCOM
181  printf("DATA CORRECT, RSSI: %d dBm\r\n",S2LPRadioGetRssidBm());
182 #endif
183  }
184  }
185  /* RX command - to ensure the device will be ready for the next reception */
186  S2LPCmdStrobeRx();
187 
188 #ifdef USE_VCOM
189  /* print the received data */
190  printf("B data received: [");
191  for(uint8_t i=0 ; i<cRxData ; i++)
192  printf("%d ", vectcRxBuff[i]);
193  printf("]\r\n");
194 #endif
195  }
196 
197  }
198 
199 }
200 
201 
202 #ifdef USE_STM32L0XX_NUCLEO
203 
208 static void SystemClock_Config(void)
209 {
210  RCC_ClkInitTypeDef RCC_ClkInitStruct;
211  RCC_OscInitTypeDef RCC_OscInitStruct;
212 
213  /* Enable Power Control clock */
214  __PWR_CLK_ENABLE();
215 
216  /* The voltage scaling allows optimizing the power consumption when the device is
217  clocked below the maximum system frequency, to update the voltage scaling value
218  regarding system frequency refer to product datasheet. */
219  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
220 
221  /* Enable HSI Oscillator and activate PLL with HSI as source */
222  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
223  RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
224  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
225  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
226  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
227  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_4;
228  RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;
229  RCC_OscInitStruct.HSICalibrationValue = 0x10;
230  HAL_RCC_OscConfig(&RCC_OscInitStruct);
231 
232  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
233  clocks dividers */
234  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
235  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
236  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
237  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
238  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
239  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
240 }
241 #else
242 static void SystemClock_Config(void)
243 {
244 
245  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
246  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
247 
248  /* Enable HSE Oscillator and Activate PLL with HSE as source */
249  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
250  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
251  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
252  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
253  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
254  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
255  RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
256  HAL_RCC_OscConfig(&RCC_OscInitStruct);
257 
258  /* Set Voltage scale1 as MCU will run at 32MHz */
259  __HAL_RCC_PWR_CLK_ENABLE();
260  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
261 
262  /* Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0 */
263  while (__HAL_PWR_GET_FLAG(PWR_FLAG_VOS) != RESET) {};
264 
265  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
266  clocks dividers */
267  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
268  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
269  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
270  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
271  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
272  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
273 
274 }
275 #endif
276 
277 
283 int main (void)
284 {
285  HAL_Init();
286  SystemClock_Config();
287 
289  SdkEvalLedInit(LED1);
291  S2LPSpiInit();
292 
293 #ifdef USE_VCOM
294  SdkEvalComInit();
295 #endif
296 
297  /* S2LP ON */
298  S2LPEnterShutdown();
299  S2LPExitShutdown();
300 
301  /* EEPROM SPI if init + data retrieving */
302  S2LPManagementIdentificationRFBoard();
303 
304  /* if the board has eeprom, we can compensate the offset calling S2LPManagementGetOffset
305  (if eeprom is not present this fcn will return 0) */
306  xRadioInit.lFrequencyBase = xRadioInit.lFrequencyBase + S2LPManagementGetOffset();
307 
308  /* if needed this will set the range extender pins */
309  S2LPManagementRangeExtInit();
310 
311  /* if needed this will set the EXT_REF bit of the S2-LP */
312  S2LPManagementTcxoInit();
313 
314  /* uC IRQ config */
316  M2S_GPIO_PIN_IRQ=SdkEvalGpioGetPin(M2S_GPIO_3);
317 
318  /* S2LP IRQ config */
320 
321  /* uC IRQ enable */
323 
324  /* S2LP Radio config */
326 
327  /* S2LP Packet config */
329 
330  /* S2LP IRQs enable */
334 
335  /* payload length config */
337 
338  /* RX timeout config */
339  S2LPTimerSetRxTimerUs(700000);
340  //SET_INFINITE_RX_TIMEOUT();
341 
342  /* IRQ registers blanking */
344 
345  /* RX command */
346  S2LPCmdStrobeRx();
347 
348  /* infinite loop */
349  while (1){
350  }
351 
352 }
353 
354 
355 
356 #ifdef USE_FULL_ASSERT
357 
364 void assert_failed(uint8_t* file, uint32_t line)
365 {
366  /* User can add his own implementation to report the file name and line number */
367  printf("Wrong parameters value: file %s on line %d\r\n", file, line);
368 
369  /* Infinite loop */
370  while (1)
371  {
372  }
373 }
374 #endif
375 
376 
394 /******************* (C) COPYRIGHT 2018 STMicroelectronics *****END OF FILE****/
void S2LPPktBasicSetPayloadLength(uint16_t nPayloadLength)
Set the payload length for S2LP Basic packets. Since the packet length depends from the address and t...
SBool
boolean type enumeration.
Definition: S2LP_Types.h:85
void S2LPGpioIrqDeInit(S2LPIrqs *pxIrqInit)
Deinit the S2LPIrqs structure setting all the bitfield to 0. Moreover, it sets the IRQ mask registers...
Definition: S2LP_Gpio.c:253
void S2LPGpioInit(SGpioInit *pxGpioInitStruct)
Initialize the S2LP GPIOx according to the specified parameters in the pxGpioInitStruct.
Definition: S2LP_Gpio.c:168
uint32_t lFrequencyBase
Definition: S2LP_Radio.h:114
SFlagStatus IRQ_RX_DATA_DISC
Definition: S2LP_Gpio.h:224
void SdkEvalM2SGpioInterruptCmd(M2SGpioPin xGpio, uint8_t nPreemption, uint8_t nSubpriority, FunctionalState xNewState)
Enables or disables the interrupt on GPIO .
uint8_t S2LPRadioInit(SRadioInit *pxSRadioInitStruct)
Initializes the S2LP analog and digital radio part according to the specified parameters in the pxSRa...
Definition: S2LP_Radio.c:559
SRadioInit xRadioInit
Radio structure fitting.
Common configuration header file.
void SdkEvalLedToggle(SdkEvalLed xLed)
Toggles the selected LED.
Definition: SDK_EVAL_Led.c:145
This file contains SDK EVAL configuration and useful defines.
PktBasicInit xBasicInit
Packet Basic structure fitting.
void S2LPPktBasicInit(PktBasicInit *pxPktBasicInit)
Initialize the S2LP Basic packet according to the specified parameters in the PktBasicInit struct....
Definition: S2LP_PktBasic.c:83
S2LP Basic Packet Init structure definition.
void S2LPGpioIrqConfig(IrqList xIrq, SFunctionalState xNewState)
Enable or disables a specific IRQ.
Definition: S2LP_Gpio.c:303
void S2LPGpioIrqClearStatus(void)
Clear the IRQ status registers.
Definition: S2LP_Gpio.c:403
uint16_t SdkEvalGpioGetPin(M2SGpioPin xGpio)
Gets the GPIO_PIN of the M2SGpioPin.
S2LP Radio Init structure definition.
Definition: S2LP_Radio.h:113
SFlagStatus IRQ_RX_DATA_READY
Definition: S2LP_Gpio.h:223
IRQ bitfield structure for S2LP. This structure is used to read or write the single IRQ bit....
Definition: S2LP_Gpio.h:222
void SdkEvalComInit(void)
Configures UART port in DMA mode for both RX and TX.
S2LPIrqs xIrqStatus
IRQ status struct declaration.
int main(void)
System main function.
uint8_t S2LPFifoReadNumberBytesRxFifo(void)
Return the number of elements in the Rx FIFO.
Definition: S2LP_Fifo.c:102
int32_t S2LPRadioGetRssidBm(void)
Returns the RSSI value.
Definition: S2LP_Qi.c:109
uint8_t vectcRxBuff[128]
Rx buffer declaration: how to store the received data.
S2LP Configuration and useful defines .
#define S2LPCmdStrobeRx()
Sends the RX command to S2-LP. Start to receive.
void SdkEvalM2SGpioInit(M2SGpioPin xGpio, M2SGpioMode xGpioMode)
Configures MCU GPIO and EXTI Line for GPIOs.
void SdkEvalIdentification(void)
Identifies the current motherboard.
SGpioInit xGpioIRQ
GPIO IRQ structure fitting.
void SdkEvalLedInit(SdkEvalLed xLed)
Configures LED GPIO.
Definition: SDK_EVAL_Led.c:98
S2LP GPIO Init structure definition.
Definition: S2LP_Gpio.h:158
#define IRQ_PREEMPTION_PRIORITY
Preemption priority IRQ.
void S2LPGpioIrqGetStatus(S2LPIrqs *pxIrqStatus)
Fill a pointer to a structure of S2LPIrqs type reading the IRQ_STATUS registers.
Definition: S2LP_Gpio.c:383
void S2LPTimerSetRxTimerUs(uint32_t lDesiredUsec)
Set the RX timeout timer counter and prescaler from the desired value in ms. it is possible to fix th...
Definition: S2LP_Timer.c:362