|
| 1 | +load("@bazel_embedded//tools/openocd:defs.bzl", "openocd_flash") |
| 2 | + |
| 3 | +cc_binary( |
| 4 | + name = "mdv6_firmware_main", |
| 5 | + # Linker file informs the toolchain how much RAM and flash you have as well as its locations on the chip |
| 6 | + additional_linker_inputs = [ |
| 7 | + "STM32CubeIDE/STM32F031C6TX_FLASH.ld", |
| 8 | + ], |
| 9 | + linkopts = ["-T $(location STM32CubeIDE/STM32F031C6TX_FLASH.ld)"], |
| 10 | + target_compatible_with = [ |
| 11 | + "@platforms//cpu:armv6-m", |
| 12 | + "@platforms//os:none", |
| 13 | + ], |
| 14 | + deps = [ |
| 15 | + ":mdv6_firmware", |
| 16 | + ], |
| 17 | +) |
| 18 | + |
| 19 | +openocd_flash( |
| 20 | + name = "mdv6_firmware_flash", |
| 21 | + device_configs = [ |
| 22 | + # Part of the STM32F0 family |
| 23 | + # https://www.st.com/resource/en/reference_manual/rm0091-stm32f0x1stm32f0x2stm32f0x8-advanced-armbased-32bit-mcus-stmicroelectronics.pdf |
| 24 | + "target/stm32f0x.cfg", |
| 25 | + ], |
| 26 | + # WARNING! `flash_offset` attribute is broken in the Bazel rule. The .elf file (mdv6_firmware_main.stripped) |
| 27 | + # contains the memory mappings already, so this attribute is necessary. |
| 28 | + flash_offset = "", |
| 29 | + # .stripped strips debug symbols to reduce the size of the binary. |
| 30 | + # see: https://bazel.build/reference/be/c-cpp#cc_binary |
| 31 | + image = ":mdv6_firmware_main.stripped", |
| 32 | + interface_configs = [ |
| 33 | + "interface/stlink.cfg", # The ST-Link V2 programmer is used to flash the firmware. |
| 34 | + ], |
| 35 | +) |
| 36 | + |
| 37 | +cc_library( |
| 38 | + name = "mdv6_firmware", |
| 39 | + srcs = glob([ |
| 40 | + "Core/Src/**/*.c", |
| 41 | + "Src/**/*.c", |
| 42 | + "STM32CubeIDE/Application/Startup/*.s", |
| 43 | + "STM32CubeIDE/Application/User/*.c", |
| 44 | + "*.c", |
| 45 | + "Drivers/STM32F0xx_HAL_Driver/Src/*.c", |
| 46 | + ], exclude = [ |
| 47 | + "Drivers/STM32F0xx_HAL_Driver/Src/*_template.c", |
| 48 | + ]) + [ |
| 49 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/bus_voltage_sensor.c", |
| 50 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/circle_limitation.c", |
| 51 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/digital_output.c", |
| 52 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/feed_forward_ctrl.c", |
| 53 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/ntc_temperature_sensor.c", |
| 54 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/open_loop.c", |
| 55 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/pid_regulator.c", |
| 56 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/pqd_motor_power_measurement.c", |
| 57 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/r_divider_bus_voltage_sensor.c", |
| 58 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/ramp_ext_mngr.c", |
| 59 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/revup_ctrl.c", |
| 60 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/speed_pos_fdbk.c", |
| 61 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Src/virtual_speed_sensor.c", |
| 62 | + ], |
| 63 | + hdrs = glob([ |
| 64 | + "Core/Inc/**/*.h", |
| 65 | + "*.h", |
| 66 | + "Inc/**/*.h", |
| 67 | + "Drivers/STM32F0xx_HAL_Driver/Inc/**/*.h", |
| 68 | + "Drivers/CMSIS/Device/ST/STM32F0xx/Include/**/*.h", |
| 69 | + "Drivers/CMSIS/Include/**/*.h", |
| 70 | + "MCSDK_v6.4.1-Full/**/*.h", |
| 71 | + ]), |
| 72 | + includes = [ |
| 73 | + "Core/Inc", |
| 74 | + "Drivers/STM32F0xx_HAL_Driver/Inc", |
| 75 | + "Drivers/CMSIS/Device/ST/STM32F0xx/Include", |
| 76 | + "Drivers/CMSIS/Include", |
| 77 | + "MCSDK_v6.4.1-Full/MotorControl/MCSDK/MCLib/Any/Inc", |
| 78 | + "Inc", |
| 79 | + ], |
| 80 | + defines = [ |
| 81 | + # Our MCU is the STM32F0251: https://www.st.com/resource/en/datasheet/stspin32f0251.pdf |
| 82 | + "STM32F031x6", |
| 83 | + # Use the HAL and Low-Layer APIs. |
| 84 | + "USE_HAL_DRIVER", |
| 85 | + "USE_FULL_LL_DRIVER", |
| 86 | + "ARM_MATH_CM0", |
| 87 | + ], |
| 88 | + alwayslink = True, |
| 89 | +) |
0 commit comments