From eb966bd8d5eb381bf7209256745fd3100d083ac4 Mon Sep 17 00:00:00 2001 From: Ana Date: Sat, 22 Feb 2025 19:42:19 +0000 Subject: [PATCH] modificacion de los archivos de chasis .hpp y .cpp --- .clang-format | 20 +- .devcontainer/Dockerfile | 180 ++++++++--------- .devcontainer/devcontainer.json | 154 +++++++-------- .github/dependabot.yml | 24 +-- .gitignore | 68 +++---- .gitmodules | 24 +-- .vscode/c_cpp_properties.json | 194 +++++++++--------- .vscode/extensions.json | 56 +++--- .vscode/settings.json | 28 +-- .vscode/tasks.json | 64 +++--- Makefile | 336 ++++++++++++++++---------------- Middlewares/owlware | 2 +- README.md | 164 ++++++++-------- app/appCode.mk | 146 +++++++------- app/inc/FreeRTOSConfig.h | 274 +++++++++++++------------- app/inc/chasisMove.hpp | 56 ++++++ app/src/CanBusTask.c | 156 +++++++-------- app/src/chassisMove.cpp | 112 +++++++++++ robotConfig | 2 +- 19 files changed, 1114 insertions(+), 946 deletions(-) create mode 100644 app/inc/chasisMove.hpp create mode 100644 app/src/chassisMove.cpp diff --git a/.clang-format b/.clang-format index d026a06..623ab5e 100644 --- a/.clang-format +++ b/.clang-format @@ -1,11 +1,11 @@ -BasedOnStyle: Google -IndentWidth: 4 -ColumnLimit: 120 -AlignConsecutiveMacros: true -IndentPPDirectives: BeforeHash - ---- -Language: Cpp -# Force pointers to the type for C++. -DerivePointerAlignment: false +BasedOnStyle: Google +IndentWidth: 4 +ColumnLimit: 120 +AlignConsecutiveMacros: true +IndentPPDirectives: BeforeHash + +--- +Language: Cpp +# Force pointers to the type for C++. +DerivePointerAlignment: false PointerAlignment: Left \ No newline at end of file diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index dba2e4a..f633d16 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,90 +1,90 @@ -# syntax=docker/dockerfile:1.3-labs -# ===== ===== ===== ===== ===== ===== -# This image is for compiling STM32 HAL Projects -# My reference from: https://www.youtube.com/watch?v=imUiQkO9YHM -# Since this images uses heredocs, you need buildkit -# ===== ===== ===== ===== ===== ===== - -# ===== ===== Base image ===== ===== -FROM ubuntu:22.04 - -# ===== ===== Arguments ===== ===== -# Download GNU ARM -ARG compiler_dwn_link=https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz?rev=e434b9ea4afc4ed7998329566b764309&hash=CA590209F5774EE1C96E6450E14A3E26 -# Host project location -#ARG wDirHost - # You actually can't have a variable for the mounting point -# Tag versioning - # See https://docs.docker.com/reference/dockerfile/#arg -ARG FreeRTOS_tag -ARG STM32F1_tag -ARG STM32F3_tag -ARG STM32F4_tag -ARG STM32H7_tag -ARG USB_tag -ARG eigen_ver - -ENV FreeRTOS_tag=${FreeRTOS_tag:-v11.1.0} -ENV STM32F1_tag=${STM32F1_tag:-v1.8.5} -ENV STM32F3_tag=${STM32F3_tag:-v1.11.5} -ENV STM32F4_tag=${STM32F4_tag:-v1.28.0} -ENV STM32H7_tag=${STM32H7_tag:-v1.11.0} -ENV USB_tag=${USB_tag:-v2.11.0} -ENV eigen_ver=${eigen_ver:-3.4.0} - -# ===== ===== ===== ===== ===== ===== -# TODO: -# * Define version for cmake, make, compiler, repos -# * Extract libraries to somewhere -# ===== ===== Actual image ===== ===== -# ===== Update repos - # As a multi-line script -RUN apt update && \ - apt upgrade -y && \ - apt install -y cmake make xz-utils git clang-format && \ - mkdir -p /opt/gcc-arm-none-eabi/ /tmp/gcc-arm-none-eabi/ - - -# ===== Install compiler - -ADD "$compiler_dwn_link" /tmp/compiler.tar.xz - -RUN tar xf /tmp/compiler.tar.xz -C /tmp/gcc-arm-none-eabi/ && \ - mv /tmp/gcc-arm-none-eabi/arm-gnu-toolchain-*/* /opt/gcc-arm-none-eabi/ && \ - rm -rf /tmp/* - -# Symlink to /usr/local/bin - # TODO: Why? -RUN ln -s /opt/gcc-arm-none-eabi/bin/* /usr/local/bin - -# Add compiler to the path, note how we don't use export to set it globally -ENV PATH="$PATH:/opt/gcc-arm-none-eabi/bin" - -# ===== STM32 dependencies -WORKDIR /opt -# Download CMSIS V2 FreeRTOS - # I think this not entirely necessary -# Currently supported chips: - # Since these are the Firmware package, it includes HAL drivers and CMSIS MCU config - # STM32F4 processor series - # Release notes: https://htmlpreview.github.io/?https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Release_Notes.html - # STM32H7 processor series - # Release notes: https://htmlpreview.github.io/?https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Release_Notes.html - # STM32F1 processor series - # STM32F3 processor series -RUN git clone --depth 1 --branch $FreeRTOS_tag https://github.com/ARM-software/CMSIS-FreeRTOS.git && \ - git clone --recursive --depth 1 --branch $STM32F4_tag https://github.com/STMicroelectronics/STM32CubeF4.git && \ - git clone --recursive --depth 1 --branch $STM32H7_tag https://github.com/STMicroelectronics/STM32CubeH7.git && \ - git clone --recursive --depth 1 --branch $STM32F1_tag https://github.com/STMicroelectronics/STM32CubeF1.git && \ - git clone --recursive --depth 1 --branch $STM32F3_tag https://github.com/STMicroelectronics/STM32CubeF3.git && \ - git clone --depth 1 --branch $USB_tag https://github.com/STMicroelectronics/stm32_mw_usb_device.git && \ - git clone --branch $eigen_ver https://gitlab.com/libeigen/eigen.git - - -# ===== ===== Build Project ===== ===== - -# Change working dir to project location in container -WORKDIR /home/myProjects - -# Keep the container running -ENTRYPOINT [ "tail", "-f", "/dev/null" ] +# syntax=docker/dockerfile:1.3-labs +# ===== ===== ===== ===== ===== ===== +# This image is for compiling STM32 HAL Projects +# My reference from: https://www.youtube.com/watch?v=imUiQkO9YHM +# Since this images uses heredocs, you need buildkit +# ===== ===== ===== ===== ===== ===== + +# ===== ===== Base image ===== ===== +FROM ubuntu:22.04 + +# ===== ===== Arguments ===== ===== +# Download GNU ARM +ARG compiler_dwn_link=https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz?rev=e434b9ea4afc4ed7998329566b764309&hash=CA590209F5774EE1C96E6450E14A3E26 +# Host project location +#ARG wDirHost + # You actually can't have a variable for the mounting point +# Tag versioning + # See https://docs.docker.com/reference/dockerfile/#arg +ARG FreeRTOS_tag +ARG STM32F1_tag +ARG STM32F3_tag +ARG STM32F4_tag +ARG STM32H7_tag +ARG USB_tag +ARG eigen_ver + +ENV FreeRTOS_tag=${FreeRTOS_tag:-v11.1.0} +ENV STM32F1_tag=${STM32F1_tag:-v1.8.5} +ENV STM32F3_tag=${STM32F3_tag:-v1.11.5} +ENV STM32F4_tag=${STM32F4_tag:-v1.28.0} +ENV STM32H7_tag=${STM32H7_tag:-v1.11.0} +ENV USB_tag=${USB_tag:-v2.11.0} +ENV eigen_ver=${eigen_ver:-3.4.0} + +# ===== ===== ===== ===== ===== ===== +# TODO: +# * Define version for cmake, make, compiler, repos +# * Extract libraries to somewhere +# ===== ===== Actual image ===== ===== +# ===== Update repos + # As a multi-line script +RUN apt update && \ + apt upgrade -y && \ + apt install -y cmake make xz-utils git clang-format && \ + mkdir -p /opt/gcc-arm-none-eabi/ /tmp/gcc-arm-none-eabi/ + + +# ===== Install compiler + +ADD "$compiler_dwn_link" /tmp/compiler.tar.xz + +RUN tar xf /tmp/compiler.tar.xz -C /tmp/gcc-arm-none-eabi/ && \ + mv /tmp/gcc-arm-none-eabi/arm-gnu-toolchain-*/* /opt/gcc-arm-none-eabi/ && \ + rm -rf /tmp/* + +# Symlink to /usr/local/bin + # TODO: Why? +RUN ln -s /opt/gcc-arm-none-eabi/bin/* /usr/local/bin + +# Add compiler to the path, note how we don't use export to set it globally +ENV PATH="$PATH:/opt/gcc-arm-none-eabi/bin" + +# ===== STM32 dependencies +WORKDIR /opt +# Download CMSIS V2 FreeRTOS + # I think this not entirely necessary +# Currently supported chips: + # Since these are the Firmware package, it includes HAL drivers and CMSIS MCU config + # STM32F4 processor series + # Release notes: https://htmlpreview.github.io/?https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Release_Notes.html + # STM32H7 processor series + # Release notes: https://htmlpreview.github.io/?https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Release_Notes.html + # STM32F1 processor series + # STM32F3 processor series +RUN git clone --depth 1 --branch $FreeRTOS_tag https://github.com/ARM-software/CMSIS-FreeRTOS.git && \ + git clone --recursive --depth 1 --branch $STM32F4_tag https://github.com/STMicroelectronics/STM32CubeF4.git && \ + git clone --recursive --depth 1 --branch $STM32H7_tag https://github.com/STMicroelectronics/STM32CubeH7.git && \ + git clone --recursive --depth 1 --branch $STM32F1_tag https://github.com/STMicroelectronics/STM32CubeF1.git && \ + git clone --recursive --depth 1 --branch $STM32F3_tag https://github.com/STMicroelectronics/STM32CubeF3.git && \ + git clone --depth 1 --branch $USB_tag https://github.com/STMicroelectronics/stm32_mw_usb_device.git && \ + git clone --branch $eigen_ver https://gitlab.com/libeigen/eigen.git + + +# ===== ===== Build Project ===== ===== + +# Change working dir to project location in container +WORKDIR /home/myProjects + +# Keep the container running +ENTRYPOINT [ "tail", "-f", "/dev/null" ] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a3240ac..69fa49c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,78 +1,78 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu -{ - "name": "Ubuntu", - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "build": { - "dockerfile": "Dockerfile", - "args": { - "-t": "owltech/compiler" - } - }, - // Avoid git problems: - "postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}/robotConfig ${containerWorkspaceFolder}/Middlewares/owlware ${containerWorkspaceFolder}/Middlewares/ST/stm32_mw_usb_device", - // - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "uname -a", - // Configure tool-specific properties. - "customizations": { - "vscode": { - "settings": { - "terminal.integrated.shell.linux": "/bin/bash", - "C_Cpp.enhancedColorization": "enabled", - "cSpell.words": [ - "automations", - "Robomaster", - "Gobilda", - "Owltech" - ], - "editor.formatOnSave": true, - "editor.defaultFormatter": "ms-vscode.cpptools", - //"editor.defaultFormatter": "xaver.clang-format", - "clang-format.executable": "${workspaceRoot}/.clang-format", - "clang-format.formatOnSave": true, - "doxdocgen.c.firstLine": "/**", - "doxdocgen.c.commentPrefix": " * ", - "doxdocgen.c.lastLine": " **/", - "doxdocgen.cpp.tparamTemplate": "@tparam {param} ", - "doxdocgen.file.fileOrder": [ - "file", - "author", - "brief", - "date" - ], - "doxdocgen.generic.dateFormat": "YYYY-MM-DD", - "doxdocgen.generic.useGitUserName": true, - "doxdocgen.generic.useGitUserEmail": true, - "cmake.configureOnOpen": false, - "files.associations": { - "main.C": "cpp", - "cmath": "cpp", - "iostream": "cpp" - } - }, - "extensions": [ - // ===== C++ - "ms-vscode.cpptools", - "ms-vscode.cpptools-extension-pack", - // ===== Build - "ms-vscode.makefile-tools", - "ms-vscode.cmake-tools", - // ===== Code documentation - "cschlosser.doxdocgen", - // ===== Intelli - "visualstudioexptteam.vscodeintellicode", - "visualstudioexptteam.intellicode-api-usage-examples", - // ===== Other tools - "xaver.clang-format", - "streetsidesoftware.code-spell-checker" - ] - } - } - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu +{ + "name": "Ubuntu", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "build": { + "dockerfile": "Dockerfile", + "args": { + "-t": "owltech/compiler" + } + }, + // Avoid git problems: + "postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}/robotConfig ${containerWorkspaceFolder}/Middlewares/owlware ${containerWorkspaceFolder}/Middlewares/ST/stm32_mw_usb_device", + // + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "uname -a", + // Configure tool-specific properties. + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.shell.linux": "/bin/bash", + "C_Cpp.enhancedColorization": "enabled", + "cSpell.words": [ + "automations", + "Robomaster", + "Gobilda", + "Owltech" + ], + "editor.formatOnSave": true, + "editor.defaultFormatter": "ms-vscode.cpptools", + //"editor.defaultFormatter": "xaver.clang-format", + "clang-format.executable": "${workspaceRoot}/.clang-format", + "clang-format.formatOnSave": true, + "doxdocgen.c.firstLine": "/**", + "doxdocgen.c.commentPrefix": " * ", + "doxdocgen.c.lastLine": " **/", + "doxdocgen.cpp.tparamTemplate": "@tparam {param} ", + "doxdocgen.file.fileOrder": [ + "file", + "author", + "brief", + "date" + ], + "doxdocgen.generic.dateFormat": "YYYY-MM-DD", + "doxdocgen.generic.useGitUserName": true, + "doxdocgen.generic.useGitUserEmail": true, + "cmake.configureOnOpen": false, + "files.associations": { + "main.C": "cpp", + "cmath": "cpp", + "iostream": "cpp" + } + }, + "extensions": [ + // ===== C++ + "ms-vscode.cpptools", + "ms-vscode.cpptools-extension-pack", + // ===== Build + "ms-vscode.makefile-tools", + "ms-vscode.cmake-tools", + // ===== Code documentation + "cschlosser.doxdocgen", + // ===== Intelli + "visualstudioexptteam.vscodeintellicode", + "visualstudioexptteam.intellicode-api-usage-examples", + // ===== Other tools + "xaver.clang-format", + "streetsidesoftware.code-spell-checker" + ] + } + } + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" } \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f33a02c..20cb428 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,12 +1,12 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for more information: -# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates -# https://containers.dev/guide/dependabot - -version: 2 -updates: - - package-ecosystem: "devcontainers" - directory: "/" - schedule: - interval: weekly +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for more information: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://containers.dev/guide/dependabot + +version: 2 +updates: + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: weekly diff --git a/.gitignore b/.gitignore index 1a5143e..43c1461 100644 --- a/.gitignore +++ b/.gitignore @@ -1,34 +1,34 @@ -# Ignore build dir -build -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app +# Ignore build dir +build +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/.gitmodules b/.gitmodules index a4e70b7..266755d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,12 @@ -[submodule "Middlewares/ST/stm32_mw_usb_device"] - path = Middlewares/ST/stm32_mw_usb_device - url = git@github.com:STMicroelectronics/stm32_mw_usb_device.git - -[submodule "Middlewares/owlware"] - path = Middlewares/owlware - url = git@github.com:RobomasterOwltech/owlware.git - -[submodule "robotConfig"] - path = robotConfig - url = git@github.com:RobomasterOwltech/robotConfig.git - branch = STM32VLDISCOVERY +[submodule "Middlewares/ST/stm32_mw_usb_device"] + path = Middlewares/ST/stm32_mw_usb_device + url = git@github.com:STMicroelectronics/stm32_mw_usb_device.git + +[submodule "Middlewares/owlware"] + path = Middlewares/owlware + url = git@github.com:RobomasterOwltech/owlware.git + +[submodule "robotConfig"] + path = robotConfig + url = git@github.com:RobomasterOwltech/robotConfig.git + branch = STM32VLDISCOVERY diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 529ddc3..10d7a7c 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,98 +1,98 @@ -{ - "env": { - "owlPath": [ - "${workspaceFolder}/app/inc", - "${workspaceFolder}/robotConfig/inc", - "/opt/eigen/Eigen", - // STM32CubeF1 - "/opt/STM32CubeF1/Drivers/STM32F1xx_HAL_Driver/Inc/", - "/opt/STM32CubeF1/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy", - "/opt/STM32CubeF1/Drivers/CMSIS/Include/", - "/opt/STM32CubeF1/Drivers/CMSIS/Core/Include/", - "/opt/STM32CubeF1/Drivers/CMSIS/Device/ST/STM32F1xx/Include", - // THE F1 board doesn't have enough space for an rtos :( - // STM32CubeF3 - "/opt/STM32CubeF3/Drivers/STM32F3xx_HAL_Driver/Inc", - "/opt/STM32CubeF3/Drivers/STM32F3xx_HAL_Driver/Inc/Legacy", - "/opt/STM32CubeF3/Drivers/CMSIS/Core/Include/", - "/opt/STM32CubeF3/Drivers/CMSIS/Include/", - "/opt/STM32CubeF3/Drivers/CMSIS/Device/ST/STM32F3xx/Include", - "/opt/STM32CubeF3/Middlewares/Third_Party/FreeRTOS/Source/include", - "/opt/STM32CubeF3/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS", - "/opt/STM32CubeF3/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F", - "/opt/STM32CubeF3/Middlewares/Third_Party/FreeRTOS/Source/portable/Common", - "/opt/STM32CubeF3/Middlewares/Third_Party/FreeRTOS/Source/portable/Tasking", - "/opt/STM32CubeF3/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang", - // STM32CubeF4 - "/opt/STM32CubeF4/Drivers/STM32F4xx_HAL_Driver/Inc/", - "/opt/STM32CubeF4/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy", - "/opt/STM32CubeF4/Drivers/CMSIS/Core/Include/", - "/opt/STM32CubeF4/Drivers/CMSIS/Include/", - "/opt/STM32CubeF4/Drivers/CMSIS/Device/ST/STM32F4xx/Include", - "/opt/STM32CubeF4/Middlewares/Third_Party/FreeRTOS/Source/include", - "/opt/STM32CubeF4/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS", - "/opt/STM32CubeF4/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F", - // STM32CubeH7 - "/opt/STM32CubeH7/Drivers/STM32H7xx_HAL_Driver/Inc/", - "/opt/STM32CubeH7/Drivers/STM32H7xx_HAL_Driver/Inc/Legacy", - "/opt/STM32CubeH7/Drivers/CMSIS/Core/Include/", - "/opt/STM32CubeH7/Drivers/CMSIS/Include/", - "/opt/STM32CubeH7/Drivers/CMSIS/Device/ST/STM32H7xx/Include", - "/opt/STM32CubeH7/Middlewares/Third_Party/FreeRTOS/Source/include", - "/opt/STM32CubeH7/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS", - // TODO: CHECK WHICH IS THE CORRECT ONE - "/opt/STM32CubeH7/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F", - // USB Config - "${workspaceFolder}/Middlewares/ST/stm32_mw_usb_device/Class/CDC/Inc", - "${workspaceFolder}/Middlewares/ST/stm32_mw_usb_device/Core/Inc" - ], - "owlDefines": [ - "USE_HAL_DRIVER", - //"STM32F407xx" - //"STM32F100xB" - "STM32F303xE" - ] - }, - "configurations": [ - { - "name": "Mac", - "includePath": [ - "${owlPath}", - "${workspaceRoot}" - ], - "defines": [ - "${owlDefines}" - ], - "macFrameworkPath": [ - "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" - ], - "compilerPath": "/Applications/ARM/bin/arm-none-eabi-gcc", - "intelliSenseMode": "gcc-arm", - "cStandard": "c99", - "cppStandard": "c++17" - }, - { - "name": "Linux", - "includePath": [ - "${owlPath}", - "${workspaceRoot}", - "/opt/gcc-arm-none-eabi/arm-none-eabi/include", - "/opt/gcc-arm-none-eabi/lib/gcc/arm-none-eabi/13.2.1/include", - "/opt/gcc-arm-none-eabi/lib/gcc/arm-none-eabi/13.2.1/include-fixed", - "/opt/gcc-arm-none-eabi/arm-none-eabi/include/c++/13.2.1", - "/opt/gcc-arm-none-eabi/arm-none-eabi/include/machine", - "/opt/gcc-arm-none-eabi/arm-none-eabi/include/newlib-nano", - "/opt/gcc-arm-none-eabi/arm-none-eabi/include/sys" - ], - "defines": [ - "${owlDefines}" - ], - "compilerPath": "/usr/local/bin/arm-none-eabi-g++", - "intelliSenseMode": "gcc-arm", - "cStandard": "c99", - "cppStandard": "c++17" - } - ], - "version": 4, - "enableConfigurationSquiggles": true +{ + "env": { + "owlPath": [ + "${workspaceFolder}/app/inc", + "${workspaceFolder}/robotConfig/inc", + "/opt/eigen/Eigen", + // STM32CubeF1 + "/opt/STM32CubeF1/Drivers/STM32F1xx_HAL_Driver/Inc/", + "/opt/STM32CubeF1/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy", + "/opt/STM32CubeF1/Drivers/CMSIS/Include/", + "/opt/STM32CubeF1/Drivers/CMSIS/Core/Include/", + "/opt/STM32CubeF1/Drivers/CMSIS/Device/ST/STM32F1xx/Include", + // THE F1 board doesn't have enough space for an rtos :( + // STM32CubeF3 + "/opt/STM32CubeF3/Drivers/STM32F3xx_HAL_Driver/Inc", + "/opt/STM32CubeF3/Drivers/STM32F3xx_HAL_Driver/Inc/Legacy", + "/opt/STM32CubeF3/Drivers/CMSIS/Core/Include/", + "/opt/STM32CubeF3/Drivers/CMSIS/Include/", + "/opt/STM32CubeF3/Drivers/CMSIS/Device/ST/STM32F3xx/Include", + "/opt/STM32CubeF3/Middlewares/Third_Party/FreeRTOS/Source/include", + "/opt/STM32CubeF3/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS", + "/opt/STM32CubeF3/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F", + "/opt/STM32CubeF3/Middlewares/Third_Party/FreeRTOS/Source/portable/Common", + "/opt/STM32CubeF3/Middlewares/Third_Party/FreeRTOS/Source/portable/Tasking", + "/opt/STM32CubeF3/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang", + // STM32CubeF4 + "/opt/STM32CubeF4/Drivers/STM32F4xx_HAL_Driver/Inc/", + "/opt/STM32CubeF4/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy", + "/opt/STM32CubeF4/Drivers/CMSIS/Core/Include/", + "/opt/STM32CubeF4/Drivers/CMSIS/Include/", + "/opt/STM32CubeF4/Drivers/CMSIS/Device/ST/STM32F4xx/Include", + "/opt/STM32CubeF4/Middlewares/Third_Party/FreeRTOS/Source/include", + "/opt/STM32CubeF4/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS", + "/opt/STM32CubeF4/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F", + // STM32CubeH7 + "/opt/STM32CubeH7/Drivers/STM32H7xx_HAL_Driver/Inc/", + "/opt/STM32CubeH7/Drivers/STM32H7xx_HAL_Driver/Inc/Legacy", + "/opt/STM32CubeH7/Drivers/CMSIS/Core/Include/", + "/opt/STM32CubeH7/Drivers/CMSIS/Include/", + "/opt/STM32CubeH7/Drivers/CMSIS/Device/ST/STM32H7xx/Include", + "/opt/STM32CubeH7/Middlewares/Third_Party/FreeRTOS/Source/include", + "/opt/STM32CubeH7/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS", + // TODO: CHECK WHICH IS THE CORRECT ONE + "/opt/STM32CubeH7/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F", + // USB Config + "${workspaceFolder}/Middlewares/ST/stm32_mw_usb_device/Class/CDC/Inc", + "${workspaceFolder}/Middlewares/ST/stm32_mw_usb_device/Core/Inc" + ], + "owlDefines": [ + "USE_HAL_DRIVER", + //"STM32F407xx" + //"STM32F100xB" + "STM32F303xE" + ] + }, + "configurations": [ + { + "name": "Mac", + "includePath": [ + "${owlPath}", + "${workspaceRoot}" + ], + "defines": [ + "${owlDefines}" + ], + "macFrameworkPath": [ + "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" + ], + "compilerPath": "/Applications/ARM/bin/arm-none-eabi-gcc", + "intelliSenseMode": "gcc-arm", + "cStandard": "c99", + "cppStandard": "c++17" + }, + { + "name": "Linux", + "includePath": [ + "${owlPath}", + "${workspaceRoot}", + "/opt/gcc-arm-none-eabi/arm-none-eabi/include", + "/opt/gcc-arm-none-eabi/lib/gcc/arm-none-eabi/13.2.1/include", + "/opt/gcc-arm-none-eabi/lib/gcc/arm-none-eabi/13.2.1/include-fixed", + "/opt/gcc-arm-none-eabi/arm-none-eabi/include/c++/13.2.1", + "/opt/gcc-arm-none-eabi/arm-none-eabi/include/machine", + "/opt/gcc-arm-none-eabi/arm-none-eabi/include/newlib-nano", + "/opt/gcc-arm-none-eabi/arm-none-eabi/include/sys" + ], + "defines": [ + "${owlDefines}" + ], + "compilerPath": "/usr/local/bin/arm-none-eabi-g++", + "intelliSenseMode": "gcc-arm", + "cStandard": "c99", + "cppStandard": "c++17" + } + ], + "version": 4, + "enableConfigurationSquiggles": true } \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 6a05fba..8ddebb3 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,29 +1,29 @@ -{ - "recommendations": [ - // ===== Containers - "ms-vscode-remote.remote-containers", - // ===== Code documentation - "cschlosser.doxdocgen", - // ===== Intelli - "visualstudioexptteam.vscodeintellicode", - "visualstudioexptteam.intellicode-api-usage-examples", - // ===== Other tools - "ms-vscode.vscode-serial-monitor", - "tomoki1207.pdf", - "streetsidesoftware.code-spell-checker", - // ===== C++ - "ms-vscode.cpptools", - "ms-vscode.cpptools-extension-pack", - // ===== Build - "ms-vscode.makefile-tools", - "ms-vscode.cmake-tools", - // ===== Code documentation - "cschlosser.doxdocgen", - // ===== Intelli - "visualstudioexptteam.vscodeintellicode", - "visualstudioexptteam.intellicode-api-usage-examples", - // ===== Other tools - "xaver.clang-format", - "streetsidesoftware.code-spell-checker" - ] +{ + "recommendations": [ + // ===== Containers + "ms-vscode-remote.remote-containers", + // ===== Code documentation + "cschlosser.doxdocgen", + // ===== Intelli + "visualstudioexptteam.vscodeintellicode", + "visualstudioexptteam.intellicode-api-usage-examples", + // ===== Other tools + "ms-vscode.vscode-serial-monitor", + "tomoki1207.pdf", + "streetsidesoftware.code-spell-checker", + // ===== C++ + "ms-vscode.cpptools", + "ms-vscode.cpptools-extension-pack", + // ===== Build + "ms-vscode.makefile-tools", + "ms-vscode.cmake-tools", + // ===== Code documentation + "cschlosser.doxdocgen", + // ===== Intelli + "visualstudioexptteam.vscodeintellicode", + "visualstudioexptteam.intellicode-api-usage-examples", + // ===== Other tools + "xaver.clang-format", + "streetsidesoftware.code-spell-checker" + ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index f3ac2bf..53895e6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,15 +1,15 @@ -{ - "files.associations": { - "main.C": "cpp", - "cmath": "cpp", - "iostream": "cpp", - "stm32f3xx_hal.h": "c", - "stm32f3xx_hal_conf.h": "c", - "stm32f3xx_hal_rcc.h": "c", - "stm32f3xx_hal_def.h": "c", - "stm32_hal_legacy.h": "c", - "stm32f3xx.h": "c", - "stm32f303xe.h": "c", - "robotpins.h": "c" - } +{ + "files.associations": { + "main.C": "cpp", + "cmath": "cpp", + "iostream": "cpp", + "stm32f3xx_hal.h": "c", + "stm32f3xx_hal_conf.h": "c", + "stm32f3xx_hal_rcc.h": "c", + "stm32f3xx_hal_def.h": "c", + "stm32_hal_legacy.h": "c", + "stm32f3xx.h": "c", + "stm32f303xe.h": "c", + "robotpins.h": "c" + } } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index a3ef604..47cdb90 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,33 +1,33 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - // ===== Upload to DevBoard ===== - // sudo st-flash write Debug/STM32VLDISCOVERY.bin 0x08000000 - { - "label": "Upload code!", - "type": "shell", - "command": "sudo", - "args": [ - "st-flash", - "write", - "${input:path2Bin}", - "0x08000000" - ], - "group": "build", - "presentation": { - "reveal": "always", - "panel": "new" - } - } - ], - "inputs": [ - { - "id": "path2Bin", - "description": "Path to the binary file generated after build", - "default": "build/owltech.bin", - "type": "promptString" - } - ] +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + // ===== Upload to DevBoard ===== + // sudo st-flash write Debug/STM32VLDISCOVERY.bin 0x08000000 + { + "label": "Upload code!", + "type": "shell", + "command": "sudo", + "args": [ + "st-flash", + "write", + "${input:path2Bin}", + "0x08000000" + ], + "group": "build", + "presentation": { + "reveal": "always", + "panel": "new" + } + } + ], + "inputs": [ + { + "id": "path2Bin", + "description": "Path to the binary file generated after build", + "default": "build/owltech.bin", + "type": "promptString" + } + ] } \ No newline at end of file diff --git a/Makefile b/Makefile index d186cf0..35ff27b 100644 --- a/Makefile +++ b/Makefile @@ -1,169 +1,169 @@ -########################################################################################################################## -# Makfile to compile an Owltech project -# For more on this topic, see: -# https://metebalci.com/blog/demystifying-arm-gnu-toolchain-specs-nano-and-nosys/ -########################################################################################################################## - -###################################### -# target -###################################### -TARGET = owltech - -####################################### -# 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. -# -x assembler-with-cpp -> Indicates that the project includes C/C++ giles -# also, enables our assembler to understand preprocesor tags -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 - -###################################### -# building variables -###################################### -# debug build? -DEBUG = 1 -# optimization -OPT = -Og -# C defines -C_DEFS = \ --DUSE_HAL_DRIVER - -####################################### -# paths -####################################### -# Build path -BUILD_DIR = build - -###################################### -# source -###################################### -# C sources -C_SOURCES = - -# C includes -C_INCLUDES = - -# ASM sources -ASMM_SOURCES = - -# macros for gcc -# AS defines -AS_DEFS = - -# AS includes -## TODO: Leave? or remove -# Seems to be good without it -AS_INCLUDES = #\ --IrobotConfig/inc - -# NOTE: You need to define that you are using RTOS -USE_FREERTOS = 1 - -# Import proyect dependencies -include robotConfig/robotConfig.mk -# Import proyect dependencies -include app/appCode.mk - -# TODO: SHOULD WE SELECT -std=gnu11?? -# compile gcc flags -# -Wall -> all warnings -# -fdata-sections -> Place each function or data item into its own section in the output file -# -ffunction-sections -> Optimization - -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)" - -####################################### -# LDFLAGS -####################################### - -# libraries -# -lc Link the standard C library -# -lm Link the math library -# -lnosys This flag tells the linker to not to use any system-specific libraries or startup code -# -lstdc++ \ -# -libstdc++ \ -# -libm -# --gc-sections -static -# --start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group -LIBS = -lc -lm -lstdc++ -lsupc++ -LIBDIR = -LDFLAGS = $(MCU) --specs=nosys.specs --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))) -OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASMM_SOURCES:.S=.o))) -vpath %.S $(sort $(dir $(ASMM_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)/%.o: %.S Makefile | $(BUILD_DIR) - $(AS) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile - $(CC) $(OBJECTS) $(LDFLAGS) -o $@ - $(SZ) $@ -# Make .hex files from all .elf files in the build dir -$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) - $(HEX) $< $@ - -# Make .bin files from all .elf files in the build dir -$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) - $(BIN) $< $@ - -# Create build dir -$(BUILD_DIR): - mkdir $@ - -####################################### -# clean up -####################################### -clean: - -rm -fR $(BUILD_DIR) - -####################################### -# dependencies -####################################### --include $(wildcard $(BUILD_DIR)/*.d) - +########################################################################################################################## +# Makfile to compile an Owltech project +# For more on this topic, see: +# https://metebalci.com/blog/demystifying-arm-gnu-toolchain-specs-nano-and-nosys/ +########################################################################################################################## + +###################################### +# target +###################################### +TARGET = owltech + +####################################### +# 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. +# -x assembler-with-cpp -> Indicates that the project includes C/C++ giles +# also, enables our assembler to understand preprocesor tags +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 + +###################################### +# building variables +###################################### +# debug build? +DEBUG = 1 +# optimization +OPT = -Og +# C defines +C_DEFS = \ +-DUSE_HAL_DRIVER + +####################################### +# paths +####################################### +# Build path +BUILD_DIR = build + +###################################### +# source +###################################### +# C sources +C_SOURCES = + +# C includes +C_INCLUDES = + +# ASM sources +ASMM_SOURCES = + +# macros for gcc +# AS defines +AS_DEFS = + +# AS includes +## TODO: Leave? or remove +# Seems to be good without it +AS_INCLUDES = #\ +-IrobotConfig/inc + +# NOTE: You need to define that you are using RTOS +USE_FREERTOS = 1 + +# Import proyect dependencies +include robotConfig/robotConfig.mk +# Import proyect dependencies +include app/appCode.mk + +# TODO: SHOULD WE SELECT -std=gnu11?? +# compile gcc flags +# -Wall -> all warnings +# -fdata-sections -> Place each function or data item into its own section in the output file +# -ffunction-sections -> Optimization + +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)" + +####################################### +# LDFLAGS +####################################### + +# libraries +# -lc Link the standard C library +# -lm Link the math library +# -lnosys This flag tells the linker to not to use any system-specific libraries or startup code +# -lstdc++ \ +# -libstdc++ \ +# -libm +# --gc-sections -static +# --start-group -lc -lm -lstdc++ -lsupc++ -Wl,--end-group +LIBS = -lc -lm -lstdc++ -lsupc++ +LIBDIR = +LDFLAGS = $(MCU) --specs=nosys.specs --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))) +OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASMM_SOURCES:.S=.o))) +vpath %.S $(sort $(dir $(ASMM_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)/%.o: %.S Makefile | $(BUILD_DIR) + $(AS) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile + $(CC) $(OBJECTS) $(LDFLAGS) -o $@ + $(SZ) $@ +# Make .hex files from all .elf files in the build dir +$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(HEX) $< $@ + +# Make .bin files from all .elf files in the build dir +$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(BIN) $< $@ + +# Create build dir +$(BUILD_DIR): + mkdir $@ + +####################################### +# clean up +####################################### +clean: + -rm -fR $(BUILD_DIR) + +####################################### +# dependencies +####################################### +-include $(wildcard $(BUILD_DIR)/*.d) + # *** EOF *** \ No newline at end of file diff --git a/Middlewares/owlware b/Middlewares/owlware index e5a6928..c332cc5 160000 --- a/Middlewares/owlware +++ b/Middlewares/owlware @@ -1 +1 @@ -Subproject commit e5a69282aba578d68f7fb33fe6973eef60d6f9e8 +Subproject commit c332cc5dc1df91a9787e2e7acb2663e700d52053 diff --git a/README.md b/README.md index 510674f..0f042b8 100644 --- a/README.md +++ b/README.md @@ -1,82 +1,82 @@ -# AppCodeTemp -Template to create FreeRTOS tasks using the team's middleware - -------------------------------------------------------------------- - -## How to use this repo: - -1. Clone it `git clone git@github.com:RobomasterOwltech/AppCodeTemp.git` -2. Go into the newly generated directory `cd AppCodeTemp` -1. Download the submodules `git submodule init && git submodule update` -1. In case any of the dependencies needs to be updated, simply do: `git submodule update --remote` - -## Having problems with git?: - -* Make sure that `postStartCommand` value is set at the `.devcontainer/devcontainer.json`. -* Make sure to have created and register ssh keys for Github, as done in [DeployTools](https://github.com/RobomasterOwltech/deployTools) - -## How to change DevBoard - -1. At the moment you clone the repo, modify the branch for the `robotConfig` repo. - 1. This will Change the defines on the `Makefile` -1. Change the OwlDefines variables at `.vscode/c_cpp_properties.json` - -## Create the container - -1. Download docker: - - For Linux: https://docs.docker.com/engine/install/ - - For Windows: https://docs.docker.com/desktop/setup/install/windows-install/ - - For MacOS: https://docs.docker.com/desktop/setup/install/mac-install/ -2. From the project root folder (AppCodeTemp) go to ".devcontainer": `cd .devcontainer` -3. Build the image: `docker build .` -4. List the images: `docker images` - - Identify the ID of the image just built -5. Go to the project root folder (AppCodeTemp): `cd ..` -6. Run the container in detach mode: `docker run -d --mount type=bind,source=$(realpath ./),target=/home/myProjects ` # Source is the absoluthe path to AppCodeTemp - -> All compilation steps need to be done form inside the container. To enter it: -> 1. List containers: `docker ps` -> - Identify the ID of the container -> 2. Enter the container: `docker exec -it bash` - -## Compile: - -1. From the project root folder (AppCodeTemp) call make - - make all - 1. You might need to specify the compiler path, in which case use: - - make GCC_PATH=/path/2/compiler - - 1. Alternatively, you can add it to your path, or set it as an environment variable. -1. If your build failed, then you can clean the `build` folder - - make clean -1. If you are encountering problems, and would like to know what is being configured by the makefiles from other projects, try: - - make showRobotConfig showRtosConfig - -### Add a file to be compiled - -1. Save your changes to the file. -1. Copy it's relative path. -1. If it is a C, add it in the `C_SOURCES` variable from the `Makefile` -1. In case your file is referencing any library, make sure it is present in the `C_INCLUDES` - -arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32F407xx -IrobotConfig/inc -Ieigen/Eigen -IDrivers/STM32F4xx_HAL_Driver/Inc -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32F4xx/Include -IDrivers/CMSIS/Include -IMiddlewares/Third_Party/FreeRTOS/Source/include -IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -IMiddlewares/ST/stm32_mw_usb_device/Class/CDC/Inc -IMiddlewares/ST/stm32_mw_usb_device/Core/Inc -IowltechMiddleware/inc -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/main.d" -Wa,-a,-ad,-alms=build/main.lst robotConfig/src/main.cpp -o build/main.o - -## NOTES: - -### C/C++ standard -If you were to change the C/C++ standard used, remember to change it in the `IntelliSense`, `makefile`, and `c_cpp_properties.json` - -For more [formatting options](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) see the link. - -## Resources - -If you would like to learn more about the used tools and information, then check: - -* [Quick intro to Makefiles](https://www.youtube.com/watch?v=aw9wHbFTnAQ) (Video) -* [GNU Make manual](https://www.gnu.org/savannah-checkouts/gnu/make/manual/make.html#Reading) -* The GNU Make [Book](https://learning.oreilly.com/library/view/the-gnu-make/9781457189883/). John Graham-Cumming. No Starch Press -* [Example on using Eigen](https://youtu.be/RgKreY1HK_8?si=aPSwUOyWYGdj3Nyl&t=284) +# AppCodeTemp +Template to create FreeRTOS tasks using the team's middleware + +------------------------------------------------------------------- + +## How to use this repo: + +1. Clone it `git clone git@github.com:RobomasterOwltech/AppCodeTemp.git` +2. Go into the newly generated directory `cd AppCodeTemp` +1. Download the submodules `git submodule init && git submodule update` +1. In case any of the dependencies needs to be updated, simply do: `git submodule update --remote` + +## Having problems with git?: + +* Make sure that `postStartCommand` value is set at the `.devcontainer/devcontainer.json`. +* Make sure to have created and register ssh keys for Github, as done in [DeployTools](https://github.com/RobomasterOwltech/deployTools) + +## How to change DevBoard + +1. At the moment you clone the repo, modify the branch for the `robotConfig` repo. + 1. This will Change the defines on the `Makefile` +1. Change the OwlDefines variables at `.vscode/c_cpp_properties.json` + +## Create the container + +1. Download docker: + - For Linux: https://docs.docker.com/engine/install/ + - For Windows: https://docs.docker.com/desktop/setup/install/windows-install/ + - For MacOS: https://docs.docker.com/desktop/setup/install/mac-install/ +2. From the project root folder (AppCodeTemp) go to ".devcontainer": `cd .devcontainer` +3. Build the image: `docker build .` +4. List the images: `docker images` + - Identify the ID of the image just built +5. Go to the project root folder (AppCodeTemp): `cd ..` +6. Run the container in detach mode: `docker run -d --mount type=bind,source=$(realpath ./),target=/home/myProjects ` # Source is the absoluthe path to AppCodeTemp + +> All compilation steps need to be done form inside the container. To enter it: +> 1. List containers: `docker ps` +> - Identify the ID of the container +> 2. Enter the container: `docker exec -it bash` + +## Compile: + +1. From the project root folder (AppCodeTemp) call make + + make all + 1. You might need to specify the compiler path, in which case use: + + make GCC_PATH=/path/2/compiler + + 1. Alternatively, you can add it to your path, or set it as an environment variable. +1. If your build failed, then you can clean the `build` folder + + make clean +1. If you are encountering problems, and would like to know what is being configured by the makefiles from other projects, try: + + make showRobotConfig showRtosConfig + +### Add a file to be compiled + +1. Save your changes to the file. +1. Copy it's relative path. +1. If it is a C, add it in the `C_SOURCES` variable from the `Makefile` +1. In case your file is referencing any library, make sure it is present in the `C_INCLUDES` + +arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32F407xx -IrobotConfig/inc -Ieigen/Eigen -IDrivers/STM32F4xx_HAL_Driver/Inc -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32F4xx/Include -IDrivers/CMSIS/Include -IMiddlewares/Third_Party/FreeRTOS/Source/include -IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -IMiddlewares/ST/stm32_mw_usb_device/Class/CDC/Inc -IMiddlewares/ST/stm32_mw_usb_device/Core/Inc -IowltechMiddleware/inc -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/main.d" -Wa,-a,-ad,-alms=build/main.lst robotConfig/src/main.cpp -o build/main.o + +## NOTES: + +### C/C++ standard +If you were to change the C/C++ standard used, remember to change it in the `IntelliSense`, `makefile`, and `c_cpp_properties.json` + +For more [formatting options](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) see the link. + +## Resources + +If you would like to learn more about the used tools and information, then check: + +* [Quick intro to Makefiles](https://www.youtube.com/watch?v=aw9wHbFTnAQ) (Video) +* [GNU Make manual](https://www.gnu.org/savannah-checkouts/gnu/make/manual/make.html#Reading) +* The GNU Make [Book](https://learning.oreilly.com/library/view/the-gnu-make/9781457189883/). John Graham-Cumming. No Starch Press +* [Example on using Eigen](https://youtu.be/RgKreY1HK_8?si=aPSwUOyWYGdj3Nyl&t=284) diff --git a/app/appCode.mk b/app/appCode.mk index fe98185..ea58d30 100644 --- a/app/appCode.mk +++ b/app/appCode.mk @@ -1,73 +1,73 @@ -# This file contains compilation instructions of the application and FreeRTOS. -# THIS IS NOT A STANDALONE MAKE FILE. -# ========================================== -# Possible improvements: -# * Make for an easy way to change the heap type -# Check for variable in FreeRTOSConfig.h -# #define USE_FreeRTOS_HEAP_4 -# * Set a variable for when the processor has a Memory Protected Unit -# ========================================== -# Made by Jorge Pérez 4 Owltech <3 - -# I knew what to put in here from the folowing sources: -# https://www.freertos.org/Documentation/01-FreeRTOS-quick-start/01-Beginners-guide/03-Build-your-first-project -## Only 3 source files that are common to all RTOS ports, -## and one microcontroller specific source file are required, -## and its API is designed to be simple and intuitive. -# Required Source files -# * FreeRTOS/Source/tasks.c -# * FreeRTOS/Source/queue.c -# * FreeRTOS/Source/list.c -# * FreeRTOS/Source/portable/[compiler]/[architecture]/port.c. -# * FreeRTOS/Source/portable/MemMang/heap_x.c where 'x' is 1, 2, 3, 4 or 5. -# Required Header files -# * FreeRTOS/Source/include -# * FreeRTOS/Source/portable/[compiler]/[architecture]. -# * Whichever directory contains the FreeRTOSConfig.h file to be used - see the Configuration File paragraph below. -# * Depending on the port, it may also be necessary for the same directories to be in the assembler's include path. - -####################################### -# Includes -####################################### - -# Include app definitions -C_INCLUDES += -Iapp/inc - -# Includes needed for FreeRTOS, if enabled -FreeRTOS_INCLUDES = \ - -I$(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/include \ - -I$(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS \ - -I$(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/$(ARCH_ARM) \ - -# Add FreeRTOS includes to whole compilation -ifeq ($(USE_FREERTOS), 1) - C_INCLUDES += $(FreeRTOS_INCLUDES) -endif - -####################################### -# Sources -####################################### -# Include app source code -C_SOURCES += $(shell find app/src/*.c) - -FreeRTOS_SOURCES = $(shell find $(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/ -maxdepth 1 -name *.c) -FreeRTOS_SOURCES += $(shell find $(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/ -name *.c) -FreeRTOS_SOURCES += $(shell find $(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c) -FreeRTOS_SOURCES += $(shell find $(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/$(ARCH_ARM)/ -name *.c) -# FreeRTOS_SOURCES += $(shell find $(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3_MPU/ -name *.c) - -# Add FreeRTOS sources, if enabled -ifeq ($(USE_FREERTOS), 1) - C_SOURCES += $(FreeRTOS_SOURCES) -endif - - -showRtosConfig: - $(info ===== ===== ===== ===== ===== ===== =====) - $(info Based on your current flags, the config is:) - $(info ===== ===== ===== ===== ===== ===== =====) - $(info Source files:) - $(info $(FreeRTOS_SOURCES)) - $(info ===== =====) - $(info Include paths:) - $(info $(FreeRTOS_INCLUDES)) +# This file contains compilation instructions of the application and FreeRTOS. +# THIS IS NOT A STANDALONE MAKE FILE. +# ========================================== +# Possible improvements: +# * Make for an easy way to change the heap type +# Check for variable in FreeRTOSConfig.h +# #define USE_FreeRTOS_HEAP_4 +# * Set a variable for when the processor has a Memory Protected Unit +# ========================================== +# Made by Jorge Pérez 4 Owltech <3 + +# I knew what to put in here from the folowing sources: +# https://www.freertos.org/Documentation/01-FreeRTOS-quick-start/01-Beginners-guide/03-Build-your-first-project +## Only 3 source files that are common to all RTOS ports, +## and one microcontroller specific source file are required, +## and its API is designed to be simple and intuitive. +# Required Source files +# * FreeRTOS/Source/tasks.c +# * FreeRTOS/Source/queue.c +# * FreeRTOS/Source/list.c +# * FreeRTOS/Source/portable/[compiler]/[architecture]/port.c. +# * FreeRTOS/Source/portable/MemMang/heap_x.c where 'x' is 1, 2, 3, 4 or 5. +# Required Header files +# * FreeRTOS/Source/include +# * FreeRTOS/Source/portable/[compiler]/[architecture]. +# * Whichever directory contains the FreeRTOSConfig.h file to be used - see the Configuration File paragraph below. +# * Depending on the port, it may also be necessary for the same directories to be in the assembler's include path. + +####################################### +# Includes +####################################### + +# Include app definitions +C_INCLUDES += -Iapp/inc + +# Includes needed for FreeRTOS, if enabled +FreeRTOS_INCLUDES = \ + -I$(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/include \ + -I$(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS \ + -I$(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/$(ARCH_ARM) \ + +# Add FreeRTOS includes to whole compilation +ifeq ($(USE_FREERTOS), 1) + C_INCLUDES += $(FreeRTOS_INCLUDES) +endif + +####################################### +# Sources +####################################### +# Include app source code +C_SOURCES += $(shell find app/src/*.c) + +FreeRTOS_SOURCES = $(shell find $(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/ -maxdepth 1 -name *.c) +FreeRTOS_SOURCES += $(shell find $(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/ -name *.c) +FreeRTOS_SOURCES += $(shell find $(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c) +FreeRTOS_SOURCES += $(shell find $(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/$(ARCH_ARM)/ -name *.c) +# FreeRTOS_SOURCES += $(shell find $(FirmwarePath)/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3_MPU/ -name *.c) + +# Add FreeRTOS sources, if enabled +ifeq ($(USE_FREERTOS), 1) + C_SOURCES += $(FreeRTOS_SOURCES) +endif + + +showRtosConfig: + $(info ===== ===== ===== ===== ===== ===== =====) + $(info Based on your current flags, the config is:) + $(info ===== ===== ===== ===== ===== ===== =====) + $(info Source files:) + $(info $(FreeRTOS_SOURCES)) + $(info ===== =====) + $(info Include paths:) + $(info $(FreeRTOS_INCLUDES)) diff --git a/app/inc/FreeRTOSConfig.h b/app/inc/FreeRTOSConfig.h index c9a5252..28e5e2b 100644 --- a/app/inc/FreeRTOSConfig.h +++ b/app/inc/FreeRTOSConfig.h @@ -1,137 +1,137 @@ -/* - * FreeRTOS Kernel V10.0.1 - * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://www.FreeRTOS.org - * http://aws.amazon.com/freertos - * - * 1 tab == 4 spaces! - */ -#ifndef FREERTOS_CONFIG_H -#define FREERTOS_CONFIG_H - -/*----------------------------------------------------------- - * Application specific definitions. - * - * These definitions should be adjusted for your particular hardware and - * application requirements. - * - * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE - * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. - * - * See http://www.freertos.org/a00110.html. - *----------------------------------------------------------*/ - -/* Ensure stdint is only used by the compiler, and not the assembler. */ -#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) -#include -extern uint32_t SystemCoreClock; -#endif - -// #define configSUPPORT_STATIC_ALLOCATION 1 - -#define configUSE_PREEMPTION 1 -#define configUSE_IDLE_HOOK 0 -#define configUSE_TICK_HOOK 0 -#define configCPU_CLOCK_HZ (SystemCoreClock) -#define configTICK_RATE_HZ ((TickType_t)1000) -#define configMAX_PRIORITIES (7) -#define configMINIMAL_STACK_SIZE ((uint16_t)128) -#define configTOTAL_HEAP_SIZE ((size_t)(2 * 1024)) -#define configMAX_TASK_NAME_LEN (16) -#define configUSE_TRACE_FACILITY 1 -#define configUSE_16_BIT_TICKS 0 -#define configIDLE_SHOULD_YIELD 1 -#define configUSE_MUTEXES 1 -#define configQUEUE_REGISTRY_SIZE 8 -#define configCHECK_FOR_STACK_OVERFLOW 0 -#define configUSE_RECURSIVE_MUTEXES 1 -#define configUSE_MALLOC_FAILED_HOOK 0 -#define configUSE_APPLICATION_TASK_TAG 0 -#define configUSE_COUNTING_SEMAPHORES 1 -#define configGENERATE_RUN_TIME_STATS 0 - -/* Co-routine definitions. */ -#define configUSE_CO_ROUTINES 0 -#define configMAX_CO_ROUTINE_PRIORITIES (2) - -/* Software timer definitions. */ -#define configUSE_TIMERS 0 -#define configTIMER_TASK_PRIORITY (2) -#define configTIMER_QUEUE_LENGTH 10 -#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2) - -/* Set the following definitions to 1 to include the API function, or zero -to exclude the API function. */ -#define INCLUDE_vTaskPrioritySet 1 -#define INCLUDE_uxTaskPriorityGet 1 -#define INCLUDE_vTaskDelete 1 -#define INCLUDE_vTaskCleanUpResources 1 -#define INCLUDE_vTaskSuspend 1 -#define INCLUDE_vTaskDelayUntil 1 -#define INCLUDE_vTaskDelay 1 -#define INCLUDE_xQueueGetMutexHolder 1 -#define INCLUDE_xTaskGetSchedulerState 1 -#define INCLUDE_eTaskGetState 1 - -/* Cortex-M specific definitions. */ -#ifdef __NVIC_PRIO_BITS -/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ -#define configPRIO_BITS __NVIC_PRIO_BITS -#else -#define configPRIO_BITS 4 /* 15 priority levels */ -#endif - -/* The lowest interrupt priority that can be used in a call to a "set priority" -function. */ -#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf - -/* The highest interrupt priority that can be used by any interrupt service -routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL -INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER -PRIORITY THAN THIS! (higher priorities are lower numeric values. */ -#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 - -/* Interrupt priorities used by the kernel port layer itself. These are generic -to all Cortex-M ports, and do not rely on any particular library functions. */ -#define configKERNEL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) -/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! -See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ -#define configMAX_SYSCALL_INTERRUPT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) - -/* Normal assert() semantics without relying on the provision of an assert.h -header file. */ -#define configASSERT(x) \ - if ((x) == 0) { \ - taskDISABLE_INTERRUPTS(); \ - for (;;) \ - ; \ - } - -/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS - standard names. */ -#define vPortSVCHandler SVC_Handler -#define xPortPendSVHandler PendSV_Handler - -/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware, - to prevent overwriting SysTick_Handler defined within STM32Cube HAL */ -/* #define xPortSysTickHandler SysTick_Handler */ - -#endif /* FREERTOS_CONFIG_H */ +/* + * FreeRTOS Kernel V10.0.1 + * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +/* Ensure stdint is only used by the compiler, and not the assembler. */ +#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) +#include +extern uint32_t SystemCoreClock; +#endif + +// #define configSUPPORT_STATIC_ALLOCATION 1 + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ (SystemCoreClock) +#define configTICK_RATE_HZ ((TickType_t)1000) +#define configMAX_PRIORITIES (7) +#define configMINIMAL_STACK_SIZE ((uint16_t)128) +#define configTOTAL_HEAP_SIZE ((size_t)(2 * 1024)) +#define configMAX_TASK_NAME_LEN (16) +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 8 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configGENERATE_RUN_TIME_STATS 0 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES (2) + +/* Software timer definitions. */ +#define configUSE_TIMERS 0 +#define configTIMER_TASK_PRIORITY (2) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xQueueGetMutexHolder 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_eTaskGetState 1 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS +/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ +#define configPRIO_BITS __NVIC_PRIO_BITS +#else +#define configPRIO_BITS 4 /* 15 priority levels */ +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 + +/* Interrupt priorities used by the kernel port layer itself. These are generic +to all Cortex-M ports, and do not rely on any particular library functions. */ +#define configKERNEL_INTERRUPT_PRIORITY (configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS)) + +/* Normal assert() semantics without relying on the provision of an assert.h +header file. */ +#define configASSERT(x) \ + if ((x) == 0) { \ + taskDISABLE_INTERRUPTS(); \ + for (;;) \ + ; \ + } + +/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS + standard names. */ +#define vPortSVCHandler SVC_Handler +#define xPortPendSVHandler PendSV_Handler + +/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware, + to prevent overwriting SysTick_Handler defined within STM32Cube HAL */ +/* #define xPortSysTickHandler SysTick_Handler */ + +#endif /* FREERTOS_CONFIG_H */ diff --git a/app/inc/chasisMove.hpp b/app/inc/chasisMove.hpp new file mode 100644 index 0000000..d337e43 --- /dev/null +++ b/app/inc/chasisMove.hpp @@ -0,0 +1,56 @@ + /* + * chassisMove.hpp + * + * Created on: Jan 02, 2025 + * Author: @sofiaariasv2002 + * @AnaValeria + * + * For mor information: + * https://learning.oreilly.com/library/view/wheeled-mobile-robotics/9780128042380/B9780128042045000020_1.xhtml#s0070 + * https://www.robomaster.com/en-US/products/components/general/M3508 + * + */ + + #include + #include "IntfMotor.hpp" + #include "ControllerCAN.hpp" + + #ifndef CHASSIS_MOVE_HPP + #define CHASSIS_MOVE_HPP + #define CHASSIS_RADIUS 0.3f // Radio del chasis (distancia del centro a una rueda) en metros + #define MAX_MOTOR_SPEED 465.0f // Velocidad máxima del motor rpm + #define K_TWIST 1.0f // Sensibilidad para torsión del chasis + #define PI 3.14159265358979323846 + + float theta_robot_rads; //angulo actual del robot + + /** + * @brief Clase para controlar el movimiento de un chasis mecanum utilizando joysticks. + * + * Esta clase permite controlar el movimiento de un robot con chasis mecanum. La clase proporciona + * métodos para convertir las entradas de joystick en velocidades de motor, además de normalizar + * las velocidades y calcular la torsión en base a las entradas de control. + */ + class chassisMove { + private: + IntfMotor* leftFrontMotor; + IntfMotor* rightFrontMotor; + IntfMotor* leftBackMotor; + IntfMotor* rightBackMotor; + + float maxMotorSpeed_rpm; + + float normalizeSpeed(float speed); + float normalizeW(float theta_joy_rads); + + public: + chassisMove(IntfMotor* leftFrontMotor, IntfMotor* rightFrontMotor, + IntfMotor* leftBackMotor, IntfMotor* rightBackMotor, + float maxMotorSpeed_rpm = MAX_MOTOR_SPEED); + + void joystickToMotors(float x1, float y1, float x2, float y2); + + void stop(); + }; + + #endif // CHASSIS_MOVE_HPP \ No newline at end of file diff --git a/app/src/CanBusTask.c b/app/src/CanBusTask.c index 19750ba..5da31db 100644 --- a/app/src/CanBusTask.c +++ b/app/src/CanBusTask.c @@ -1,79 +1,79 @@ -/* - * BaseFileC.h - * - * Created on: May 24, 2023 - * Author: @yourName - */ - -#ifndef CANBUSTASK_C -#define CANBUSTASK_C - -#include "CanBusTask.h" -#ifdef __cplusplus -extern "C" { -#endif - -// YOUR CODE -// We need at least the following principles: -// * StartReceiveInt: Sets up an interrupt-based reception for USART2 and configures the necessary variables used by the -// ISR for the transfer. -// * StartCAN4Traffic: Starts a continuous stream of data transmitted from UART4 to be received by USART2 (provided the -// jumpers are correctly set). -// * canActionTask: This function initializes USART2 and associated hardware, starts a reception, and waits for -// completion (with a deadline of 100 ms). The complete message is either printed or a timeout occurs and an error is -// printed. -// * CAN2_IRQHandler: An ISR is issued when an interrupt occurs for the USART2 peripheral. - -#ifdef __cplusplus -} -#endif - -#endif /* TemplateCFile_C */ - -osSemaphoreId_t I2C_semaphore; -I2C_HandleTypeDef hi2c1; - -void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef* hi2c) { - if (hi2c->State == HAL_I2C_STATE_READY) { - osSemaphoreRelease(I2C_semaphore); - } -} - -void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef* hi2c) { - if (hi2c->State == HAL_I2C_STATE_READY) { - osSemaphoreRelease(I2C_semaphore); - } -} - -static void Task1(void* argument) { - while (1) { - HAL_I2C_Master_Transmit_IT(&hi2c1, I2C_addr, write_data_array, sizeof(write_data_array)); - osSemaphoreAcquire(I2C_semaphore, 100); - HAL_I2C_Master_Receive_IT(&hi2c1, I2C_addr, read_data_array, sizeof(read_data_array)); - osSemaphoreAcquire(I2C_semaphore, 100); - } -} - -osSemaphoreId_t I2C_semaphore; -I2C_HandleTypeDef hi2c1; - -void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef* hi2c) { - if (hi2c->State == HAL_I2C_STATE_READY) { - osSemaphoreRelease(I2C_semaphore); - } -} - -void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef* hi2c) { - if (hi2c->State == HAL_I2C_STATE_READY) { - osSemaphoreRelease(I2C_semaphore); - } -} - -static void Task1(void* argument) { - while (1) { - HAL_I2C_Master_Transmit_IT(&hi2c1, I2C_addr, write_data_array, sizeof(write_data_array)); - osSemaphoreAcquire(I2C_semaphore, 100); - HAL_I2C_Master_Receive_IT(&hi2c1, I2C_addr, read_data_array, sizeof(read_data_array)); - osSemaphoreAcquire(I2C_semaphore, 100); - } +/* + * BaseFileC.h + * + * Created on: May 24, 2023 + * Author: @yourName + */ + +#ifndef CANBUSTASK_C +#define CANBUSTASK_C + +#include "CanBusTask.h" +#ifdef __cplusplus +extern "C" { +#endif + +// YOUR CODE +// We need at least the following principles: +// * StartReceiveInt: Sets up an interrupt-based reception for USART2 and configures the necessary variables used by the +// ISR for the transfer. +// * StartCAN4Traffic: Starts a continuous stream of data transmitted from UART4 to be received by USART2 (provided the +// jumpers are correctly set). +// * canActionTask: This function initializes USART2 and associated hardware, starts a reception, and waits for +// completion (with a deadline of 100 ms). The complete message is either printed or a timeout occurs and an error is +// printed. +// * CAN2_IRQHandler: An ISR is issued when an interrupt occurs for the USART2 peripheral. + +#ifdef __cplusplus +} +#endif + +#endif /* TemplateCFile_C */ + +osSemaphoreId_t I2C_semaphore; +I2C_HandleTypeDef hi2c1; + +void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef* hi2c) { + if (hi2c->State == HAL_I2C_STATE_READY) { + osSemaphoreRelease(I2C_semaphore); + } +} + +void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef* hi2c) { + if (hi2c->State == HAL_I2C_STATE_READY) { + osSemaphoreRelease(I2C_semaphore); + } +} + +static void Task1(void* argument) { + while (1) { + HAL_I2C_Master_Transmit_IT(&hi2c1, I2C_addr, write_data_array, sizeof(write_data_array)); + osSemaphoreAcquire(I2C_semaphore, 100); + HAL_I2C_Master_Receive_IT(&hi2c1, I2C_addr, read_data_array, sizeof(read_data_array)); + osSemaphoreAcquire(I2C_semaphore, 100); + } +} + +osSemaphoreId_t I2C_semaphore; +I2C_HandleTypeDef hi2c1; + +void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef* hi2c) { + if (hi2c->State == HAL_I2C_STATE_READY) { + osSemaphoreRelease(I2C_semaphore); + } +} + +void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef* hi2c) { + if (hi2c->State == HAL_I2C_STATE_READY) { + osSemaphoreRelease(I2C_semaphore); + } +} + +static void Task1(void* argument) { + while (1) { + HAL_I2C_Master_Transmit_IT(&hi2c1, I2C_addr, write_data_array, sizeof(write_data_array)); + osSemaphoreAcquire(I2C_semaphore, 100); + HAL_I2C_Master_Receive_IT(&hi2c1, I2C_addr, read_data_array, sizeof(read_data_array)); + osSemaphoreAcquire(I2C_semaphore, 100); + } } \ No newline at end of file diff --git a/app/src/chassisMove.cpp b/app/src/chassisMove.cpp new file mode 100644 index 0000000..805a53d --- /dev/null +++ b/app/src/chassisMove.cpp @@ -0,0 +1,112 @@ +#include "chassisMove.hpp" + +/** + * @brief Normaliza la velocidad del motor para asegurarse de que no exceda la velocidad máxima. + * + * @param speed Velocidad a normalizar. + * @return La velocidad normalizada. +*/ +float chassisMove::normalizeSpeed(float speed) { + if (speed > maxMotorSpeed_rpm) return maxMotorSpeed_rpm; + if (speed < -maxMotorSpeed_rpm) return -maxMotorSpeed_rpm; + return speed; +} + +/** + * @brief Normaliza la velocidad angular (torsión) en función de los valores de entrada del joystick. + * + * @param theta_joy Ángulo del joystick que indica la dirección de la torsión. + * @param theta_robot Ángulo actual del robot. + * @return La velocidad angular normalizada en radianes por segundo. + */ +float chassisMove::normalizeW(float theta_joy_rads) { + float angle_error = theta_joy_rads - theta_robot_rads; + if (angle_error > M_PI) angle_error -= 2 * PI; + if (angle_error < -M_PI) angle_error += 2 * PI; + float w_rs = K_TWIST * angle_error; + //TODO: si se actualiza? + //theta_robot_rads=w_rs; + return w_rs; +} + +chassisMove::chassisMove(IntfMotor* leftFrontMotor, IntfMotor* rightFrontMotor, + IntfMotor* leftBackMotor, IntfMotor* rightBackMotor, + float maxMotorSpeed) + : leftFrontMotor(leftFrontMotor), rightFrontMotor(rightFrontMotor), + leftBackMotor(leftBackMotor), rightBackMotor(rightBackMotor), + maxMotorSpeed(maxMotorSpeed_rpm) {} + +/** + * @brief Convierte las entradas de los joysticks en velocidades de los motores. + * + * Este método toma las entradas de los dos joysticks (para movimiento y torsión) y las convierte en + * velocidades para cada rueda del chasis mecanum. + * + * @param x1 Entrada del joystick 1 (eje X para desplazamiento en el plano horizontal). + * @param y1 Entrada del joystick 1 (eje Y para desplazamiento en el plano vertical). + * @param x2 Entrada del joystick 2 (eje X para control de torsión). + * @param y2 Entrada del joystick 2 (eje Y para control de torsión). + * @param theta_robot Ángulo de orientación del robot (en radianes). + * @param theta_joy Ángulo de orientación del joystick2 (en radianes). + */ +void chassisMove::joystickToMotors(float x1, float y1, float x2, float y2) { + // Cálculo del ángulo deseado + float theta_joy_rads = atan2(y2, x2); + // Cálculo de la torsión (velocidad angular) + float w_rs = normalizeW(theta_joy_rads) + + // u + Eigen::Vector3f joystick_input(x1, y1, w); + // M + Eigen::MatrixXf control_matrix(4, 3); + control_matrix << -1, -1, CHASSIS_RADIUS, // Delantera izquierda + 1, -1, CHASSIS_RADIUS, // Delantera derecha + 1, 1, CHASSIS_RADIUS, // Trasera derecha + -1, 1, CHASSIS_RADIUS; // Trasera izquierda + + //v=M*u + Eigen::VectorXf wheel_speed = control_matrix * joystick_input; + wheel_speed = wheel_speed.unaryExpr([this](float speed) { return normalizeSpeed(speed); }); + + leftFrontMotor->actuate(wheel_speed[0]); // Delantera izquierda + rightFrontMotor->actuate(wheel_speed[1]); // Delantera derecha + rightBackMotor->actuate(wheel_speed[2]); // Trasera derecha + leftBackMotor->actuate(wheel_speed[3]); // Trasera izquierda +} + +void chassisMove::stop() { + leftFrontMotor->stop(0); + rightFrontMotor->stop(0); + leftBackMotor->stop(0); + rightBackMotor->stop(0); +} + //PARTE ANA - leer referencia de velovidad en el IMU + //x1, y1, z1 son aceleromentro + //x2, y2, z2 son giroscopio + +//se llaman los valores dados por el acelerometro de la imu y por las velocidades de los motores. +void chassisMove::LecturaDeDatos(float x1, float y1,float z1 ,float x2,float y2,float z2 ){ + + // Leer los datos del acelerómetro + int16_t ax = IMU_ReadRegister16(0x3B); // Eje X https://invensense.tdk.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf + int16_t ay = IMU_ReadRegister16(0x3D); // Eje Y se encuentra en la pagina 7 del datasheet + int16_t az = IMU_ReadRegister16(0x3F); // Eje Z + + // Leer los datos del giroscopio + int16_t gx = IMU_ReadRegister16(0x43); // Eje X + int16_t gy = IMU_ReadRegister16(0x45); // Eje Y + int16_t gz = IMU_ReadRegister16(0x47); // Eje Z + + float x1g = x1 * (9.81/16384.0); // Conversión dependiendo del acelerometro es el de 16384 y el 9.81 es valor gravedad nos da asi la aceleracion en m/s^2 + float y1g = y1 * (9.81/16384.0); //https://www.diarioelectronicohoy.com/blog/configurar-el-mpu6050 ----se que tal vez no es muy confiable pero es entendible + float z1g = z1 * (9.81/16384.0); + float x2g = x2 * (250.0/32767.0); + float y2g = y2 * (250.0/32767.0); + float z2g = z2 * (250.0/32767.0); // Conversión dependiendo del giroscopio es el de 32767 valores y el 250 grados por segundo es valor gravedad nos da en grados por segundo + + //para imprimir los valores dados por el acelerometro de la imu y por las velocidades de los motores. + printf("Acelerómetro: X=%.2f , Y=%.2f , Z=%.2f \n", x 1g, y1g, z1g); + printf("giroscopio: X=%.2f , Y=%.2f , Z=%.2f \n", x2g, y2g, z2g); + //printf("velocidades llantas: LF=%.2f , RF=%.2f , RB=%.2f, LB=%.2f \n", leftFrontSpeed, rightFrontSpeed, rightBackSpeed, leftBackSpeed); + +} diff --git a/robotConfig b/robotConfig index 4eb10cf..1e796e8 160000 --- a/robotConfig +++ b/robotConfig @@ -1 +1 @@ -Subproject commit 4eb10cf505c67e5eef39c2dd317c92f00899dd89 +Subproject commit 1e796e8bc8f331246d5195ebc7ef8e89cc23f658