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 519b2bc commit 346ee2d
Show file tree
Hide file tree
Showing 160 changed files with 4,590 additions and 3,179 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="-1023957529592819746" 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="-1023394016594099746" 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
27 changes: 27 additions & 0 deletions bootloader-tftp/Makefile-16x4u.GD32
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
BOARD=BOARD_16X4U_PIXEL

DEFINES =DISABLE_JSON
DEFINES+=DISABLE_RTC
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_STORE_USE_SPI

DEFINES+=DEBUG_STACK

DEFINES+=NDEBUG

SRCDIR=firmware lib

LIBS=remoteconfig flashcodeinstall configstore display flashcode flash

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

prerequisites:
6 changes: 5 additions & 1 deletion bootloader-tftp/Makefile.GD32
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
BOARD=BOARD_GD32F450VI

DEFINES =DISABLE_JSON
DEFINES+=DISABLE_RTC
DEFINES+=DISABLE_FS
Expand All @@ -8,10 +10,12 @@ DEFINES+=CONFIG_REMOTECONFIG_MINIMUM

DEFINES+=UDP_MAX_PORTS_ALLOWED=2

#DEFINES+=ENET_LINK_CHECK_REG_POLL
DEFINES+=ENET_LINK_CHECK_REG_POLL

DEFINES+=CONFIG_STORE_USE_I2C

DEFINES+=DEBUG_STACK

DEFINES+=NDEBUG

SRCDIR=firmware lib
Expand Down
16 changes: 7 additions & 9 deletions bootloader-tftp/firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ int main(void) {
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
if (isNotRemote && isNotKey) {
// https://developer.arm.com/documentation/ka001423/1-0
// https://developer.arm.com/documentation/ka001423/1-0
//1. Disable interrupt response.
__disable_irq();
Expand Down Expand Up @@ -97,19 +98,15 @@ int main(void) {
}

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

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

FlashCodeInstall flashCodeInstall;
ConfigStore configStore;

StoreNetwork storeNetwork;
nw.SetNetworkStore(&storeNetwork);
nw.Init(&storeNetwork);
nw.Print();

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

remoteConfig.SetEnableReboot(true);

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

hw.SetMode(hardware::ledblink::Mode::FAST);
Expand Down
15 changes: 15 additions & 0 deletions bootloader-tftp/gd32f4xx.size
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
build_gd32/main.elf :
section size addr
.vectors 0x1ac 0x8000000
.text 0x629c 0x80001ac
.rodata 0xc18 0x8006448
.data 0x70 0x20000000
.stack 0x800 0x10000000
.tcmsram 0x2690 0x10000800
.heap 0x400 0x10002e90
.bss 0x3a6bc 0x20030000
.ramadd 0x0 0x2006a6bc
.bkpsram 0x0 0x40024000
Total 0x44a1c


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.2";
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,13 +33,23 @@
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_emac_status(const bool isLinkUp) {
Display::Get()->ClearEndOfLine();
Display::Get()->Printf(LINE_IP, "Ethernet Link %s", isLinkUp ? "UP" : "DOWN");
}

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());
}

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
13 changes: 9 additions & 4 deletions firmware-template-gd32/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ ENET_PHY?=DP83848
FAMILY?=gd32f4xx
MCU?=gd32f450

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

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

Expand Down Expand Up @@ -121,7 +119,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 @@ -132,9 +132,14 @@ $(BUILD)startup_$(MCU).o : $(FIRMWARE_DIR)/startup_$(MCU).S
$(BUILD)main.elf: Makefile.GD32 $(LINKER) $(BUILD)startup_$(MCU).o $(OBJECTS) $(LIBDEP)
$(LD) $(BUILD)startup_$(MCU).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 --remove-section=.tcmsram* --remove-section=.ramadd* --remove-section=.bkpsram* -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)
33 changes: 33 additions & 0 deletions firmware-template-gd32/calculate_unused_ram.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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_tcmsram=$(grep ".tcmsram" "$size_file" | awk '{print $2}')
used_heap=$(grep ".heap" "$size_file" | awk '{print $2}')

total_tcmsram=$(grep "TCMSRAM (rw)" "$linker_script" | awk '{print $NF}' | sed 's/K$//' | awk '{printf "%d", $0 * 1024}')
unused_tcmsram=$(( $(echo $total_tcmsram) - $(echo $used_stack) - $(echo $used_tcmsram) - $(echo $used_heap) ))

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) ))

used_ramadd=$(grep ".ramadd" "$size_file" | awk '{print $2}')

total_ramadd=$(grep "RAMADD (xrw)" "$linker_script" | awk '{print $NF}' | sed 's/K$//' | awk '{printf "%d", $0 * 1024}')
unused_ramadd=$(( $(echo $total_ramadd) - $(echo $used_ramadd) - $(echo $used_bss)))

cat $1
echo "TCMSRAM $total_tcmsram bytes, Unused TCMSRAM: $unused_tcmsram bytes"
echo "RAM $total_ram bytes, Unused: $unused_ram bytes"
echo "RAMADD $total_ramadd bytes, Unused: $unused_ramadd bytes"
echo
Loading

0 comments on commit 346ee2d

Please sign in to comment.