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.
- lib-artnet : V1.58
- lib-e131 : V1.27
- Removed  lib-artnet4
- Improved Network abstraction layer
- Improved PHY initialization process
- Improved embedded HTTP server
- Added support for secondary (permanent) IP address
    - The node is always available on the secondary IP address (2.x.x.x) for ping and http requests.
  • Loading branch information
vanvught committed Oct 18, 2023
1 parent 9b2f2d0 commit 6a37c9a
Show file tree
Hide file tree
Showing 419 changed files with 13,207 additions and 8,826 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
*/build_gd32/*
*/lib_gd32/*
*.su
*.map
*.list
*.size

*.bin
udp_send
0/*
do-tftp.sh

gd32f10x*.*
lib-gd32/gd32f10x/*
Expand Down
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}])
81 changes: 49 additions & 32 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 @@ -8,33 +10,33 @@ AR = $(PREFIX)ar

BOARD?=BOARD_GD32F207RG
ENET_PHY?=DP83848
FAMILY?=gd32f20x

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=gd32f207.bin
LIST=$(FAMILY).list
MAP=$(FAMILY).map
SIZE=$(FAMILY).size
BUILD=build_gd32/

# Input
SOURCE=./
FIRMWARE_DIR=./../firmware-template-gd32/
LINKER=$(FIRMWARE_DIR)gd32f207rg_flash.ld

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

ifeq ($(findstring ARTNET_VERSION=4,$(DEFINES)),ARTNET_VERSION=4)
ifeq ($(findstring ARTNET_HAVE_DMXIN,$(DEFINES)),ARTNET_HAVE_DMXIN)
DEFINES+=-DE131_HAVE_DMXIN
endif
endif

MCU=GD32F207RG

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

LIBS+=c++ c gd32

$(info [${LIBS}])

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

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

# The variable for the libraries include directory
Expand All @@ -45,24 +47,30 @@ LIBINCDIRS+=$(addsuffix /include, $(LIBINCDIRS))
LIBGD32=$(addprefix -L../lib-,$(LIBS))
LIBGD32:=$(addsuffix /lib_gd32, $(LIBGD32))

# The variable for the ld -l flag
# The variable for the ld -l flag
LDLIBS:=$(addprefix -l,$(LIBS))

# The variables for the dependency check
# The variables for the dependency check
LIBDEP=$(addprefix ../lib-,$(LIBS))

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

COPS=-DBARE_METAL -DGD32 -DGD32F20X_CL -D$(BOARD) -DPHY_TYPE=$(ENET_PHY)
COPS=-DBARE_METAL -DGD32 -D$(LINE_UC) -D$(MCU) -D$(BOARD) -DPHY_TYPE=$(ENET_PHY)
COPS+=$(DEFINES) $(MAKE_FLAGS) $(INCLUDES) $(LIBINCDIRS)
COPS+=-Os -mcpu=cortex-m3 -mthumb
COPS+=-nostartfiles -ffreestanding -nostdlib
COPS+=-fstack-usage -Wstack-usage=10240
COPS+=-fstack-usage
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 @@ -81,18 +89,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 @@ -115,22 +122,32 @@ clean: $(LIBDEP)
lisdep: $(LIBDEP)

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

#
# Build bin
#

$(BUILD_DIRS) :
mkdir -p $(BUILD_DIRS)

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

$(BUILD)main.elf: Makefile.GD32 $(LINKER) $(BUILD)startup_$(FAMILY)_cl.o $(OBJECTS) $(LIBDEP)
$(LD) $(BUILD)startup_$(FAMILY)_cl.o $(OBJECTS) -Map $(MAP) -T $(LINKER) $(LDOPS) -o $(BUILD)main.elf $(LIBGD32) $(LDLIBS) $(PLATFORM_LIBGCC) -lgcc

$(BUILD)hardfault_handler.o : $(FIRMWARE_DIR)/hardfault_handler.c
$(CC) $(COPS) -c $(FIRMWARE_DIR)/hardfault_handler.c -o $(BUILD)hardfault_handler.o

$(BUILD)main.elf: Makefile.GD32 $(LINKER) $(BUILD)startup_$(FAMILY)_cl.o $(BUILD)hardfault_handler.o $(OBJECTS) $(LIBDEP)
$(LD) $(BUILD)startup_$(FAMILY)_cl.o $(BUILD)hardfault_handler.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) --remove-section=.sram1* --remove-section=.sram2*

$(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)
32 changes: 32 additions & 0 deletions firmware-template-gd32/calculate_unused_ram.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

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

size_file="$1"
linker_script="$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_data) - $(echo $used_bss) ))

used_stack=$(grep ".stack" "$size_file" | awk '{print $2}')
used_heap=$(grep ".heap" "$size_file" | awk '{print $2}')

total_ram1=$(grep "RAM1 (xrw)" "$linker_script" | awk '{print $NF}' | sed 's/K$//' | awk '{printf "%d", $0 * 1024}')
unused_ram1=$(( $(echo $total_ram1) - $(echo $used_stack)- $(echo $used_heap) ))

used_ram2=$(grep ".sram2" "$size_file" | awk '{print $2}')

total_ram2=$(grep "RAM2 (xrw)" "$linker_script" | awk '{print $NF}' | sed 's/K$//' | awk '{printf "%d", $0 * 1024}')
unused_ram2=$(( $(echo $total_ram2) - $(echo $used_ram2) ))

cat $1
echo "SRAM0 $total_ram bytes, Unused: $unused_ram bytes"
echo "SRAM1 $total_ram1 bytes, Unused: $unused_ram1 bytes"
echo "SRAM2 $total_ram2 bytes, Unused: $unused_ram2 bytes"
echo
Loading

0 comments on commit 6a37c9a

Please sign in to comment.