Skip to content

Commit 57593c5

Browse files
committed
Add support to X-NUCLEO-S2915A1 and improve stability
1 parent 56777b2 commit 57593c5

File tree

2 files changed

+65
-78
lines changed

2 files changed

+65
-78
lines changed

src/S2LP.cpp

Lines changed: 60 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@
5555

5656
#define LINEAR_FIFO_ADDRESS 0xFF /*!< Linear FIFO address*/
5757

58-
#define XTAL_FREQUENCY 50000000U
59-
60-
#define PREAMBLE_LENGTH (64*4)
61-
#define DATARATE 38400
62-
#define MIN_PERIOD_WAKEUP ((8000*((PREAMBLE_LENGTH/4)-2))/DATARATE)
63-
6458
/* Class Implementation ------------------------------------------------------*/
6559

6660
/** Constructor
@@ -89,7 +83,6 @@ S2LP::S2LP(SPIClass *spi, int csn, int sdn, int irqn, uint32_t frequency, uint32
8983
memset((void *)vectcTxBuff, 0, FIFO_SIZE*sizeof(uint8_t));
9084
cRxData = 0;
9185
is_waiting_for_read = false;
92-
is_tx_done_before_read = false;
9386
is_bypass_enabled = false;
9487
}
9588

@@ -125,7 +118,7 @@ void S2LP::begin(void)
125118
SRadioInit xRadioInit = {
126119
lFrequencyBase, /* base carrier frequency */
127120
MOD_2FSK, /* modulation type */
128-
DATARATE, /* data rate */
121+
38400, /* data rate */
129122
20000, /* frequency deviation */
130123
100000 /* bandwidth */
131124
};
@@ -161,7 +154,7 @@ void S2LP::begin(void)
161154
S2LPRadioSetPALevelMaxIndex(7);
162155

163156
PktBasicInit xBasicInit={
164-
PREAMBLE_LENGTH, /* Preamble length */
157+
16, /* Preamble length */
165158
32, /* Sync length */
166159
0x88888888, /* Sync word */
167160
S_ENABLE, /* Variable length */
@@ -186,7 +179,7 @@ void S2LP::begin(void)
186179
S2LPPktBasicAddressesInit(&xAddressInit);
187180

188181
SCsmaInit xCsmaInit={
189-
S_DISABLE, /* Persistent mode enable/disable */
182+
S_ENABLE, /* Persistent mode enable/disable */
190183
CSMA_PERIOD_64TBIT, /* CS Period */
191184
3, /* CS Timeout */
192185
5, /* Max number of backoffs */
@@ -215,26 +208,15 @@ void S2LP::begin(void)
215208
S2LPGpioIrqConfig(RX_DATA_READY,S_ENABLE);
216209
S2LPGpioIrqConfig(TX_DATA_SENT , S_ENABLE);
217210

218-
/* IRQ registers blanking */
219-
S2LPGpioIrqClearStatus();
220-
221211
/* clear FIFO if needed */
222212
S2LPCmdStrobeFlushRxFifo();
223213

224-
/* set the LDC mode wkup */
225-
S2LPTimerSetWakeUpTimerUs(1000*MIN_PERIOD_WAKEUP);
214+
/* Set infinite Timeout */
215+
S2LPTimerSetRxTimerCounter(0);
216+
S2LPTimerSetRxTimerStopCondition(ANY_ABOVE_THRESHOLD);
226217

227-
/* set the rx timeout */
228-
S2LPTimerSetRxTimerUs(30000);
229-
230-
/* use SLEEP_A mode (default) */
231-
S2LPTimerSleepB(S_DISABLE);
232-
233-
/* enable LDC mode, FAST RX TERM and start Rx */
234-
S2LPTimerLdcrMode(S_ENABLE);
235-
236-
/* enable the fast rx timer */
237-
S2LpTimerFastRxTermTimer(S_ENABLE);
218+
/* IRQ registers blanking */
219+
S2LPGpioIrqClearStatus();
238220

239221
uint8_t tmp = 0x90;
240222
S2LPSpiWriteRegisters(0x76, 1, &tmp);
@@ -293,7 +275,6 @@ void S2LP::end(void)
293275
memset((void *)vectcTxBuff, 0, FIFO_SIZE*sizeof(uint8_t));
294276
cRxData = 0;
295277
is_waiting_for_read = false;
296-
is_tx_done_before_read = false;
297278
is_bypass_enabled = false;
298279
}
299280

@@ -335,10 +316,6 @@ uint8_t S2LP::send(uint8_t *payload, uint8_t payload_len, uint8_t dest_addr, boo
335316
return 1;
336317
}
337318

338-
/* Disable LDC */
339-
S2LPTimerLdcrMode(S_DISABLE);
340-
S2LpTimerFastRxTermTimer(S_DISABLE);
341-
342319
S2LPPktBasicSetPayloadLength(payload_len);
343320

344321
S2LPSetRxSourceReferenceAddress(dest_addr);
@@ -383,14 +360,7 @@ uint8_t S2LP::send(uint8_t *payload, uint8_t payload_len, uint8_t dest_addr, boo
383360
S2LPCsma(S_DISABLE);
384361
}
385362

386-
/* Enable LDC */
387-
S2LPTimerLdcrMode(S_ENABLE);
388-
S2LpTimerFastRxTermTimer(S_ENABLE);
389-
390-
if(is_waiting_for_read)
391-
{
392-
is_tx_done_before_read = true;
393-
} else
363+
if(!is_waiting_for_read)
394364
{
395365
uint8_t tmp = 0x90;
396366
S2LPSpiWriteRegisters(0x76, 1, &tmp);
@@ -454,37 +424,64 @@ uint8_t S2LP::read(uint8_t *payload, uint8_t payload_len)
454424

455425
is_waiting_for_read = false;
456426

457-
if(is_tx_done_before_read)
458-
{
459-
is_tx_done_before_read = false;
460-
uint8_t tmp = 0x90;
461-
S2LPSpiWriteRegisters(0x76, 1, &tmp);
462-
463-
if(s_paInfo.paRfRangeExtender == RANGE_EXT_SKYWORKS_SKY66420)
464-
{
465-
FEM_Operation_SKY66420(FEM_RX);
466-
}
427+
uint8_t tmp = 0x90;
428+
S2LPSpiWriteRegisters(0x76, 1, &tmp);
467429

468-
/* Return to RX state */
469-
S2LPCmdStrobeCommand(CMD_RX);
470-
} else
430+
if(s_paInfo.paRfRangeExtender == RANGE_EXT_SKYWORKS_SKY66420)
471431
{
472-
/* Return to Sleep state */
473-
S2LPCmdStrobeCommand(CMD_SLEEP);
474-
475-
if(S2LPManagementGetCut()==S2LP_CUT_2_0)
476-
{
477-
/* apply the workaround to exit from SLEEP (2nd part) */
478-
delay(6);
479-
S2LPTimerLdcIrqWa(S_DISABLE);
480-
}
432+
FEM_Operation_SKY66420(FEM_RX);
481433
}
482434

435+
/* Return to RX state */
436+
S2LPCmdStrobeCommand(CMD_RX);
437+
483438
enableS2LPIrq();
484439

485440
return ret_val;
486441
}
487442

443+
/**
444+
* @brief Sets the channel number.
445+
* @param cChannel the channel number.
446+
* @retval None.
447+
*/
448+
void S2LP::setRadioChannel(uint8_t cChannel)
449+
{
450+
return S2LPRadioSetChannel(cChannel);
451+
}
452+
453+
/**
454+
* @brief Returns the actual channel number.
455+
* @param None.
456+
* @retval uint8_t Actual channel number.
457+
*/
458+
uint8_t S2LP::getRadioChannel(void)
459+
{
460+
return S2LPRadioGetChannel();
461+
}
462+
463+
/**
464+
* @brief Set the channel space factor in channel space register.
465+
* The channel spacing step is computed as F_Xo/32768.
466+
* @param fChannelSpace the channel space expressed in Hz.
467+
* @retval None.
468+
*/
469+
void S2LP::setRadioChannelSpace(uint32_t lChannelSpace)
470+
{
471+
return S2LPRadioSetChannelSpace(lChannelSpace);
472+
}
473+
474+
/**
475+
* @brief Return the channel space register.
476+
* @param None.
477+
* @retval uint32_t Channel space. The channel space is: CS = channel_space_factor x XtalFrequency/2^15
478+
* where channel_space_factor is the CHSPACE register value.
479+
*/
480+
uint32_t S2LP::getRadioChannelSpace(void)
481+
{
482+
return S2LPRadioGetChannelSpace();
483+
}
484+
488485
/**
489486
* @brief Set the Ready state.
490487
* @param None.
@@ -496,22 +493,14 @@ uint8_t S2LP::S2LPSetReadyState(void)
496493
uint32_t start_time;
497494
uint32_t current_time;
498495

496+
S2LPCmdStrobeCommand(CMD_SABORT);
497+
499498
start_time = millis();
500499

501500
do
502501
{
503502
S2LPRefreshStatus();
504503

505-
if(g_xStatus.MC_STATE == MC_STATE_RX || g_xStatus.MC_STATE == MC_STATE_TX)
506-
{
507-
S2LPCmdStrobeCommand(CMD_SABORT);
508-
} else
509-
{
510-
S2LPCmdStrobeCommand(CMD_READY);
511-
}
512-
513-
S2LPRefreshStatus();
514-
515504
current_time = millis();
516505
} while(g_xStatus.MC_STATE != MC_STATE_READY && (current_time - start_time) <= 1000);
517506

@@ -554,11 +543,6 @@ void S2LP::S2LPIrqHandler(void)
554543
/* Check the S2LP RX_DATA_READY IRQ flag */
555544
if(xIrqStatus.IRQ_RX_DATA_READY)
556545
{
557-
if(S2LPManagementGetCut()==S2LP_CUT_2_0)
558-
{/* apply the workaround to exit from SLEEP (1st part) */
559-
S2LPTimerLdcIrqWa(S_ENABLE);
560-
}
561-
562546
/* Get the RX FIFO size */
563547
cRxData = S2LPFifoReadNumberBytesRxFifo();
564548

src/S2LP.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ class S2LP
109109
uint8_t send(uint8_t *payload, uint8_t payload_len, uint8_t dest_addr, bool use_csma_ca = true);
110110
uint8_t getRecvPayloadLen(void);
111111
uint8_t read(uint8_t *payload, uint8_t payload_len);
112+
void setRadioChannel(uint8_t cChannel);
113+
uint8_t getRadioChannel(void);
114+
void setRadioChannelSpace(uint32_t lChannelSpace);
115+
uint32_t getRadioChannelSpace(void);
112116

113117
protected:
114118
uint8_t S2LPSetReadyState(void);
@@ -371,8 +375,7 @@ class S2LP
371375
uint8_t vectcTxBuff[FIFO_SIZE];
372376
uint8_t cRxData;
373377
volatile bool is_waiting_for_read;
374-
volatile bool is_tx_done_before_read;
375-
bool is_bypass_enabled;
378+
bool is_bypass_enabled;
376379
};
377380

378381
#endif /* __S2LP_H__ */

0 commit comments

Comments
 (0)