Skip to content
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

chore: st table generator #225

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,30 @@ jobs:
command: manifest
#token: ${{ steps.token.outputs.token }}
token: ${{ secrets.AUTOMATIC_RELEASE_TOKEN }}
build_upload_packages:
name: Build & Upload Packages
needs: release_please
if: ${{ needs.release_please.outputs.releases_created }}
permissions:
contents: write
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false
- uses: hendrikmuhs/ccache-action@6d1841ec156c39a52b1b23a810da917ab98da1f4 # v1.2.10
with:
key: ${{ github.job }}-${{ matrix.os }}
variant: sccache
- uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7
with:
configurePreset: "host-single-MinSizeRel"
buildPreset: "release-package"
configurePresetAdditionalArgs: "['-DCMAKE_C_COMPILER_LAUNCHER=sccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=sccache']"
- run: gh release upload ${{ needs.release_please.outputs.tag_name }} build/**/hal_st-*.zip --clobber
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.24)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}")

if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(HALST_STANDALONE On)
Expand Down Expand Up @@ -40,6 +42,7 @@ else()
set(HALST_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL")
endif()

add_subdirectory(tools)
add_subdirectory(st)
add_subdirectory(hal_st)
add_subdirectory(hal_st_lwip)
Expand All @@ -53,6 +56,32 @@ if (HALST_STANDALONE)
emil_folderize_all_targets()
endif()

if (EMIL_HOST_BUILD)
install(EXPORT halstTargets
FILE hal_stTargets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hal_st
)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
# When cross-compiling for a 32-bit architecture and re-using host tooling from a 64-bit architecture
# ARCH_INDEPENDENT is necessary here. See: https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html.
ARCH_INDEPENDENT
)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
endif()

set(CPACK_GENERATOR "ZIP;TGZ")
set(CPACK_SOURCE_IGNORE_FILES ".vs/;.git/;build/")
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
Expand Down
5 changes: 5 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/hal_stTargets.cmake")

check_required_components(TableGenerator)
12 changes: 4 additions & 8 deletions hal_st/stm32fxxx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include(table_generator.cmake)

add_library(hal_st.stm32fxxx STATIC)
emil_build_for(hal_st.stm32fxxx TARGET_MCU_VENDOR st PREREQUISITE_BOOL HALST_STANDALONE)

Expand Down Expand Up @@ -123,17 +125,11 @@ if (TARGET_MCU_VENDOR STREQUAL st)
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PinoutTableDefault.cpp GeneratePinoutTableCpp.xsl "${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PinoutTableDefaultStructure.xml")
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PinoutTableDefault.hpp GeneratePinoutTableHpp.xsl "${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PinoutTableDefaultStructure.xml")

generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PeripheralTableStructure.xml GeneratePeripheralTableStructure.xsl $<IF:$<STREQUAL:${TARGET_MCU_FAMILY},stm32wbxx>,PeripheralTableWbxx.xml,PeripheralTableFxxx.xml>
--stringparam mcu-document ${mcu_xml})
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PeripheralTable.cpp GeneratePeripheralTableCpp.xsl "${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PeripheralTableStructure.xml")
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PeripheralTable.hpp GeneratePeripheralTableHpp.xsl "${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PeripheralTableStructure.xml")

target_sources(hal_st.stm32fxxx PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PinoutTableDefaultStructure.xml"
"${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PinoutTableDefault.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PinoutTableDefault.hpp"
"${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PeripheralTableStructure.xml"
"${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PeripheralTable.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PeripheralTable.hpp"
)

st_table_generator(hal_st.stm32fxxx ${mcu_xml})
endif()
2 changes: 1 addition & 1 deletion hal_st/stm32fxxx/DefaultClockNucleoG070RB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* VDD(V) = 3.3
* Main regulator output voltage = Scale1 mode
*/
void ConfigureDefaultClockNucleo070RB()
void ConfigureDefaultClockNucleoG070RB()
{
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
Expand Down
2 changes: 1 addition & 1 deletion hal_st/stm32fxxx/DefaultClockNucleoG070RB.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef HAL_ST_DEFAULT_CLOCK_HPP
#define HAL_ST_DEFAULT_CLOCK_HPP

void ConfigureDefaultClockNucleo070RB();
void ConfigureDefaultClockNucleoG070RB();

#endif
22 changes: 22 additions & 0 deletions hal_st/stm32fxxx/PeripheralTableG0xx.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<peripherals xmlns:xi="http://www.w3.org/2001/XInclude">
<peripheral name="Uart" type="USART_TypeDef*">
<item name="UART"/>
<item name="USART"/>
<interrupt/>
</peripheral>
<peripheral name="Spi" type="SPI_TypeDef*"><item name="SPI"/><interrupt/></peripheral>
<peripheral name="I2c" type="I2C_TypeDef*"><item name="I2C"/><interrupt/></peripheral>
<peripheral name="Timer" type="TIM_TypeDef*" prefix="TIM">
<item name="TIM1_8"/>
<item name="TIM6_7"/>
<item name="TIM1_8F7"/>
<item name="TIM6_7F7"/>
<item name="TIM1_8F37"/>
<item name="TIM6_7F37"/>
<item name="TIM1_8F77"/>
<item name="TIM6_7F77"/>
</peripheral>
<peripheral name="Adc" type="ADC_TypeDef*"><item name="ADC"/></peripheral>
<peripheral name="Rtc" type="RTC_TypeDef*"><item name="RTC"/></peripheral>
</peripherals>
75 changes: 75 additions & 0 deletions hal_st/stm32fxxx/table_generator.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
function(hal_st_fetch_table_generator)
# This function will first try to use `find_package` to import
# amp-hal-st table generators. If there is an installed version
# of amp-hal-st present those table generators will be used.
# Otherwise the latest hal-st release will be downloaded and those
# table generators will be used instead.
#
# (See: https://cmake.org/cmake/help/latest/module/FetchContent.html#commands)

if (EMIL_HOST_BUILD AND NOT CMAKE_CROSSCOMPILING)
# In a host build where we are not cross-compiling we use the built table generators
return()
endif()

FetchContent_GetProperties(table_generator)
if (table_generator_POPULATED)
return()
endif()

set(hal_st_version "2.1.0") # x-release-please-version

if (CMAKE_HOST_WIN32)
set(os_postfix "win64")
set(host_executable_postfix ".exe")
elseif (CMAKE_HOST_APPLE)
set(os_postfix "Darwin")
elseif (CMAKE_HOST_UNIX)
set(os_postfix "Linux")
else()
message(FATAL_ERROR "No suitable table generators found for ${CMAKE_HOST_SYSTEM_NAME} (${CMAKE_HOST_SYSTEM_PROCESSOR})")
endif()

FetchContent_Declare(table_generator
URL https://github.com/philips-software/amp-hal-st/releases/download/v${hal_st_version}/hal_st-${hal_st_version}-${os_postfix}.zip
FIND_PACKAGE_ARGS NAMES hal_st GLOBAL
)
FetchContent_MakeAvailable(table_generator)

if (NOT ${table_generators_FOUND})
if (NOT TARGET tools.st_table_generator)
add_executable(tools.st_table_generator IMPORTED GLOBAL)
set_target_properties(tools.st_table_generator PROPERTIES
IMPORTED_LOCATION "${table_generators_SOURCE_DIR}/bin/tools.st_table_generator${host_executable_postfix}"
)
endif()
else()
message(STATUS "Using table generator from installed location")
endif()
endfunction()

function(st_table_generator target mcu_xml)
hal_st_fetch_table_generator()

cmake_path(SET generated_dir_tables "generated/stm32fxxx")
cmake_path(ABSOLUTE_PATH generated_dir_tables BASE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} NORMALIZE OUTPUT_VARIABLE generated_dir_tables)

set(generated_files "${generated_dir_tables}/PeripheralTable.cpp" "${generated_dir_tables}/PeripheralTable.hpp")

add_custom_command(
OUTPUT ${generated_files}
COMMAND ${CMAKE_COMMAND} -E make_directory ${generated_dir_tables}
COMMAND tools.st_table_generator "${mcu_xml}" ${generated_dir_tables}
MAIN_DEPENDENCY "${mcu_xml}"
DEPENDS tools.st_table_generator
)

target_sources(${target} PRIVATE
${generated_files}
)

target_include_directories(${target} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
endfunction()
11 changes: 11 additions & 0 deletions st/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ target_compile_definitions(st.hal_driver_stm32g0xx PUBLIC
USE_HAL_DRIVER=1
STM32G0=1
DEVICE_HEADER="stm32g0xx.h"
$<$<STREQUAL:${TARGET_MCU},stm32g030>:STM32G030xx=1>
$<$<STREQUAL:${TARGET_MCU},stm32g031>:STM32G031xx=1>
$<$<STREQUAL:${TARGET_MCU},stm32g041>:STM32G041xx=1>
$<$<STREQUAL:${TARGET_MCU},stm32g050>:STM32G050xx=1>
$<$<STREQUAL:${TARGET_MCU},stm32g051>:STM32G051xx=1>
$<$<STREQUAL:${TARGET_MCU},stm32g061>:STM32G061xx=1>
$<$<STREQUAL:${TARGET_MCU},stm32g070>:STM32G070xx=1>
$<$<STREQUAL:${TARGET_MCU},stm32g071>:STM32G071xx=1>
$<$<STREQUAL:${TARGET_MCU},stm32g081>:STM32G081xx=1>
$<$<STREQUAL:${TARGET_MCU},stm32g0b0>:STM32G0B0xx=1>
$<$<STREQUAL:${TARGET_MCU},stm32g0b1>:STM32G0B1xx=1>
$<$<STREQUAL:${TARGET_MCU},stm32g0c1>:STM32G0C1xx=1>
)

add_hal_driver(st.hal_driver_stm32g4xx STM32G4xx_HAL_Driver CMSIS_STM32G4xx)
Expand Down
2 changes: 2 additions & 0 deletions st/ldscripts/sections.ld
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ SECTIONS

KEEP(*(.isr_vector))
*(.after_vectors .after_vectors.*)
*(.text.Reset_Handler)
*(.text.Default_Handler)
} >FLASH

.inits : ALIGN(4)
Expand Down
1 change: 1 addition & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(st_table_generator)
12 changes: 12 additions & 0 deletions tools/st_table_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if (NOT CMAKE_CROSSCOMPILING)
add_executable(tools.st_table_generator)
install(TARGETS tools.st_table_generator EXPORT halstTargets DESTINATION bin)

target_sources(tools.st_table_generator PRIVATE Main.cpp)

target_link_libraries(tools.st_table_generator PRIVATE
args
hal.generic
infra.syntax
)
endif()
Loading
Loading