一般调试我们用两种方法,断点和打印,考虑到射频和RTC,我们主要用打印调试的方法。
1、实现串口打印
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) PUTCHAR_PROTOTYPE { HAL_UART_Transmit(&UartHandle, (uint8_t *)&ch, 1, 0xFFFF); return ch; }
2、分等级调试打印
typedef enum { LOG_LEVEL_OFF=0, LOG_LEVEL_INFO, LOG_LEVEL_DEVELOP, LOG_LEVEL_ALL, }LOG_LEVEL; #define log_develop(level,...) do { if(level>=LOG_LEVEL_DEVELOP) { printf("\nFILE:%s LINE:%d,FUNC:%s ", __FILE__, __LINE__ ,__func__); printf(##__VA_ARGS__); } } while (0) #define log_info(level, ...) do { if(level>=LOG_LEVEL_INFO) printf(##__VA_ARGS__ ); } while (0) #define log_debug(level, ...) do { if(level>=LOG_LEVEL_ALL) printf(##__VA_ARGS__ ); } while (0)
3、定义调试等级
LOG_LEVEL loglevel;//定义打印等级,可以根据自己的实际设定,一般在调试阶段我们设定为LOG_LEVEL_ALL,即所有信息可见。
4、关键部分加入打印
以US915频段说明,其余频段类似。
4.1、在RegionUS915TxConfig函数打印发送的参数
bool RegionUS915TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime_t* txTimeOnAir ) { RadioModems_t modem; int8_t phyDr = DataratesUS915[txConfig->Datarate]; int8_t txPowerLimited = LimitTxPower( txConfig->TxPower, NvmCtx.Bands[NvmCtx.Channels[txConfig->Channel].Band].TxMaxPower, txConfig->Datarate, NvmCtx.ChannelsMask ); uint32_t bandwidth = GetBandwidth( txConfig->Datarate ); int8_t phyTxPower = 0; // Calculate physical TX power phyTxPower = RegionCommonComputeTxPower( txPowerLimited, txConfig->MaxEirp, txConfig->AntennaGain ); // Setup the radio frequency Radio.SetChannel( NvmCtx.Channels[txConfig->Channel].Frequency ); if( txConfig->Datarate == DR_7 ) { // High Speed FSK channel modem = MODEM_FSK; Radio.SetTxConfig( modem, phyTxPower, 25000, bandwidth, phyDr * 1000, 0, 5, false, true, 0, 0, false, 4000 ); } else { modem = MODEM_LORA; Radio.SetTxConfig( modem, phyTxPower, 0, bandwidth, phyDr, 1, 8, false, true, 0, 0, false, 4000 ); } // Setup maximum payload lenght of the radio driver Radio.SetMaxPayloadLength( modem, txConfig->PktLen ); // Get the time-on-air of the next tx frame *txTimeOnAir = Radio.TimeOnAir( modem, txConfig->PktLen ); *txPower = txPowerLimited; log_info (loglevel, "[%.3fMHz, SF%d ,%ddBm ,%dbyte]", Channels[txConfig->Channel].Frequency/1e6, phyDr, phyTxPower, txConfig->PktLen ); return true; } ———————————————— 版权声明:本文为CSDN博主「freemote」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/freemote/article/details/104927220