Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ COPY setup/container_packages_installation_scripts ${INSTALLATION_SCRIPTS_LOCATI

RUN apt-get update -y && \
apt-get upgrade -y && \
apt-get install -y pixz wget curl gcc g++ git subversion autoconf pkg-config automake libtool cmake make build-essential ninja-build zsh \
apt-get install -y pixz wget curl gcc g++ git unzip subversion autoconf pkg-config automake libtool cmake make build-essential ninja-build zsh \
libusb-1.0.0 libusb-dev libusb-1.0.0-dev gnupg libncursesw5 libncurses5-dev \
bash-completion vim htop libreadline-dev clang clang-tidy lcov flawfinder cppcheck && \
apt-get clean
apt-get clean

#install scripts
RUN chmod +x ${INSTALLATION_SCRIPTS_LOCATION}/*
Expand All @@ -40,3 +40,11 @@ RUN apt-get update && \

COPY setup/create_project ${CREATE_PROJECT_SCRIPT}
ENV PATH="${PATH}:${CREATE_PROJECT_SCRIPT}"

# Set zsh as the default shell
RUN sed -i -e "s/bin\/bash/bin\/zsh/" /etc/passwd
RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"




105 changes: 105 additions & 0 deletions setup/create_project/create_launch_json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash


target_config_name=${TARGET_CONFIG[${MCU_FAMILY}]}
declare -n target_config=$target_config_name

target_sel_name=${TARGET_SEL[${MCU_FAMILY}]}
declare -n target_sel=$target_sel_name

interface_config_name=${INTERFACE_CONFIG[${MCU_FAMILY}]}
declare -n interface_config=$interface_config_name


COMMON_CONFIG=$(cat << EOM
{
"name": "Debug Test",
"type": "cppdbg",
"request": "launch",
"program": "\${workspaceFolder}/${BUILD_DIR}/${TESTS_DIR}/${PROJECT_NAME}_test.elf",
"args": [],
"stopAtEntry": false,
"cwd": "\${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb-multiarch",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
EOM
)

DEDICATED_CONFIGS=""
for cores in ${MCU_SRC_DIRS[@]}; do

svd_file=$(find "${PROJECT_NAME}" -name '*.svd' )

BOARD_OR_TARGET=${target_sel[$cores]}
BOARD_OR_TARGET_VALUE=${target_config[$cores]}
INTERFACE=${interface_config[$cores]}

if [[ ${#MCU_SRC_DIRS[@]} -gt 1 ]];then

executable=\"./${BUILD_DIR}/${PROJECT_NAME}_${cores}.elf\"
cores=${cores^^}
svd_file=$(echo "${svd_file}" | grep -E "${UPPERCASE_MCU_FAMILY:0:8}[a-z A-Z 0-9]_C${cores:0:3}\.svd$")
else
cores=""
executable=\"./${BUILD_DIR}/${PROJECT_NAME}.elf\"
fi

svd_file="${svd_file#*/}"
cores=${cores,,}
DEDICATED_CONFIGS+=$(cat << EOM
{
"name": "Cortex Debug ${cores}",
"cwd": "${workspaceFolder}",
"executable": $executable,
"request": "launch",
"type": "cortex-debug",
"runToEntryPoint": "main",
"servertype": "openocd",
"configFiles": [
"/usr/local/share/openocd/scripts/interface/${INTERFACE}.cfg",
"/usr/local/share/openocd/scripts/${BOARD_OR_TARGET}/${BOARD_OR_TARGET_VALUE}.cfg"
],
"svdFile": "${svd_file}"

},
{
"name": "Flash and Debug ${cores}",
"cwd": "${workspaceFolder}",
"executable": $executable,
"request": "launch",
"type": "cortex-debug",
"runToEntryPoint": "main",
"servertype": "openocd",
"configFiles": [
"/usr/local/share/openocd/scripts/interface/${INTERFACE}.cfg",
"/usr/local/share/openocd/scripts/${BOARD_OR_TARGET}/${BOARD_OR_TARGET_VALUE}.cfg"
],
"preLaunchTask": "Flash Core ${cores}"
},
EOM
)
done

LAUNCH_JSON=$(cat << EOM
{
"version": "0.2.0",
"configurations": [
$COMMON_CONFIG,
$DEDICATED_CONFIGS
]
}
EOM
)

echo "${LAUNCH_JSON}" > $PROJECT_NAME/.vscode/launch.json

3 changes: 3 additions & 0 deletions setup/create_project/create_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ source ./download_cmsis.sh
source ./download_linker_and_startup_script.sh
./create_settings_json.sh
source ./create_c_cpp_properties_json.sh
source ./create_tasks_json.sh
source ./download_svd_files.sh
source ./create_launch_json.sh
source ./copy_files.sh
set --
source ./move_makefiles.sh
Expand Down
15 changes: 9 additions & 6 deletions setup/create_project/create_root_makefile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,31 @@ for dir in "${MCU_SRC_DIRS[@]}"; do
if [[ ${#MCU_SRC_DIRS[@]} -eq 1 ]]; then
dir=$MCU_SRC_DIR_DEFAULT
suffix=""
create_rule --target "build_test" --command "\$(MAKE) -C ${CORE_DIR}/${dir} build_test"
create_rule --target "clean_test" --command "\$(MAKE) -C ${CORE_DIR}/${dir} clean_test"
create_rule --target "run_test" --command "\$(MAKE) -C ${CORE_DIR}/${dir} run_test"
else
if [[ "$dir" == "${MCU_SRC_DIRS[0]}" ]]; then
create_rule --target "build_test" --command "\$(MAKE) -C ${CORE_DIR}/${dir} build_test"
create_rule --target "clean_test" --command "\$(MAKE) -C ${CORE_DIR}/${dir} clean_test"
create_rule --target "run_test" --command "\$(MAKE) -C ${CORE_DIR}/${dir} run_test"
fi
fi
create_rule --target "all${suffix}" --command "\$(MAKE) -C ${CORE_DIR}/${dir} all"
create_rule --target "build_project${suffix}" --command "\$(MAKE) -C ${CORE_DIR}/${dir} build_project"
create_rule --target "build_test${suffix}" --command "\$(MAKE) -C ${CORE_DIR}/${dir} build_test"
create_rule --target "flash${suffix}" --command "\$(MAKE) -C ${CORE_DIR}/${dir} flash"
create_rule --target "clean${suffix}" --command "\$(MAKE) -C ${CORE_DIR}/${dir} clean"
create_rule --target "clean_test${suffix}" --command "\$(MAKE) -C ${CORE_DIR}/${dir} clean_test"
build_all_deps+="all${suffix} "
build_project_deps+="build_project${suffix} "
build_test_deps+="build_test${suffix} "
flash_deps+="flash${suffix} "
clean_deps+="clean${suffix} "
clean_test_deps+="clean_test${suffix} "
done

if [[ ${#MCU_SRC_DIRS[@]} -gt 1 ]]; then
create_rule --target "all" --dependencies "${build_all_deps}"
create_rule --target "build_projects" --dependencies "${build_project_deps}"
create_rule --target "build_tests" --dependencies "${build_test_deps}"
create_rule --target "flash" --dependencies "${flash_deps}"
create_rule --target "clean" --dependencies "${clean_deps}"
create_rule --target "clean_tests" --dependencies "${clean_test_deps}"
fi


Expand Down
22 changes: 12 additions & 10 deletions setup/create_project/create_sub_makefile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ MPU_ARCH=""
FPU_V=""
FPU=""
SRC_PATH=""
#if there is more than one core, the build directory is Build/mx. if single core -> Build/
SRC_BUILD_PATH="/${SRC_PATH}"
#if there is more than one core, the target is projectName_mx.elf. if single core -> projectName.elf
BUILD_PATH_SUFFIX="_${SRC_PATH}"
#Directories excluded from the main build
EXCLUDED_DIRS=""
#Directories excluded from the test build
Expand All @@ -117,9 +113,14 @@ FPU_FLAGS=""
# Main script execution
parse_args "$@"
check_missing_params
change_pthsfx_bldpth_if_single_core
exclude_files

#if there is more than one core, the build directory is Build/mx. if single core -> Build/
SRC_BUILD_PATH="/${SRC_PATH}"
#if there is more than one core, the target is projectName_mx.elf. if single core -> projectName.elf
BUILD_PATH_SUFFIX="_${SRC_PATH}"
change_pthsfx_bldpth_if_single_core

core_name="$(get_core_name ${MPU_ARCH})"
BOARD_OR_TARGET=${target_sel[$core_name]}
BOARD_OR_TARGET_VALUE=${target_config[$core_name]}
Expand All @@ -135,7 +136,7 @@ LINKER_SCRIPT_PATH=${STARTUP_REL_PATH}/$LINKER_SCRIPT
OBJ_DIR=${BUILD_PATH}${SRC_BUILD_PATH}
TEST_OBJ_DIR=${BUILD_PATH}/${TESTS_DIR}${SRC_BUILD_PATH}
TARGET=${BUILD_PATH}/${PROJECT_NAME}${BUILD_PATH_SUFFIX}.elf
TEST_TARGET=${TEST_BUILD_PATH}/${PROJECT_NAME}${BUILD_PATH_SUFFIX}.elf
TEST_TARGET=${TEST_BUILD_PATH}/${PROJECT_NAME}_test.elf

# Define include directories
INC_DIRS="\$(shell find ${CORE_REL_PATH} -type d -name .svn -prune -o -type d -print)"
Expand All @@ -157,8 +158,8 @@ TEST_C_SOURCES_CORE="\$(shell find ${TESTS_REL_PATH} -name '*.c') \$(shell find
ASM_OBJECTS="\$(STARTUP_SCRIPT_PATH:\${STARTUP_REL_PATH}/%.s=\$(OBJ_DIR)/${STARTUP_DIR}/%.o)"
CXX_OBJECTS="\$(CXX_SOURCES_CORE:\${CORE_REL_PATH}/%.cpp=\$(OBJ_DIR)/%.o)"
C_OBJECTS="\$(C_SOURCES_CORE:\${CORE_REL_PATH}/%.c=\$(OBJ_DIR)/%.o)"
TEST_CXX_OBJ="\$(TEST_CXX_SOURCES_CORE:../../%.cpp=${TEST_OBJ_DIR}/%.o)"
TEST_C_OBJ="\$(TEST_C_SOURCES_CORE:../../%.c=${TEST_OBJ_DIR}/%.o)"
TEST_CXX_OBJ="\$(TEST_CXX_SOURCES_CORE:../..//%.cpp=${TEST_OBJ_DIR}/%.o)"
TEST_C_OBJ="\$(TEST_C_SOURCES_CORE:../..//%.c=${TEST_OBJ_DIR}/%.o)"

DEPS="\$(CXX_OBJECTS:.o=.d) \$(C_OBJECTS:.o=.d) \$(ASM_OBJECTS:.o=.d)"

Expand Down Expand Up @@ -221,6 +222,7 @@ run_test: build_test
@echo ' '

\$(TEST_TARGET): \$(TEST_CXX_OBJECTS) \$(TEST_C_OBJECTS)
@mkdir -p \$(dir \$@)
\$(TEST_CXX) $^ -o \$@
@echo 'Finished building test target: \$@'
@echo ' '
Expand Down Expand Up @@ -256,10 +258,10 @@ run_test: build_test
.PHONY: clean clean_test

clean:
rm -rf \$(OBJ_DIR)
rm -rf \$(OBJ_DIR)/* \$(TARGET)

clean_test:
rm -rf \$(TEST_OBJ_DIR)
rm -rf \$(TEST_OBJ_DIR) \$(TEST_TARGET)

EOM
)
Expand Down
124 changes: 124 additions & 0 deletions setup/create_project/create_tasks_json.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,127 @@
#!/bin/bash


#!/bin/bash
PROBLEM_MATCHER=$(cat << 'EOM'
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(.*):(\\\\\\d+):(\\\\\\d+):\\\\\\s+(warning|error):\\\\\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"presentation": {
"reveal": "always"
}
EOM
)

DEDICATED_MAKE_RULES=""
if [[ ${#MCU_SRC_DIRS[@]} -gt 1 ]]; then
for cores in ${MCU_SRC_DIRS[@]}; do
# Use printf and sed to adjust the indentation
INDENTED_PROBLEM_MATCHER=$(printf "$PROBLEM_MATCHER" | sed 's/^/\t/')
DEDICATED_MAKE_RULES+=$(cat << EOM
{
//Build for Core ${cores}
"label": "Build Core ${cores}",
"type": "process",
"command": "make",
"args": [
"build_project_${cores}"
],
$INDENTED_PROBLEM_MATCHER
},
{
//Clean for Core ${cores}
"label": "Clean Core ${cores}",
"type": "process",
"command": "make",
"args": [
"clean_${cores}"
],
},
{
"label": "Flash Core ${cores}",
"type": "process",
"command": "make",
"args": [
"flash_${cores}"
],
"presentation": {
"reveal": "always"
},
"dependsOn": "Clean Core ${cores} & Build Core ${cores}"
},
{
"label": "Clean & Build Core ${cores}",
"dependsOrder": "sequence",
"dependsOn": ["Clean Core ${cores}", "Build Core ${cores}"]
},
EOM
)\\n
done
fi

INDENTED_MAKE_RULES=$(printf "$DEDICATED_MAKE_RULES" | sed 's/^/\t\t/')
COMMON_TASKS=$(cat << EOM
{
"version": "2.0.0",
"tasks": [
{
"label": "Clean Project",
"type": "process",
"command": "make",
"args": [
"clean"
],
"problemMatcher": []
},
{
"label": "Build Project",
"type": "process",
"command": "make",
"args": [
"all"
],
},
{
"label": "Flash Project",
"type": "process",
"command": "make",
"args": [
"flash"
],
"dependsOrder": "sequence",
"dependsOn": ["Clean Project", "Build Project"]
},
{
"label": "Build Test",
"type": "process",
"command": "make",
"args": [
"build_test"
],
},
{
"label": "Run Test",
"type": "process",
"command": "make",
"args": [
"run_test"
],
},
$INDENTED_MAKE_RULES
]
}

EOM
)


echo "${COMMON_TASKS}" > $PROJECT_NAME/.vscode/tasks.json
Loading