From 5432fbb8b3e62b13089f45748a0bf1ab1129e6fd Mon Sep 17 00:00:00 2001 From: Gus Tahara-Edmonds Date: Sat, 18 Nov 2023 10:29:46 -0800 Subject: [PATCH] Track .ioc checksums to remove code generation from CI (#1087) ### Summary We currently re-generate STM32CubeMX code during CI, which is flaky and slow. This is because the binary builds depend on a checksum of the `.ioc` files, which are generated during STM32CubeMX code generation. These are currently git ignored, forcing code regeneration in CI. However, we can instead track the checksums, and add a new job to verify the `.ioc` matches the tracked checksum. This gives us the best of both worlds: - We can verify that the `.ioc` file is up to date with the code generated by STM32CubeMX by comparing the checksums. If they don't match, you will need to re-generate code locally. - CI is fast. ### Changelist - Track `.ioc` MD5 checksums - Add H7 dev board (I forgot to do this before whoops) ### Testing Done ### Resolved Issues ### Checklist *Please change `[ ]` to `[x]` when you are ready.* - [x] I have read and followed the code conventions detailed in [README.md](../README.md) (*This will save time for both you and the reviewer!*). - [x] If this pull request is longer then **500** lines, I have provided *explicit* justification in the summary above explaining why I *cannot* break this up into multiple pull requests (*Small PR's are faster and less painful for everyone involved!*). --- .github/workflows/ci.yml | 30 +++++++++---------- .github/workflows/master_cd.yml | 4 ++- .gitignore | 1 - .vscode/cmake-variants.yaml | 2 +- firmware/dev/f4dev/src/cubemx/f4dev.ioc.md5 | 1 + firmware/dev/h7dev/src/cubemx/Src/main.c | 3 ++ .../dev/h7dev/src/cubemx/Src/stm32h7xx_it.c | 4 +-- firmware/dev/h7dev/src/cubemx/h7dev.ioc.md5 | 1 + firmware/thruna/BMS/BMS.ioc.md5 | 1 + firmware/thruna/DCM/DCM.ioc.md5 | 1 + firmware/thruna/DIM/src/cubemx/DIM.ioc.md5 | 1 + firmware/thruna/FSM/FSM.ioc.md5 | 1 + firmware/thruna/PDM/PDM.ioc.md5 | 1 + 13 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 firmware/dev/f4dev/src/cubemx/f4dev.ioc.md5 create mode 100644 firmware/dev/h7dev/src/cubemx/h7dev.ioc.md5 create mode 100644 firmware/thruna/BMS/BMS.ioc.md5 create mode 100644 firmware/thruna/DCM/DCM.ioc.md5 create mode 100644 firmware/thruna/DIM/src/cubemx/DIM.ioc.md5 create mode 100644 firmware/thruna/FSM/FSM.ioc.md5 create mode 100644 firmware/thruna/PDM/PDM.ioc.md5 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41342a1265..877d1cad2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,8 @@ jobs: ioc_dir: firmware/thruna/BMS - board: f4dev ioc_dir: firmware/dev/f4dev/src/cubemx + - board: h7dev + ioc_dir: firmware/dev/h7dev/src/cubemx container: image: ubcformulaelectric/environment:latest @@ -66,20 +68,15 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - # xvfb-run is required to prefix any commands that run STM32CubeMX - # It fakes out a display, since STM32CubeMX throws an error if it doesn't detect a display - - name: Generate code + # To ensure that the generated STM32CubeMX code is up to date with the .ioc file, we + # we also generate a checksum from the .ioc file when code is generated during builds. + # During CI, we re-generate the checksum. If it matches, then the code is up to date, + # otherwise, you need to re-generate STM32CubeMX code locally. + - name: Generate checksum run: | - echo "test: $GITHUB_WORKSPACE" - xvfb-run python3 scripts/utilities/generate_cube_code.py \ - --board ${{ matrix.board }} \ - --log4j_properties_output ~/.stm32cubemx/log4j.properties \ - --ioc $GITHUB_WORKSPACE/${{ matrix.ioc_dir }}/${{ matrix.board }}.ioc \ - --codegen_output_dir $GITHUB_WORKSPACE/${{ matrix.ioc_dir }} \ - --cube_bin /usr/local/STM32CubeMX/STM32CubeMX - - - name: Fix formatting - run: python3 scripts/clang_format/fix_formatting.py + python3 scripts/utilities/generate_md5_checksum.py \ + $GITHUB_WORKSPACE/${{ matrix.ioc_dir }}/${{ matrix.board }}.ioc \ + $GITHUB_WORKSPACE/${{ matrix.ioc_dir }}/${{ matrix.board }}.ioc.md5 - name: Check for differences run: git --no-pager diff --color --exit-code @@ -98,6 +95,7 @@ jobs: - DCM - DIM - f4dev + - h7dev container: image: ubcformulaelectric/environment:latest credentials: @@ -133,7 +131,7 @@ jobs: password: ${{ secrets.DOCKER_TOKEN }} env: - BUILD_DIR: build_x86 + BUILD_DIR: build_fw_test steps: @@ -168,7 +166,7 @@ jobs: password: ${{ secrets.DOCKER_TOKEN }} env: - BUILD_DIR: build_x86 + BUILD_DIR: build_fw_test steps: # Fix to ensure that commands like git status work in child directories @@ -202,7 +200,7 @@ jobs: password: ${{ secrets.DOCKER_TOKEN }} env: - BUILD_DIR: build_x86 + BUILD_DIR: build_fw_test steps: # Fix to ensure that commands like git status work in child directories diff --git a/.github/workflows/master_cd.yml b/.github/workflows/master_cd.yml index d8ed52e229..34b1d04877 100644 --- a/.github/workflows/master_cd.yml +++ b/.github/workflows/master_cd.yml @@ -27,6 +27,8 @@ jobs: build_dir: firmware/thruna/BMS/BMS.elf - board: f4dev build_dir: firmware/dev/f4dev/f4dev.elf + - board: h7dev + build_dir: firmware/dev/f4dev/h7dev.elf container: image: ubcformulaelectric/environment:latest credentials: @@ -72,7 +74,7 @@ jobs: uses: ./.github/actions/push_release with: # https://github.com/actions/download-artifact#download-all-artifacts - files: "FSM.elf/FSM.elf BMS.elf/BMS.elf DCM.elf/DCM.elf DIM.elf/DIM.elf PDM.elf/PDM.elf f4dev.elf/f4dev.elf CanMsgs.dbc/CanMsgs.dbc" + files: "FSM.elf/FSM.elf BMS.elf/BMS.elf DCM.elf/DCM.elf DIM.elf/DIM.elf PDM.elf/PDM.elf f4dev.elf/f4dev.elf h7dev.elf/h7dev.elf CanMsgs.dbc/CanMsgs.dbc" latest: true title: "Stable Binaries and DBCs" body: "This release contains the latest stable binaries and DBCs." diff --git a/.gitignore b/.gitignore index f24188b19a..2b7ce47ece 100644 --- a/.gitignore +++ b/.gitignore @@ -101,7 +101,6 @@ cmake-build-* *.l1p *.l2p *.iex -*.md5 # STM32CubeMX .mxproject diff --git a/.vscode/cmake-variants.yaml b/.vscode/cmake-variants.yaml index 4b2bdc362c..9b7243fdcc 100644 --- a/.vscode/cmake-variants.yaml +++ b/.vscode/cmake-variants.yaml @@ -1,5 +1,5 @@ platform: - default: arm + default: firmware_deploy choices: firmware_deploy: short: Firmware Deploy diff --git a/firmware/dev/f4dev/src/cubemx/f4dev.ioc.md5 b/firmware/dev/f4dev/src/cubemx/f4dev.ioc.md5 new file mode 100644 index 0000000000..75cc0a94e0 --- /dev/null +++ b/firmware/dev/f4dev/src/cubemx/f4dev.ioc.md5 @@ -0,0 +1 @@ +eeda1272ba9532f2df9a7512c39e8643 \ No newline at end of file diff --git a/firmware/dev/h7dev/src/cubemx/Src/main.c b/firmware/dev/h7dev/src/cubemx/Src/main.c index 03d6539e47..4d0420d160 100644 --- a/firmware/dev/h7dev/src/cubemx/Src/main.c +++ b/firmware/dev/h7dev/src/cubemx/Src/main.c @@ -23,6 +23,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "string.h" +#include "hw_hardFaultHandler.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -109,6 +110,8 @@ int main(void) /* USER CODE BEGIN 2 */ // __HAL_DBGMCU_FREEZE_IWDG(); + hw_hardFaultHandler_handleFault(); + // Configure and initialize SEGGER SystemView. SEGGER_SYSVIEW_Conf(); /* USER CODE END 2 */ diff --git a/firmware/dev/h7dev/src/cubemx/Src/stm32h7xx_it.c b/firmware/dev/h7dev/src/cubemx/Src/stm32h7xx_it.c index 6c9d529826..f1211ac404 100644 --- a/firmware/dev/h7dev/src/cubemx/Src/stm32h7xx_it.c +++ b/firmware/dev/h7dev/src/cubemx/Src/stm32h7xx_it.c @@ -22,7 +22,7 @@ #include "stm32h7xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ -#include "Io_SharedHardFaultHandler.h" +#include "hw_hardFaultHandler.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -86,7 +86,7 @@ void NMI_Handler(void) void HardFault_Handler(void) { /* USER CODE BEGIN HardFault_IRQn 0 */ - Io_SharedHardFaultHandler_HandleHardFault(); + hw_hardFaultHandler_handleFault(); /* USER CODE END HardFault_IRQn 0 */ while (1) { diff --git a/firmware/dev/h7dev/src/cubemx/h7dev.ioc.md5 b/firmware/dev/h7dev/src/cubemx/h7dev.ioc.md5 new file mode 100644 index 0000000000..7bf29737d6 --- /dev/null +++ b/firmware/dev/h7dev/src/cubemx/h7dev.ioc.md5 @@ -0,0 +1 @@ +3c0783d07b4f61d0b1f0c73c7592fcca \ No newline at end of file diff --git a/firmware/thruna/BMS/BMS.ioc.md5 b/firmware/thruna/BMS/BMS.ioc.md5 new file mode 100644 index 0000000000..32f8e9c9cf --- /dev/null +++ b/firmware/thruna/BMS/BMS.ioc.md5 @@ -0,0 +1 @@ +07584c0edf7569aaf2d92d1a4cfd039c \ No newline at end of file diff --git a/firmware/thruna/DCM/DCM.ioc.md5 b/firmware/thruna/DCM/DCM.ioc.md5 new file mode 100644 index 0000000000..4ca3bc3f76 --- /dev/null +++ b/firmware/thruna/DCM/DCM.ioc.md5 @@ -0,0 +1 @@ +d260ccc38dd514961b5318c4a6b673e3 \ No newline at end of file diff --git a/firmware/thruna/DIM/src/cubemx/DIM.ioc.md5 b/firmware/thruna/DIM/src/cubemx/DIM.ioc.md5 new file mode 100644 index 0000000000..91d764483b --- /dev/null +++ b/firmware/thruna/DIM/src/cubemx/DIM.ioc.md5 @@ -0,0 +1 @@ +bb13c45725652542bc8d2e080e9b0a06 \ No newline at end of file diff --git a/firmware/thruna/FSM/FSM.ioc.md5 b/firmware/thruna/FSM/FSM.ioc.md5 new file mode 100644 index 0000000000..1dbbd650c1 --- /dev/null +++ b/firmware/thruna/FSM/FSM.ioc.md5 @@ -0,0 +1 @@ +66b685c1e9c81840c30fa4a2e30cf328 \ No newline at end of file diff --git a/firmware/thruna/PDM/PDM.ioc.md5 b/firmware/thruna/PDM/PDM.ioc.md5 new file mode 100644 index 0000000000..c20362ad78 --- /dev/null +++ b/firmware/thruna/PDM/PDM.ioc.md5 @@ -0,0 +1 @@ +4def9a455a9cc19cb897bc45ccee1923 \ No newline at end of file