From 04c5f18d9cb464c77c7a89e38ccac26ec01f2506 Mon Sep 17 00:00:00 2001 From: Sebastian Renner Date: Mon, 22 Jul 2019 12:32:34 +0200 Subject: [PATCH] Optimizing F7 template --- templates/f7/Makefile | 5 +++-- templates/f7/NIST_Makefile | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ templates/f7/Src/main.c | 10 +++++----- templates/f7/middleware.py | 2 +- 4 files changed, 201 insertions(+), 8 deletions(-) create mode 100644 templates/f7/NIST_Makefile diff --git a/templates/f7/Makefile b/templates/f7/Makefile index ccf62e3..3217c8e 100644 --- a/templates/f7/Makefile +++ b/templates/f7/Makefile @@ -20,9 +20,9 @@ TARGET = f7 # building variables ###################################### # debug build? -DEBUG = 1 +DEBUG = 0 # optimization -OPT = -Og +OPT = -O2 ####################################### @@ -130,6 +130,7 @@ endif # Generate dependency information CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" +#CFLAGS +=-std=c99 -Wextra -Wshadow ####################################### diff --git a/templates/f7/NIST_Makefile b/templates/f7/NIST_Makefile new file mode 100644 index 0000000..8e15c91 --- /dev/null +++ b/templates/f7/NIST_Makefile @@ -0,0 +1,192 @@ +########################################################################################################################## +# File automatically-generated by tool: [projectgenerator] version: [3.3.0] date: [Sun Jul 14 11:29:48 CEST 2019] +########################################################################################################################## + +# ------------------------------------------------ +# Generic Makefile (based on gcc) +# +# ChangeLog : +# 2017-02-10 - Several enhancements + project update mode +# 2015-07-22 - first version +# ------------------------------------------------ + +###################################### +# target +###################################### +TARGET = f7 + + +###################################### +# building variables +###################################### +# debug build? +DEBUG = 0 +# optimization +OPT = -O2 + + +####################################### +# paths +####################################### +# Build path +BUILD_DIR = build + +###################################### +# source +###################################### +# C sources +C_SOURCES = \ +Src/main.c \ +Src/stm32f7xx_it.c \ +Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_cortex.c \ +Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_gpio.c \ +Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usart.c \ +Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_dma.c \ +Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_rcc.c \ +Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_utils.c \ +Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_exti.c \ +Src/system_stm32f7xx.c \ +Src/RTT/SEGGER_RTT.c \ +Src/RTT/SEGGER_RTT_printf.c \ +$(SRC_FILES) + + +# ASM sources +ASM_SOURCES = \ +startup_stm32f746xx.s + + +####################################### +# binaries +####################################### +PREFIX = arm-none-eabi- +# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) +# either it can be added to the PATH environment variable. +ifdef GCC_PATH +CC = $(GCC_PATH)/$(PREFIX)gcc +AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp +CP = $(GCC_PATH)/$(PREFIX)objcopy +SZ = $(GCC_PATH)/$(PREFIX)size +else +CC = $(PREFIX)gcc +AS = $(PREFIX)gcc -x assembler-with-cpp +CP = $(PREFIX)objcopy +SZ = $(PREFIX)size +endif +HEX = $(CP) -O ihex +BIN = $(CP) -O binary -S + +####################################### +# CFLAGS +####################################### +# cpu +CPU = -mcpu=cortex-m7 + +# fpu +FPU = -mfpu=fpv5-sp-d16 + +# float-abi +FLOAT-ABI = -mfloat-abi=hard + +# mcu +MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) + +# macros for gcc +# AS defines +AS_DEFS = + +# C defines +C_DEFS = \ +-DUSE_FULL_LL_DRIVER \ +-DUSE_HAL_DRIVER \ +-DSTM32F746xx \ +-DUSE_FULL_LL_DRIVER \ +-DUSE_HAL_DRIVER \ +-DUSE_HAL_DRIVER \ +-DSTM32F746xx + + +# AS includes +AS_INCLUDES = + +# C includes +C_INCLUDES = \ +-IInc \ +-IDrivers/STM32F7xx_HAL_Driver/Inc \ +-IDrivers/STM32F7xx_HAL_Driver/Inc/Legacy \ +-IDrivers/CMSIS/Device/ST/STM32F7xx/Include \ +-IDrivers/CMSIS/Include \ + + +# compile gcc flags +ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections + +CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections + +ifeq ($(DEBUG), 1) +CFLAGS += -g -gdwarf-2 +endif + + +# Generate dependency information +CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" +CFLAGS +=-std=c99 -Wall -Wextra -Wshadow +LFLAGS=-lm + + +####################################### +# LDFLAGS +####################################### +# link script +LDSCRIPT = STM32F746ZGTx_FLASH.ld + +# libraries +LIBS = -lc -lm -lnosys +LIBDIR = +LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections + +# default action: build all +all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin + + +####################################### +# build the application +####################################### +# list of objects +OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) +vpath %.c $(sort $(dir $(C_SOURCES))) +# list of ASM program objects +OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) +vpath %.s $(sort $(dir $(ASM_SOURCES))) + +$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) + $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ + +$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) + $(AS) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile + $(CC) $(OBJECTS) $(LDFLAGS) -o $@ + $(SZ) $@ + +$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(HEX) $< $@ + +$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(BIN) $< $@ + +$(BUILD_DIR): + mkdir $@ + +####################################### +# clean up +####################################### +clean: + -rm -fR $(BUILD_DIR) + +####################################### +# dependencies +####################################### +-include $(wildcard $(BUILD_DIR)/*.d) + +# *** EOF *** diff --git a/templates/f7/Src/main.c b/templates/f7/Src/main.c index e33a55a..3cc530f 100644 --- a/templates/f7/Src/main.c +++ b/templates/f7/Src/main.c @@ -24,7 +24,7 @@ #include "api.h" #include //#define DEBUG -#define MAX_LEN 1400 +#define MAX_LEN 100 #ifdef DEBUG #include "SEGGER_RTT.h" @@ -213,9 +213,9 @@ int main(void) dbg_printf("p: "); for (int i = 0; i < nplen; i++) dbg_printf("%02x", npub[i]); dbg_printf("\n"); dbg_printf("k: "); for (int i = 0; i < klen; i++) dbg_printf("%02x", k[i]); dbg_printf("\n"); #endif - LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_7); + LL_GPIO_ResetOutputPin(GPIOD, LL_GPIO_PIN_7); res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k); - LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_7); + LL_GPIO_SetOutputPin(GPIOD, LL_GPIO_PIN_7); break; case 'd': @@ -226,9 +226,9 @@ int main(void) dbg_printf("k: "); for (int i = 0; i < klen; i++) dbg_printf("%02x", k[i]); dbg_printf("\n"); #endif - LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12); + LL_GPIO_ResetOutputPin(GPIOD, LL_GPIO_PIN_7); res = crypto_aead_decrypt(m, &mlen, nsec, c, clen, ad, adlen, npub, k); - LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12); + LL_GPIO_SetOutputPin(GPIOD, LL_GPIO_PIN_7); break; default: diff --git a/templates/f7/middleware.py b/templates/f7/middleware.py index 1365bb9..627ba43 100755 --- a/templates/f7/middleware.py +++ b/templates/f7/middleware.py @@ -55,7 +55,6 @@ def submit(channel, action, data): h = struct.pack("