Skip to content

Commit cc243be

Browse files
committed
Refine flashcode FMC and bootloader linker script selection
Adds conditional linker script selection for several GD32 MCUs when CONFIG_REMOTECONFIG_MINIMUM is set, using MAKE_FLAGS/DEFINES as the source for flag detection. Refactors GD32 FMC flashcode state handling with clearer state names and bank helper functions (lock/unlock/busy/program/erase), adds read/write address and size guards plus alignment assertions, and switches FMC logging to dedicated debug macros. Also fixes H7xx erase-state typo (kEraseProgram), makes write data pointer const-correct, and updates minor debug/copyright details.
1 parent c8f6d74 commit cc243be

4 files changed

Lines changed: 208 additions & 159 deletions

File tree

common/make/gd32/Mcu.mk

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ ifndef MCU
44
$(error MCU is not set)
55
endif
66

7+
FLAGS:=$(MAKE_FLAGS)
8+
ifeq ($(FLAGS),)
9+
FLAGS:=$(DEFINES)
10+
endif
11+
712
$(info $$MCU [${MCU}])
813

914
# Extract upper and lower case versions of MCU name
@@ -24,20 +29,32 @@ ifeq ($(strip $(MCU)),GD32F103RC)
2429
endif
2530

2631
ifeq ($(strip $(MCU)),GD32F107RC)
27-
LINKER=$(FIRMWARE_DIR)gd32f107rc_flash.ld
32+
ifeq ($(findstring CONFIG_REMOTECONFIG_MINIMUM,$(FLAGS)),CONFIG_REMOTECONFIG_MINIMUM)
33+
LINKER=$(FIRMWARE_DIR)gd32f107rc-bootloader_flash.ld
34+
else
35+
LINKER=$(FIRMWARE_DIR)gd32f107rc_flash.ld
36+
endif
2837
FAMILY=gd32f10x
2938
LINE=gd32f10x_cl
3039
TARGET=gd32f107.bin
3140
endif
3241

3342
ifeq ($(strip $(MCU)),GD32F207VC)
34-
LINKER=$(FIRMWARE_DIR)gd32f207vc_flash.ld
43+
ifeq ($(findstring CONFIG_REMOTECONFIG_MINIMUM,$(FLAGS)),CONFIG_REMOTECONFIG_MINIMUM)
44+
LINKER=$(FIRMWARE_DIR)gd32f207vc-bootloader_flash.ld
45+
else
46+
LINKER=$(FIRMWARE_DIR)gd32f207vc_flash.ld
47+
endif
3548
FAMILY=gd32f20x
3649
LINE=gd32f20x_cl
3750
endif
3851

3952
ifeq ($(strip $(MCU)),GD32F207RG)
40-
LINKER=$(FIRMWARE_DIR)gd32f207rg_flash.ld
53+
ifeq ($(findstring CONFIG_REMOTECONFIG_MINIMUM,$(FLAGS)),CONFIG_REMOTECONFIG_MINIMUM)
54+
LINKER=$(FIRMWARE_DIR)gd32f207rg-bootloader_flash.ld
55+
else
56+
LINKER=$(FIRMWARE_DIR)gd32f207rg_flash.ld
57+
endif
4158
FAMILY=gd32f20x
4259
LINE=gd32f20x_cl
4360
endif
@@ -50,7 +67,11 @@ ifeq ($(strip $(MCU)),GD32F303RC)
5067
endif
5168

5269
ifeq ($(strip $(MCU)),GD32F407RE)
53-
LINKER=$(FIRMWARE_DIR)gd32f407re_flash.ld
70+
ifeq ($(findstring CONFIG_REMOTECONFIG_MINIMUM,$(FLAGS)),CONFIG_REMOTECONFIG_MINIMUM)
71+
LINKER=$(FIRMWARE_DIR)gd32f407re-bootloader_flash.ld
72+
else
73+
LINKER=$(FIRMWARE_DIR)gd32f407re_flash.ld
74+
endif
5475
FAMILY=gd32f4xx
5576
LINE=gd32f407
5677
endif

lib-flashcode/include/flashcode.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <cstdint>
3030
#include <span>
3131

32+
#include "firmware/debug/debug_debug.h"
33+
3234
#ifdef DEBUG_FLASHCODE
3335
#define FLASHCODE_DEBUG_ENTRY() DEBUG_ENTRY()
3436
#define FLASHCODE_DEBUG_EXIT() DEBUG_EXIT()
@@ -49,6 +51,26 @@
4951
} while (false)
5052
#endif
5153

54+
#ifdef DEBUG_FMC
55+
#define FMC_DEBUG_ENTRY() DEBUG_ENTRY()
56+
#define FMC_DEBUG_EXIT() DEBUG_EXIT()
57+
#define FMC_DEBUG_PRINTF(...) DEBUG_PRINTF(__VA_ARGS__)
58+
#define FMC_DEBUG_PUTS(...) DEBUG_PUTS(__VA_ARGS__)
59+
#else
60+
#define FMC_DEBUG_ENTRY() \
61+
do { \
62+
} while (false)
63+
#define FMC_DEBUG_EXIT() \
64+
do { \
65+
} while (false)
66+
#define FMC_DEBUG_PRINTF(...) \
67+
do { \
68+
} while (false)
69+
#define FMC_DEBUG_PUTS(...) \
70+
do { \
71+
} while (false)
72+
#endif // DEBUG_COMMON_FMC
73+
5274
namespace flashcode {
5375
enum class Result { kOk, kError };
5476
} // namespace flashcode

0 commit comments

Comments
 (0)