Skip to content

Commit

Permalink
Merge pull request #40 from ThundeRatz/develop
Browse files Browse the repository at this point in the history
🔖 Release
  • Loading branch information
LucasHaug authored Apr 25, 2023
2 parents b26c100 + e8602f9 commit ee41e9e
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 237 deletions.
5 changes: 4 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"ms-vscode.cpptools",
"EditorConfig.EditorConfig",
"cschlosser.doxdocgen",
"editorconfig.editorconfig",
"davidanson.vscode-markdownlint",
"zachflower.uncrustify",
"marus25.Cortex-Debug",
],

Expand Down
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

"[c]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "zachflower.uncrustify",
},

"[makefile]": {
Expand All @@ -21,4 +22,21 @@
"files.trimTrailingWhitespace": false,
"files.trimFinalNewlines": false,
},

"doxdocgen.generic.dateFormat": "MM/YYYY",
"doxdocgen.file.copyrightTag": [
"@copyright MIT License - Copyright (c) {year} ThundeRatz"
],
"doxdocgen.generic.authorTag": "@author {author} <{email}>",
"doxdocgen.file.fileOrder": [
"file",
"author",
"brief",
"date",
"empty",
"copyright",
"empty",
"custom"
],

}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 ThundeRatz Robotics Team
Copyright (c) 2022 ThundeRatz Robotics Team

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
69 changes: 49 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,25 @@ TESTS_BIN := $(shell find $(TEST_DIR)/bin -name "*.c")

CURRENT_TEST_BIN := $(shell find $(TEST_DIR)/bin -name ${TEST_NAME}.c)

CONFIG_HEADERS :=
ifneq ($(TEST_NAME),)
ifeq ($(CURRENT_TEST_BIN),)
$(error Invalid test name, $(TEST_NAME).c not found)
endif
endif

ifeq ($(TEST), 1)
ifneq ($(TEST_NAME),)
C_SOURCES := $(filter-out $(shell find src -name "main.c"), $(C_SOURCES))
endif

CONFIG_HEADERS :=
BOARD_CONFIG_HEADER :=
GENERAL_CONFIG_HEADERS :=

ifneq ($(CFG_DIR),)
BOARD_CONFIG_HEADER += $(shell find -wholename ./$(CFG_DIR)/board/$(TARGET_BOARD).h)

GENERAL_CONFIG_HEADERS += $(shell find $(CFG_DIR) -name "*.h" -not -path "$(CFG_DIR)/board/*")

CONFIG_HEADERS += $(shell find $(CFG_DIR) -name "*.h")
endif

Expand All @@ -72,7 +84,10 @@ vpath %.c $(sort $(dir $(CUBE_SOURCES)))
vpath %.c $(sort $(dir $(C_SOURCES)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
vpath %.c $(sort $(dir $(TESTS_SOURCES)))

ifneq ($(TEST_NAME),)
vpath %.c $(sort $(dir $(CURRENT_TEST_BIN)))
endif

###############################################################################
## Compiler settings
Expand Down Expand Up @@ -105,9 +120,17 @@ C_INCLUDES := $(addprefix -I, \
)

C_TESTS_INCLUDES := $(addprefix -I, \
$(sort $(dir $(TESTS_HEADERS))) \
$(sort $(dir $(TESTS_HEADERS))) \
)

C_GENERAL_CONFIG_INCLUDES :=

ifneq ($(CFG_DIR),)
C_CONFIG_INCLUDES += $(addprefix -include , \
$(GENERAL_CONFIG_HEADERS) $(BOARD_CONFIG_HEADER) \
)
endif

# Adds libs sources and include directories
ifneq ($(wildcard $(LIB_DIR)/.*),)
-include $(shell find -L $(LIB_DIR) -name "sources.mk")
Expand Down Expand Up @@ -149,7 +172,7 @@ CFLAGS := \
$(OPT) -std=c11 -MMD -MP \

ifneq ($(CFG_DIR),)
CFLAGS += -include $(CFG_DIR)/board/$(TARGET_BOARD).h
CFLAGS += $(C_CONFIG_INCLUDES)
endif

ifeq ($(DEBUG),1)
Expand All @@ -161,10 +184,10 @@ TEST_CFLAGS := \
$(CFLAGS) $(C_TESTS_INCLUDES) \

# Build target base name definition
ifeq ($(TEST), 1)
BUILD_TARGET_BASE_NAME := $(TEST_NAME)_$(PROJECT_NAME)
ifneq ($(TEST_NAME),)
BUILD_TARGET_BASE_NAME := $(TEST_NAME)_$(PROJECT_RELEASE)
else
BUILD_TARGET_BASE_NAME := $(PROJECT_NAME)
BUILD_TARGET_BASE_NAME := $(PROJECT_RELEASE)
endif

# Linker Flags
Expand Down Expand Up @@ -207,13 +230,13 @@ $(BUILD_DIR)/$(TEST_DIR)/%.o: %.c config.mk Makefile | $(BUILD_DIR)
$(AT)$(CC) -c $(TEST_CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(TEST_DIR)/$(notdir $(<:.c=.lst)) -MF"$(@:.o=.d)" $< -o $@

# The .elf file depend on all object files and the Makefile
$(BUILD_DIR)/$(PROJECT_NAME).elf: $(OBJECTS) $(CUBE_OBJECTS) $(LIB_OBJECTS) config.mk Makefile | $(BUILD_DIR)
$(BUILD_DIR)/$(PROJECT_RELEASE).elf: $(OBJECTS) $(CUBE_OBJECTS) $(LIB_OBJECTS) config.mk Makefile | $(BUILD_DIR)
@echo "CC $@"
$(AT)$(CC) $(OBJECTS) $(CUBE_OBJECTS) $(LIB_OBJECTS) $(LDFLAGS) -o $@
$(AT)$(SIZE) $@

# The .elf file depend on all object files and the Makefile
$(BUILD_DIR)/$(TEST_NAME)_$(PROJECT_NAME).elf: $(OBJECTS) $(TESTS_OBJECTS) $(CUBE_OBJECTS) $(LIB_OBJECTS) config.mk Makefile | $(BUILD_DIR)
$(BUILD_DIR)/$(TEST_NAME)_$(PROJECT_RELEASE).elf: $(OBJECTS) $(TESTS_OBJECTS) $(CUBE_OBJECTS) $(LIB_OBJECTS) config.mk Makefile | $(BUILD_DIR)
@echo "CC $@"
$(AT)$(CC) $(OBJECTS) $(TESTS_OBJECTS) $(CUBE_OBJECTS) $(LIB_OBJECTS) $(LDFLAGS) -o $@
$(AT)$(SIZE) $@
Expand Down Expand Up @@ -262,7 +285,7 @@ endif
# Create cube script
.cube: config.mk Makefile
@echo "Creating Cube script"
@echo "config load "$(CUBE_DIR)"/"$(PROJECT_NAME)".ioc" > $@
@echo "config load "$(CUBE_DIR)"/"$(PROJECT_RELEASE)".ioc" > $@
@echo "project generate" >> $@
@echo "exit" >> $@

Expand Down Expand Up @@ -326,7 +349,7 @@ clean_cube:
# Clean build files
# - Ignores cube-related build files (ST and CMSIS libraries)
clean:
ifeq ($(TEST), 0)
ifeq ($(TEST_NAME),)
@echo "Cleaning build files"
$(AT)-rm -rf $(OBJECTS) $(OBJECTS:.o=.d) $(OBJECTS:.o=.lst)
else
Expand Down Expand Up @@ -417,15 +440,19 @@ define VS_CPP_PROPERTIES
"configurations": [
{
"name": "STM32_TR",

"includePath": [
$(subst -I,$(NULL),$(subst $(SPACE),$(COMMA),$(strip $(foreach inc,$(C_INCLUDES) $(C_TESTS_INCLUDES),"$(inc)"))))
],
"forcedInclude": [
$(subst $(SPACE),$(COMMA),$(strip $(foreach inc,$(BOARD_CONFIG_HEADER) $(GENERAL_CONFIG_HEADERS),"$(inc)")))
],

"defines": [
$(subst -D,$(NULL),$(subst $(SPACE),$(COMMA),$(strip $(foreach def,$(C_DEFS),"$(def)"))))
],

"compilerPath": "$${env:ARM_GCC_PATH}/arm-none-eabi-gcc",
"compilerPath": "$(ARM_GCC_PATH)/arm-none-eabi-gcc",
"cStandard": "c99",
"cppStandard": "c++14",
"intelliSenseMode": "clang-x64"
Expand All @@ -438,13 +465,15 @@ endef
export VS_LAUNCH
export VS_CPP_PROPERTIES

vs_files: $(VS_LAUNCH_FILE) $(VS_C_CPP_PROPERTIES_FILE)
vs_files: vs_launch vs_c_cpp_properties

$(VS_LAUNCH_FILE): config.mk Makefile | $(VSCODE_FOLDER)
$(AT)echo "$$VS_LAUNCH" > $@
vs_launch: config.mk Makefile | $(VSCODE_FOLDER)
$(AT)rm -f $(VS_LAUNCH_FILE)
$(AT)echo "$$VS_LAUNCH" > $(VS_LAUNCH_FILE)

$(VS_C_CPP_PROPERTIES_FILE): config.mk Makefile | $(VSCODE_FOLDER)
$(AT)echo "$$VS_CPP_PROPERTIES" > $@
vs_c_cpp_properties: config.mk Makefile $(C_HEADERS) $(TESTS_HEADERS) $(BOARD_CONFIG_HEADER) $(GENERAL_CONFIG_HEADERS) | $(VSCODE_FOLDER)
$(AT)rm -f $(VS_C_CPP_PROPERTIES_FILE)
$(AT)echo "$$VS_CPP_PROPERTIES" > $(VS_C_CPP_PROPERTIES_FILE)

$(VSCODE_FOLDER):
$(AT)mkdir -p $@
Expand All @@ -454,8 +483,8 @@ $(VSCODE_FOLDER):
# Include dependecy files for .h dependency detection
-include $(wildcard $(BUILD_DIR)/**/*.d)

.PHONY: \
all cube prepare flash load jflash info reset clean_cube \
clean clean_all format help vs_files rtt
.PHONY: \
all cube prepare flash load .jlink-flash jflash info reset clean_cube \
clean clean_all format help vs_files rtt vs_launch vs_c_cpp_properties

.DEFAULT_GOAL := all
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ novamente para que eles sejam gerados do zero.

O arquivo [config.mk](config.mk) deve ser alterado de acordo com o projeto.

Para isso é necessário mudar o nome do projeto, o qual deve ter o mesmo do arquivo do Cube (por exemplo, `stm32_project_template.ioc`), porém sem a extensão `.ioc`.
Para isso é necessário mudar o nome do projeto, o qual deve ter o mesmo do arquivo do Cube (por exemplo, `stm32_project_template.ioc`), porém sem a extensão `.ioc` (no caso de não se utilizar o versionamento dos arquivos do Cube).

```Makefile
# Cube file name without .ioc extension
PROJECT_NAME = stm32_project_template
```

Expand Down Expand Up @@ -207,21 +206,19 @@ git submodule update --init

## Diretório de testes

O diretório definido pela variável `TEST_DIR` contém arquivos para testes de partes específicas do projeto, separando isso do código do projeto em si. Esses arquivos devem ser implementados de acordo com as necessidades dos desenvolvedores.
O diretório definido pela variável `TEST_DIR` contém arquivos para testes de partes específicas do projeto, separando isso do código do projeto em si. Esses arquivos devem ser implementados de acordo com as necessidades dos desenvolvedores.

Para se habilitar a compilação e gravação dos testes, deve-se definir o valor da variável `TEST` para 1, isso pode ser feito tanto no arquivo `config.mk`, quanto pela linha de comando ao rodar o `make` passando no comando `TEST=1`, por exemplo:
Para se habilitar a compilação e gravação dos testes, deve-se definir o valor da variável `TEST_NAME` para o nome do arquivo de teste que se quer utilizar, isso pode ser feito tanto no arquivo `config.mk`, quanto pela linha de comando ao rodar o `make`, como por exemplo:

```bash
make flash TEST=1
make flash TEST_NAME=test_digital_sensors
```

Uma observação é que o comando `make clean`, quando `TEST` for 1, irá apagar os arquivos de compilação referentes aos arquivos de teste.
Caso o valor da variável `TEST_NAME` seja vazio, não se utilizará o modo de teste.

Cada arquivo de teste no diretório de testes funciona de forma independente, ou seja, cada um deve ter uma função `main()`, sendo cada um compilado, gravado e executado separadamente. A escolha de qual teste será rodado é feita pela variável `TEST_NAME`, que assim como a variável `TEST`, pode ser definida no arquivo `config.mk` ou pela linha de comando, por exemplo:
Uma observação é que o comando `make clean`, quando `TEST_NAME` não for vazio, irá apagar os arquivos de compilação referentes aos arquivos de teste.

```bash
make TEST=1 TEST_NAME=test_sensors
```
Cada arquivo de teste no diretório de testes funciona de forma independente, ou seja, cada um deve ter uma função `main()`, sendo cada um compilado, gravado e executado separadamente.

Note que o nome do teste não inclui a extensão do arquivo.

Expand Down
9 changes: 5 additions & 4 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

# Cube file name without .ioc extension
PROJECT_NAME = stm32_project_template
VERSION := 1
VERSION := v1

TARGET_BOARD := target_$(PROJECT_NAME)_$(VERSION)
PROJECT_RELEASE := $(PROJECT_NAME)_$(VERSION)

TARGET_BOARD := target_$(PROJECT_RELEASE)

DEVICE_FAMILY := STM32F3xx
DEVICE_TYPE := STM32F303xx
Expand All @@ -33,6 +35,5 @@ TEST_DIR := tests
# Default values, can be set on the command line or here
DEBUG ?= 1
VERBOSE ?= 0
TEST ?= 0

TEST_NAME ?= test_main
TEST_NAME ?=
Loading

0 comments on commit ee41e9e

Please sign in to comment.