-
Notifications
You must be signed in to change notification settings - Fork 124
MDv6 Ansible Flashing #3614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Andrewyx
wants to merge
65
commits into
UBC-Thunderbots:master
Choose a base branch
from
Andrewyx:Andrewyx/MDv6_Flashing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
MDv6 Ansible Flashing #3614
Changes from all commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
7ff486b
project vimrc for FZF
itsarune e2258b1
filter out .swp files
itsarune f293ab4
bootstrap bazel embedded
itsarune c118b47
Merge branch 'vimrc' of github.com:itsarune/Software into mdv6_firmware
itsarune b9f3498
still working on compilation
itsarune b6abd24
wip mdv6 firmware
itsarune 4096749
wip
itsarune a08bac2
wip
itsarune 63a0307
wip
itsarune 0a63875
wip
itsarune 7545dd2
Add new cross-compiler config
itsarune 0db7c0f
wip move software/motor -> firmware/motor
itsarune 6ae782b
Updated main from MDV6 spi branch
itsarune 46e6eb7
wip
itsarune 3cd5057
compiles but doesn't link
itsarune 3aa48ae
both compiles AND links!
itsarune b147774
add bazel-embedded
itsarune d592ca0
wip
itsarune cdfb16b
wip
itsarune 530796f
perhaps flashing works
itsarune 9fc2642
wip
itsarune 5a8c997
wip
d2e0816
add arm toolchain to opt/tbotspython
354b482
debug overflow
074a75f
Merge branch 'master' of github.com:UBC-Thunderbots/Software into mdv…
itsarune 5b15b11
wip
itsarune 42c0442
compiles now
itsarune bc19655
Add compile and linker flags to optimize space usage
321de05
Merge branch 'master' of github.com:UBC-Thunderbots/Software into mdv…
59c8679
Build mdv6 firmware in CI
dcb0a3a
shouldn't commit this
8297d83
fix syntax issue in actions file
a7f0085
fix firmware builds
0d9fe8f
Bazel 8 hail mary
179ff2f
fix alt builds
fd8e159
don't test firmware file
4a85591
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] f781b24
openocd flashing works i think?
3a39581
Merge branch 'master' of github.com:UBC-Thunderbots/Software into mdv…
5003131
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 143ac88
merged
Andrewyx 4d95caa
modified locations
Andrewyx a430356
Replaced with remote
Andrewyx 5a1c878
ansible deploy
Andrewyx 09cd5fa
prototype ansible
Andrewyx 76e716a
cleanup
Andrewyx 4b60e93
ci fix
Andrewyx 95ee9a7
config created
Andrewyx 7312e03
openocd setup
Andrewyx 60379ff
cleanup
Andrewyx 114756a
reformat
Andrewyx d29a363
Merge branch 'master' of https://github.com/UBC-Thunderbots/Software …
Andrewyx b5f0ba9
test
Andrewyx 6946d51
testing code
Andrewyx 41f4699
Working flashing script
sunghyuneun 796527d
Got rid of old unnecessary dependency
sunghyuneun ce0f946
merged
Andrewyx 2ab768f
linking fixed, working state
Andrewyx 3a290aa
Fixed Ansible Playbook
sunghyuneun 5d49916
Please test this commit
GrayHoang 5e3e2d0
fix paths
Thunderbots 72f8d66
Merge branch 'master' of https://github.com/UBC-Thunderbots/Software …
Thunderbots 5eed821
more merge
Thunderbots a7a0643
fix merge
Thunderbots 88f1619
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| load("@bazel_embedded//tools/openocd:defs.bzl", "openocd_flash") | ||
|
|
||
| cc_binary( | ||
| name = "mdv6_firmware_main", | ||
| # Linker file informs the toolchain how much RAM and flash you have as well as its locations on the chip | ||
| additional_linker_inputs = [ | ||
| "STM32CubeIDE/STM32F031C6TX_FLASH.ld", | ||
| ], | ||
| linkopts = ["-T $(location STM32CubeIDE/STM32F031C6TX_FLASH.ld)"], | ||
| target_compatible_with = [ | ||
| "@platforms//cpu:armv6-m", | ||
| "@platforms//os:none", | ||
| ], | ||
| deps = [ | ||
| ":mdv6_firmware", | ||
| ], | ||
| ) | ||
|
|
||
| openocd_flash( | ||
| name = "mdv6_firmware_flash", | ||
| device_configs = [ | ||
| # Part of the STM32F0 family | ||
| # https://www.st.com/resource/en/reference_manual/rm0091-stm32f0x1stm32f0x2stm32f0x8-advanced-armbased-32bit-mcus-stmicroelectronics.pdf | ||
| "target/stm32f0x.cfg", | ||
| ], | ||
| # WARNING! `flash_offset` attribute is broken in the Bazel rule. The .elf file (mdv6_firmware_main.stripped) | ||
| # contains the memory mappings already, so this attribute is necessary. | ||
| flash_offset = "", | ||
| # .stripped strips debug symbols to reduce the size of the binary. | ||
| # see: https://bazel.build/reference/be/c-cpp#cc_binary | ||
| image = ":mdv6_firmware_main.stripped", | ||
| interface_configs = [ | ||
| "interface/stlink.cfg", # The ST-Link V2 programmer is used to flash the firmware. | ||
| ], | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "mdv6_firmware", | ||
| srcs = glob([ | ||
| "Core/Src/**/*.c", | ||
| "Src/**/*.c", | ||
| "STM32CubeIDE/Application/Startup/*.s", | ||
| "STM32CubeIDE/Application/User/*.c", | ||
| "*.c", | ||
| "Drivers/STM32F0xx_HAL_Driver/Src/*.c", | ||
| ], exclude = [ | ||
| "Drivers/STM32F0xx_HAL_Driver/Src/*_template.c", | ||
| ]) + [ | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/bus_voltage_sensor.c", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/circle_limitation.c", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/digital_output.c", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/feed_forward_ctrl.c", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/ntc_temperature_sensor.c", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/open_loop.c", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/pid_regulator.c", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/pqd_motor_power_measurement.c", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/r_divider_bus_voltage_sensor.c", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/ramp_ext_mngr.c", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/revup_ctrl.c", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/speed_pos_fdbk.c", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/virtual_speed_sensor.c", | ||
| ], | ||
| hdrs = glob([ | ||
| "Core/Inc/**/*.h", | ||
| "*.h", | ||
| "Inc/**/*.h", | ||
| "Drivers/STM32F0xx_HAL_Driver/Inc/**/*.h", | ||
| "Drivers/CMSIS/Device/ST/STM32F0xx/Include/**/*.h", | ||
| "Drivers/CMSIS/Include/**/*.h", | ||
| "MCSDK_v6.4.1-Full/**/*.h", | ||
| ]), | ||
| includes = [ | ||
| "Core/Inc", | ||
| "Drivers/STM32F0xx_HAL_Driver/Inc", | ||
| "Drivers/CMSIS/Device/ST/STM32F0xx/Include", | ||
| "Drivers/CMSIS/Include", | ||
| "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Inc", | ||
| "Inc", | ||
| ], | ||
| defines = [ | ||
| # Our MCU is the STM32F0251: https://www.st.com/resource/en/datasheet/stspin32f0251.pdf | ||
| "STM32F031x6", | ||
| # Use the HAL and Low-Layer APIs. | ||
| "USE_HAL_DRIVER", | ||
| "USE_FULL_LL_DRIVER", | ||
| "ARM_MATH_CM0", | ||
| ], | ||
| alwayslink = True, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| filegroup( | ||
| name = "includes", | ||
| srcs = glob([ | ||
| "arm-none-eabi/include", | ||
| "lib/gcc/arm-none-eabi/14.3.1/include", | ||
| ]), | ||
| ) |
112 changes: 112 additions & 0 deletions
112
src/software/embedded/ansible/playbooks/deploy_motor_firmware.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| --- | ||
| - name: Deploy firmware to the motor driver boards | ||
| hosts: THUNDERBOTS_HOSTS | ||
|
|
||
| vars: | ||
| repo_root: "{{ workspace_dir | default(playbook_dir + '/../../../../') }}" | ||
| # Bazel output location (convenience symlink) | ||
| # bazel_raw_out_path: "bazel-bin/external/+_repo_rules2+mdv6_firmware/mdv6_firmware_main" | ||
| # bazel_out_path: "bazel-bin/external/+_repo_rules2+mdv6_firmware/mdv6_firmware_main.bin" | ||
| firmware_bin_name: "mdv6_firmware_main.bin" | ||
| firmware_archive_name: "mdv6_firmware.tar.gz" | ||
| script_path: "software/embedded/drivers/flash_motor_drivers.py" | ||
| cfg_path: "software/embedded/drivers/raspberrypi.cfg" | ||
| stm32_cfg_path: "software/embedded/drivers/stm32_rpi.cfg" | ||
| remote_dir: "~/motor_firmware" | ||
| arm_toolchain_path: "/opt/tbotspython/arm-none-eabi-gcc/bin" | ||
|
|
||
| tasks: | ||
| - name: Build firmware locally | ||
| delegate_to: localhost | ||
| ansible.builtin.command: "bazel build @mdv6_firmware//:mdv6_firmware_main --platforms=//toolchains/cc:motor_board" | ||
| args: | ||
| chdir: "{{ repo_root }}" | ||
| changed_when: false | ||
|
|
||
| - name: Get binary path | ||
| delegate_to: localhost | ||
| ansible.builtin.command: "bazel cquery @mdv6_firmware//:mdv6_firmware_main --output=files --platforms=//toolchains/cc:motor_board" | ||
| args: | ||
| chdir: "{{ repo_root }}" | ||
| register: cquery_result | ||
| changed_when: false | ||
|
|
||
| - name: Set path facts | ||
| ansible.builtin.set_fact: | ||
| bazel_raw_out_path: "{{ cquery_result.stdout.strip() }}" | ||
| bazel_out_path: "{{ cquery_result.stdout.strip() }}.bin" | ||
|
|
||
| - name: Debug resolved paths | ||
| ansible.builtin.debug: | ||
| msg: "ELF Path: {{ bazel_raw_out_path }} | BIN Path: {{ bazel_out_path }}" | ||
|
|
||
| - name: Convert .elf binary to .bin binary | ||
| delegate_to: localhost | ||
| ansible.builtin.command: "{{ arm_toolchain_path }}/arm-none-eabi-objcopy -O binary {{ bazel_raw_out_path }} {{ bazel_out_path }}" | ||
| args: | ||
| chdir: "{{ repo_root }}" | ||
|
|
||
| - name: Archive firmware binary locally | ||
| delegate_to: localhost | ||
| ansible.builtin.command: "tar -czf {{ firmware_archive_name }} {{ bazel_out_path | basename }}" # noqa: command-instead-of-module | ||
| args: | ||
| chdir: "{{ repo_root }}/{{ bazel_out_path | dirname }}" | ||
| changed_when: false | ||
|
|
||
| - name: Remove existing remote directory | ||
| ansible.builtin.file: | ||
| path: "{{ remote_dir }}" | ||
| state: absent | ||
|
|
||
| - name: Create directory on remote | ||
| ansible.builtin.file: | ||
| path: "{{ remote_dir }}" | ||
| state: directory | ||
| mode: "0755" | ||
|
|
||
| - name: Copy firmware archive to remote | ||
| ansible.builtin.copy: | ||
| src: "{{ repo_root }}/{{ bazel_out_path | dirname }}/{{ firmware_archive_name }}" | ||
| dest: "{{ remote_dir }}/{{ firmware_archive_name }}" | ||
| mode: "0644" | ||
|
|
||
| - name: Copy flashing script to remote | ||
| ansible.builtin.copy: | ||
| src: "{{ repo_root }}/{{ script_path }}" | ||
| dest: "{{ remote_dir }}/flash_motor_drivers.py" | ||
| mode: "0755" | ||
|
|
||
| - name: Copy openocd config to remote | ||
| ansible.builtin.copy: | ||
| src: "{{ repo_root }}/{{ cfg_path }}" | ||
| dest: "{{ remote_dir }}/raspberrypi.cfg" | ||
| mode: "0644" | ||
|
|
||
| - name: Copy STM32 OpenOCD config to remote | ||
| ansible.builtin.copy: | ||
| src: "{{ repo_root }}/{{ stm32_cfg_path }}" | ||
| dest: "{{ remote_dir }}/stm32_rpi.cfg" | ||
| mode: "0644" | ||
|
|
||
| - name: Unarchive firmware on remote | ||
| ansible.builtin.unarchive: | ||
| src: "{{ remote_dir }}/{{ firmware_archive_name }}" | ||
| dest: "{{ remote_dir }}" | ||
| remote_src: true | ||
|
|
||
| - name: Configure Pinmux for SWD | ||
| ansible.builtin.shell: "echo {{ ansible_sudo_pass }} | sudo -S pinctrl set 4 ip pu && echo {{ ansible_sudo_pass }} | sudo -S pinctrl set 17 ip pu && echo {{ | ||
| ansible_sudo_pass }} | sudo -S pinctrl set 18 ip pu" | ||
| ignore_errors: true | ||
|
|
||
| - name: Run flashing script for Motor Driver A | ||
| ansible.builtin.shell: "echo {{ ansible_sudo_pass }} | sudo -S python3 flash_motor_drivers.py 12" | ||
| args: | ||
| chdir: "{{ remote_dir }}" | ||
| changed_when: true | ||
|
|
||
| - name: Run flashing script for Motor Driver C | ||
| ansible.builtin.shell: "echo {{ ansible_sudo_pass }} | sudo -S python3 flash_motor_drivers.py 23" | ||
| args: | ||
| chdir: "{{ remote_dir }}" | ||
| changed_when: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| ansible==11.9.0 | ||
| gpiozero==2.0.1 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: create issue for this TODO and tag issue number