Commit 4e35a853 authored by Kongou Hikari's avatar Kongou Hikari

Template: Optimize for code size

parent 9592ed5c
......@@ -11,9 +11,9 @@ TARGET = gd32vf103
# building variables
######################################
# debug build?
DEBUG = 1
DEBUG = 0
# optimization
OPT = -Og
OPT = -O2
# Build path
BUILD_DIR = build
......@@ -85,7 +85,7 @@ C_INCLUDES = \
# compile gcc flags
ASFLAGS := $(CFLAGS) $(ARCH) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wl,-Bstatic#, -ffreestanding -nostdlib
CFLAGS := $(CFLAGS) $(ARCH) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wl,-Bstatic#, -ffreestanding -nostdlib
CFLAGS := $(CFLAGS) $(ARCH) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wl,-Bstatic -ffunction-sections -fdata-sections # -ffreestanding -nostdlib
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
......@@ -101,9 +101,9 @@ CFLAGS += -std=gnu11 -MMD -MP # -MF$(@:%.o=%.d) -MT$(@:%.o=%.d)
LDSCRIPT = $(FIRMWARE_DIR)/RISCV/env_Eclipse/GD32VF103x8.lds
# libraries
LIBS = -lc_nano -lm
#LIBS = -lc_nano -lm
LIBDIR =
LDFLAGS = $(ARCH) -T$(LDSCRIPT) $(LIBDIR) $(LIBS) $(PERIFLIB_SOURCES) -Wl,--no-relax -Wl,--gc-sections -Wl,-M=$(BUILD_DIR)/$(TARGET).map -nostartfiles #-ffreestanding -nostdlib
LDFLAGS = -flto $(ARCH) -T$(LDSCRIPT) $(LIBDIR) $(LIBS) $(PERIFLIB_SOURCES) -Wl,--no-relax -Wl,--gc-sections -Wl,-M=$(BUILD_DIR)/$(TARGET).map -nostartfiles #-ffreestanding -nostdlib
# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
......
......@@ -43,15 +43,19 @@ OF SUCH DAMAGE.
*/
void delay_1ms(uint32_t count)
{
uint64_t start_mtime, delta_mtime;
volatile uint64_t start_mtime, delta_mtime;
// Don't start measuruing until we see an mtime tick
uint64_t tmp = get_timer_value();
volatile uint64_t tmp = get_timer_value();
do {
start_mtime = get_timer_value();
} while (start_mtime == tmp);
start_mtime = get_timer_value();
} while(start_mtime == tmp);
uint64_t delay_ticks = SystemCoreClock / 4; // 1 second
delay_ticks = delay_ticks * count / 1000;
do {
delta_mtime = get_timer_value() - start_mtime;
}while(delta_mtime <(SystemCoreClock/4000.0 *count ));
delta_mtime = get_timer_value() - start_mtime;
} while(delta_mtime < delay_ticks);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment