Skip to content

Commit

Permalink
Merge pull request #28 from ThundeRatz/develop
Browse files Browse the repository at this point in the history
Atualização da versão estável
  • Loading branch information
lucastrschneider authored Jan 13, 2022
2 parents 5e9be4a + 57a4eb5 commit b26c100
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 17 deletions.
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) 2018 ThundeRatz Robotics Team
Copyright (c) 2021 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
42 changes: 29 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,34 @@ C_SOURCES := $(shell find src -name "*.c")
C_HEADERS := $(shell find inc -name "*.h")
LIB_SOURCES :=

TEST_HEADERS := $(shell find $(TEST_DIR)/inc -name "*.h")
TEST_SOURCES := $(shell find $(TEST_DIR)/src -name "*.c")
TESTS_HEADERS := $(shell find $(TEST_DIR)/inc -name "*.h")
TESTS_SOURCES := $(shell find $(TEST_DIR)/src -name "*.c")
TESTS_BIN := $(shell find $(TEST_DIR)/bin -name "*.c")

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

CONFIG_HEADERS :=

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

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

# Object Files
CUBE_OBJECTS := $(addprefix $(BUILD_DIR)/$(CUBE_DIR)/,$(notdir $(CUBE_SOURCES:.c=.o)))
CUBE_OBJECTS += $(addprefix $(BUILD_DIR)/$(CUBE_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
OBJECTS := $(addprefix $(BUILD_DIR)/obj/,$(notdir $(C_SOURCES:.c=.o)))
TEST_OBJECTS := $(addprefix $(BUILD_DIR)/$(TEST_DIR)/,$(notdir $(TEST_SOURCES:.c=.o)))
CUBE_OBJECTS := $(addprefix $(BUILD_DIR)/$(CUBE_DIR)/,$(notdir $(CUBE_SOURCES:.c=.o)))
CUBE_OBJECTS += $(addprefix $(BUILD_DIR)/$(CUBE_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
OBJECTS := $(addprefix $(BUILD_DIR)/obj/,$(notdir $(C_SOURCES:.c=.o)))
TESTS_OBJECTS := $(addprefix $(BUILD_DIR)/$(TEST_DIR)/,$(notdir $(TESTS_SOURCES:.c=.o)))
TESTS_OBJECTS += $(addprefix $(BUILD_DIR)/$(TEST_DIR)/,$(notdir $(CURRENT_TEST_BIN:.c=.o)))

vpath %.c $(sort $(dir $(CUBE_SOURCES)))
vpath %.c $(sort $(dir $(C_SOURCES)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
vpath %.c $(sort $(dir $(TEST_SOURCES)))
vpath %.c $(sort $(dir $(TESTS_SOURCES)))
vpath %.c $(sort $(dir $(CURRENT_TEST_BIN)))

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

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

# Adds libs sources and include directories
Expand Down Expand Up @@ -151,7 +162,7 @@ TEST_CFLAGS := \

# Build target base name definition
ifeq ($(TEST), 1)
BUILD_TARGET_BASE_NAME := test_$(PROJECT_NAME)
BUILD_TARGET_BASE_NAME := $(TEST_NAME)_$(PROJECT_NAME)
else
BUILD_TARGET_BASE_NAME := $(PROJECT_NAME)
endif
Expand Down Expand Up @@ -202,9 +213,9 @@ $(BUILD_DIR)/$(PROJECT_NAME).elf: $(OBJECTS) $(CUBE_OBJECTS) $(LIB_OBJECTS) conf
$(AT)$(SIZE) $@

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

# The .hex file depend on the .elf file and build directory existence
Expand Down Expand Up @@ -232,9 +243,11 @@ $(BUILD_DIR):

ifeq ($(OS),Windows_NT)
CUBE_JAR := "$(CUBE_PATH)\STM32CubeMX.exe"
JAVA_EXE := "$(CUBE_PATH)\jre\bin\java.exe"
JLINK_EXE := JLink.exe
else
CUBE_JAR := "$(CUBE_PATH)/STM32CubeMX"
JAVA_EXE := "$(CUBE_PATH)/jre/bin/java"
JLINK_EXE := JLinkExe
endif

Expand All @@ -255,6 +268,9 @@ endif

# Generate Cube Files
cube: .cube
$(AT)$(JAVA_EXE) -jar $(CUBE_JAR) -q $<

cube_old: .cube
$(AT)java -jar $(CUBE_JAR) -q $<

# Prepare workspace
Expand Down Expand Up @@ -316,7 +332,7 @@ ifeq ($(TEST), 0)
else
# Clean test build files
@echo "Cleaning test build files"
$(AT)-rm -rf $(TEST_OBJECTS) $(TEST_OBJECTS:.o=.d) $(TEST_OBJECTS:.o=.lst)
$(AT)-rm -rf $(TESTS_OBJECTS) $(TESTS_OBJECTS:.o=.d) $(TESTS_OBJECTS:.o=.lst)
endif

# Clean all build files
Expand All @@ -326,7 +342,7 @@ clean_all:

# Format source code using uncrustify
format:
$(AT)uncrustify -c uncrustify.cfg --replace --no-backup $(C_SOURCES) $(C_HEADERS) $(TEST_HEADERS) $(TEST_SOURCES)
$(AT)uncrustify -c uncrustify.cfg --replace --no-backup $(C_SOURCES) $(C_HEADERS) $(TESTS_HEADERS) $(TESTS_SOURCES) $(TESTS_BIN) $(CONFIG_HEADERS)

# Display help
help:
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,23 @@ 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 proejto em si. Esses arquivos devem ser implementados de acordo com as necessidades dos desenvolvedores. O diretório contém uma função `main()` própria. Para se fazer os testes com esses arquivos, compilá-los e gravar o executável gerado, deve-se mudar o valor da variável `TEST` para 1.
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:

```bash
make flash TEST=1
```

Uma observação é que o comando `make clean`, quando `TEST` for 1, irá apagar os arquivos de compilação referentes aos arquivos 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:

```bash
make TEST=1 TEST_NAME=test_sensors
```

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

## Debug

Expand Down
2 changes: 2 additions & 0 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ TEST_DIR := tests
DEBUG ?= 1
VERBOSE ?= 0
TEST ?= 0

TEST_NAME ?= test_main
4 changes: 2 additions & 2 deletions tests/src/tests_main.c → tests/bin/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/

#include <stdio.h>
#include "mcu.h"
#include "tests_core.h"

int main(void) {
mcu_init();
test_core_init();

for (;;) {
}
Expand Down
Empty file removed tests/inc/.keep
Empty file.
20 changes: 20 additions & 0 deletions tests/inc/tests_core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @file tests_core.h
*
* @brief Core functions to the tests
*
* @date 04/2021
*
* @copyright MIT License
*
*/

/*****************************************
* Public Functions Prototypes
*****************************************/

/**
* @brief Initialize tests core
*
*/
void test_core_init(void);
21 changes: 21 additions & 0 deletions tests/src/tests_core.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @file tests_core.c
*
* @brief Core functions to the tests
*
* @date 04/2021
*
* @copyright MIT License
*
*/

#include "tests_core.h"
#include "mcu.h"

/*****************************************
* Public Functions Bodies Definitions
*****************************************/

void test_core_init(void) {
mcu_init();
}

0 comments on commit b26c100

Please sign in to comment.