Skip to content

Commit 9ccef8f

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 e9615ca commit 9ccef8f

5 files changed

Lines changed: 365 additions & 316 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
Lines changed: 157 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,157 @@
1-
MEMORY
2-
{
3-
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K
4-
TCMSRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
5-
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
6-
RAMADD (xrw) : ORIGIN = 0x20030000, LENGTH = 0
7-
BKPSRAM (rw) : ORIGIN = 0x40024000, LENGTH = 4K
8-
}
9-
10-
ENTRY(Reset_Handler)
11-
12-
SECTIONS
13-
{
14-
__heap_size = DEFINED(__heap_size) ? __heap_size : 4K;
15-
__stack_size = DEFINED(__stack_size) ? __stack_size : 4K;
16-
17-
.vectors :
18-
{
19-
. = ALIGN(4);
20-
KEEP(*(.vectors))
21-
. = ALIGN(4);
22-
__Vectors_End = .;
23-
__Vectors_Size = __Vectors_End - __gVectors;
24-
} >FLASH
25-
26-
.text :
27-
{
28-
. = ALIGN(4);
29-
*(.text.unlikely*)
30-
*(.text.hot*)
31-
*(.text)
32-
*(.text*)
33-
*(.glue_7)
34-
*(.glue_7t)
35-
*(.eh_frame)
36-
KEEP (*(.init))
37-
KEEP (*(.fini))
38-
. = ALIGN(4);
39-
_etext = .;
40-
} >FLASH
41-
42-
.rodata :
43-
{
44-
. = ALIGN(4);
45-
*(.rodata)
46-
*(.rodata*)
47-
. = ALIGN(4);
48-
} >FLASH
49-
50-
.preinit_array :
51-
{
52-
PROVIDE_HIDDEN (__preinit_array_start = .);
53-
KEEP (*(.preinit_array*))
54-
PROVIDE_HIDDEN (__preinit_array_end = .);
55-
} >FLASH
56-
57-
.init_array :
58-
{
59-
PROVIDE_HIDDEN (__init_array_start = .);
60-
KEEP (*(SORT(.init_array.*)))
61-
KEEP (*(.init_array*))
62-
PROVIDE_HIDDEN (__init_array_end = .);
63-
} >FLASH
64-
65-
.fini_array :
66-
{
67-
PROVIDE_HIDDEN (__fini_array_start = .);
68-
KEEP (*(.fini_array*))
69-
KEEP (*(SORT(.fini_array.*)))
70-
PROVIDE_HIDDEN (__fini_array_end = .);
71-
} >FLASH
72-
73-
.stack :
74-
{
75-
. = ALIGN(4);
76-
PROVIDE( stack_low = . );
77-
. = . + __stack_size;
78-
PROVIDE( _sp = . );
79-
. = ALIGN(4);
80-
} >TCMSRAM
81-
82-
.tcmsram :
83-
{
84-
. = ALIGN(4);
85-
*(.tcmsram)
86-
*(.tcmsram*)
87-
. = ALIGN(4);
88-
_snetwork = .;
89-
*(.network*)
90-
. = ALIGN(4);
91-
_enetwork = .;
92-
} >TCMSRAM
93-
94-
.heap :
95-
{
96-
. = ALIGN(4);
97-
heap_low = .;
98-
. = . + __heap_size;
99-
heap_top = .;
100-
. = ALIGN(4);
101-
} >TCMSRAM
102-
103-
_sidata = LOADADDR(.data);
104-
.data :
105-
{
106-
. = ALIGN(4);
107-
_sdata = .;
108-
*(.data)
109-
*(.data*)
110-
. = ALIGN(4);
111-
_edata = .;
112-
} >RAM AT> FLASH
113-
114-
. = ALIGN(4);
115-
.bss :
116-
{
117-
_sbss = .;
118-
__bss_start__ = _sbss;
119-
*(.bss)
120-
*(.bss*)
121-
*(COMMON)
122-
. = ALIGN(4);
123-
_ebss = .;
124-
__bss_end__ = _ebss;
125-
} >RAM
126-
127-
. = ALIGN(8);
128-
PROVIDE ( end = _ebss );
129-
PROVIDE ( _end = _ebss );
130-
131-
.ramadd :
132-
{
133-
_sramadd = .;
134-
. = ALIGN(4);
135-
*(.ramadd)
136-
*(.ramadd*)
137-
. = ALIGN(4);
138-
_eramadd = .;
139-
} >RAMADD
140-
141-
.bkpsram :
142-
{
143-
. = ALIGN(4);
144-
*(.bkpsram)
145-
*(.bkpsram*)
146-
*(.configstore*)
147-
} >BKPSRAM
148-
149-
/DISCARD/ :
150-
{
151-
*(*.ARM.*)
152-
*(*.comment)
153-
*(*.debug*)
154-
}
155-
}
156-
157-
GROUP(libgcc.a)
1+
MEMORY
2+
{
3+
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K
4+
TCMSRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
5+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
6+
RAMADD (xrw) : ORIGIN = 0x20030000, LENGTH = 0
7+
BKPSRAM (rw) : ORIGIN = 0x40024000, LENGTH = 4K
8+
}
9+
10+
ENTRY(Reset_Handler)
11+
12+
SECTIONS
13+
{
14+
__heap_size = DEFINED(__heap_size) ? __heap_size : 4K;
15+
__stack_size = DEFINED(__stack_size) ? __stack_size : 4K;
16+
17+
.vectors :
18+
{
19+
. = ALIGN(4);
20+
KEEP(*(.vectors))
21+
. = ALIGN(4);
22+
__Vectors_End = .;
23+
__Vectors_Size = __Vectors_End - __gVectors;
24+
} >FLASH
25+
26+
.text :
27+
{
28+
. = ALIGN(4);
29+
*(.text.unlikely*)
30+
*(.text.hot*)
31+
*(.text)
32+
*(.text*)
33+
*(.glue_7)
34+
*(.glue_7t)
35+
*(.eh_frame)
36+
KEEP (*(.init))
37+
KEEP (*(.fini))
38+
. = ALIGN(4);
39+
_etext = .;
40+
} >FLASH
41+
42+
.rodata :
43+
{
44+
. = ALIGN(4);
45+
*(.rodata)
46+
*(.rodata*)
47+
. = ALIGN(4);
48+
} >FLASH
49+
50+
.preinit_array :
51+
{
52+
PROVIDE_HIDDEN (__preinit_array_start = .);
53+
KEEP (*(.preinit_array*))
54+
PROVIDE_HIDDEN (__preinit_array_end = .);
55+
} >FLASH
56+
57+
.init_array :
58+
{
59+
PROVIDE_HIDDEN (__init_array_start = .);
60+
KEEP (*(SORT(.init_array.*)))
61+
KEEP (*(.init_array*))
62+
PROVIDE_HIDDEN (__init_array_end = .);
63+
} >FLASH
64+
65+
.fini_array :
66+
{
67+
PROVIDE_HIDDEN (__fini_array_start = .);
68+
KEEP (*(.fini_array*))
69+
KEEP (*(SORT(.fini_array.*)))
70+
PROVIDE_HIDDEN (__fini_array_end = .);
71+
} >FLASH
72+
73+
.stack :
74+
{
75+
. = ALIGN(4);
76+
PROVIDE( stack_low = . );
77+
. = . + __stack_size;
78+
PROVIDE( _sp = . );
79+
. = ALIGN(4);
80+
} >TCMSRAM
81+
82+
.tcmsram :
83+
{
84+
. = ALIGN(4);
85+
*(.tcmsram)
86+
*(.tcmsram*)
87+
. = ALIGN(4);
88+
_snetwork = .;
89+
*(.network*)
90+
. = ALIGN(4);
91+
_enetwork = .;
92+
} >TCMSRAM
93+
94+
.heap :
95+
{
96+
. = ALIGN(4);
97+
heap_low = .;
98+
. = . + __heap_size;
99+
heap_top = .;
100+
. = ALIGN(4);
101+
} >TCMSRAM
102+
103+
_sidata = LOADADDR(.data);
104+
.data :
105+
{
106+
. = ALIGN(4);
107+
_sdata = .;
108+
*(.data)
109+
*(.data*)
110+
. = ALIGN(4);
111+
_edata = .;
112+
} >RAM AT> FLASH
113+
114+
. = ALIGN(4);
115+
.bss :
116+
{
117+
_sbss = .;
118+
__bss_start__ = _sbss;
119+
*(.bss)
120+
*(.bss*)
121+
*(COMMON)
122+
. = ALIGN(4);
123+
_ebss = .;
124+
__bss_end__ = _ebss;
125+
} >RAM
126+
127+
. = ALIGN(8);
128+
PROVIDE ( end = _ebss );
129+
PROVIDE ( _end = _ebss );
130+
131+
.ramadd :
132+
{
133+
_sramadd = .;
134+
. = ALIGN(4);
135+
*(.ramadd)
136+
*(.ramadd*)
137+
. = ALIGN(4);
138+
_eramadd = .;
139+
} >RAMADD
140+
141+
.bkpsram :
142+
{
143+
. = ALIGN(4);
144+
*(.bkpsram)
145+
*(.bkpsram*)
146+
*(.configstore*)
147+
} >BKPSRAM
148+
149+
/DISCARD/ :
150+
{
151+
*(*.ARM.*)
152+
*(*.comment)
153+
*(*.debug*)
154+
}
155+
}
156+
157+
GROUP(libgcc.a)

0 commit comments

Comments
 (0)