Skip to content

Commit

Permalink
feat: Add new STM32H5 family to hal-st (#365)
Browse files Browse the repository at this point in the history
* Add HAL and CMSIS Drivers

Add HAL and CMSIS drivers from the STM32CubeH5 MCU Firmware Package version v1.3.0.

Add HAL driver v1.3.0 from https://github.com/STMicroelectronics/stm32h5xx_hal_driver
Adds CMSIS core drivers v1.3.0 from https://github.com/STMicroelectronics/STM32CubeH5
Adds CMSIS device drivers v1.3.0 from https://github.com/STMicroelectronics/cmsis_device_h5

* Adjust startup procedure to call into Default_Handler_Forwarded

* Bringup STM32H5xx series

* Add differentiation for ADC channel types

ADC channel types might be P or N which is used for the ADC's differencial function.
Only select the P type channels if present.
  • Loading branch information
fabiangottstein authored Aug 27, 2024
1 parent e99f4ab commit ad0cb38
Show file tree
Hide file tree
Showing 416 changed files with 564,847 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
matrix:
configuration: ["RelWithDebInfo"]
gcc: [ "10.3-2021.10" ]
target: ["stm32wb55", "stm32g070", "stm32g431", "stm32f407", "stm32f429", "stm32f746", "stm32f767", "stm32wba52"]
target: ["stm32wb55", "stm32g070", "stm32g431", "stm32f407", "stm32f429", "stm32f746", "stm32f767", "stm32wba52", "stm32h563", "stm32h573"]
include:
- gcc: "7-2018-q2"
configuration: "RelWithDebInfo"
Expand Down
50 changes: 50 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,26 @@
"TARGET_MCU": "stm32wba52",
"TARGET_MCU_VARIANT": "stm32wba52cg"
}
},
{
"name": "stm32h563",
"inherits": "stm32",
"toolchainFile": "${sourceDir}/build/${presetName}/_deps/emil-src/cmake/toolchain-arm-gcc-m33-fpv5-sp-d16.cmake",
"cacheVariables": {
"TARGET_CORTEX": "m33",
"TARGET_MCU_FAMILY": "stm32h5xx",
"TARGET_MCU": "stm32h563"
}
},
{
"name": "stm32h573",
"inherits": "stm32",
"toolchainFile": "${sourceDir}/build/${presetName}/_deps/emil-src/cmake//toolchain-arm-gcc-m33-fpv5-sp-d16.cmake",
"cacheVariables": {
"TARGET_CORTEX": "m33",
"TARGET_MCU_FAMILY": "stm32h5xx",
"TARGET_MCU": "stm32h573"
}
}
],
"buildPresets": [
Expand Down Expand Up @@ -240,6 +260,36 @@
"name": "stm32wba52-Debug",
"configuration": "Debug",
"configurePreset": "stm32wba52"
},
{
"name": "stm32h563-Debug",
"configuration": "Debug",
"configurePreset": "stm32h563"
},
{
"name": "stm32h563-RelWithDebInfo",
"configuration": "RelWithDebInfo",
"configurePreset": "stm32h563"
},
{
"name": "stm32h563-MinSizeRel",
"configuration": "MinSizeRel",
"configurePreset": "stm32h563"
},
{
"name": "stm32h573-Debug",
"configuration": "Debug",
"configurePreset": "stm32h573"
},
{
"name": "stm32h573-RelWithDebInfo",
"configuration": "RelWithDebInfo",
"configurePreset": "stm32h573"
},
{
"name": "stm32h573-MinSizeRel",
"configuration": "MinSizeRel",
"configurePreset": "stm32h573"
}
],
"testPresets": [
Expand Down
1 change: 1 addition & 0 deletions examples/blink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ emil_build_for(hal_st.blink_nucleo144
TARGET_MCU stm32f429
TARGET_MCU stm32f746
TARGET_MCU stm32f767
TARGET_MCU stm32h563
PREREQUISITE_BOOL HALST_BUILD_EXAMPLES
)

Expand Down
1 change: 1 addition & 0 deletions examples/helloworld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ emil_generate_artifacts(TARGET hal_st.helloworld_nucleo64 LST MAP BIN HEX)
add_executable(hal_st.helloworld_nucleo144 Main.cpp)
emil_build_for(hal_st.helloworld_nucleo144
TARGET_MCU stm32f767
TARGET_MCU stm32h563
PREREQUISITE_BOOL HALST_BUILD_EXAMPLES
)

Expand Down
9 changes: 9 additions & 0 deletions examples/helloworld/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#if defined(STM32WBA)
unsigned int hse_value = 32'000'000;
#elif defined(STM32H5)
unsigned int hse_value = 8'000'000;
#else
unsigned int hse_value = 24'000'000;
#endif
Expand Down Expand Up @@ -51,6 +53,13 @@ int main()

static hal::DmaStm::TransmitStream transmitStream{ dmaStm, hal::DmaChannelId{ 1, 1, GPDMA1_REQUEST_USART1_TX } };
static hal::UartStmDma stLinkUartDma{ transmitStream, 1, stLinkUartTxPin, stLinkUartRxPin };

#elif defined(STM32H5)
static hal::GpioPinStm stLinkUartTxPin{ hal::Port::D, 8 };
static hal::GpioPinStm stLinkUartRxPin{ hal::Port::D, 9 };

static hal::DmaStm::TransmitStream transmitStream{ dmaStm, hal::DmaChannelId{ 1, 1, GPDMA1_REQUEST_USART3_TX } };
static hal::UartStmDma stLinkUartDma{ transmitStream, 3, stLinkUartTxPin, stLinkUartRxPin };
#endif

static services::StreamWriterOnSerialCommunication::WithStorage<64> streamWriterOnSerialCommunication{ stLinkUartDma };
Expand Down
2 changes: 2 additions & 0 deletions hal_st/stm32fxxx/AnalogToDigitalPinStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ namespace hal
, interruptHandler(ADC1_2_IRQn, [this]()
#elif defined(STM32WBA)
, interruptHandler(ADC4_IRQn, [this]()
#elif defined(STM32H5)
, interruptHandler(ADC2_IRQn, [this]()
#else
, interruptHandler(ADC_IRQn, [this]()
#endif
Expand Down
2 changes: 1 addition & 1 deletion hal_st/stm32fxxx/BackupRamStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace hal
{
#if defined(STM32G0)
return infra::MakeRange(&TAMP->BKP0R, &TAMP->BKP4R + 1);
#elif defined(STM32G4) || defined(STM32WBA)
#elif defined(STM32G4) || defined(STM32WBA) || defined(STM32H5)
return infra::MakeRange(&TAMP->BKP0R, &TAMP->BKP15R + 1);
#else
return infra::MakeRange(&peripheralRtc[0]->BKP0R, &peripheralRtc[0]->BKP19R + 1);
Expand Down
30 changes: 20 additions & 10 deletions hal_st/stm32fxxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ target_sources(hal_st.stm32fxxx PRIVATE
$<$<STREQUAL:${TARGET_MCU},stm32f407>:DefaultClockDiscoveryF407G.hpp>
$<$<STREQUAL:${TARGET_MCU},stm32f746>:DefaultClockDiscoveryF746G.cpp>
$<$<STREQUAL:${TARGET_MCU},stm32f746>:DefaultClockDiscoveryF746G.hpp>
$<$<STREQUAL:${TARGET_MCU},stm32h573>:DefaultClockDiscoveryH573I.cpp>
$<$<STREQUAL:${TARGET_MCU},stm32h573>:DefaultClockDiscoveryH573I.hpp>
$<$<STREQUAL:${TARGET_MCU},stm32f429>:DefaultClockNucleoF429ZI.cpp>
$<$<STREQUAL:${TARGET_MCU},stm32f429>:DefaultClockNucleoF429ZI.hpp>
$<$<STREQUAL:${TARGET_MCU},stm32f767>:DefaultClockNucleoF767ZI.cpp>
Expand All @@ -37,6 +39,8 @@ target_sources(hal_st.stm32fxxx PRIVATE
$<$<STREQUAL:${TARGET_MCU},stm32g431>:DefaultClockNucleoG431RB.hpp>
$<$<STREQUAL:${TARGET_MCU},stm32g474>:DefaultClockNucleoG474xxx.cpp>
$<$<STREQUAL:${TARGET_MCU},stm32g474>:DefaultClockNucleoG474xxx.hpp>
$<$<STREQUAL:${TARGET_MCU},stm32h563>:DefaultClockNucleoH563ZI.cpp>
$<$<STREQUAL:${TARGET_MCU},stm32h563>:DefaultClockNucleoH563ZI.hpp>
$<$<STREQUAL:${TARGET_MCU},stm32wb55>:DefaultClockNucleoWB55RG.cpp>
$<$<STREQUAL:${TARGET_MCU},stm32wb55>:DefaultClockNucleoWB55RG.hpp>
$<$<STREQUAL:${TARGET_MCU},stm32wba52>:DefaultClockNucleoWBA52CG.cpp>
Expand All @@ -49,8 +53,8 @@ target_sources(hal_st.stm32fxxx PRIVATE
EthernetMacStm.hpp
EthernetSmiStm.cpp
EthernetSmiStm.hpp
FlashInternalStm.cpp
FlashInternalStm.hpp
$<$<NOT:$<STREQUAL:${TARGET_MCU_FAMILY},stm32h5xx>>:FlashInternalStm.cpp>
$<$<NOT:$<STREQUAL:${TARGET_MCU_FAMILY},stm32h5xx>>:FlashInternalStm.hpp>
GpioStm.cpp
GpioStm.hpp
$<$<NOT:$<STREQUAL:${TARGET_MCU_FAMILY},stm32g0xx>>:I2cStm.cpp>
Expand Down Expand Up @@ -135,6 +139,12 @@ if (TARGET_MCU_VENDOR STREQUAL st)
elseif (TARGET_MCU STREQUAL stm32wba52)
set(gpio_xml "${CMAKE_CURRENT_SOURCE_DIR}/ip/GPIO-STM32WBA52x_gpio_v1_0_Modes.xml")
set(mcu_xml "${CMAKE_CURRENT_SOURCE_DIR}/mcu/STM32WBA52CGUx.xml")
elseif (TARGET_MCU STREQUAL stm32h563)
set(gpio_xml "${CMAKE_CURRENT_SOURCE_DIR}/ip/GPIO-STM32H56x_gpio_v1_0_Modes.xml")
set(mcu_xml "${CMAKE_CURRENT_SOURCE_DIR}/mcu/STM32H563ZITx.xml")
elseif (TARGET_MCU STREQUAL stm32h573)
set(gpio_xml "${CMAKE_CURRENT_SOURCE_DIR}/ip/GPIO-STM32H56x_gpio_v1_0_Modes.xml")
set(mcu_xml "${CMAKE_CURRENT_SOURCE_DIR}/mcu/STM32H573IIKxQ.xml")
else()
message(FATAL_ERROR "Unknown TARGET_MCU \"${TARGET_MCU}\". Please configure HALST_XML_GPIO and HALST_XML_STM32.")
endif()
Expand All @@ -145,19 +155,19 @@ if (TARGET_MCU_VENDOR STREQUAL st)
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PinoutTableDefault.hpp GeneratePinoutTableHpp.xsl "${CMAKE_CURRENT_BINARY_DIR}/generated/stm32fxxx/PinoutTableDefaultStructure.xml")

if (TARGET_MCU_FAMILY STREQUAL stm32wbxx)
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PeripheralTableStructure.xml GeneratePeripheralTableStructure.xsl PeripheralTableWbxx.xml
--stringparam mcu-document ${mcu_xml})
set(peripheral_xml "PeripheralTableWbxx.xml")
elseif (TARGET_MCU_FAMILY STREQUAL stm32wbaxx)
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PeripheralTableStructure.xml GeneratePeripheralTableStructure.xsl PeripheralTableWbaxx.xml
--stringparam mcu-document ${mcu_xml})
set(peripheral_xml "PeripheralTableWbaxx.xml")
elseif (TARGET_MCU_FAMILY STREQUAL stm32g4xx)
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PeripheralTableStructure.xml GeneratePeripheralTableStructure.xsl PeripheralTableGxxx.xml
--stringparam mcu-document ${mcu_xml})
set(peripheral_xml "PeripheralTableGxxx.xml")
elseif (TARGET_MCU_FAMILY STREQUAL stm32h5xx)
set(peripheral_xml "PeripheralTableH5xx.xml")
else()
generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PeripheralTableStructure.xml GeneratePeripheralTableStructure.xsl PeripheralTableFxxx.xml
--stringparam mcu-document ${mcu_xml})
set(peripheral_xml "PeripheralTableFxxx.xml")
endif()

generate_xslt(hal_st.stm32fxxx generated/stm32fxxx/PeripheralTableStructure.xml GeneratePeripheralTableStructure.xsl ${peripheral_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")

Expand Down
52 changes: 52 additions & 0 deletions hal_st/stm32fxxx/DefaultClockDiscoveryH573I.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include DEVICE_HEADER
#include "hal_st/stm32fxxx/DefaultClockDiscoveryH573I.hpp"

/* The system Clock is configured as follows:
* System Clock source = PLL (HSE)
* SYSCLK(Hz) = 250000000
* HCLK(Hz) = 250000000
* AHB Prescaler = 1
* APB1 Prescaler = 1
* APB2 Prescaler = 1
* APB3 Prescaler = 1
* HSE Frequency(Hz) = 25MHz
* VDD(V) = 3.3
* Main regulator output voltage = Scale0 mode
*/
void ConfigureDefaultClockDiscoveryH573I()
{
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
RCC_OscInitTypeDef RCC_OscInitStruct = {};

// Configure the main internal regulator output voltage
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);

while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY))
{
}

// Enable HSE Oscillator and activate PLL with HSE as source
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS_DIGITAL;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLL1_SOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 2; // Divides the 25MHz HSE to 12.5MHz
RCC_OscInitStruct.PLL.PLLN = 40; // Multiplies the 12.5MHz to 500MHz
RCC_OscInitStruct.PLL.PLLP = 2; // Divides the 500MHz to 250MHz for SYSCLK
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1_VCIRANGE_3;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1_VCORANGE_WIDE;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

// Select PLL as system clock source and configure the HCLK, PCLK1, PCLK2 and PCLK3
// clocks dividers
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_PCLK3;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
}
6 changes: 6 additions & 0 deletions hal_st/stm32fxxx/DefaultClockDiscoveryH573I.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef HAL_ST_DEFAULT_CLOCK_HPP
#define HAL_ST_DEFAULT_CLOCK_HPP

void ConfigureDefaultClockDiscoveryH573I();

#endif
52 changes: 52 additions & 0 deletions hal_st/stm32fxxx/DefaultClockNucleoH563ZI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include DEVICE_HEADER
#include "hal_st/stm32fxxx/DefaultClockNucleoH563ZI.hpp"

/* The system Clock is configured as follows:
* System Clock source = PLL (HSE)
* SYSCLK(Hz) = 250000000
* HCLK(Hz) = 250000000
* AHB Prescaler = 1
* APB1 Prescaler = 1
* APB2 Prescaler = 1
* APB3 Prescaler = 1
* HSE Frequency(Hz) = 8MHz
* VDD(V) = 3.3
* Main regulator output voltage = Scale0 mode
*/
void ConfigureDefaultClockNucleoH563ZI()
{
RCC_ClkInitTypeDef RCC_ClkInitStruct = {};
RCC_OscInitTypeDef RCC_OscInitStruct = {};

// Configure the main internal regulator output voltage
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);

while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY))
{
}

// Enable HSE Oscillator and activate PLL with HSE as source
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLL1_SOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 4; // Divides the 8MHz HSI to 2MHz
RCC_OscInitStruct.PLL.PLLN = 250; // Multiplies the 2MHz to 500MHz
RCC_OscInitStruct.PLL.PLLP = 2; // Divides the 500MHz to 250MHz for SYSCLK
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1_VCIRANGE_1;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1_VCORANGE_WIDE;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

// Select PLL as system clock source and configure the HCLK, PCLK1, PCLK2 and PCLK3
// clocks dividers
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_PCLK3;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
}
6 changes: 6 additions & 0 deletions hal_st/stm32fxxx/DefaultClockNucleoH563ZI.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef HAL_ST_DEFAULT_CLOCK_HPP
#define HAL_ST_DEFAULT_CLOCK_HPP

void ConfigureDefaultClockNucleoH563ZI();

#endif
4 changes: 2 additions & 2 deletions hal_st/stm32fxxx/DmaStm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace hal
{
#if defined(STM32G0) || defined(STM32G4) || defined(STM32WB) || defined(STM32WBA)
#if defined(STM32G0) || defined(STM32G4) || defined(STM32WB) || defined(STM32WBA) || defined(STM32H5)
#define DMA_CHANNEL_BASED
#else
#define DMA_STREAM_BASED
Expand Down Expand Up @@ -114,7 +114,7 @@ namespace hal
uint8_t dmaMux;
#endif
uint8_t streamIndex = 0xff;

#ifdef GPDMA1
struct LinkedList
{
Expand Down
Loading

0 comments on commit ad0cb38

Please sign in to comment.