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 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 94de065 commit 05cd0d7
Show file tree
Hide file tree
Showing 150 changed files with 4,221 additions and 3,000 deletions.
2 changes: 1 addition & 1 deletion bootloader-tftp/.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 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"/>
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-968318607671822594" 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="-967755094673102594" 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 changes: 3 additions & 1 deletion bootloader-tftp/Makefile.GD32
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ DEFINES+=DISABLE_FS
DEFINES+=DISABLE_PRINTF_FLOAT

DEFINES+=ENABLE_TFTP_SERVER
DEFINES+=CONFIG_REMOTECONFIG_MINIMUM

DEFINES+=UDP_MAX_PORTS_ALLOWED=2

#DEFINES+=ENET_LINK_CHECK_REG_POLL

DEFINES+=CONFIG_REMOTECONFIG_MINIMUM
DEFINES+=CONFIG_STORE_USE_ROM

DEFINES+=DEBUG_STACK

DEFINES+=NDEBUG

SRCDIR=firmware lib
Expand Down
19 changes: 10 additions & 9 deletions bootloader-tftp/firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ int main(void) {
gpio_mode_set(KEY_BOOTLOADER_TFTP_GPIOx, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, KEY_BOOTLOADER_TFTP_GPIO_PINx);
#endif

if ((bkp_data_read(BKP_DATA_1) != 0xA5A5) && (gpio_input_bit_get(KEY_BOOTLOADER_TFTP_GPIOx, KEY_BOOTLOADER_TFTP_GPIO_PINx))) {
const auto isNotRemote = (bkp_data_read(BKP_DATA_1) != 0xA5A5);
const auto isNotKey = (gpio_input_bit_get(KEY_BOOTLOADER_TFTP_GPIOx, KEY_BOOTLOADER_TFTP_GPIO_PINx));

if (isNotRemote && isNotKey) {
// https://developer.arm.com/documentation/ka001423/1-0
//1. Disable interrupt response.
__disable_irq();
Expand Down Expand Up @@ -94,18 +97,15 @@ int main(void) {
}

Hardware hw;
Network nw;
Display display(4);
ConfigStore configStore;
StoreNetwork storeNetwork;
Network nw(&storeNetwork);
FirmwareVersion fw(SOFTWARE_VERSION, __DATE__, __TIME__);

fw.Print("Bootloader TFTP Server");

FlashCodeInstall flashCodeInstall;
ConfigStore configStore;

StoreNetwork storeNetwork;
nw.SetNetworkStore(&storeNetwork);
nw.Init(&storeNetwork);
printf("Remote=%c, Key=%c\n", isNotRemote ? 'N' : 'Y', isNotKey ? 'N' : 'Y');
fw.Print("Bootloader TFTP Server");
nw.Print();

hw.SetMode(hardware::ledblink::Mode::OFF_ON);
Expand All @@ -121,6 +121,7 @@ int main(void) {

remoteConfig.SetEnableReboot(true);

network::display_ip();
display.Printf(3, "Bootloader TFTP Srvr");

hw.SetMode(hardware::ledblink::Mode::FAST);
Expand Down
12 changes: 12 additions & 0 deletions bootloader-tftp/gd32f10x.size
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
build_gd32/main.elf :
section size addr
.vectors 0x150 0x8000000
.text 0x5d0c 0x8000150
.rodata 0xbc0 0x8005e5c
.stack 0x800 0x20000000
.heap 0x400 0x20000800
.data 0x70 0x20000c00
.bss 0x16834 0x20000c70
Total 0x1dec0


2 changes: 1 addition & 1 deletion bootloader-tftp/include/software_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
#ifndef SOFTWARE_VERSION_H_
#define SOFTWARE_VERSION_H_

constexpr char SOFTWARE_VERSION[] = "1.7";
constexpr char SOFTWARE_VERSION[] = "2.0";

#endif /* SOFTWARE_VERSION_H_ */
20 changes: 15 additions & 5 deletions bootloader-tftp/lib/networkdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file networkdisplay.cpp
*
*/
/* Copyright (C) 2022 by Arjan van Vught mailto:info@gd32-dmx.org
/* Copyright (C) 2022-2023 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -33,16 +33,26 @@
namespace network {
static constexpr auto LINE_IP = 2U;

void display_emac_config() {
Display::Get()->ClearEndOfLine();
Display::Get()->Printf(LINE_IP, "Ethernet config");
}

void display_emac_start() {
Display::Get()->ClearLine(LINE_IP);
Display::Get()->PutString("Ethernet start");
Display::Get()->ClearEndOfLine();
Display::Get()->Printf(LINE_IP, "Ethernet start");
}

void display_ip() {
Display::Get()->ClearLine(LINE_IP);
Display::Get()->ClearEndOfLine();
Display::Get()->Printf(LINE_IP, "" IPSTR "/%d %c", IP2STR(Network::Get()->GetIp()), Network::Get()->GetNetmaskCIDR(), Network::Get()->GetAddressingMode());
}

void display_emac_status(const bool isLinkUp) {
Display::Get()->ClearEndOfLine();
Display::Get()->Printf(LINE_IP, "Ethernet Link %s", isLinkUp ? "UP" : "DOWN");
}

void display_netmask() {
display_ip();
}
Expand All @@ -54,7 +64,7 @@ void display_hostname() {
}

void display_emac_shutdown() {
Display::Get()->ClearLine(LINE_IP);
Display::Get()->ClearEndOfLine();
Display::Get()->PutString("Ethernet shutdown");
}

Expand Down
17 changes: 12 additions & 5 deletions firmware-template-gd32/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ AR = $(PREFIX)ar
BOARD?=BOARD_GD32F107RC
ENET_PHY?=DP83848
FAMILY?=gd32f10x
MCU?=gd32f107

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
TARGET=gd32f107.bin
TARGET=$(MCU).bin
LIST=$(FAMILY).list
MAP=$(FAMILY).map
BUILD=build_gd32/
Expand All @@ -34,7 +35,6 @@ LIBS+=c++ c gd32
$(info [${LIBS}])

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

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

Expand Down Expand Up @@ -118,7 +118,9 @@ lisdep: $(LIBDEP)
$(LIBDEP):
$(MAKE) -f Makefile.GD32 $(MAKECMDGOALS) 'FAMILY=${FAMILY}' 'BOARD=${BOARD}' 'PHY_TYPE=${ENET_PHY}' 'MAKE_FLAGS=$(DEFINES)' -C $@

#
# Build bin
#

$(BUILD_DIRS) :
mkdir -p $(BUILD_DIRS)
Expand All @@ -129,9 +131,14 @@ $(BUILD)startup_$(FAMILY)_cl.o : $(FIRMWARE_DIR)/startup_$(FAMILY)_cl.S
$(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
$(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))))
$(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
55 changes: 20 additions & 35 deletions firmware-template-gd32/gd32f107rc_flash.ld
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ENTRY(Reset_Handler)
SECTIONS
{
__heap_size = DEFINED(__heap_size) ? __heap_size : 1K;
__stack_size = DEFINED(__stack_size) ? __stack_size : 1K;
__stack_size = DEFINED(__stack_size) ? __stack_size : 2K;

.vectors :
{
Expand All @@ -30,10 +30,8 @@ SECTIONS
*(.glue_7)
*(.glue_7t)
*(.eh_frame)

KEEP (*(.init))
KEEP (*(.fini))

. = ALIGN(4);
_etext = .;
} >FLASH
Expand All @@ -46,19 +44,6 @@ SECTIONS
. = ALIGN(4);
} >FLASH

.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} >FLASH

.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH

.ARM.attributes : { *(.ARM.attributes) } > FLASH

.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
Expand All @@ -82,6 +67,24 @@ SECTIONS
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH

.stack :
{
. = ALIGN(4);
PROVIDE( stack_low = . );
. = __stack_size;
PROVIDE( _sp = . );
. = ALIGN(4);
} >RAM AT>RAM

.heap :
{
. = ALIGN(4);
heap_low = .;
. = . + __heap_size;
heap_top = .;
. = ALIGN(4);
} >RAM AT>RAM

_sidata = LOADADDR(.data);
.data :
{
Expand Down Expand Up @@ -109,28 +112,10 @@ SECTIONS
. = ALIGN(8);
PROVIDE ( end = _ebss );
PROVIDE ( _end = _ebss );

.heap ORIGIN(RAM) + LENGTH(RAM) - __stack_size - __heap_size :
{
. = ALIGN(4);
heap_low = .;
. = . + __heap_size;
heap_top = .;
. = ALIGN(4);
} >RAM AT>RAM

.stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size :
{
. = ALIGN(4);
PROVIDE( _heap_end = . );
. = __stack_size;
PROVIDE( _sp = . );
. = ALIGN(4);
} >RAM AT>RAM

/DISCARD/ :
{
*(*.ARM.attributes)
*(*.ARM.*)
*(*.comment)
*(*.debug*)
}
Expand Down
6 changes: 3 additions & 3 deletions firmware-template-gd32/startup_gd32f10x_cl.S
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
.type Reset_Handler, %function

Reset_Handler:
ldr r0, =_sp
mov sp, r0

movs r1, #0
b DataInit

Expand All @@ -44,6 +41,9 @@ Zerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss
#if defined (DEBUG_STACK)
bl stack_debug_init
#endif
bl SystemInit
bl main
bx lr
Expand Down
Empty file modified include/.settings/org.eclipse.core.resources.prefs
100644 → 100755
Empty file.
Loading

0 comments on commit 05cd0d7

Please sign in to comment.