diff --git a/third_party_libs/devices/arm/st_microelectronics/stm32f1cube/BUILD b/third_party_libs/devices/arm/st_microelectronics/stm32f1cube/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/third_party_libs/devices/arm/st_microelectronics/stm32f1cube/stm32f1_defs.bzl b/third_party_libs/devices/arm/st_microelectronics/stm32f1cube/stm32f1_defs.bzl new file mode 100644 index 0000000..41e6845 --- /dev/null +++ b/third_party_libs/devices/arm/st_microelectronics/stm32f1cube/stm32f1_defs.bzl @@ -0,0 +1,150 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + + +INCLUDE_DIRECTORIES = [ + "Drivers/CMSIS/Core_A/Include", + "Drivers/CMSIS/Core/Include", + "Drivers/CMSIS/Device/ST/STM32F1xx/Include", + "Drivers/CMSIS/DSP/Include", + "Drivers/CMSIS/Include", + "Drivers/CMSIS/NN/Include", + "Drivers/CMSIS/RTOS2/Include", + "Drivers/STM32F1xx_HAL_Driver/Inc", + "Drivers/STM32F1xx_HAL_Driver/Inc/Legacy", + "Middlewares/ST/STM32_Network_Library/Includes", + "Middlewares/ST/STM32_USB_Device_Library/Class/AUDIO/Inc", + "Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc", + "Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc", + "Middlewares/ST/STM32_USB_Device_Library/Class/DFU/Inc", + "Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc", + "Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc", + "Middlewares/ST/STM32_USB_Device_Library/Core/Inc", + "Middlewares/ST/STM32_USB_Host_Library/Class/AUDIO/Inc", + "Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc", + "Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc", + "Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc", + "Middlewares/ST/STM32_USB_Host_Library/Class/MTP/Inc", + "Middlewares/ST/STM32_USB_Host_Library/Core/Inc", + "Middlewares/Third_Party/FatFs/src", + "Middlewares/Third_Party/FatFs/src/drivers", + "Middlewares/Third_Party/LwIP/system/arch", + "Middlewares/Third_Party/mbedTLS/include/mbedtls", + "Middlewares/Third_Party/mbedTLS/include", +] + +CMSIS_GLOB_EXCLUSIONS = [ + "**/IAR/**", + "Drivers/CMSIS/Core_A/**", + "Drivers/CMSIS/NN/**", + "Drivers/CMSIS/DSP/**", + "Drivers/CMSIS/RTOS2/**", +] + +STM32_DEFINES = { + "stm32f103xx" : [ + "USE_HAL_DRIVER", + "STM32F103xx" + ] + +} + + +def stm32f1_startup_file(device): + return "@stm32f1cube//Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/startup_" + device + ".s" + +def stm32f1_project(name, config): + include_directories = INCLUDE_DIRECTORIES + defines = [] + glob_excludes = ["**/*template.c"] + + cc_library( + name = name + "_hal_driver", + srcs = native.glob(["Drivers/STM32F1xx_HAL_Driver/**/*.c"], exclude = glob_excludes), + hdrs = native.glob(["**/*.h"]), + copts = ["-include stdint.h"], + defines = defines, + includes = include_directories, + deps = [config], + tags = ["manual"], + alwayslink = True, + ) + + cc_library( + name = name + "_stm32_network_library", + srcs = native.glob(["Middlewares/ST/STM32_Network_Library/**/*.c"], exclude = glob_excludes), + hdrs = native.glob(["**/*.h"]), + defines = defines, + includes = include_directories, + deps = [config], + tags = ["manual"], + alwayslink = True, + ) + + cc_library( + name = name + "_stm32_usb_device_library", + srcs = native.glob(["MiddleWares/ST/STM32_USB_Device_Library/**/*.c"], exclude = glob_excludes), + hdrs = native.glob(["**/*.h"]), + defines = defines, + includes = include_directories, + deps = [config], + tags = ["manual"], + alwayslink = True, + ) + + cc_library( + name = name + "_stm32_usb_host_library", + srcs = native.glob(["MiddleWares/ST/STM32_USB_Host_Library/**/*.c"], exclude = glob_excludes), + hdrs = native.glob(["**/*.h"]), + defines = defines, + includes = include_directories, + deps = [config], + tags = ["manual"], + alwayslink = True, + ) + + cc_library( + name = name + "_st_middlewares", + deps = [ + ":" + name + "_stm32_network_library", + ":" + name + "_stm32_usb_device_library", + ":" + name + "_stm32_usb_host_library", + ], + tags = ["manual"], + alwayslink = True, + ) + + cc_library( + name = name + "_fatfs", + srcs = native.glob(["Middlewares/Third_Party/FatFs/src/*.c"], exclude = glob_excludes), + hdrs = native.glob(["Middlewares/Third_Party/FatFs/src/*.h"]), + includes = include_directories, + deps = [config], + tags = ["manual"], + alwayslink = True, + ) + + cc_library( + name = name + "_mbed_tls", + srcs = native.glob( + ["Middlewares/Third_Party/mbedTLS/library/*.c"], + exclude = glob_excludes, + ), + hdrs = native.glob(["Middlewares/Third_Party/mbedTLS/include/mbedtls/*.h"]), + copts = [ + '-DMBEDTLS_CONFIG_FILE=\\"mbedtls_conf.h\\"', + ], + includes = include_directories, + deps = [config], + tags = ["manual"], + alwayslink = True, + ) + + cc_library( + name = name + "_third_party_middlewares", + deps = [ + ":" + name + "_fatfs", + ":" + name + "_mbed_tls", + ], + tags = ["manual"], + alwayslink = True, + ) diff --git a/third_party_libs/devices/arm/st_microelectronics/stm32f1cube/stm32f1_repository.bzl b/third_party_libs/devices/arm/st_microelectronics/stm32f1cube/stm32f1_repository.bzl new file mode 100644 index 0000000..46360ab --- /dev/null +++ b/third_party_libs/devices/arm/st_microelectronics/stm32f1cube/stm32f1_repository.bzl @@ -0,0 +1,66 @@ +load(":stm32f1_defs.bzl", "STM32_DEFINES") + +VERSIONS = { + "1.8.2" : { + "commit" : "441b2cbdc25aa50437a59c4bffe22b88e78942c9", + "sha256" : "" + } +} + + +def _stm32f1xx_repository_impl(rctx): + REPOSITORY_NAME = "STM32CubeF1" + BASE_URL = "https://github.com/STMicroelectronics/" + REPOSITORY_NAME + "/archive/" + + version_info = VERSIONS[rctx.attr.version] + rctx.download_and_extract( + url = BASE_URL + version_info["commit"] + ".zip", + stripPrefix = REPOSITORY_NAME + "-" + version_info["commit"], + sha256 = version_info["sha256"], + ) + rctx.symlink(Label("//third_party_libs/devices/arm/st_microelectronics/stm32f1cube:stm32f1_defs.bzl"), "stm32f1_defs.bzl") + target_template = """ +stm32f1_project( + name = "{name}", + config = "{config}", +) +""" + + startup_template = """ +cc_library( + name = "startup_{device}", + srcs = ["Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/startup_{device}.s"], + alwayslink = True, + tags = ["manual"], +) +""" + tartup_targets = [startup_template.format(device = device) for device in STM32_DEFINES.keys()] + startup_targets_str = "\n".join(startup_targets) + targets = [target_template.format(config = config, name = name) for name, config in rctx.attr.project_configs.items()] + targets_str = "\n".join(targets) + rctx.file("BUILD", """ +package(default_visibility = ["//visibility:public"]) +exports_files(glob(["**/*.s"])) +load(":stm32f1_defs.bzl","stm32f1_project") +""" + targets_str + startup_targets_str) + +stm32f1_repository_simple = repository_rule( + implementation = _stm32f1xx_repository_impl, + attrs = { + "version": attr.string( + doc = "Release version of repository", + default = "v1.7.0", + values = VERSIONS.keys(), + ), + "project_configs": attr.string_dict( + doc = "The key as the named prefix for this project and the value as the Label for your projects config cc_library", + mandatory = True, + ), + }, +) + +def stm32f1_repository(project_configs, version = "v1.7.0"): + stm32f1_repository_simple(name = "stm32f1cube", project_configs = project_configs, version = version) + + +