Skip to content

Commit 4b956bb

Browse files
committed
STM32WL LORA driver: add debug print
1 parent b7c2dd0 commit 4b956bb

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

connectivity/drivers/lora/TARGET_STM32WL/STM32WL_LoRaRadio.cpp

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ SPDX-License-Identifier: BSD-3-Clause
3939
#include "Timer.h"
4040
#include "STM32WL_LoRaRadio.h"
4141

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+
4252
uint8_t regulator_mode = MBED_CONF_STM32WL_LORA_DRIVER_REGULATOR_MODE;
4353

4454
uint8_t crystal_select = MBED_CONF_STM32WL_LORA_DRIVER_CRYSTAL_SELECT;
@@ -136,7 +146,6 @@ STM32WL_LoRaRadio::STM32WL_LoRaRadio()
136146

137147
STM32WL_LoRaRadio::~STM32WL_LoRaRadio()
138148
{
139-
140149
}
141150

142151
/**
@@ -271,7 +280,6 @@ static void RadioIrqProcess()
271280
{
272281
radio_irq_masks_t irq_status;
273282

274-
275283
irq_status = (radio_irq_masks_t)STM32WL_LoRaRadio::get_irq_status();
276284
/* clear IRQs lines after recovering their status */
277285
STM32WL_LoRaRadio::clear_irq_status(IRQ_RADIO_ALL);
@@ -293,7 +301,8 @@ static void RadioIrqProcess()
293301
STM32WL_LoRaRadio::HAL_SUBGHZ_RxTxTimeoutCallback();
294302
}
295303
}
296-
/* ----- */
304+
305+
297306
/* HAL_SUBGHz Callbacks definitions */
298307
void STM32WL_LoRaRadio::HAL_SUBGHZ_TxCpltCallback(void)
299308
{
@@ -352,7 +361,6 @@ void STM32WL_LoRaRadio::HAL_SUBGHZ_CADStatusCallback(void)
352361
}
353362
}
354363

355-
356364
void STM32WL_LoRaRadio::HAL_SUBGHZ_RxTxTimeoutCallback(void)
357365
{
358366
if ((_radio_events->tx_timeout) && (_operating_mode == MODE_TX)) {
@@ -373,14 +381,13 @@ void STM32WL_LoRaRadio::HAL_SUBGHZ_RxTxTimeoutCallback(void)
373381
}
374382
}
375383

376-
/* ----- */
377-
/* HAL_SUBGHz Callbacks definitions END */
378384

379385

380386
/* STM32WL specific BSP Nucleo board functions */
381387
void STM32WL_LoRaRadio::SUBGRF_SetSwitch(uint8_t paSelect, RFState_t rxtx)
382388
{
383389
RBI_Switch_TypeDef state = RBI_SWITCH_RX;
390+
DEBUG_PRINTF("STM32WL_LoRaRadio::SUBGRF_SetSwitch %u %u\n", paSelect, rxtx);
384391

385392
if (rxtx == RFSWITCH_TX) {
386393
if (paSelect == RFO_LP) {
@@ -400,6 +407,7 @@ void STM32WL_LoRaRadio::SUBGRF_SetSwitch(uint8_t paSelect, RFState_t rxtx)
400407

401408
uint8_t STM32WL_LoRaRadio::SUBGRF_SetRfTxPower(int8_t power)
402409
{
410+
DEBUG_PRINTF("STM32WL_LoRaRadio::SUBGRF_SetRfTxPower %u\n", power);
403411
uint8_t paSelect = RFO_LP;
404412

405413
int32_t TxConfig = board_rf_switch_config;
@@ -434,6 +442,7 @@ uint8_t STM32WL_LoRaRadio::SUBGRF_SetRfTxPower(int8_t power)
434442
void STM32WL_LoRaRadio::SUBGRF_SetTxParams(uint8_t paSelect, int8_t power, radio_ramp_time_t rampTime)
435443
{
436444
uint8_t buf[2];
445+
DEBUG_PRINTF("STM32WL_LoRaRadio::SUBGRF_SetTxParams %u %u\n", paSelect, power);
437446

438447
if (paSelect == RFO_LP) {
439448
if (power == 15) {
@@ -496,6 +505,7 @@ void STM32WL_LoRaRadio::Radio_SMPS_Set(uint8_t level)
496505
void STM32WL_LoRaRadio::calibrate_image(uint32_t freq)
497506
{
498507
uint8_t cal_freq[2];
508+
DEBUG_PRINTF("STM32WL_LoRaRadio::calibrate_image %u\n", freq);
499509

500510
if (freq > 900000000) {
501511
cal_freq[0] = 0xE1;
@@ -521,6 +531,7 @@ void STM32WL_LoRaRadio::calibrate_image(uint32_t freq)
521531

522532
void STM32WL_LoRaRadio::set_channel(uint32_t frequency)
523533
{
534+
DEBUG_PRINTF("STM32WL_LoRaRadio::set_channel %u\n", frequency);
524535
#if MBED_CONF_STM32WL_LORA_DRIVER_SLEEP_MODE == 1
525536
// At this point, we are not sure what is the Modem type, set both
526537
_mod_params.params.lora.operational_frequency = frequency;
@@ -571,6 +582,7 @@ void STM32WL_LoRaRadio::standby(void)
571582
void STM32WL_LoRaRadio::SUBGRF_SetTcxoMode(radio_TCXO_ctrl_voltage_t voltage,
572583
uint32_t timeout)
573584
{
585+
DEBUG_PRINTF("STM32WL_LoRaRadio::SUBGRF_SetTcxoMode %u\n", voltage);
574586
uint8_t buf[4];
575587

576588
buf[0] = voltage & 0x07;
@@ -585,7 +597,7 @@ void STM32WL_LoRaRadio::init_radio(radio_events_t *events)
585597
{
586598
HAL_StatusTypeDef error_value;
587599
uint32_t vector = 0;
588-
600+
DEBUG_PRINTF("STM32WL_LoRaRadio::init_radio\n");
589601
_radio_events = events;
590602

591603
_tx_timeout = 0;
@@ -602,7 +614,6 @@ void STM32WL_LoRaRadio::init_radio(radio_events_t *events)
602614
SUBGRF_SetTxParams(RFO_LP, 0, RADIO_RAMP_200_US);
603615

604616
sleep();
605-
606617
}
607618

608619

@@ -634,6 +645,7 @@ void STM32WL_LoRaRadio::cold_start_wakeup()
634645

635646
void STM32WL_LoRaRadio::set_public_network(bool enable)
636647
{
648+
DEBUG_PRINTF("STM32WL_LoRaRadio::set_public_network %u\n", enable);
637649
if (enable) {
638650
// Change LoRa modem SyncWord
639651
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)
680692
}
681693
break;
682694
}
695+
DEBUG_PRINTF("STM32WL_LoRaRadio::time_on_air %u %u => %u\n", modem, pkt_len, air_time);
683696

684697
return air_time;
685698
}
686699

687700
void STM32WL_LoRaRadio::radio_reset()
688701
{
702+
DEBUG_PRINTF("STM32WL_LoRaRadio::radio_reset\n");
689703

690704
// give some time for automatic image calibration
691705
rtos::ThisThread::sleep_for(6ms);
@@ -704,10 +718,12 @@ void STM32WL_LoRaRadio::wakeup()
704718
cold_start_wakeup();
705719
#endif
706720
}
721+
DEBUG_PRINTF("STM32WL_LoRaRadio::wakeup\n");
707722
}
708723

709724
void STM32WL_LoRaRadio::sleep(void)
710725
{
726+
DEBUG_PRINTF("STM32WL_LoRaRadio::sleep\n");
711727
#if MBED_CONF_STM32WL_LORA_DRIVER_SLEEP_MODE == 1
712728
// cold start, power consumption 160 nA
713729
sleep_state = 0x00;
@@ -739,7 +755,9 @@ uint32_t STM32WL_LoRaRadio::random(void)
739755
read_register(RANDOM_NUMBER_GENERATORBASEADDR, buf, 4);
740756
standby();
741757

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;
743761
}
744762

745763
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
748766

749767
error_value = HAL_SUBGHZ_ExecSetCmd(&hsubghz, (SUBGHZ_RadioSetCmd_t)cmd, buffer, size);
750768
MBED_ASSERT(error_value == HAL_OK);
751-
752769
}
753770

754771
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
757774

758775
error_value = HAL_SUBGHZ_ExecGetCmd(&hsubghz, (SUBGHZ_RadioGetCmd_t)cmd, buffer, size);
759776
MBED_ASSERT(error_value == HAL_OK);
760-
761777
}
762778

763779
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)
813829
void STM32WL_LoRaRadio::set_modem(uint8_t modem)
814830
{
815831
_active_modem = modem;
832+
DEBUG_PRINTF("STM32WL_LoRaRadio::set_modem %u\n", modem);
816833

817834
// setting modem type must happen in standby mode
818835
if (_operating_mode != MODE_STDBY_RC) {
@@ -875,6 +892,7 @@ void STM32WL_LoRaRadio::set_tx_config(radio_modems_t modem,
875892
bool iq_inverted,
876893
uint32_t timeout)
877894
{
895+
DEBUG_PRINTF("STM32WL_LoRaRadio::set_tx_config %u %u %u %u\n", modem, power, fdev, bandwidth);
878896

879897
uint8_t modem_type = (uint8_t) modem;
880898
switch (modem_type) {
@@ -966,6 +984,7 @@ void STM32WL_LoRaRadio::set_rx_config(radio_modems_t modem,
966984
uint8_t max_payload_len;
967985
(void) freq_hop_on;
968986
(void) hop_period;
987+
DEBUG_PRINTF("STM32WL_LoRaRadio::set_rx_config %u %u %u %u\n", modem, bandwidth, datarate, coderate);
969988

970989
if (rx_continuous) {
971990
_reception_mode = RECEPTION_MODE_CONTINUOUS;
@@ -1089,6 +1108,7 @@ void STM32WL_LoRaRadio::configure_dio_irq(uint16_t irq_mask, uint16_t dio1_mask,
10891108

10901109
void STM32WL_LoRaRadio::send(uint8_t *buffer, uint8_t size)
10911110
{
1111+
DEBUG_PRINTF("STM32WL_LoRaRadio::send %u\n", size);
10921112
set_tx_power(_tx_power);
10931113
configure_dio_irq(IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT,
10941114
IRQ_TX_DONE | IRQ_RX_TX_TIMEOUT,
@@ -1127,6 +1147,8 @@ void STM32WL_LoRaRadio::send(uint8_t *buffer, uint8_t size)
11271147

11281148
void STM32WL_LoRaRadio::receive(void)
11291149
{
1150+
DEBUG_PRINTF("STM32WL_LoRaRadio::receive\n");
1151+
11301152
if (get_modem() == MODEM_LORA) {
11311153
if (_reception_mode != RECEPTION_MODE_CONTINUOUS) {
11321154
// Data-sheet Table 13-11: StopOnPreambParam
@@ -1243,6 +1265,7 @@ void STM32WL_LoRaRadio::set_pa_config(uint8_t pa_DC, uint8_t hp_max,
12431265
uint8_t device_type, uint8_t pa_LUT)
12441266
{
12451267
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);
12461269

12471270
buf[0] = pa_DC;
12481271
buf[1] = hp_max;
@@ -1253,6 +1276,7 @@ void STM32WL_LoRaRadio::set_pa_config(uint8_t pa_DC, uint8_t hp_max,
12531276

12541277
void STM32WL_LoRaRadio::set_crc_seed(uint16_t seed)
12551278
{
1279+
DEBUG_PRINTF("STM32WL_LoRaRadio::set_crc_seed\n");
12561280
if (_active_modem == MODEM_FSK) {
12571281
uint8_t buf[2];
12581282
buf[0] = (uint8_t)((seed >> 8) & 0xFF);
@@ -1263,6 +1287,7 @@ void STM32WL_LoRaRadio::set_crc_seed(uint16_t seed)
12631287

12641288
void STM32WL_LoRaRadio::set_crc_polynomial(uint16_t polynomial)
12651289
{
1290+
DEBUG_PRINTF("STM32WL_LoRaRadio::set_crc_polynomial\n");
12661291
if (_active_modem == MODEM_FSK) {
12671292
uint8_t buf[2];
12681293
buf[0] = (uint8_t)((polynomial >> 8) & 0xFF);
@@ -1273,6 +1298,7 @@ void STM32WL_LoRaRadio::set_crc_polynomial(uint16_t polynomial)
12731298

12741299
void STM32WL_LoRaRadio::set_whitening_seed(uint16_t seed)
12751300
{
1301+
DEBUG_PRINTF("STM32WL_LoRaRadio::set_whitening_seed\n");
12761302
if (_active_modem == MODEM_FSK) {
12771303
uint8_t reg_value = read_register(REG_LR_WHITSEEDBASEADDR_MSB) & 0xFE;
12781304
reg_value = ((seed >> 8) & 0x01) | reg_value;
@@ -1286,6 +1312,7 @@ void STM32WL_LoRaRadio::set_packet_params(packet_params_t *packet_params)
12861312
uint8_t n;
12871313
uint8_t crc_val = 0;
12881314
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);
12891316

12901317
// Check if required configuration corresponds to the stored packet type
12911318
// 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
13631390

13641391
uint8_t STM32WL_LoRaRadio::get_status(void)
13651392
{
1393+
DEBUG_PRINTF("STM32WL_LoRaRadio::get_status\n");
13661394
switch (_operating_mode) {
13671395
case MODE_TX:
13681396
return RF_TX_RUNNING;
@@ -1382,12 +1410,15 @@ int8_t STM32WL_LoRaRadio::get_rssi()
13821410

13831411
read_opmode_command((uint8_t) RADIO_GET_RSSIINST, buf, 1);
13841412
rssi = -buf[0] >> 1;
1413+
1414+
DEBUG_PRINTF("STM32WL_LoRaRadio::get_rssi %d\n", rssi);
13851415
return rssi;
13861416
}
13871417

13881418
void STM32WL_LoRaRadio::get_rx_buffer_status(uint8_t *payload_len,
13891419
uint8_t *start_ptr)
13901420
{
1421+
// DEBUG_PRINTF("STM32WL_LoRaRadio::get_rx_buffer_status\n");
13911422
uint8_t status[2];
13921423

13931424
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,
14061437

14071438
void STM32WL_LoRaRadio::get_packet_status(packet_status_t *pkt_status)
14081439
{
1440+
// DEBUG_PRINTF("STM32WL_LoRaRadio::get_packet_status\n");
14091441
uint8_t status[3];
14101442

14111443
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)
14371469
radio_error_t STM32WL_LoRaRadio::get_device_errors(void)
14381470
{
14391471
radio_error_t error;
1472+
DEBUG_PRINTF("STM32WL_LoRaRadio::get_device_errors\n");
14401473

14411474
read_opmode_command((uint8_t) RADIO_GET_ERROR, (uint8_t *)&error, 2);
14421475
return error;
14431476
}
14441477

14451478
void STM32WL_LoRaRadio::clear_device_errors(void)
14461479
{
1480+
DEBUG_PRINTF("STM32WL_LoRaRadio::clear_device_errors\n");
14471481
uint8_t buf[2] = {0x00, 0x00};
14481482
write_opmode_command((uint8_t) RADIO_CLR_ERROR, buf, 2);
14491483
}

0 commit comments

Comments
 (0)