@@ -39,6 +39,16 @@ SPDX-License-Identifier: BSD-3-Clause
39
39
#include " Timer.h"
40
40
#include " STM32WL_LoRaRadio.h"
41
41
42
+ #ifndef DEBUG_STDIO
43
+ #define DEBUG_STDIO 0
44
+ #endif
45
+
46
+ #if DEBUG_STDIO
47
+ #define DEBUG_PRINTF (...) do { printf (__VA_ARGS__); } while (0 )
48
+ #else
49
+ #define DEBUG_PRINTF (...) {}
50
+ #endif
51
+
42
52
uint8_t regulator_mode = MBED_CONF_STM32WL_LORA_DRIVER_REGULATOR_MODE;
43
53
44
54
uint8_t crystal_select = MBED_CONF_STM32WL_LORA_DRIVER_CRYSTAL_SELECT;
@@ -136,7 +146,6 @@ STM32WL_LoRaRadio::STM32WL_LoRaRadio()
136
146
137
147
STM32WL_LoRaRadio::~STM32WL_LoRaRadio ()
138
148
{
139
-
140
149
}
141
150
142
151
/* *
@@ -270,7 +279,7 @@ void HAL_SUBGHZ_MspInit(SUBGHZ_HandleTypeDef *subghzHandle)
270
279
static void RadioIrqProcess ()
271
280
{
272
281
radio_irq_masks_t irq_status;
273
-
282
+ core_util_critical_section_enter ();
274
283
275
284
irq_status = (radio_irq_masks_t )STM32WL_LoRaRadio::get_irq_status ();
276
285
/* clear IRQs lines after recovering their status */
@@ -292,8 +301,10 @@ static void RadioIrqProcess()
292
301
if ((irq_status & IRQ_RX_TX_TIMEOUT) == IRQ_RX_TX_TIMEOUT) {
293
302
STM32WL_LoRaRadio::HAL_SUBGHZ_RxTxTimeoutCallback ();
294
303
}
304
+ core_util_critical_section_exit ();
295
305
}
296
- /* ----- */
306
+
307
+
297
308
/* HAL_SUBGHz Callbacks definitions */
298
309
void STM32WL_LoRaRadio::HAL_SUBGHZ_TxCpltCallback (void )
299
310
{
@@ -352,7 +363,6 @@ void STM32WL_LoRaRadio::HAL_SUBGHZ_CADStatusCallback(void)
352
363
}
353
364
}
354
365
355
-
356
366
void STM32WL_LoRaRadio::HAL_SUBGHZ_RxTxTimeoutCallback (void )
357
367
{
358
368
if ((_radio_events->tx_timeout ) && (_operating_mode == MODE_TX)) {
@@ -373,14 +383,13 @@ void STM32WL_LoRaRadio::HAL_SUBGHZ_RxTxTimeoutCallback(void)
373
383
}
374
384
}
375
385
376
- /* ----- */
377
- /* HAL_SUBGHz Callbacks definitions END */
378
386
379
387
380
388
/* STM32WL specific BSP Nucleo board functions */
381
389
void STM32WL_LoRaRadio::SUBGRF_SetSwitch (uint8_t paSelect, RFState_t rxtx)
382
390
{
383
391
RBI_Switch_TypeDef state = RBI_SWITCH_RX;
392
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::SUBGRF_SetSwitch %u %u\n " , paSelect, rxtx);
384
393
385
394
if (rxtx == RFSWITCH_TX) {
386
395
if (paSelect == RFO_LP) {
@@ -400,6 +409,7 @@ void STM32WL_LoRaRadio::SUBGRF_SetSwitch(uint8_t paSelect, RFState_t rxtx)
400
409
401
410
uint8_t STM32WL_LoRaRadio::SUBGRF_SetRfTxPower (int8_t power)
402
411
{
412
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::SUBGRF_SetRfTxPower %u\n " , power);
403
413
uint8_t paSelect = RFO_LP;
404
414
405
415
int32_t TxConfig = board_rf_switch_config;
@@ -434,6 +444,7 @@ uint8_t STM32WL_LoRaRadio::SUBGRF_SetRfTxPower(int8_t power)
434
444
void STM32WL_LoRaRadio::SUBGRF_SetTxParams (uint8_t paSelect, int8_t power, radio_ramp_time_t rampTime)
435
445
{
436
446
uint8_t buf[2 ];
447
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::SUBGRF_SetTxParams %u %u\n " , paSelect, power);
437
448
438
449
if (paSelect == RFO_LP) {
439
450
if (power == 15 ) {
@@ -496,6 +507,7 @@ void STM32WL_LoRaRadio::Radio_SMPS_Set(uint8_t level)
496
507
void STM32WL_LoRaRadio::calibrate_image (uint32_t freq)
497
508
{
498
509
uint8_t cal_freq[2 ];
510
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::calibrate_image %u\n " , freq);
499
511
500
512
if (freq > 900000000 ) {
501
513
cal_freq[0 ] = 0xE1 ;
@@ -521,6 +533,7 @@ void STM32WL_LoRaRadio::calibrate_image(uint32_t freq)
521
533
522
534
void STM32WL_LoRaRadio::set_channel (uint32_t frequency)
523
535
{
536
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::set_channel %u\n " , frequency);
524
537
#if MBED_CONF_STM32WL_LORA_DRIVER_SLEEP_MODE == 1
525
538
// At this point, we are not sure what is the Modem type, set both
526
539
_mod_params.params .lora .operational_frequency = frequency;
@@ -571,6 +584,7 @@ void STM32WL_LoRaRadio::standby(void)
571
584
void STM32WL_LoRaRadio::SUBGRF_SetTcxoMode (radio_TCXO_ctrl_voltage_t voltage,
572
585
uint32_t timeout)
573
586
{
587
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::SUBGRF_SetTcxoMode %u\n " , voltage);
574
588
uint8_t buf[4 ];
575
589
576
590
buf[0 ] = voltage & 0x07 ;
@@ -585,7 +599,7 @@ void STM32WL_LoRaRadio::init_radio(radio_events_t *events)
585
599
{
586
600
HAL_StatusTypeDef error_value;
587
601
uint32_t vector = 0 ;
588
-
602
+ DEBUG_PRINTF ( " STM32WL_LoRaRadio::init_radio \n " );
589
603
_radio_events = events;
590
604
591
605
_tx_timeout = 0 ;
@@ -602,7 +616,6 @@ void STM32WL_LoRaRadio::init_radio(radio_events_t *events)
602
616
SUBGRF_SetTxParams (RFO_LP, 0 , RADIO_RAMP_200_US);
603
617
604
618
sleep ();
605
-
606
619
}
607
620
608
621
@@ -634,6 +647,7 @@ void STM32WL_LoRaRadio::cold_start_wakeup()
634
647
635
648
void STM32WL_LoRaRadio::set_public_network (bool enable)
636
649
{
650
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::set_public_network %u\n " , enable);
637
651
if (enable) {
638
652
// Change LoRa modem SyncWord
639
653
write_to_register (REG_LR_SYNCWORD, (LORA_MAC_PUBLIC_SYNCWORD >> 8 ) & 0xFF );
@@ -680,12 +694,14 @@ uint32_t STM32WL_LoRaRadio::time_on_air(radio_modems_t modem, uint8_t pkt_len)
680
694
}
681
695
break ;
682
696
}
697
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::time_on_air %u %u => %u\n " , modem, pkt_len, air_time);
683
698
684
699
return air_time;
685
700
}
686
701
687
702
void STM32WL_LoRaRadio::radio_reset ()
688
703
{
704
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::radio_reset\n " );
689
705
690
706
// give some time for automatic image calibration
691
707
rtos::ThisThread::sleep_for (6ms);
@@ -704,10 +720,12 @@ void STM32WL_LoRaRadio::wakeup()
704
720
cold_start_wakeup ();
705
721
#endif
706
722
}
723
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::wakeup\n " );
707
724
}
708
725
709
726
void STM32WL_LoRaRadio::sleep (void )
710
727
{
728
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::sleep\n " );
711
729
#if MBED_CONF_STM32WL_LORA_DRIVER_SLEEP_MODE == 1
712
730
// cold start, power consumption 160 nA
713
731
sleep_state = 0x00 ;
@@ -739,7 +757,9 @@ uint32_t STM32WL_LoRaRadio::random(void)
739
757
read_register (RANDOM_NUMBER_GENERATORBASEADDR, buf, 4 );
740
758
standby ();
741
759
742
- return (buf[0 ] << 24 ) | (buf[1 ] << 16 ) | (buf[2 ] << 8 ) | buf[3 ];
760
+ uint32_t random_value = (buf[0 ] << 24 ) | (buf[1 ] << 16 ) | (buf[2 ] << 8 ) | buf[3 ] ;
761
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::random %u\n " , random_value);
762
+ return random_value;
743
763
}
744
764
745
765
void STM32WL_LoRaRadio::write_opmode_command (uint8_t cmd, uint8_t *buffer, uint16_t size)
@@ -748,7 +768,6 @@ void STM32WL_LoRaRadio::write_opmode_command(uint8_t cmd, uint8_t *buffer, uint1
748
768
749
769
error_value = HAL_SUBGHZ_ExecSetCmd (&hsubghz, (SUBGHZ_RadioSetCmd_t)cmd, buffer, size);
750
770
MBED_ASSERT (error_value == HAL_OK);
751
-
752
771
}
753
772
754
773
void STM32WL_LoRaRadio::read_opmode_command (uint8_t cmd, uint8_t *buffer, uint16_t size)
@@ -757,7 +776,6 @@ void STM32WL_LoRaRadio::read_opmode_command(uint8_t cmd, uint8_t *buffer, uint16
757
776
758
777
error_value = HAL_SUBGHZ_ExecGetCmd (&hsubghz, (SUBGHZ_RadioGetCmd_t)cmd, buffer, size);
759
778
MBED_ASSERT (error_value == HAL_OK);
760
-
761
779
}
762
780
763
781
void STM32WL_LoRaRadio::write_to_register (uint16_t addr, uint8_t data)
@@ -813,6 +831,7 @@ void STM32WL_LoRaRadio::write_fifo(uint8_t *buffer, uint8_t size)
813
831
void STM32WL_LoRaRadio::set_modem (uint8_t modem)
814
832
{
815
833
_active_modem = modem;
834
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::set_modem %u\n " , modem);
816
835
817
836
// setting modem type must happen in standby mode
818
837
if (_operating_mode != MODE_STDBY_RC) {
@@ -875,6 +894,7 @@ void STM32WL_LoRaRadio::set_tx_config(radio_modems_t modem,
875
894
bool iq_inverted,
876
895
uint32_t timeout)
877
896
{
897
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::set_tx_config %u %u %u %u\n " , modem, power, fdev, bandwidth);
878
898
879
899
uint8_t modem_type = (uint8_t ) modem;
880
900
switch (modem_type) {
@@ -966,6 +986,7 @@ void STM32WL_LoRaRadio::set_rx_config(radio_modems_t modem,
966
986
uint8_t max_payload_len;
967
987
(void ) freq_hop_on;
968
988
(void ) hop_period;
989
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::set_rx_config %u %u %u %u\n " , modem, bandwidth, datarate, coderate);
969
990
970
991
if (rx_continuous) {
971
992
_reception_mode = RECEPTION_MODE_CONTINUOUS;
@@ -1089,6 +1110,7 @@ void STM32WL_LoRaRadio::configure_dio_irq(uint16_t irq_mask, uint16_t dio1_mask,
1089
1110
1090
1111
void STM32WL_LoRaRadio::send (uint8_t *buffer, uint8_t size)
1091
1112
{
1113
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::send %u\n " , size);
1092
1114
set_tx_power (_tx_power);
1093
1115
configure_dio_irq (IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT,
1094
1116
IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT,
@@ -1127,6 +1149,8 @@ void STM32WL_LoRaRadio::send(uint8_t *buffer, uint8_t size)
1127
1149
1128
1150
void STM32WL_LoRaRadio::receive (void )
1129
1151
{
1152
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::receive\n " );
1153
+
1130
1154
if (get_modem () == MODEM_LORA) {
1131
1155
if (_reception_mode != RECEPTION_MODE_CONTINUOUS) {
1132
1156
// Data-sheet Table 13-11: StopOnPreambParam
@@ -1243,6 +1267,7 @@ void STM32WL_LoRaRadio::set_pa_config(uint8_t pa_DC, uint8_t hp_max,
1243
1267
uint8_t device_type, uint8_t pa_LUT)
1244
1268
{
1245
1269
uint8_t buf[4 ];
1270
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::set_pa_config %u %u %u %u\n " , pa_DC, hp_max, device_type, pa_LUT);
1246
1271
1247
1272
buf[0 ] = pa_DC;
1248
1273
buf[1 ] = hp_max;
@@ -1253,6 +1278,7 @@ void STM32WL_LoRaRadio::set_pa_config(uint8_t pa_DC, uint8_t hp_max,
1253
1278
1254
1279
void STM32WL_LoRaRadio::set_crc_seed (uint16_t seed)
1255
1280
{
1281
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::set_crc_seed\n " );
1256
1282
if (_active_modem == MODEM_FSK) {
1257
1283
uint8_t buf[2 ];
1258
1284
buf[0 ] = (uint8_t )((seed >> 8 ) & 0xFF );
@@ -1263,6 +1289,7 @@ void STM32WL_LoRaRadio::set_crc_seed(uint16_t seed)
1263
1289
1264
1290
void STM32WL_LoRaRadio::set_crc_polynomial (uint16_t polynomial)
1265
1291
{
1292
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::set_crc_polynomial\n " );
1266
1293
if (_active_modem == MODEM_FSK) {
1267
1294
uint8_t buf[2 ];
1268
1295
buf[0 ] = (uint8_t )((polynomial >> 8 ) & 0xFF );
@@ -1273,6 +1300,7 @@ void STM32WL_LoRaRadio::set_crc_polynomial(uint16_t polynomial)
1273
1300
1274
1301
void STM32WL_LoRaRadio::set_whitening_seed (uint16_t seed)
1275
1302
{
1303
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::set_whitening_seed\n " );
1276
1304
if (_active_modem == MODEM_FSK) {
1277
1305
uint8_t reg_value = read_register (REG_LR_WHITSEEDBASEADDR_MSB) & 0xFE ;
1278
1306
reg_value = ((seed >> 8 ) & 0x01 ) | reg_value;
@@ -1286,6 +1314,7 @@ void STM32WL_LoRaRadio::set_packet_params(packet_params_t *packet_params)
1286
1314
uint8_t n;
1287
1315
uint8_t crc_val = 0 ;
1288
1316
uint8_t buf[9 ] = {0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
1317
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::set_packet_params %u\n " , packet_params->modem_type );
1289
1318
1290
1319
// Check if required configuration corresponds to the stored packet type
1291
1320
// If not, silently update radio packet type
@@ -1363,6 +1392,7 @@ void STM32WL_LoRaRadio::set_buffer_base_addr(uint8_t tx_base_addr, uint8_t rx_ba
1363
1392
1364
1393
uint8_t STM32WL_LoRaRadio::get_status (void )
1365
1394
{
1395
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::get_status\n " );
1366
1396
switch (_operating_mode) {
1367
1397
case MODE_TX:
1368
1398
return RF_TX_RUNNING;
@@ -1382,12 +1412,15 @@ int8_t STM32WL_LoRaRadio::get_rssi()
1382
1412
1383
1413
read_opmode_command ((uint8_t ) RADIO_GET_RSSIINST, buf, 1 );
1384
1414
rssi = -buf[0 ] >> 1 ;
1415
+
1416
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::get_rssi %d\n " , rssi);
1385
1417
return rssi;
1386
1418
}
1387
1419
1388
1420
void STM32WL_LoRaRadio::get_rx_buffer_status (uint8_t *payload_len,
1389
1421
uint8_t *start_ptr)
1390
1422
{
1423
+ // DEBUG_PRINTF("STM32WL_LoRaRadio::get_rx_buffer_status\n");
1391
1424
uint8_t status[2 ];
1392
1425
1393
1426
read_opmode_command ((uint8_t ) RADIO_GET_RXBUFFERSTATUS, status, 2 );
@@ -1406,6 +1439,7 @@ void STM32WL_LoRaRadio::get_rx_buffer_status(uint8_t *payload_len,
1406
1439
1407
1440
void STM32WL_LoRaRadio::get_packet_status (packet_status_t *pkt_status)
1408
1441
{
1442
+ // DEBUG_PRINTF("STM32WL_LoRaRadio::get_packet_status\n");
1409
1443
uint8_t status[3 ];
1410
1444
1411
1445
read_opmode_command ((uint8_t ) RADIO_GET_PACKETSTATUS, status, 3 );
@@ -1437,13 +1471,15 @@ void STM32WL_LoRaRadio::get_packet_status(packet_status_t *pkt_status)
1437
1471
radio_error_t STM32WL_LoRaRadio::get_device_errors (void )
1438
1472
{
1439
1473
radio_error_t error;
1474
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::get_device_errors\n " );
1440
1475
1441
1476
read_opmode_command ((uint8_t ) RADIO_GET_ERROR, (uint8_t *)&error, 2 );
1442
1477
return error;
1443
1478
}
1444
1479
1445
1480
void STM32WL_LoRaRadio::clear_device_errors (void )
1446
1481
{
1482
+ DEBUG_PRINTF (" STM32WL_LoRaRadio::clear_device_errors\n " );
1447
1483
uint8_t buf[2 ] = {0x00 , 0x00 };
1448
1484
write_opmode_command ((uint8_t ) RADIO_CLR_ERROR, buf, 2 );
1449
1485
}
0 commit comments