Skip to content

Commit 37ca842

Browse files
STM32CubeWL: Fix printf format warnings
These warnings are caused because frequencies are stored as `uint32_t`, which is `unsigned long`, while the printf format expects `int`. In practice, this does not actually cause problems, since on STM32 gcc `long` and `int` are both 32-bits and frequencies are never large enough to cause signed vs unsigned ambiguity. Since printf has no format specifiers for e.g. uint32_t (libc does have some macros for this, but those really hurt readability), this is tricky to fix in a portable way (other architectures or compilers might have `uint32_t` equal to `unsigned int` instead of `unsigned long`), this fix just casts the frequency to `unsigned` before passing it to printf (and for good measure, also convert the specifier from `%d` to `%u`). This does mean this printing will break if `int` is not at least 32-bits (e.g. on AVR), but given the scope of this library, that should be acceptable.
1 parent 0db2870 commit 37ca842

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/STM32CubeWL/LoRaWAN/Mac/Region/RegionCommon.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ void RegionCommonRxBeaconSetup( RegionCommonRxBeaconSetupParams_t* rxBeaconSetup
565565
1, 0, 10, rxBeaconSetupParams->SymbolTimeout, true, rxBeaconSetupParams->BeaconSize, false, 0, 0, false, rxContinuous );
566566

567567
Radio.Rx( rxBeaconSetupParams->RxTime );
568-
MW_LOG(TS_ON, VLEVEL_M, "RX_BC on freq %d Hz at DR %d\r\n", rxBeaconSetupParams->Frequency, rxBeaconSetupParams->BeaconDatarate );
568+
MW_LOG(TS_ON, VLEVEL_M, "RX_BC on freq %u Hz at DR %d\r\n", (unsigned)rxBeaconSetupParams->Frequency, rxBeaconSetupParams->BeaconDatarate );
569569
}
570570

571571
void RegionCommonCountNbOfEnabledChannels( RegionCommonCountNbOfEnabledChannelsParams_t* countNbOfEnabledChannelsParams,
@@ -699,17 +699,17 @@ void RegionCommonRxConfigPrint(LoRaMacRxSlot_t rxSlot, uint32_t frequency, int8_
699699
{
700700
if ( rxSlot < RX_SLOT_NONE )
701701
{
702-
MW_LOG(TS_ON, VLEVEL_M, "RX_%s on freq %d Hz at DR %d\r\n", EventRXSlotStrings[rxSlot], frequency, dr );
702+
MW_LOG(TS_ON, VLEVEL_M, "RX_%s on freq %u Hz at DR %d\r\n", EventRXSlotStrings[rxSlot], (unsigned)frequency, dr );
703703
}
704704
else
705705
{
706-
MW_LOG(TS_ON, VLEVEL_M, "RX on freq %d Hz at DR %d\r\n", frequency, dr );
706+
MW_LOG(TS_ON, VLEVEL_M, "RX on freq %u Hz at DR %d\r\n", (unsigned)frequency, dr );
707707
}
708708
}
709709

710710
void RegionCommonTxConfigPrint(uint32_t frequency, int8_t dr)
711711
{
712-
MW_LOG(TS_ON, VLEVEL_M, "TX on freq %d Hz at DR %d\r\n", frequency, dr );
712+
MW_LOG(TS_ON, VLEVEL_M, "TX on freq %u Hz at DR %d\r\n", (unsigned)frequency, dr );
713713
}
714714

715715
#pragma GCC diagnostic pop

0 commit comments

Comments
 (0)