Skip to content

Commit 9c6b054

Browse files
committed
Refine GD32 build flags and debug bit printing
Updates GD32 make rules to better control networking-related defines: add UDP/RTC restrictions for `CONFIG_REMOTECONFIG_MINIMUM`, introduce RTL8201F-specific link-check behavior (interrupt vs polling), and centralize `PHY_TYPE` via `DEFINES` to avoid duplication in compiler options. It also enhances `debug::PrintBits` with an optional label and `0x`-prefixed hex output, plus small readability-only cleanups in `Atof` and `asctime`.
1 parent a7a86e9 commit 9c6b054

5 files changed

Lines changed: 30 additions & 6 deletions

File tree

common/include/common/utils/utils_string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ inline float Atof(const char* buffer, uint32_t size) {
8181
}
8282

8383
while (size > 0 && *p >= '0' && *p <= '9') {
84-
result = result * 10.0F + static_cast<float>(*p - '0');
84+
result = (result * 10.0F) + static_cast<float>(*p - '0');
8585
++p;
8686
--size;
8787
}

common/include/firmware/debug/debug_printbits.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
namespace debug {
3636
template <typename T>
3737
requires std::unsigned_integral<T>
38-
inline void PrintBits(T value) {
38+
inline void PrintBits(T value, const char* string = nullptr) {
3939
if constexpr (!config::kDumpEnabled) {
4040
return;
4141
}
@@ -46,7 +46,10 @@ inline void PrintBits(T value) {
4646

4747
static_assert(sizeof(T) <= sizeof(unsigned));
4848

49-
printf("%.*x ", kHexDigits, static_cast<unsigned>(value));
49+
if (string != nullptr) {
50+
printf("%s :", string);
51+
}
52+
printf("0x%.*x ", kHexDigits, static_cast<unsigned>(value));
5053

5154
for (int bit_number = kMaxBitIndex; bit_number >= 0; --bit_number) {
5255
const auto kMask = static_cast<T>(1) << bit_number;

common/make/gd32/Validate.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ endif
2424

2525
ifeq ($(findstring CONFIG_REMOTECONFIG_MINIMUM,$(FLAGS)),CONFIG_REMOTECONFIG_MINIMUM)
2626
DEFINES+=-DCONFIG_NET_APPS_NO_MDNS
27+
DEFINES+=-DCONFIG_UDP_NO_OPTIMIZE
28+
DEFINES+=-DDISABLE_RTC
2729
else
2830
ifeq ($(findstring NO_EMAC,$(FLAGS)),NO_EMAC)
2931
else
@@ -56,8 +58,23 @@ ifdef FATFS_MKFS
5658
DEFINES+=-DCONFIG_FATFS_MKFS
5759
endif
5860

61+
# Hardware Scenario Flag Condition Resulting Compiler Definitions (DEFINES)
62+
# Using RTL8201F ENET_LINK_CHECK is missing -DRTL8201F_LED1_LINK_ALL -DENET_LINK_CHECK_USE_INT (Uses Interrupts)
63+
# Using RTL8201F ENET_LINK_CHECK is present -DRTL8201F_LED1_LINK_ALL
64+
# Other Hardware Any -DENET_LINK_CHECK_REG_POLL (Uses Polling)
65+
66+
ifneq ($(findstring RTL8201F,$(FLAGS)),)
67+
DEFINES+=-DRTL8201F_LED1_LINK_ALL
68+
ifeq ($(findstring ENET_LINK_CHECK,$(FLAGS)),)
69+
DEFINES+=-DENET_LINK_CHECK_USE_INT
70+
endif
71+
else
72+
DEFINES+=-DENET_LINK_CHECK_REG_POLL
73+
endif
74+
5975
$(info $$DEFINES [${DEFINES}])
6076

6177
DEFINES:= $(sort $(DEFINES))
6278

6379
$(info $$DEFINES [${DEFINES}])
80+

firmware-template-gd32/Rules.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ FIRMWARE_DIR=./../firmware-template-gd32/
2424
PROJECT=$(notdir $(patsubst %/,%,$(CURDIR)))
2525
$(info $$PROJECT [${PROJECT}])
2626

27-
DEFINES:=$(addprefix -D,$(DEFINES)) -DCONFIG_NETWORK_MEMORY_BLOCKS=1
27+
DEFINES:=$(addprefix -D,$(DEFINES))
28+
DEFINES+=-DCONFIG_NETWORK_MEMORY_BLOCKS=1
29+
DEFINES+=-DPHY_TYPE=$(ENET_PHY)
2830

2931
include ../common/make/gd32/Board.mk
3032
include ../common/make/gd32/Mcu.mk
@@ -48,7 +50,7 @@ LDLIBS:=$(addprefix -l,$(LIBS))
4850
# The variables for the dependency check
4951
LIBDEP=$(addprefix ../lib-,$(LIBS))
5052

51-
COPS=-DGD32 -D$(FAMILY_UCA) -D$(LINE_UC) -D$(MCU) -D$(BOARD) -DPHY_TYPE=$(ENET_PHY)
53+
COPS=-DGD32 -D$(FAMILY_UCA) -D$(LINE_UC) -D$(MCU) -D$(BOARD)
5254
COPS+=$(strip $(DEFINES) $(MAKE_FLAGS) $(INCLUDES) $(LIBINCDIRS))
5355
COPS+=$(strip $(ARMOPS) $(CMSISOPS))
5456
COPS+=-Os -nostartfiles -ffreestanding -nostdlib

lib-clib/src/asctime.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ static const char kWdayName[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "S
3535
static char s_buffer[kMaxAscTime + 1];
3636

3737
extern "C" char* asctime(const struct tm* p_tm) {
38-
if (!p_tm) return nullptr;
38+
if (p_tm == nullptr) {
39+
return nullptr;
40+
}
3941

4042
const char* const kWday = (p_tm->tm_wday >= 0 && p_tm->tm_wday <= 6) ? kWdayName[p_tm->tm_wday] : "???";
4143
const char* const kMon = (p_tm->tm_mon >= 0 && p_tm->tm_mon <= 11) ? kMonName[p_tm->tm_mon] : "???";

0 commit comments

Comments
 (0)