Skip to content

Commit 4c13268

Browse files
committed
V2.0
- Improved build system - Added stack debug framework - Removed not used source files - Added support DMX delta output - Added Manufacturer PIDs (https://www.gd32-dmx.org/rdm.html) - Added support for void __libc_init_array(void) - Changed the layout of the config store. - Before upgrading the firmware it is advised to make a backup of the configuration. - After the upgrade, then restore the saved configuration.
1 parent 454dcbe commit 4c13268

207 files changed

Lines changed: 5131 additions & 46587 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ lib-network/src/apps/*
6363
lib-network/src/emac/*
6464
lib-network/src/net/*
6565

66+
*.list
67+
*.map
6668
*.bin
69+
*.size
70+
6771
do-tftp.sh
6872
udp_send
73+

Board-tester/.settings/language.settings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
66
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
77
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="([^/\\\\]*)((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
8-
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1021011516338226530" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
8+
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1020270605534866530" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
99
<language-scope id="org.eclipse.cdt.core.gcc"/>
1010
<language-scope id="org.eclipse.cdt.core.g++"/>
1111
</provider>

Board-tester/gd32f10x.list

Lines changed: 0 additions & 4841 deletions
This file was deleted.

Board-tester/gd32f10x.map

Lines changed: 0 additions & 1580 deletions
This file was deleted.

firmware-template-gd32/Includes.mk

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,57 @@
1-
INCLUDES:= -I./include -I../include -I../lib-hal/include -I../lib-debug/include
1+
INCLUDES:=-I./include -I../include -I../lib-hal/include -I../lib-debug/include
22
INCLUDES+=$(addprefix -I,$(EXTRA_INCLUDES))
33
INCLUDES+=-I../firmware-template-gd32/include
44
INCLUDES+=-I../firmware-template-gd32/template
55
INCLUDES+=-I../lib-gd32/${FAMILY}/${FAMILY_UC}_standard_peripheral/Include
66
INCLUDES+=-I../lib-gd32/${FAMILY}/CMSIS
77
INCLUDES+=-I../lib-gd32/${FAMILY}/CMSIS/GD/${FAMILY_UC}/Include
8-
INCLUDES+=-I../lib-gd32/include
8+
INCLUDES+=-I../lib-gd32/include
9+
10+
USB_HOST=
11+
ifeq ($(findstring ENABLE_USB_HOST,$(DEFINES)), ENABLE_USB_HOST)
12+
USB_HOST=1
13+
endif
14+
ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
15+
USB_HOST=1
16+
endif
17+
18+
USB_HOST_MSC=
19+
ifeq ($(findstring ENABLE_USB_HOST,$(DEFINES)), ENABLE_USB_HOST)
20+
USB_HOST_MSC=1
21+
endif
22+
ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
23+
USB_HOST_MSC=1
24+
endif
25+
26+
ifdef USB_HOST
27+
INCLUDES+=-I../lib-gd32/device/usb
28+
INCLUDES+=-I../lib-hal/device/usb/host/gd32
29+
endif
30+
31+
ifeq ($(findstring gd32f20x,$(FAMILY)), gd32f20x)
32+
ifdef USB_HOST
33+
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/driver/Include
34+
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/host/core/Include
35+
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/ustd/common
36+
ifdef USB_HOST_MSC
37+
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/host/class/msc/Include
38+
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/ustd/class/msc
39+
endif
40+
endif
41+
endif
42+
43+
ifeq ($(findstring gd32f4xx,$(FAMILY)), gd32f4xx)
44+
ifdef USB_HOST
45+
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/driver/Include
46+
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/host/core/Include
47+
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/ustd/common
48+
ifdef USB_HOST_MSC
49+
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/host/class/msc/Include
50+
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/ustd/class/msc
51+
endif
52+
endif
53+
endif
54+
55+
ifdef USB_HOST_MSC
56+
EXTRA_INCLUDES+=../lib-hal/ff12c
57+
endif

firmware-template-gd32/Mcu.mk

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
ifndef MCU
2+
$(error MCU is not set)
3+
endif
4+
5+
MCU_UC=$(shell echo $(MCU) | rev | cut -c3- | rev )
6+
MCU_LC=$(shell echo $(MCU_UC) | tr A-Z a-z )
7+
8+
$(info $$MCU [${MCU}])
9+
$(info $$MCU_LC [${MCU_LC}])
10+
$(info $$MCU_UC [${MCU_UC}])
11+
12+
ifeq ($(strip $(MCU)),GD32F103RC)
13+
LINKER=$(FIRMWARE_DIR)gd32f103rc_flash.ld
14+
FAMILY=gd32f10x
15+
LINE=gd32f10x_hd
16+
endif
17+
18+
ifeq ($(strip $(MCU)),GD32F107RC)
19+
LINKER=$(FIRMWARE_DIR)gd32f107rc_flash.ld
20+
FAMILY=gd32f10x
21+
LINE=gd32f10x_cl
22+
endif
23+
24+
ifeq ($(strip $(MCU)),GD32F207VC)
25+
LINKER=$(FIRMWARE_DIR)gd32f207vc_flash.ld
26+
FAMILY=gd32f20x
27+
LINE=gd32f20x_cl
28+
endif
29+
30+
ifeq ($(strip $(MCU)),GD32F207RG)
31+
LINKER=$(FIRMWARE_DIR)gd32f207rg_flash.ld
32+
FAMILY=gd32f20x
33+
LINE=gd32f20x_cl
34+
endif
35+
36+
ifeq ($(strip $(MCU)),GD32F303RC)
37+
LINKER=$(FIRMWARE_DIR)gd32f303rc_flash.ld
38+
FAMILY=gd32f30x
39+
LINE=gd32f30x_hd
40+
endif
41+
42+
ifeq ($(strip $(MCU)),GD32F407RE)
43+
LINKER=$(FIRMWARE_DIR)gd32f407re_flash.ld
44+
FAMILY=gd32f4xx
45+
LINE=gd32f407
46+
endif
47+
48+
ifeq ($(strip $(MCU)),GD32F450VE)
49+
LINKER=$(FIRMWARE_DIR)gd32f450ve_flash.ld
50+
FAMILY=gd32f4xx
51+
LINE=gd32f450
52+
endif
53+
54+
ifeq ($(strip $(MCU)),GD32F450VI)
55+
LINKER=$(FIRMWARE_DIR)gd32f450vi_flash.ld
56+
FAMILY=gd32f4xx
57+
LINE=gd32f450
58+
endif
59+
60+
ifndef LINKER
61+
$(error MCU is not configured)
62+
endif
63+
64+
FAMILY_UC=$(shell echo $(FAMILY) | tr a-w A-W)
65+
66+
$(info $$FAMILY [${FAMILY}])
67+
$(info $$FAMILY_UC [${FAMILY_UC}])
68+
69+
LINE_UC=$(shell echo $(LINE) | tr a-z A-Z)
70+
71+
$(info $$LINE [${LINE}])
72+
$(info $$LINE_UC [${LINE_UC}])

firmware-template-gd32/Rules.mk

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
$(info "Rules.mk")
2+
13
PREFIX ?= arm-none-eabi-
24

35
CC = $(PREFIX)gcc
@@ -6,16 +8,9 @@ AS = $(CC)
68
LD = $(PREFIX)ld
79
AR = $(PREFIX)ar
810

9-
FAMILY?=gd32f10x
1011
BOARD?=BOARD_GD32F103RC
1112

12-
FAMILY:=$(shell echo $(FAMILY) | tr A-Z a-z)
13-
FAMILY_UC=$(shell echo $(FAMILY) | tr a-w A-W)
14-
15-
$(info $$FAMILY [${FAMILY}])
16-
$(info $$FAMILY_UC [${FAMILY_UC}])
17-
18-
# Output
13+
# Output
1914
TARGET=$(FAMILY).bin
2015
LIST=$(FAMILY).list
2116
MAP=$(FAMILY).map
@@ -24,17 +19,17 @@ BUILD=build_gd32/
2419
# Input
2520
SOURCE = ./
2621
FIRMWARE_DIR = ./../firmware-template-gd32/
27-
LINKER = $(FIRMWARE_DIR)/gd32f103rc_flash.ld
2822

23+
DEFINES:=$(addprefix -D,$(DEFINES))
24+
DEFINES+=-DCONFIG_STORE_USE_ROM
25+
26+
MCU=GD32F103RC
27+
28+
include ../firmware-template-gd32/Mcu.mk
2929
include ../firmware-template/libs.mk
3030

3131
LIBS+=c++ c gd32
3232

33-
$(info [${LIBS}])
34-
35-
DEFINES:=$(addprefix -D,$(DEFINES))
36-
DEFINES+=-DCONFIG_STORE_USE_ROM
37-
3833
include ../firmware-template-gd32/Includes.mk
3934

4035
# The variable for the libraries include directory
@@ -51,21 +46,23 @@ LDLIBS:=$(addprefix -l,$(LIBS))
5146
# The variables for the dependency check
5247
LIBDEP=$(addprefix ../lib-,$(LIBS))
5348

49+
$(info $$BOARD [${BOARD}])
50+
$(info $$DEFINES [${DEFINES}])
51+
$(info $$LIBS [${LIBS}])
5452
$(info $$LIBDEP [${LIBDEP}])
5553

56-
COPS=-DBARE_METAL -DGD32 -DGD32F10X_HD -D$(BOARD)
57-
#COPS+=-DDISABLE_PRINTF_FLOAT
58-
COPS+=$(DEFINES) $(MAKE_FLAGS) $(INCLUDES)
59-
COPS+=$(LIBINCDIRS)
54+
COPS=-DBARE_METAL -DGD32 -D$(LINE_UC) -D$(MCU) -D$(BOARD)
55+
COPS+=$(DEFINES) $(MAKE_FLAGS) $(INCLUDES) $(LIBINCDIRS)
6056
COPS+=-Os -mcpu=cortex-m3 -mthumb
6157
COPS+=-nostartfiles -ffreestanding -nostdlib
6258
COPS+=-fstack-usage
63-
COPS+=-Wstack-usage=4096
6459
COPS+=-ffunction-sections -fdata-sections
60+
COPS+=-Wall -Werror -Wpedantic -Wextra -Wunused -Wsign-conversion -Wconversion
61+
COPS+=-Wduplicated-cond -Wlogical-op
6562

66-
CPPOPS=-std=c++11
63+
CPPOPS=-std=c++11
6764
CPPOPS+=-Wnon-virtual-dtor -Woverloaded-virtual -Wnull-dereference -fno-rtti -fno-exceptions -fno-unwind-tables
68-
#CPPOPS+=-Wuseless-cast -Wold-style-cast
65+
CPPOPS+=-Wuseless-cast -Wold-style-cast
6966
CPPOPS+=-fno-threadsafe-statics
7067

7168
LDOPS=--gc-sections --print-gc-sections
@@ -84,18 +81,17 @@ OBJECTS:=$(ASM_OBJECTS) $(C_OBJECTS)
8481

8582
define compile-objects
8683
$(BUILD)$1/%.o: $(SOURCE)$1/%.cpp
87-
$(CPP) $(COPS) $(CPPOPS) -c $$< -o $$@
84+
$(CPP) $(COPS) $(CPPOPS) -c $$< -o $$@
8885

8986
$(BUILD)$1/%.o: $(SOURCE)$1/%.c
9087
$(CC) $(COPS) -c $$< -o $$@
91-
88+
9289
$(BUILD)$1/%.o: $(SOURCE)$1/%.S
9390
$(CC) $(COPS) -D__ASSEMBLY__ -c $$< -o $$@
9491
endef
9592

96-
9793
all : builddirs prerequisites $(TARGET)
98-
94+
9995
.PHONY: clean builddirs
10096

10197
builddirs:
@@ -118,7 +114,7 @@ clean: $(LIBDEP)
118114
lisdep: $(LIBDEP)
119115

120116
$(LIBDEP):
121-
$(MAKE) -f Makefile.GD32 $(MAKECMDGOALS) 'FAMILY=${FAMILY}' 'MAKE_FLAGS=$(DEFINES)' -C $@
117+
$(MAKE) -f Makefile.GD32 $(MAKECMDGOALS) 'FAMILY=${FAMILY}' 'MCU=${MCU}' 'BOARD=${BOARD}' 'MAKE_FLAGS=$(DEFINES)' -C $@
122118

123119
# Build bin
124120

@@ -127,13 +123,18 @@ $(BUILD_DIRS) :
127123

128124
$(BUILD)startup_$(FAMILY)_hd.o : $(FIRMWARE_DIR)/startup_$(FAMILY)_hd.S
129125
$(AS) $(COPS) -D__ASSEMBLY__ -c $(FIRMWARE_DIR)/startup_$(FAMILY)_hd.S -o $(BUILD)startup_$(FAMILY)_hd.o
130-
126+
131127
$(BUILD)main.elf: Makefile.GD32 $(LINKER) $(BUILD)startup_$(FAMILY)_hd.o $(OBJECTS) $(LIBDEP)
132128
$(LD) $(BUILD)startup_$(FAMILY)_hd.o $(OBJECTS) -Map $(MAP) -T $(LINKER) $(LDOPS) -o $(BUILD)main.elf $(LIBGD32) $(LDLIBS) $(PLATFORM_LIBGCC) -lgcc
133129
$(PREFIX)objdump -D $(BUILD)main.elf | $(PREFIX)c++filt > $(LIST)
134-
$(PREFIX)size -A -x $(BUILD)main.elf
130+
$(PREFIX)size -A -x $(BUILD)main.elf > $(FAMILY).size
131+
$(MAKE) -f Makefile.GD32 calculate_unused_ram SIZE_FILE=$(FAMILY).size LINKER_SCRIPT=$(LINKER)
132+
133+
$(TARGET) : $(BUILD)main.elf
134+
$(PREFIX)objcopy $(BUILD)main.elf -O binary $(TARGET)
135+
136+
$(foreach bdir,$(SRCDIR),$(eval $(call compile-objects,$(bdir))))
135137

136-
$(TARGET) : $(BUILD)main.elf
137-
$(PREFIX)objcopy $(BUILD)main.elf -O binary $(TARGET)
138-
139-
$(foreach bdir,$(SRCDIR),$(eval $(call compile-objects,$(bdir))))
138+
.PHONY: calculate_unused_ram
139+
calculate_unused_ram: $(FAMILY).size $(LINKER)
140+
@$(FIRMWARE_DIR)/calculate_unused_ram.sh $(FAMILY).size $(LINKER)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
if [ $# -lt 2 ]; then
4+
echo "Usage: $0 <size_file> <linker_script>"
5+
exit 1
6+
fi
7+
8+
size_file="$1"
9+
linker_script="$2"
10+
11+
used_stack=$(grep ".stack" "$size_file" | awk '{print $2}')
12+
used_heap=$(grep ".heap" "$size_file" | awk '{print $2}')
13+
used_data=$(grep '.data' "$size_file" | tail -n 1 | awk '{print $2}')
14+
used_bss=$(grep ".bss" "$size_file" | awk '{print $2}')
15+
16+
total_ram=$(grep "RAM (xrw)" "$linker_script" | awk '{print $NF}' | sed 's/K$//' | awk '{printf "%d", $0 * 1024}')
17+
unused_ram=$(( $(echo $total_ram) - $(echo $used_stack) - $(echo $used_heap) - $(echo $used_data) - $(echo $used_bss) ))
18+
19+
cat $1
20+
echo "RAM $total_ram bytes, Unused: $unused_ram bytes"
21+
echo

0 commit comments

Comments
 (0)