Skip to content

Commit

Permalink
V2.0
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
vanvught committed Oct 18, 2023
1 parent 81c6f2e commit 175c406
Show file tree
Hide file tree
Showing 215 changed files with 6,019 additions and 46,830 deletions.
2 changes: 1 addition & 1 deletion Board-tester/.settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="768215401449997159" 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">
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1013393762152823842" 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">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand Down
4,459 changes: 0 additions & 4,459 deletions Board-tester/gd32f30x.list

This file was deleted.

1,909 changes: 0 additions & 1,909 deletions Board-tester/gd32f30x.map

This file was deleted.

53 changes: 51 additions & 2 deletions firmware-template-gd32/Includes.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,57 @@
INCLUDES:= -I./include -I../include -I../lib-hal/include -I../lib-debug/include
INCLUDES:=-I./include -I../include -I../lib-hal/include -I../lib-debug/include
INCLUDES+=$(addprefix -I,$(EXTRA_INCLUDES))
INCLUDES+=-I../firmware-template-gd32/include
INCLUDES+=-I../firmware-template-gd32/template
INCLUDES+=-I../lib-gd32/${FAMILY}/${FAMILY_UC}_standard_peripheral/Include
INCLUDES+=-I../lib-gd32/${FAMILY}/CMSIS
INCLUDES+=-I../lib-gd32/${FAMILY}/CMSIS/GD/${FAMILY_UC}/Include
INCLUDES+=-I../lib-gd32/include
INCLUDES+=-I../lib-gd32/include

USB_HOST=
ifeq ($(findstring ENABLE_USB_HOST,$(DEFINES)), ENABLE_USB_HOST)
USB_HOST=1
endif
ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
USB_HOST=1
endif

USB_HOST_MSC=
ifeq ($(findstring ENABLE_USB_HOST,$(DEFINES)), ENABLE_USB_HOST)
USB_HOST_MSC=1
endif
ifeq ($(findstring ENABLE_USB_HOST,$(MAKE_FLAGS)), ENABLE_USB_HOST)
USB_HOST_MSC=1
endif

ifdef USB_HOST
INCLUDES+=-I../lib-gd32/device/usb
INCLUDES+=-I../lib-hal/device/usb/host/gd32
endif

ifeq ($(findstring gd32f20x,$(FAMILY)), gd32f20x)
ifdef USB_HOST
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/driver/Include
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/host/core/Include
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/ustd/common
ifdef USB_HOST_MSC
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/host/class/msc/Include
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F20x_usbfs_library/ustd/class/msc
endif
endif
endif

ifeq ($(findstring gd32f4xx,$(FAMILY)), gd32f4xx)
ifdef USB_HOST
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/driver/Include
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/host/core/Include
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/ustd/common
ifdef USB_HOST_MSC
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/host/class/msc/Include
INCLUDES+=-I../lib-gd32/${FAMILY}/GD32F4xx_usb_library/ustd/class/msc
endif
endif
endif

ifdef USB_HOST_MSC
EXTRA_INCLUDES+=../lib-hal/ff12c
endif
72 changes: 72 additions & 0 deletions firmware-template-gd32/Mcu.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
ifndef MCU
$(error MCU is not set)
endif

MCU_UC=$(shell echo $(MCU) | rev | cut -c3- | rev )
MCU_LC=$(shell echo $(MCU_UC) | tr A-Z a-z )

$(info $$MCU [${MCU}])
$(info $$MCU_LC [${MCU_LC}])
$(info $$MCU_UC [${MCU_UC}])

ifeq ($(strip $(MCU)),GD32F103RC)
LINKER=$(FIRMWARE_DIR)gd32f103rc_flash.ld
FAMILY=gd32f10x
LINE=gd32f10x_hd
endif

ifeq ($(strip $(MCU)),GD32F107RC)
LINKER=$(FIRMWARE_DIR)gd32f107rc_flash.ld
FAMILY=gd32f10x
LINE=gd32f10x_cl
endif

ifeq ($(strip $(MCU)),GD32F207VC)
LINKER=$(FIRMWARE_DIR)gd32f207vc_flash.ld
FAMILY=gd32f20x
LINE=gd32f20x_cl
endif

ifeq ($(strip $(MCU)),GD32F207RG)
LINKER=$(FIRMWARE_DIR)gd32f207rg_flash.ld
FAMILY=gd32f20x
LINE=gd32f20x_cl
endif

ifeq ($(strip $(MCU)),GD32F303RC)
LINKER=$(FIRMWARE_DIR)gd32f303rc_flash.ld
FAMILY=gd32f30x
LINE=gd32f30x_hd
endif

ifeq ($(strip $(MCU)),GD32F407RE)
LINKER=$(FIRMWARE_DIR)gd32f407re_flash.ld
FAMILY=gd32f4xx
LINE=gd32f407
endif

ifeq ($(strip $(MCU)),GD32F450VE)
LINKER=$(FIRMWARE_DIR)gd32f450ve_flash.ld
FAMILY=gd32f4xx
LINE=gd32f450
endif

ifeq ($(strip $(MCU)),GD32F450VI)
LINKER=$(FIRMWARE_DIR)gd32f450vi_flash.ld
FAMILY=gd32f4xx
LINE=gd32f450
endif

ifndef LINKER
$(error MCU is not configured)
endif

FAMILY_UC=$(shell echo $(FAMILY) | tr a-w A-W)

$(info $$FAMILY [${FAMILY}])
$(info $$FAMILY_UC [${FAMILY_UC}])

LINE_UC=$(shell echo $(LINE) | tr a-z A-Z)

$(info $$LINE [${LINE}])
$(info $$LINE_UC [${LINE_UC}])
68 changes: 34 additions & 34 deletions firmware-template-gd32/Rules.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$(info "Rules.mk")

PREFIX ?= arm-none-eabi-

CC = $(PREFIX)gcc
Expand All @@ -6,16 +8,9 @@ AS = $(CC)
LD = $(PREFIX)ld
AR = $(PREFIX)ar

FAMILY?=gd32f30x
BOARD?=BOARD_GD32F303RC

FAMILY:=$(shell echo $(FAMILY) | tr A-Z a-z)
FAMILY_UC=$(shell echo $(FAMILY) | tr a-w A-W)

$(info $$FAMILY [${FAMILY}])
$(info $$FAMILY_UC [${FAMILY_UC}])

# Output
# Output
TARGET=$(FAMILY).bin
LIST=$(FAMILY).list
MAP=$(FAMILY).map
Expand All @@ -24,17 +19,17 @@ BUILD=build_gd32/
# Input
SOURCE = ./
FIRMWARE_DIR = ./../firmware-template-gd32/
LINKER = $(FIRMWARE_DIR)/gd32f303rc_flash.ld

DEFINES:=$(addprefix -D,$(DEFINES))
DEFINES+=-DCONFIG_STORE_USE_ROM

MCU=GD32F303RC

include ../firmware-template-gd32/Mcu.mk
include ../firmware-template/libs.mk

LIBS+=c++ c gd32

$(info [${LIBS}])

DEFINES:=$(addprefix -D,$(DEFINES))
DEFINES+=-DCONFIG_STORE_USE_ROM

include ../firmware-template-gd32/Includes.mk

# The variable for the libraries include directory
Expand All @@ -51,22 +46,23 @@ LDLIBS:=$(addprefix -l,$(LIBS))
# The variables for the dependency check
LIBDEP=$(addprefix ../lib-,$(LIBS))

$(info $$BOARD [${BOARD}])
$(info $$DEFINES [${DEFINES}])
$(info $$LIBS [${LIBS}])
$(info $$LIBDEP [${LIBDEP}])

COPS=-DBARE_METAL -DGD32 -DGD32F30X_HD -D$(BOARD)
#COPS+=-DDISABLE_PRINTF_FLOAT
COPS+=$(DEFINES) $(MAKE_FLAGS) $(INCLUDES)
COPS+=$(LIBINCDIRS)
COPS+=-Os -mcpu=cortex-m4 -mthumb -g -mfloat-abi=hard -fsingle-precision-constant -mfpu=fpv4-sp-d16
COPS+=-DARM_MATH_CM4 -D__FPU_PRESENT=1
COPS=-DBARE_METAL -DGD32 -DGD32F30X_HD -D$(MCU) -D$(BOARD)
COPS+=$(DEFINES) $(MAKE_FLAGS) $(INCLUDES) $(LIBINCDIRS)
COPS+=-Os -mcpu=cortex-m4 -mthumb -g -mfloat-abi=hard -fsingle-precision-constant -mfpu=fpv4-sp-d16 -DARM_MATH_CM4 -D__FPU_PRESENT=1
COPS+=-nostartfiles -ffreestanding -nostdlib
COPS+=-fstack-usage
COPS+=-Wstack-usage=4096
COPS+=-ffunction-sections -fdata-sections
COPS+=-Wall -Werror -Wpedantic -Wextra -Wunused -Wsign-conversion -Wconversion
COPS+=-Wduplicated-cond -Wlogical-op

CPPOPS=-std=c++11
CPPOPS=-std=c++11
CPPOPS+=-Wnon-virtual-dtor -Woverloaded-virtual -Wnull-dereference -fno-rtti -fno-exceptions -fno-unwind-tables
#CPPOPS+=-Wuseless-cast -Wold-style-cast
CPPOPS+=-Wuseless-cast -Wold-style-cast
CPPOPS+=-fno-threadsafe-statics

LDOPS=--gc-sections --print-gc-sections
Expand All @@ -85,18 +81,17 @@ OBJECTS:=$(ASM_OBJECTS) $(C_OBJECTS)

define compile-objects
$(BUILD)$1/%.o: $(SOURCE)$1/%.cpp
$(CPP) $(COPS) $(CPPOPS) -c $$< -o $$@
$(CPP) $(COPS) $(CPPOPS) -c $$< -o $$@

$(BUILD)$1/%.o: $(SOURCE)$1/%.c
$(CC) $(COPS) -c $$< -o $$@

$(BUILD)$1/%.o: $(SOURCE)$1/%.S
$(CC) $(COPS) -D__ASSEMBLY__ -c $$< -o $$@
endef


all : builddirs prerequisites $(TARGET)

.PHONY: clean builddirs

builddirs:
Expand All @@ -119,7 +114,7 @@ clean: $(LIBDEP)
lisdep: $(LIBDEP)

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

# Build bin

Expand All @@ -128,13 +123,18 @@ $(BUILD_DIRS) :

$(BUILD)startup_$(FAMILY)_hd.o : $(FIRMWARE_DIR)/startup_$(FAMILY)_hd.S
$(AS) $(COPS) -D__ASSEMBLY__ -c $(FIRMWARE_DIR)/startup_$(FAMILY)_hd.S -o $(BUILD)startup_$(FAMILY)_hd.o

$(BUILD)main.elf: Makefile.GD32 $(LINKER) $(BUILD)startup_$(FAMILY)_hd.o $(OBJECTS) $(LIBDEP)
$(LD) $(BUILD)startup_$(FAMILY)_hd.o $(OBJECTS) -Map $(MAP) -T $(LINKER) $(LDOPS) -o $(BUILD)main.elf $(LIBGD32) $(LDLIBS) $(PLATFORM_LIBGCC) -lgcc
$(PREFIX)objdump -D $(BUILD)main.elf | $(PREFIX)c++filt > $(LIST)
$(PREFIX)size -A -x $(BUILD)main.elf
$(PREFIX)size -A -x $(BUILD)main.elf > $(FAMILY).size
$(MAKE) -f Makefile.GD32 calculate_unused_ram SIZE_FILE=$(FAMILY).size LINKER_SCRIPT=$(LINKER)

$(TARGET) : $(BUILD)main.elf
$(PREFIX)objcopy $(BUILD)main.elf -O binary $(TARGET)

$(foreach bdir,$(SRCDIR),$(eval $(call compile-objects,$(bdir))))

$(TARGET) : $(BUILD)main.elf
$(PREFIX)objcopy $(BUILD)main.elf -O binary $(TARGET)

$(foreach bdir,$(SRCDIR),$(eval $(call compile-objects,$(bdir))))
.PHONY: calculate_unused_ram
calculate_unused_ram: $(FAMILY).size $(LINKER)
@$(FIRMWARE_DIR)/calculate_unused_ram.sh $(FAMILY).size $(LINKER)
21 changes: 21 additions & 0 deletions firmware-template-gd32/calculate_unused_ram.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

if [ $# -lt 2 ]; then
echo "Usage: $0 <size_file> <linker_script>"
exit 1
fi

size_file="$1"
linker_script="$2"

used_stack=$(grep ".stack" "$size_file" | awk '{print $2}')
used_heap=$(grep ".heap" "$size_file" | awk '{print $2}')
used_data=$(grep '.data' "$size_file" | tail -n 1 | awk '{print $2}')
used_bss=$(grep ".bss" "$size_file" | awk '{print $2}')

total_ram=$(grep "RAM (xrw)" "$linker_script" | awk '{print $NF}' | sed 's/K$//' | awk '{printf "%d", $0 * 1024}')
unused_ram=$(( $(echo $total_ram) - $(echo $used_stack) - $(echo $used_heap) - $(echo $used_data) - $(echo $used_bss) ))

cat $1
echo "RAM $total_ram bytes, Unused: $unused_ram bytes"
echo
Loading

0 comments on commit 175c406

Please sign in to comment.