Appiko
SDK_BasicGeneric_A.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 
64  BASE_FREQUENCY,
65  MODULATION_SELECT,
66  DATARATE,
67  FREQ_DEVIATION,
68  BANDWIDTH
69 };
70 
71 
76  PREAMBLE_LENGTH,
77  SYNC_LENGTH,
78  SYNC_WORD,
79  VARIABLE_LENGTH,
80  EXTENDED_LENGTH_FIELD,
81  CRC_MODE,
82  EN_ADDRESS,
83  EN_FEC,
84  EN_WHITENING
85 };
86 
87 
95 };
96 
97 
101 volatile FlagStatus xTxDoneFlag = RESET;
102 
103 
108 
109 
113 uint8_t vectcTxBuff[20]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
114 
118 #define IRQ_PREEMPTION_PRIORITY 0x03
119 
136 static uint16_t M2S_GPIO_PIN_IRQ;
137 
138 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
139 {
140  if(GPIO_Pin==M2S_GPIO_PIN_IRQ)
141  {
142  /* Get the IRQ status */
144 
145  /* Check the SPIRIT TX_DATA_SENT IRQ flag */
147  {
148  /* set the tx_done_flag to manage the event in the main() */
149  xTxDoneFlag = SET;
150 
151  /* toggle LED1 */
152  SdkEvalLedToggle(LED1);
153  }
154  }
155 
156 }
157 
158 #ifdef USE_STM32L0XX_NUCLEO
159 
164 static void SystemClock_Config(void)
165 {
166  RCC_ClkInitTypeDef RCC_ClkInitStruct;
167  RCC_OscInitTypeDef RCC_OscInitStruct;
168 
169  /* Enable Power Control clock */
170  __PWR_CLK_ENABLE();
171 
172  /* The voltage scaling allows optimizing the power consumption when the device is
173  clocked below the maximum system frequency, to update the voltage scaling value
174  regarding system frequency refer to product datasheet. */
175  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
176 
177  /* Enable HSI Oscillator and activate PLL with HSI as source */
178  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
179  RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
180  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
181  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
182  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
183  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_4;
184  RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;
185  RCC_OscInitStruct.HSICalibrationValue = 0x10;
186  HAL_RCC_OscConfig(&RCC_OscInitStruct);
187 
188  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
189  clocks dividers */
190  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
191  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
192  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
193  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
194  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
195  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
196 }
197 #else
198 static void SystemClock_Config(void)
199 {
200 
201  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
202  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
203 
204  /* Enable HSE Oscillator and Activate PLL with HSE as source */
205  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
206  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
207  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
208  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
209  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
210  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
211  RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
212  HAL_RCC_OscConfig(&RCC_OscInitStruct);
213 
214  /* Set Voltage scale1 as MCU will run at 32MHz */
215  __HAL_RCC_PWR_CLK_ENABLE();
216  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
217 
218  /* Poll VOSF bit of in PWR_CSR. Wait until it is reset to 0 */
219  while (__HAL_PWR_GET_FLAG(PWR_FLAG_VOS) != RESET) {};
220 
221  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
222  clocks dividers */
223  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
224  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
225  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
226  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
227  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
228  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);
229 
230 }
231 #endif
232 
233 
239 int main (void)
240 {
241  HAL_Init();
242  SystemClock_Config();
243  //Empty Func
245  //Set LED pin as a output
246  SdkEvalLedInit(LED1);
247  //Set SDN pin as a output
249  //SPI Init
250  S2LPSpiInit();
251 
252 
253 #ifdef USE_VCOM
254  SdkEvalComInit();
255 #endif
256 
257  /* S2LP ON */
258  //Make SDN pin high
259  S2LPEnterShutdown();
260  //Make SDN pin low
261  S2LPExitShutdown();
262 
263 
264  /* EEPROM SPI if init + data retrieving */
265  //Something weird
266  S2LPManagementIdentificationRFBoard();
267 
268  /* if the board has eeprom, we can compensate the offset calling S2LPManagementGetOffset
269  (if eeprom is not present this fcn will return 0) */
270  //Add weird offset
271  xRadioInit.lFrequencyBase = xRadioInit.lFrequencyBase + S2LPManagementGetOffset();
272 
273  /* if needed this will set the range extender pins */
274 
275  S2LPManagementRangeExtInit();
276 
277  /* if needed this will set the EXT_REF bit of the S2-LP */
278  S2LPManagementTcxoInit();
279 
280  /* uC IRQ config */
281  //Enable IRQ for that pin
283  M2S_GPIO_PIN_IRQ=SdkEvalGpioGetPin(M2S_GPIO_3);
284 
285 
286  /* S2LP IRQ config */
288 
289  /* uC IRQ enable */
291 
292 
293  /* S2LP Radio config */
295 
296  /* S2LP Radio set power */
297  S2LPRadioSetMaxPALevel(S_DISABLE);
298  if(!S2LPManagementGetRangeExtender())
299  {
300  /* if we haven't an external PA, use the library function */
301  S2LPRadioSetPALeveldBm(7,POWER_DBM);
302  }
303  else
304  {
305  /* in case we are using the PA board, the S2LPRadioSetPALeveldBm will be not functioning because
306  the output power is affected by the amplification of this external component.
307  Set the raw register. */
308  uint8_t paLevelValue=0x25; /* for example, this value will give 23dBm about */
309  S2LPSpiWriteRegisters(PA_POWER8_ADDR, 1, &paLevelValue);
310  }
312 
313  /* S2LP Packet config */
315 
316  /* S2LP IRQs enable */
317  S2LPGpioIrqDeInit(NULL);
318  S2LPGpioIrqConfig(TX_DATA_SENT , S_ENABLE);
319 
320  /* payload length config */
322 
323  /* IRQ registers blanking */
325 
326  /* infinite loop */
327  while (1){
328 #ifdef USE_VCOM
329  printf("A data to transmit: [");
330 
331  for(uint8_t i=0 ; i<20 ; i++)
332  printf("%d ", vectcTxBuff[i]);
333  printf("]\n\r");
334 #endif
335 
336  /* fit the TX FIFO */
337  S2LPCmdStrobeFlushTxFifo();
338  S2LPSpiWriteFifo(20, vectcTxBuff);
339 
340  /* send the TX command */
341  S2LPCmdStrobeTx();
342 
343  /* wait for TX done */
344  while(!xTxDoneFlag);
345  xTxDoneFlag = RESET;
346 
347  /* pause between two transmissions */
348  SdkDelayMs(500);
349 
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 
377 
395 /******************* (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...
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
SFlagStatus IRQ_TX_DATA_SENT
Definition: S2LP_Gpio.h:225
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
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
int main(void)
System main function.
uint8_t vectcTxBuff[20]
Tx buffer declaration: data to transmit.
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.
SGpioInit xGpioIRQ
GPIO 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
#define PA_POWER8_ADDR
PA_POWER8 register.
Definition: S2LP_Regs.h:1073
uint16_t SdkEvalGpioGetPin(M2SGpioPin xGpio)
Gets the GPIO_PIN of the M2SGpioPin.
S2LP Radio Init structure definition.
Definition: S2LP_Radio.h:113
volatile FlagStatus xTxDoneFlag
Declare the Tx done flag.
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.
void S2LPRadioSetPALeveldBm(uint8_t cIndex, int32_t wPowerdBm)
Sets a specific PA_LEVEL register, with a value given in dBm.
Definition: S2LP_Radio.c:1209
void S2LPRadioSetPALevelMaxIndex(uint8_t cIndex)
Sets a specific PA_LEVEL_MAX_INDEX.
Definition: S2LP_Radio.c:1256
S2LP Configuration and useful defines .
#define IRQ_PREEMPTION_PRIORITY
Preemption priority IRQ.
S2LPIrqs xIrqStatus
IRQ status struct declaration.
#define S2LPCmdStrobeTx()
Sends the TX command to S2-LP. Start to transmit.
SRadioInit xRadioInit
Radio structure fitting.
void SdkEvalM2SGpioInit(M2SGpioPin xGpio, M2SGpioMode xGpioMode)
Configures MCU GPIO and EXTI Line for GPIOs.
void S2LPRadioSetMaxPALevel(SFunctionalState xNewState)
Set the MAX_DBM bit. This will allow to transmit at the maximum power.
Definition: S2LP_Radio.c:1184
void SdkEvalIdentification(void)
Identifies the current motherboard.
PktBasicInit xBasicInit
Packet Basic 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
void S2LPGpioIrqGetStatus(S2LPIrqs *pxIrqStatus)
Fill a pointer to a structure of S2LPIrqs type reading the IRQ_STATUS registers.
Definition: S2LP_Gpio.c:383