Skip to content
Open
Show file tree
Hide file tree
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 Nov 23, 2023
e2258b1
filter out .swp files
itsarune Nov 25, 2023
f293ab4
bootstrap bazel embedded
itsarune Jun 27, 2025
c118b47
Merge branch 'vimrc' of github.com:itsarune/Software into mdv6_firmware
itsarune Jul 3, 2025
b9f3498
still working on compilation
itsarune Jul 3, 2025
b6abd24
wip mdv6 firmware
itsarune Jul 8, 2025
4096749
wip
itsarune Jul 12, 2025
a08bac2
wip
itsarune Jul 12, 2025
63a0307
wip
itsarune Jul 19, 2025
0a63875
wip
itsarune Jul 19, 2025
7545dd2
Add new cross-compiler config
itsarune Jul 19, 2025
0db7c0f
wip move software/motor -> firmware/motor
itsarune Jul 19, 2025
6ae782b
Updated main from MDV6 spi branch
itsarune Jul 21, 2025
46e6eb7
wip
itsarune Jul 22, 2025
3cd5057
compiles but doesn't link
itsarune Aug 2, 2025
3aa48ae
both compiles AND links!
itsarune Aug 2, 2025
b147774
add bazel-embedded
itsarune Aug 8, 2025
d592ca0
wip
itsarune Aug 9, 2025
cdfb16b
wip
itsarune Aug 9, 2025
530796f
perhaps flashing works
itsarune Aug 9, 2025
9fc2642
wip
itsarune Aug 11, 2025
5a8c997
wip
Sep 6, 2025
d2e0816
add arm toolchain to opt/tbotspython
Sep 6, 2025
354b482
debug overflow
Sep 6, 2025
074a75f
Merge branch 'master' of github.com:UBC-Thunderbots/Software into mdv…
itsarune Sep 21, 2025
5b15b11
wip
itsarune Sep 21, 2025
42c0442
compiles now
itsarune Sep 28, 2025
bc19655
Add compile and linker flags to optimize space usage
Jan 1, 2026
321de05
Merge branch 'master' of github.com:UBC-Thunderbots/Software into mdv…
Jan 1, 2026
59c8679
Build mdv6 firmware in CI
Jan 1, 2026
dcb0a3a
shouldn't commit this
Jan 1, 2026
8297d83
fix syntax issue in actions file
Jan 1, 2026
a7f0085
fix firmware builds
Jan 1, 2026
0d9fe8f
Bazel 8 hail mary
Jan 1, 2026
179ff2f
fix alt builds
Jan 1, 2026
fd8e159
don't test firmware file
Jan 1, 2026
4a85591
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jan 3, 2026
f781b24
openocd flashing works i think?
Jan 11, 2026
3a39581
Merge branch 'master' of github.com:UBC-Thunderbots/Software into mdv…
Jan 11, 2026
5003131
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jan 11, 2026
143ac88
merged
Andrewyx Feb 15, 2026
4d95caa
modified locations
Andrewyx Feb 15, 2026
a430356
Replaced with remote
Andrewyx Feb 15, 2026
5a1c878
ansible deploy
Andrewyx Feb 16, 2026
09cd5fa
prototype ansible
Andrewyx Feb 16, 2026
76e716a
cleanup
Andrewyx Feb 16, 2026
4b60e93
ci fix
Andrewyx Feb 16, 2026
95ee9a7
config created
Andrewyx Feb 17, 2026
7312e03
openocd setup
Andrewyx Feb 17, 2026
60379ff
cleanup
Andrewyx Feb 17, 2026
114756a
reformat
Andrewyx Feb 17, 2026
d29a363
Merge branch 'master' of https://github.com/UBC-Thunderbots/Software …
Andrewyx Feb 17, 2026
b5f0ba9
test
Andrewyx Feb 22, 2026
6946d51
testing code
Andrewyx Feb 26, 2026
41f4699
Working flashing script
sunghyuneun Mar 21, 2026
796527d
Got rid of old unnecessary dependency
sunghyuneun Mar 21, 2026
ce0f946
merged
Andrewyx Mar 21, 2026
2ab768f
linking fixed, working state
Andrewyx Mar 22, 2026
3a290aa
Fixed Ansible Playbook
sunghyuneun Mar 25, 2026
5d49916
Please test this commit
GrayHoang Mar 27, 2026
5e3e2d0
fix paths
Thunderbots Mar 28, 2026
72f8d66
Merge branch 'master' of https://github.com/UBC-Thunderbots/Software …
Thunderbots Apr 4, 2026
5eed821
more merge
Thunderbots Apr 4, 2026
a7a0643
fix merge
Thunderbots Apr 4, 2026
88f1619
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Apr 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ jobs:
cd src
bazel build //software/embedded:thunderloop_main --copt=-O3 --platforms=//toolchains/cc:robot

- name: Motor Firmware build Test
run: |
cd src
bazel build @mdv6_firmware//:mdv6_firmware_main --platforms=//toolchains/cc:motor_board

motor-firmware:
name: Motor Firmware
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/environment-setup

- name: Build Motor Firmware
run: |
cd src
bazel build @mdv6_firmware//:mdv6_firmware_main --platforms=//toolchains/cc:motor_board

software-tests:
name: Software Tests
Expand Down Expand Up @@ -90,7 +106,7 @@ jobs:
//software/simulated_tests/... \
//software/ai/hl/... \
//software/ai/navigator/...

- name: Upload simulated test proto logs
# Ensure that simulated test logs get uploaded
if: always()
Expand Down
4 changes: 4 additions & 0 deletions environment_setup/setup_software.sh
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,8 @@ print_status_msg "Set up ansible-lint"
/opt/tbotspython/bin/ansible-galaxy collection install ansible.posix
print_status_msg "Finished setting up ansible-lint"

print_status_msg "Setting up STM32 cross-compiler"
install_stm32_cross_compiler $g_arch
print_status_msg "Done setting up STM32 cross-compiler"

print_status_msg "Done Software Setup, please reboot for changes to take place"
13 changes: 13 additions & 0 deletions environment_setup/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ install_python_dev_cross_compile_headers() {
rm -rf /tmp/tbots_download_cache/python-3.12.0.tar.xz
}

install_stm32_cross_compiler() {
arch="aarch64"
if is_x86 $1; then
arch="x86_64"
fi
download_link=https://developer.arm.com/-/media/Files/downloads/gnu/14.3.rel1/binrel/arm-gnu-toolchain-14.3.rel1-${arch}-arm-none-eabi.tar.xz

wget -N $download_link -O /tmp/tbots_download_cache/arm-gnu-toolchain.tar.xz
tar -xf /tmp/tbots_download_cache/arm-gnu-toolchain.tar.xz -C /tmp/tbots_download_cache/
sudo mv /tmp/tbots_download_cache/arm-gnu-toolchain-14.3.rel1-${arch}-arm-none-eabi /opt/tbotspython/arm-none-eabi-gcc
rm /tmp/tbots_download_cache/arm-gnu-toolchain.tar.xz
}

install_python_toolchain_headers() {
sudo mkdir -p /opt/tbotspython/py_headers/include/
sudo ln -sfn "$(python3.12-config --includes | awk '{for(i=1;i<=NF;++i) if ($i ~ /^-I/) print substr($i, 3)}' | head -n1)" /opt/tbotspython/py_headers/include/
Expand Down
36 changes: 36 additions & 0 deletions src/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ http_archive(
url = "https://github.com/saebyn/munkres-cpp/archive/61086fcf5b3a8ad4bda578cdc2d1dca57b548786.tar.gz",
)

# For flashing the motor driver board
http_archive(
name = "bazel_embedded",
sha256 = "91a78efbb0f94479fe9ca2912aced712be9e7028325bada9a73e7d325427b404",
strip_prefix = "bazel-embedded-cf5b240d510313b3383e0cdb550eb9f32be7244e",
url = "https://github.com/bazelembedded/bazel-embedded/archive/cf5b240d510313b3383e0cdb550eb9f32be7244e.zip",
)

openocd = use_extension("//starlark/firmware:open_ocd.bzl", "openocd_extension")
use_repo(openocd, "com_openocd")

http_archive(
name = "LTC4151",
build_file = "@//extlibs:LTC4151.BUILD",
Expand All @@ -201,6 +212,24 @@ http_archive(
url = "https://github.com/kerrydwong/LTC4151/archive/729952f10bcdcf359877b6f728565c17a8f17423.tar.gz",
)

# TODO: Perhaps set this to pull latest
#http_archive(
# name = "mdv6_firmware",
# build_file = "@//extlibs:mdv6_firmware.bzl",
# sha256 = "8054aca4ae3543e39d3587c58aa5904917d9b268922564f6ca3acf4b59bd8fe8",
# strip_prefix = "MDv6_Firmware-81627d25b5f147c0b5b3f8ceb2c22c883625a3d1",
# url = "https://github.com/UBC-Thunderbots/MDv6_Firmware/archive/81627d25b5f147c0b5b3f8ceb2c22c883625a3d1.tar.gz",
#)

git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "mdv6_firmware",
branch = "LEDtest",
build_file = "@//extlibs:mdv6_firmware.bzl",
remote = "https://github.com/UBC-Thunderbots/MDv6_Firmware.git",
)

http_archive(
name = "trinamic",
build_file = "@//extlibs:trinamic.BUILD",
Expand All @@ -224,6 +253,7 @@ register_toolchains(
"//toolchains/cc:cc_toolchain_for_k8_aarch64_linux",
"//toolchains/cc:cc_toolchain_for_k8",
"//toolchains/cc:cc_toolchain_for_aarch64",
"//toolchains/cc:cc_toolchain_for_stm32",
)

##############################################
Expand Down Expand Up @@ -256,6 +286,12 @@ new_local_repository(
path = "/opt/tbotspython/aarch64-tbots-linux-gnu/",
)

new_local_repository(
name = "motor_board_gcc",
build_file = "@//extlibs:motor_board_gcc.BUILD",
path = "/opt/tbotspython/arm-none-eabi-gcc/",
)

new_local_repository(
name = "py_cc_toolchain_host",
build_file = "@//extlibs:py_cc_toolchain.BUILD",
Expand Down
22 changes: 22 additions & 0 deletions src/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions src/extlibs/mdv6_firmware.bzl
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,
)
9 changes: 9 additions & 0 deletions src/extlibs/motor_board_gcc.BUILD
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 src/software/embedded/ansible/playbooks/deploy_motor_firmware.yml
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
1 change: 1 addition & 0 deletions src/software/embedded/ansible/playbooks/setup_pi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
ansible.builtin.import_tasks:
file: ../tasks/setup_robot_software_deps.yml

# TODO ADD COMPILE OPENOCD FROM SOURCE OPTIONS
Copy link
Copy Markdown
Contributor

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

- name: Setup systemd
tags:
- dependencies
Expand Down
1 change: 1 addition & 0 deletions src/software/embedded/ansible/requirements.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ansible==11.9.0
gpiozero==2.0.1
Loading
Loading