Initial commit

This commit is contained in:
SocChina2025
2025-05-07 22:22:44 +08:00
commit 7f9bede0c7
131 changed files with 190978 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
Copyright 2022 STMicroelectronics.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,775 @@
/**
******************************************************************************
* @file stm32h5xx_nucleo.c
* @author MCD Application Team
* @brief This file provides set of firmware functions to manage:
* - LEDs and push-button available on STM32H5xx-Nucleo Kit
* from STMicroelectronics
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32h5xx_nucleo.h"
#if defined(__ICCARM__)
#include <LowLevelIOInterface.h>
#endif /* __ICCARM__ */
/** @addtogroup BSP
* @{
*/
/** @addtogroup STM32H5XX_NUCLEO
* @{
*/
/** @addtogroup STM32H5XX_NUCLEO_LOW_LEVEL
* @brief This file provides set of firmware functions to manage Leds and push-button
* available on STM32H5xx-Nucleo Kit from STMicroelectronics.
* @{
*/
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_Private_Defines LOW LEVEL Private Defines
* @{
*/
/**
* @}
*/
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_Private_TypesDefinitions LOW LEVEL Private Typedef
* @{
*/
typedef void (* BSP_EXTI_LineCallback)(void);
/**
* @}
*/
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_Exported_Variables LOW LEVEL Exported Variables
* @{
*/
EXTI_HandleTypeDef hpb_exti[BUTTON_NBR];
#if (USE_BSP_COM_FEATURE > 0)
UART_HandleTypeDef hcom_uart[COM_NBR];
USART_TypeDef *COM_USART[COM_NBR] = {COM1_UART};
#endif /* USE_BSP_COM_FEATURE */
/**
* @}
*/
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_Private_Variables LOW LEVEL Private Variables
* @{
*/
static GPIO_TypeDef *LED_PORT[LED_NBR] =
{
#if defined (USE_NUCLEO_144)
LED1_GPIO_PORT,
#endif /* defined (USE_NUCLEO_144) */
LED2_GPIO_PORT,
#if defined (USE_NUCLEO_144)
LED3_GPIO_PORT
#endif /* defined (USE_NUCLEO_144) */
};
static const uint16_t LED_PIN[LED_NBR] =
{
#if defined (USE_NUCLEO_144)
LED1_PIN,
#endif /* defined (USE_NUCLEO_144) */
LED2_PIN,
#if defined (USE_NUCLEO_144)
LED3_PIN
#endif /* defined (USE_NUCLEO_144) */
};
static GPIO_TypeDef *BUTTON_PORT[BUTTON_NBR] = {BUTTON_USER_GPIO_PORT};
static const uint16_t BUTTON_PIN[BUTTON_NBR] = {BUTTON_USER_PIN};
static const IRQn_Type BUTTON_IRQn[BUTTON_NBR] = {BUTTON_USER_EXTI_IRQ};
#if (USE_BSP_COM_FEATURE > 0)
#if (USE_COM_LOG > 0)
static COM_TypeDef COM_ActiveLogPort = COM1;
#endif /* USE_COM_LOG */
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
static uint32_t IsComMspCbValid[COM_NBR] = {0};
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 1) */
#endif /* USE_BSP_COM_FEATURE */
/**
* @}
*/
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_Private_FunctionPrototypes LOW LEVEL Private functions Prototypes
* @{
*/
static void BUTTON_USER_EXTI_Callback(void);
#if (USE_BSP_COM_FEATURE > 0)
static void COM1_MspInit(UART_HandleTypeDef *huart);
static void COM1_MspDeInit(UART_HandleTypeDef *huart);
#endif /* USE_BSP_COM_FEATURE */
#if defined(__ICCARM__)
/* New definition from EWARM V9, compatible with EWARM8 */
int iar_fputc(int ch);
#define PUTCHAR_PROTOTYPE int iar_fputc(int ch)
#elif defined ( __CC_ARM ) || defined(__ARMCC_VERSION)
/* ARM Compiler 5/6*/
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#elif defined(__GNUC__)
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#endif /* __ICCARM__ */
/**
* @}
*/
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_Exported_Functions LOW LEVEL Exported Functions
* @{
*/
/**
* @brief This method returns the STM32H5XX NUCLEO BSP Driver revision
* @retval version: 0xXYZR (8bits for each decimal, R for RC)
*/
int32_t BSP_GetVersion(void)
{
return (int32_t)STM32H5XX_NUCLEO_BSP_VERSION;
}
/**
* @brief This method returns the board name
* @retval pointer to the board name string
*/
const uint8_t *BSP_GetBoardName(void)
{
return (uint8_t *)STM32H5XX_NUCLEO_BSP_BOARD_NAME;
}
/**
* @brief This method returns the board ID
* @retval pointer to the board name string
*/
const uint8_t *BSP_GetBoardID(void)
{
return (uint8_t *)STM32H5XX_NUCLEO_BSP_BOARD_ID;
}
/**
* @brief Configures LED GPIO.
* @param Led Specifies the Led to be configured.
* This parameter can be one of following parameters:
* @arg LED1
* @arg LED2
* @arg LED3
* @retval BSP status
*/
int32_t BSP_LED_Init(Led_TypeDef Led)
{
int32_t ret = BSP_ERROR_NONE;
GPIO_InitTypeDef gpio_init_structure;
if ((Led != LED2)
#if defined (USE_NUCLEO_144)
&& (Led != LED1) && (Led != LED3)
#endif /* defined (USE_NUCLEO_144) */
)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Enable the GPIO LED Clock */
if (Led == LED2)
{
LED2_GPIO_CLK_ENABLE();
}
#if defined (USE_NUCLEO_144)
else if (Led == LED1)
{
LED1_GPIO_CLK_ENABLE();
}
else
{
LED3_GPIO_CLK_ENABLE();
}
#endif /* defined (USE_NUCLEO_144) */
/* Configure the GPIO_LED pin */
gpio_init_structure.Pin = LED_PIN[Led];
gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
gpio_init_structure.Pull = GPIO_NOPULL;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(LED_PORT[Led], &gpio_init_structure);
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);
}
return ret;
}
/**
* @brief DeInit LEDs.
* @param Led LED to be de-init.
* This parameter can be one of the following values:
* @arg LED1
* @arg LED2
* @arg LED3
* @note Led DeInit does not disable the GPIO clock nor disable the Mfx
* @retval BSP status
*/
int32_t BSP_LED_DeInit(Led_TypeDef Led)
{
int32_t ret = BSP_ERROR_NONE;
GPIO_InitTypeDef gpio_init_structure;
if ((Led != LED2)
#if defined (USE_NUCLEO_144)
&& (Led != LED1) && (Led != LED3)
#endif /* defined (USE_NUCLEO_144) */
)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* Turn off LED */
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);
/* DeInit the GPIO_LED pin */
gpio_init_structure.Pin = LED_PIN[Led];
HAL_GPIO_DeInit(LED_PORT[Led], gpio_init_structure.Pin);
}
return ret;
}
/**
* @brief Turns selected LED On.
* @param Led Specifies the Led to be set on.
* This parameter can be one of following parameters:
* @arg LED1
* @arg LED2
* @arg LED3
* @retval BSP status
*/
int32_t BSP_LED_On(Led_TypeDef Led)
{
int32_t ret = BSP_ERROR_NONE;
if ((Led != LED2)
#if defined (USE_NUCLEO_144)
&& (Led != LED1) && (Led != LED3)
#endif /* defined (USE_NUCLEO_144) */
)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_SET);
}
return ret;
}
/**
* @brief Turns selected LED Off.
* @param Led: Specifies the Led to be set off.
* This parameter can be one of following parameters:
* @arg LED1
* @arg LED2
* @arg LED3
* @retval BSP status
*/
int32_t BSP_LED_Off(Led_TypeDef Led)
{
int32_t ret = BSP_ERROR_NONE;
if ((Led != LED2)
#if defined (USE_NUCLEO_144)
&& (Led != LED1) && (Led != LED3)
#endif /* defined (USE_NUCLEO_144) */
)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);
}
return ret;
}
/**
* @brief Toggles the selected LED.
* @param Led Specifies the Led to be toggled.
* This parameter can be one of following parameters:
* @arg LED1
* @arg LED2
* @arg LED3
* @retval BSP status
*/
int32_t BSP_LED_Toggle(Led_TypeDef Led)
{
int32_t ret = BSP_ERROR_NONE;
if ((Led != LED2)
#if defined (USE_NUCLEO_144)
&& (Led != LED1) && (Led != LED3)
#endif /* defined (USE_NUCLEO_144) */
)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
HAL_GPIO_TogglePin(LED_PORT[Led], LED_PIN[Led]);
}
return ret;
}
/**
* @brief Get the state of the selected LED.
* @param Led LED to get its state
* This parameter can be one of following parameters:
* @arg LED1
* @arg LED2
* @arg LED3
* @retval LED status
*/
int32_t BSP_LED_GetState(Led_TypeDef Led)
{
int32_t ret;
if ((Led != LED2)
#if defined (USE_NUCLEO_144)
&& (Led != LED1) && (Led != LED3)
#endif /* defined (USE_NUCLEO_144) */
)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
ret = (int32_t)HAL_GPIO_ReadPin(LED_PORT [Led], LED_PIN [Led]);
}
return ret;
}
/**
* @brief Configures button GPIO and EXTI Line.
* @param Button Button to be configured
* This parameter can be one of the following values:
* @arg BUTTON_USER: Wakeup Push Button
* @param ButtonMode Button mode
* This parameter can be one of the following values:
* @arg BUTTON_MODE_GPIO: Button will be used as simple IO
* @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line
* with interrupt generation capability
*/
int32_t BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
{
GPIO_InitTypeDef gpio_init_structure;
static BSP_EXTI_LineCallback ButtonCallback[BUTTON_NBR] = {BUTTON_USER_EXTI_Callback};
static uint32_t BSP_BUTTON_PRIO [BUTTON_NBR] = {BSP_BUTTON_USER_IT_PRIORITY};
static const uint32_t BUTTON_EXTI_LINE[BUTTON_NBR] = {BUTTON_USER_EXTI_LINE};
/* Enable the BUTTON clock */
BUTTON_USER_GPIO_CLK_ENABLE();
gpio_init_structure.Pin = BUTTON_PIN [Button];
gpio_init_structure.Pull = GPIO_PULLDOWN;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
if (ButtonMode == BUTTON_MODE_GPIO)
{
/* Configure Button pin as input */
gpio_init_structure.Mode = GPIO_MODE_INPUT;
HAL_GPIO_Init(BUTTON_PORT [Button], &gpio_init_structure);
}
else /* (ButtonMode == BUTTON_MODE_EXTI) */
{
/* Configure Button pin as input with External interrupt */
gpio_init_structure.Mode = GPIO_MODE_IT_RISING;
HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
(void)HAL_EXTI_GetHandle(&hpb_exti[Button], BUTTON_EXTI_LINE[Button]);
(void)HAL_EXTI_RegisterCallback(&hpb_exti[Button], HAL_EXTI_COMMON_CB_ID, ButtonCallback[Button]);
/* Enable and set Button EXTI Interrupt to the lowest priority */
HAL_NVIC_SetPriority((BUTTON_IRQn[Button]), BSP_BUTTON_PRIO[Button], 0x00);
HAL_NVIC_EnableIRQ((BUTTON_IRQn[Button]));
}
return BSP_ERROR_NONE;
}
/**
* @brief Push Button DeInit.
* @param Button Button to be configured
* This parameter can be one of the following values:
* @arg BUTTON_USER: Wakeup Push Button
* @note PB DeInit does not disable the GPIO clock
*/
int32_t BSP_PB_DeInit(Button_TypeDef Button)
{
GPIO_InitTypeDef gpio_init_structure;
gpio_init_structure.Pin = BUTTON_PIN[Button];
HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
return BSP_ERROR_NONE;
}
/**
* @brief Returns the selected button state.
* @param Button Button to be checked
* This parameter can be one of the following values:
* @arg BUTTON_USER: Wakeup Push Button
* @retval The Button GPIO pin value (GPIO_PIN_RESET = button pressed)
*/
int32_t BSP_PB_GetState(Button_TypeDef Button)
{
return (int32_t)HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
}
/**
* @brief BSP Button IRQ handler
* @param Button Can only be BUTTON_USER
* @retval None
*/
void BSP_PB_IRQHandler(Button_TypeDef Button)
{
HAL_EXTI_IRQHandler(&hpb_exti[Button]);
}
/**
* @brief BSP Push Button callback
* @param Button Specifies the pin connected EXTI line
* @retval None
*/
__weak void BSP_PB_Callback(Button_TypeDef Button)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(Button);
/* This function should be implemented by the user application.
It is called into this driver when an event on Button is triggered. */
}
#if (USE_BSP_COM_FEATURE > 0)
/**
* @brief Configures COM port.
* @param COM COM port to be configured.
* This parameter can be COM1
* @param COM_Init Pointer to a UART_HandleTypeDef structure that contains the
* configuration information for the specified USART peripheral.
* @retval BSP error code
*/
int32_t BSP_COM_Init(COM_TypeDef COM, COM_InitTypeDef *COM_Init)
{
int32_t ret = BSP_ERROR_NONE;
if (COM >= COM_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
#if (USE_HAL_UART_REGISTER_CALLBACKS == 0)
/* Init the UART Msp */
COM1_MspInit(&hcom_uart[COM]);
#else
if (IsComMspCbValid[COM] == 0U)
{
if (BSP_COM_RegisterDefaultMspCallbacks(COM) != BSP_ERROR_NONE)
{
return BSP_ERROR_MSP_FAILURE;
}
}
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 0) */
if (MX_USART_Init(&hcom_uart[COM], COM_Init) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
return ret;
}
/**
* @brief DeInit COM port.
* @param COM COM port to be configured.
* This parameter can be COM1
* @retval BSP status
*/
int32_t BSP_COM_DeInit(COM_TypeDef COM)
{
int32_t ret = BSP_ERROR_NONE;
if (COM >= COM_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
/* USART configuration */
hcom_uart[COM].Instance = COM_USART[COM];
#if (USE_HAL_UART_REGISTER_CALLBACKS == 0)
COM1_MspDeInit(&hcom_uart[COM]);
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 0) */
if (HAL_UART_DeInit(&hcom_uart[COM]) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
}
return ret;
}
/**
* @brief Configures COM port.
* @param huart USART handle
* @param COM_Init Pointer to a UART_HandleTypeDef structure that contains the
* configuration information for the specified USART peripheral.
* @retval HAL error code
*/
__weak HAL_StatusTypeDef MX_USART_Init(UART_HandleTypeDef *huart, MX_UART_InitTypeDef *COM_Init)
{
/* USART configuration */
huart->Instance = COM_USART[COM1];
huart->Init.BaudRate = COM_Init->BaudRate;
huart->Init.Mode = UART_MODE_TX_RX;
huart->Init.Parity = (uint32_t)COM_Init->Parity;
huart->Init.WordLength = (uint32_t)COM_Init->WordLength;
huart->Init.StopBits = (uint32_t)COM_Init->StopBits;
huart->Init.HwFlowCtl = (uint32_t)COM_Init->HwFlowCtl;
huart->Init.OverSampling = UART_OVERSAMPLING_8;
huart->Init.ClockPrescaler = UART_PRESCALER_DIV1;
return HAL_UART_Init(huart);
}
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
/**
* @brief Register Default COM Msp Callbacks
* @param COM COM port to be configured.
* This parameter can be COM1
* @retval BSP status
*/
int32_t BSP_COM_RegisterDefaultMspCallbacks(COM_TypeDef COM)
{
int32_t ret = BSP_ERROR_NONE;
if (COM >= COM_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
__HAL_UART_RESET_HANDLE_STATE(&hcom_uart[COM]);
/* Register default MspInit/MspDeInit Callback */
if (HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPINIT_CB_ID, COM1_MspInit) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else if (HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPDEINIT_CB_ID, COM1_MspDeInit) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
IsComMspCbValid[COM] = 1U;
}
}
/* BSP status */
return ret;
}
/**
* @brief Register COM Msp Callback registering
* @param COM COM port to be configured.
* This parameter can be COM1
* @param Callbacks pointer to COM1 MspInit/MspDeInit callback functions
* @retval BSP status
*/
int32_t BSP_COM_RegisterMspCallbacks(COM_TypeDef COM, BSP_COM_Cb_t *Callback)
{
int32_t ret = BSP_ERROR_NONE;
if (COM >= COM_NBR)
{
ret = BSP_ERROR_WRONG_PARAM;
}
else
{
__HAL_UART_RESET_HANDLE_STATE(&hcom_uart[COM]);
/* Register MspInit/MspDeInit Callbacks */
if (HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPINIT_CB_ID, Callback->pMspInitCb) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else if (HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPDEINIT_CB_ID, Callback->pMspDeInitCb) != HAL_OK)
{
ret = BSP_ERROR_PERIPH_FAILURE;
}
else
{
IsComMspCbValid[COM] = 1U;
}
}
/* BSP status */
return ret;
}
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
#if (USE_COM_LOG > 0)
/**
* @brief Select the active COM port.
* @param COM COM port to be activated.
* This parameter can be COM1
* @retval BSP status
*/
int32_t BSP_COM_SelectLogPort(COM_TypeDef COM)
{
if (COM_ActiveLogPort != COM)
{
COM_ActiveLogPort = COM;
}
return BSP_ERROR_NONE;
}
#if defined(__ICCARM__)
size_t __write(int file, unsigned char const *ptr, size_t len)
{
size_t idx;
unsigned char const *pdata = ptr;
for (idx = 0; idx < len; idx++)
{
iar_fputc((int)*pdata);
pdata++;
}
return len;
}
#endif /* __ICCARM__ */
/**
* @brief Redirect console output to COM
*/
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&hcom_uart [COM_ActiveLogPort], (uint8_t *) &ch, 1, COM_POLL_TIMEOUT);
return ch;
}
#endif /* USE_COM_LOG */
#endif /* USE_BSP_COM_FEATURE */
/**
* @}
*/
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_Private_Functions LOW LEVEL Private functions
* @{
*/
/**
* @brief Key EXTI line detection callbacks.
* @retval BSP status
*/
static void BUTTON_USER_EXTI_Callback(void)
{
BSP_PB_Callback(BUTTON_USER);
}
#if (USE_BSP_COM_FEATURE > 0)
/**
* @brief Initializes UART MSP.
* @param huart UART handle
* @retval BSP status
*/
static void COM1_MspInit(UART_HandleTypeDef *huart)
{
GPIO_InitTypeDef gpio_init_structure;
/* Prevent unused argument(s) compilation warning */
UNUSED(huart);
/* Enable GPIO clock */
COM1_TX_GPIO_CLK_ENABLE();
COM1_RX_GPIO_CLK_ENABLE();
/* Enable USART clock */
COM1_CLK_ENABLE();
/* Configure USART Tx as alternate function */
gpio_init_structure.Pin = COM1_TX_PIN;
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Alternate = COM1_TX_AF;
HAL_GPIO_Init(COM1_TX_GPIO_PORT, &gpio_init_structure);
/* Configure USART Rx as alternate function */
gpio_init_structure.Pin = COM1_RX_PIN;
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Alternate = COM1_RX_AF;
HAL_GPIO_Init(COM1_RX_GPIO_PORT, &gpio_init_structure);
}
/**
* @brief Initialize USART Msp part
* @param huart UART handle
* @retval BSP status
*/
static void COM1_MspDeInit(UART_HandleTypeDef *huart)
{
GPIO_InitTypeDef gpio_init_structure;
/* Prevent unused argument(s) compilation warning */
UNUSED(huart);
/* COM GPIO pin configuration */
gpio_init_structure.Pin = COM1_TX_PIN;
HAL_GPIO_DeInit(COM1_TX_GPIO_PORT, gpio_init_structure.Pin);
gpio_init_structure.Pin = COM1_RX_PIN;
HAL_GPIO_DeInit(COM1_RX_GPIO_PORT, gpio_init_structure.Pin);
/* Disable USART clock */
COM1_CLK_DISABLE();
}
#endif /* USE_BSP_COM_FEATURE */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/

View File

@@ -0,0 +1,364 @@
/**
******************************************************************************
* @file stm32h5xx_nucleo.h
* @author MCD Application Team
* @brief This file contains definitions for:
* - LEDs and push-button available on STM32H5xx-Nucleo Kit
* from STMicroelectronics
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32H5XX_NUCLEO_H
#define STM32H5XX_NUCLEO_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32h5xx_nucleo_conf.h"
#include "stm32h5xx_nucleo_errno.h"
#if (USE_BSP_COM_FEATURE > 0)
#include <stdio.h>
#endif /* USE_BSP_COM_FEATURE */
/** @addtogroup BSP
* @{
*/
/** @defgroup STM32H5XX_NUCLEO STM32H5XX_NUCLEO
* @{
*/
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL LOW LEVEL
* @{
*/
/**
* @brief Define for STM32H5XX_NUCLEO board
*/
#if !defined (USE_STM32H5XX_NUCLEO)
#define USE_STM32H5XX_NUCLEO
#endif /* !defined (USE_STM32H5XX_NUCLEO) */
#if !defined (USE_NUCLEO_144) && !defined (USE_NUCLEO_64) && !defined (USE_NUCLEO_H533RE)
#error "Board Pin number not defined!! Add USE_NUCLEO_144 or USE_NUCLEO_64 or USE_NUCLEO_H533RE define in conf.h file"
#endif /* (!defined (USE_NUCLEO_144) && !defined (USE_NUCLEO_64) && !defined (USE_NUCLEO_H533RE)) */
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_Exported_Types LOW LEVEL Exported Types
* @{
*/
typedef enum
{
#if defined (USE_NUCLEO_144)
LED1 = 0,
LED_GREEN = LED1,
LED2 = 1,
LED_YELLOW = LED2,
LED3 = 2,
LED_RED = LED3,
#else
LED2 = 0,
LED_GREEN = LED2,
#endif /* defined (USE_NUCLEO_144) */
LED_NBR
} Led_TypeDef;
typedef enum
{
BUTTON_USER = 0U,
BUTTON_NBR
} Button_TypeDef;
typedef enum
{
BUTTON_MODE_GPIO = 0,
BUTTON_MODE_EXTI = 1
} ButtonMode_TypeDef;
#if (USE_BSP_COM_FEATURE > 0)
typedef enum
{
COM1 = 0U,
COM_NBR
} COM_TypeDef;
typedef enum
{
COM_STOPBITS_1 = UART_STOPBITS_1,
COM_STOPBITS_2 = UART_STOPBITS_2,
} COM_StopBitsTypeDef;
typedef enum
{
COM_PARITY_NONE = UART_PARITY_NONE,
COM_PARITY_EVEN = UART_PARITY_EVEN,
COM_PARITY_ODD = UART_PARITY_ODD,
} COM_ParityTypeDef;
typedef enum
{
COM_HWCONTROL_NONE = UART_HWCONTROL_NONE,
COM_HWCONTROL_RTS = UART_HWCONTROL_RTS,
COM_HWCONTROL_CTS = UART_HWCONTROL_CTS,
COM_HWCONTROL_RTS_CTS = UART_HWCONTROL_RTS_CTS,
} COM_HwFlowCtlTypeDef;
typedef enum
{
COM_WORDLENGTH_7B = UART_WORDLENGTH_7B,
COM_WORDLENGTH_8B = UART_WORDLENGTH_8B,
COM_WORDLENGTH_9B = UART_WORDLENGTH_9B,
} COM_WordLengthTypeDef;
typedef struct
{
uint32_t BaudRate;
COM_WordLengthTypeDef WordLength;
COM_StopBitsTypeDef StopBits;
COM_ParityTypeDef Parity;
COM_HwFlowCtlTypeDef HwFlowCtl;
} COM_InitTypeDef;
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
typedef struct
{
void (* pMspInitCb)(UART_HandleTypeDef *);
void (* pMspDeInitCb)(UART_HandleTypeDef *);
} BSP_COM_Cb_t;
#endif /* (USE_HAL_UART_REGISTER_CALLBACKS == 1) */
#define MX_UART_InitTypeDef COM_InitTypeDef
#endif /* USE_BSP_COM_FEATURE */
/**
* @}
*/
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_Exported_Constants LOW LEVEL Exported Constants
* @{
*/
/**
* @brief STM32H5XX NUCLEO BSP Driver version number V1.1.0
*/
#define STM32H5XX_NUCLEO_BSP_VERSION_MAIN (0x01U) /*!< [31:24] main version */
#define STM32H5XX_NUCLEO_BSP_VERSION_SUB1 (0x01U) /*!< [23:16] sub1 version */
#define STM32H5XX_NUCLEO_BSP_VERSION_SUB2 (0x00U) /*!< [15:8] sub2 version */
#define STM32H5XX_NUCLEO_BSP_VERSION_RC (0x00U) /*!< [7:0] release candidate */
#define STM32H5XX_NUCLEO_BSP_VERSION ((STM32H5XX_NUCLEO_BSP_VERSION_MAIN << 24)\
|(STM32H5XX_NUCLEO_BSP_VERSION_SUB1 << 16)\
|(STM32H5XX_NUCLEO_BSP_VERSION_SUB2 << 8 )\
|(STM32H5XX_NUCLEO_BSP_VERSION_RC))
#if defined (USE_NUCLEO_144)
#define STM32H5XX_NUCLEO_BSP_BOARD_NAME "NUCLEO-H563ZI";
#define STM32H5XX_NUCLEO_BSP_BOARD_ID "MB1404A";
#else
#if defined (USE_NUCLEO_H533RE)
#define STM32H5XX_NUCLEO_BSP_BOARD_NAME "NUCLEO-H533RE";
#define STM32H5XX_NUCLEO_BSP_BOARD_ID "MB1814C";
#else
#define STM32H5XX_NUCLEO_BSP_BOARD_NAME "NUCLEO-H503RB";
#define STM32H5XX_NUCLEO_BSP_BOARD_ID "MB1814B";
#endif /* USE_NUCLEO_H533RE */
#endif /* USE_NUCLEO_144 */
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_LED LOW LEVEL LED
* @{
*/
#if defined (USE_NUCLEO_144)
#define LED1_PIN GPIO_PIN_0
#define LED1_GPIO_PORT GPIOB
#define LED1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define LED1_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
#define LED2_PIN GPIO_PIN_4
#define LED2_GPIO_PORT GPIOF
#define LED2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define LED2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOF_CLK_DISABLE()
#define LED3_PIN GPIO_PIN_4
#define LED3_GPIO_PORT GPIOG
#define LED3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
#define LED3_GPIO_CLK_DISABLE() __HAL_RCC_GPIOG_CLK_DISABLE()
#else /* defined (USE_NUCLEO_64) */
#define LED2_PIN GPIO_PIN_5
#define LED2_GPIO_PORT GPIOA
#define LED2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define LED2_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
#endif /* defined (USE_NUCLEO_144) */
/**
* @}
*/
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_BUTTON LOW LEVEL BUTTON
* @{
*/
/* Button state */
#define BUTTON_RELEASED 0U
#define BUTTON_PRESSED 1U
/**
* @brief Key push-button
*/
#define BUTTON_USER_PIN GPIO_PIN_13
#define BUTTON_USER_GPIO_PORT GPIOC
#define BUTTON_USER_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define BUTTON_USER_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
#define BUTTON_USER_EXTI_IRQ EXTI13_IRQn
#define BUTTON_USER_EXTI_LINE EXTI_LINE_13
/**
* @}
*/
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_COM LOW LEVEL COM
* @{
*/
/**
* @brief Definition for COM port1, connected to USART3
*/
#if (USE_BSP_COM_FEATURE > 0)
#if defined (USE_NUCLEO_144)
#define COM1_UART USART3
#define COM1_CLK_ENABLE() __HAL_RCC_USART3_CLK_ENABLE()
#define COM1_CLK_DISABLE() __HAL_RCC_USART3_CLK_DISABLE()
#define COM1_TX_PIN GPIO_PIN_8
#define COM1_TX_GPIO_PORT GPIOD
#define COM1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define COM1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
#define COM1_TX_AF GPIO_AF7_USART3
#define COM1_RX_PIN GPIO_PIN_9
#define COM1_RX_GPIO_PORT GPIOD
#define COM1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define COM1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
#define COM1_RX_AF GPIO_AF7_USART3
#else /* defined (USE_NUCLEO_64) */
#if defined (USE_NUCLEO_H533RE)
#define COM1_UART USART2
#define COM1_CLK_ENABLE() __HAL_RCC_USART2_CLK_ENABLE()
#define COM1_CLK_DISABLE() __HAL_RCC_USART2_CLK_DISABLE()
#define COM1_TX_PIN GPIO_PIN_2
#define COM1_TX_GPIO_PORT GPIOA
#define COM1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define COM1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
#define COM1_TX_AF GPIO_AF7_USART2
#define COM1_RX_PIN GPIO_PIN_3
#define COM1_RX_GPIO_PORT GPIOA
#define COM1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define COM1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
#define COM1_RX_AF GPIO_AF7_USART2
#else
#define COM1_UART USART3
#define COM1_CLK_ENABLE() __HAL_RCC_USART3_CLK_ENABLE()
#define COM1_CLK_DISABLE() __HAL_RCC_USART3_CLK_DISABLE()
#define COM1_TX_PIN GPIO_PIN_4
#define COM1_TX_GPIO_PORT GPIOA
#define COM1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define COM1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
#define COM1_TX_AF GPIO_AF13_USART3
#define COM1_RX_PIN GPIO_PIN_3
#define COM1_RX_GPIO_PORT GPIOA
#define COM1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define COM1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
#define COM1_RX_AF GPIO_AF13_USART3
#endif /* defined (USE_NUCLEO_64) */
#endif /* defined (USE_NUCLEO_H533RE) */
#define COM_POLL_TIMEOUT 1000
#endif /* USE_BSP_COM_FEATURE */
/**
* @}
*/
/**
* @}
*/
/** @addtogroup STM32H5XX_NUCLEO_LOW_LEVEL_Exported_Variables
* @{
*/
extern EXTI_HandleTypeDef hpb_exti[];
#if (USE_BSP_COM_FEATURE > 0)
extern UART_HandleTypeDef hcom_uart[];
extern USART_TypeDef *COM_USART[];
#endif /* USE_BSP_COM_FEATURE */
/**
* @}
*/
/** @defgroup STM32H5XX_NUCLEO_LOW_LEVEL_Exported_FunctionsPrototypes LOW LEVEL Exported Functions Prototypes
* @{
*/
int32_t BSP_GetVersion(void);
const uint8_t *BSP_GetBoardName(void);
const uint8_t *BSP_GetBoardID(void);
int32_t BSP_LED_Init(Led_TypeDef Led);
int32_t BSP_LED_DeInit(Led_TypeDef Led);
int32_t BSP_LED_On(Led_TypeDef Led);
int32_t BSP_LED_Off(Led_TypeDef Led);
int32_t BSP_LED_Toggle(Led_TypeDef Led);
int32_t BSP_LED_GetState(Led_TypeDef Led);
int32_t BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
int32_t BSP_PB_DeInit(Button_TypeDef Button);
int32_t BSP_PB_GetState(Button_TypeDef Button);
void BSP_PB_IRQHandler(Button_TypeDef Button);
void BSP_PB_Callback(Button_TypeDef Button);
#if (USE_BSP_COM_FEATURE > 0)
int32_t BSP_COM_Init(COM_TypeDef COM, COM_InitTypeDef *COM_Init);
int32_t BSP_COM_DeInit(COM_TypeDef COM);
#if (USE_COM_LOG > 0)
int32_t BSP_COM_SelectLogPort(COM_TypeDef COM);
#endif /* USE_COM_LOG */
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
int32_t BSP_COM_RegisterDefaultMspCallbacks(COM_TypeDef COM);
int32_t BSP_COM_RegisterMspCallbacks(COM_TypeDef COM, BSP_COM_Cb_t *Callback);
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
HAL_StatusTypeDef MX_USART_Init(UART_HandleTypeDef *huart, MX_UART_InitTypeDef *COM_Init);
#endif /* USE_BSP_COM_FEATURE */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32H5XX_NUCLEO_H */

View File

@@ -0,0 +1,45 @@
/**
******************************************************************************
* @file stm32h5xx_nucleo_errno.h
* @author MCD Application Team
* @brief Error Code.
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32H5XX_NUCLEO_ERRNO_H
#define STM32H5XX_NUCLEO_ERRNO_H
#ifdef __cplusplus
extern "C" {
#endif
/* Common Error codes */
#define BSP_ERROR_NONE 0
#define BSP_ERROR_NO_INIT -1
#define BSP_ERROR_WRONG_PARAM -2
#define BSP_ERROR_BUSY -3
#define BSP_ERROR_PERIPH_FAILURE -4
#define BSP_ERROR_COMPONENT_FAILURE -5
#define BSP_ERROR_UNKNOWN_FAILURE -6
#define BSP_ERROR_UNKNOWN_COMPONENT -7
#define BSP_ERROR_BUS_FAILURE -8
#define BSP_ERROR_CLOCK_FAILURE -9
#define BSP_ERROR_MSP_FAILURE -10
#define BSP_ERROR_FEATURE_NOT_SUPPORTED -11
#ifdef __cplusplus
}
#endif
#endif /* STM32H5XX_NUCLEO_ERRNO_H */