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