2021-07-16 12:22:35 +02:00
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
******************************************************************************
|
|
|
|
* @file stm32h7xx_nucleo.c
|
|
|
|
* @author MCD Application Team
|
|
|
|
* @brief This file provides set of firmware functions to manage:
|
|
|
|
* - LEDs and push-button available on STM32H7xx-Nucleo Kit
|
|
|
|
* from STMicroelectronics
|
|
|
|
******************************************************************************
|
|
|
|
* @attention
|
|
|
|
*
|
|
|
|
* <h2><center>© Copyright (c) 2018 STMicroelectronics.
|
|
|
|
* All rights reserved.</center></h2>
|
|
|
|
*
|
|
|
|
* This software component is licensed by ST under BSD 3-Clause license,
|
|
|
|
* the "License"; You may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at:
|
|
|
|
* opensource.org/licenses/BSD-3-Clause
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
|
#include "stm32h7xx_nucleo.h"
|
|
|
|
|
|
|
|
/** @addtogroup BSP
|
2022-05-27 02:17:19 +02:00
|
|
|
* @{
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
/** @addtogroup STM32H7XX_NUCLEO
|
2022-05-27 02:17:19 +02:00
|
|
|
* @{
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
/** @addtogroup STM32H7XX_NUCLEO_LOW_LEVEL
|
2022-05-27 02:17:19 +02:00
|
|
|
* @brief This file provides set of firmware functions to manage Leds and
|
|
|
|
* push-button available on STM32H7xx-Nucleo Kit from STMicroelectronics.
|
|
|
|
* @{
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Private_Defines LOW LEVEL Private
|
|
|
|
* Defines
|
|
|
|
* @{
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Private_TypesDefinitions LOW LEVEL
|
|
|
|
* Private Typedef
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
typedef void (*BSP_EXTI_LineCallback)(void);
|
2021-07-16 12:22:35 +02:00
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Exported_Variables LOW LEVEL Exported
|
|
|
|
* Variables
|
|
|
|
* @{
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
EXTI_HandleTypeDef hpb_exti[BUTTONn];
|
|
|
|
#if (USE_BSP_COM_FEATURE > 0)
|
|
|
|
UART_HandleTypeDef hcom_uart[COMn];
|
2022-05-27 02:17:19 +02:00
|
|
|
USART_TypeDef *COM_USART[COMn] = {COM1_UART};
|
2021-07-16 12:22:35 +02:00
|
|
|
#endif
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Private_Variables LOW LEVEL Private
|
|
|
|
* Variables
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
static GPIO_TypeDef *LED_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT,
|
2021-07-16 12:22:35 +02:00
|
|
|
LED3_GPIO_PORT};
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
static const uint16_t LED_PIN[LEDn] = {LED1_PIN, LED2_PIN, LED3_PIN};
|
2021-07-16 12:22:35 +02:00
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
static GPIO_TypeDef *BUTTON_PORT[BUTTONn] = {BUTTON_USER_GPIO_PORT};
|
2021-07-16 12:22:35 +02:00
|
|
|
static const uint16_t BUTTON_PIN[BUTTONn] = {BUTTON_USER_PIN};
|
|
|
|
static const IRQn_Type BUTTON_IRQn[BUTTONn] = {BUTTON_USER_EXTI_IRQn};
|
|
|
|
|
|
|
|
#if (USE_BSP_COM_FEATURE > 0)
|
2022-05-27 02:17:19 +02:00
|
|
|
#if (USE_COM_LOG > 0)
|
|
|
|
static COM_TypeDef COM_ActiveLogPort = COM1;
|
|
|
|
#endif
|
|
|
|
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
|
|
|
|
static uint32_t IsComMspCbValid[COMn] = {0};
|
|
|
|
#endif
|
2021-07-16 12:22:35 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Private_FunctionPrototypes LOW LEVEL
|
|
|
|
* Private functions Prototypes
|
|
|
|
* @{
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
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
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Exported_Functions LOW LEVEL Exported
|
|
|
|
* Functions
|
|
|
|
* @{
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @brief This method returns the STM32H7XX NUCLEO BSP Driver revision
|
|
|
|
* @retval version: 0xXYZR (8bits for each decimal, R for RC)
|
|
|
|
*/
|
|
|
|
int32_t BSP_GetVersion(void) { return (int32_t)STM32H7XX_NUCLEO_BSP_VERSION; }
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
int32_t ret = BSP_ERROR_NONE;
|
2022-05-27 02:17:19 +02:00
|
|
|
GPIO_InitTypeDef gpio_init_structure;
|
2021-07-16 12:22:35 +02:00
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if ((Led != LED1) && (Led != LED2) && (Led != LED3)) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_WRONG_PARAM;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
2021-07-16 12:22:35 +02:00
|
|
|
/* Enable the GPIO LED Clock */
|
2022-05-27 02:17:19 +02:00
|
|
|
if (Led == LED1) {
|
2021-07-16 12:22:35 +02:00
|
|
|
LED1_GPIO_CLK_ENABLE();
|
2022-05-27 02:17:19 +02:00
|
|
|
} else if (Led == LED2) {
|
2021-07-16 12:22:35 +02:00
|
|
|
LED2_GPIO_CLK_ENABLE();
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
2021-07-16 12:22:35 +02:00
|
|
|
LED3_GPIO_CLK_ENABLE();
|
|
|
|
}
|
|
|
|
/* Configure the GPIO_LED pin */
|
2022-05-27 02:17:19 +02:00
|
|
|
gpio_init_structure.Pin = LED_PIN[Led];
|
|
|
|
gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
|
|
|
|
gpio_init_structure.Pull = GPIO_NOPULL;
|
2021-07-16 12:22:35 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
int32_t ret = BSP_ERROR_NONE;
|
2022-05-27 02:17:19 +02:00
|
|
|
GPIO_InitTypeDef gpio_init_structure;
|
2021-07-16 12:22:35 +02:00
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if ((Led != LED1) && (Led != LED2) && (Led != LED3)) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_WRONG_PARAM;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
2021-07-16 12:22:35 +02:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
int32_t ret = BSP_ERROR_NONE;
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if ((Led != LED1) && (Led != LED2) && (Led != LED3)) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_WRONG_PARAM;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
2021-07-16 12:22:35 +02:00
|
|
|
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_SET);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
int32_t ret = BSP_ERROR_NONE;
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if ((Led != LED1) && (Led != LED2) && (Led != LED3)) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_WRONG_PARAM;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
2021-07-16 12:22:35 +02:00
|
|
|
HAL_GPIO_WritePin(LED_PORT[Led], LED_PIN[Led], GPIO_PIN_RESET);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
int32_t ret = BSP_ERROR_NONE;
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if ((Led != LED1) && (Led != LED2) && (Led != LED3)) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_WRONG_PARAM;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
2021-07-16 12:22:35 +02:00
|
|
|
HAL_GPIO_TogglePin(LED_PORT[Led], LED_PIN[Led]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
int32_t ret;
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if ((Led != LED1) && (Led != LED2) && (Led != LED3)) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_WRONG_PARAM;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
|
|
|
ret = (int32_t)HAL_GPIO_ReadPin(LED_PORT[Led], LED_PIN[Led]);
|
2021-07-16 12:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
GPIO_InitTypeDef gpio_init_structure;
|
2022-05-27 02:17:19 +02:00
|
|
|
static BSP_EXTI_LineCallback ButtonCallback[BUTTONn] = {
|
|
|
|
BUTTON_USER_EXTI_Callback};
|
|
|
|
static uint32_t BSP_BUTTON_PRIO[BUTTONn] = {BSP_BUTTON_USER_IT_PRIORITY};
|
2021-07-16 12:22:35 +02:00
|
|
|
static const uint32_t BUTTON_EXTI_LINE[BUTTONn] = {BUTTON_USER_EXTI_LINE};
|
|
|
|
|
|
|
|
/* Enable the BUTTON clock */
|
|
|
|
BUTTON_USER_GPIO_CLK_ENABLE();
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
gpio_init_structure.Pin = BUTTON_PIN[Button];
|
2021-07-16 12:22:35 +02:00
|
|
|
gpio_init_structure.Pull = GPIO_PULLDOWN;
|
|
|
|
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if (ButtonMode == BUTTON_MODE_GPIO) {
|
2021-07-16 12:22:35 +02:00
|
|
|
/* Configure Button pin as input */
|
|
|
|
gpio_init_structure.Mode = GPIO_MODE_INPUT;
|
2022-05-27 02:17:19 +02:00
|
|
|
HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
|
|
|
|
} else /* (ButtonMode == BUTTON_MODE_EXTI) */
|
2021-07-16 12:22:35 +02:00
|
|
|
{
|
|
|
|
/* 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]);
|
2022-05-27 02:17:19 +02:00
|
|
|
(void)HAL_EXTI_RegisterCallback(&hpb_exti[Button], HAL_EXTI_COMMON_CB_ID,
|
|
|
|
ButtonCallback[Button]);
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
return (int32_t)HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @brief BSP Button IRQ handler
|
|
|
|
* @param Button Can only be BUTTON_USER
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
void BSP_PB_IRQHandler(Button_TypeDef Button) {
|
2021-07-16 12:22:35 +02:00
|
|
|
HAL_EXTI_IRQHandler(&hpb_exti[Button]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @brief BSP Push Button callback
|
|
|
|
* @param Button Specifies the pin connected EXTI line
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
__weak void BSP_PB_Callback(Button_TypeDef Button) {
|
2021-07-16 12:22:35 +02:00
|
|
|
/* 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)
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
int32_t ret = BSP_ERROR_NONE;
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if (COM >= COMn) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_WRONG_PARAM;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
2021-07-16 12:22:35 +02:00
|
|
|
#if (USE_HAL_UART_REGISTER_CALLBACKS == 0)
|
|
|
|
/* Init the UART Msp */
|
|
|
|
COM1_MspInit(&hcom_uart[COM]);
|
|
|
|
#else
|
2022-05-27 02:17:19 +02:00
|
|
|
if (IsComMspCbValid[COM] == 0U) {
|
|
|
|
if (BSP_COM_RegisterDefaultMspCallbacks(COM) != BSP_ERROR_NONE) {
|
2021-07-16 12:22:35 +02:00
|
|
|
return BSP_ERROR_MSP_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if (MX_USART3_Init(&hcom_uart[COM], COM_Init) != HAL_OK) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_PERIPH_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
int32_t ret = BSP_ERROR_NONE;
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if (COM >= COMn) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_WRONG_PARAM;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
2021-07-16 12:22:35 +02:00
|
|
|
/* 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) */
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if (HAL_UART_DeInit(&hcom_uart[COM]) != HAL_OK) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_PERIPH_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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_USART3_Init(UART_HandleTypeDef *huart,
|
|
|
|
MX_UART_InitTypeDef *COM_Init) {
|
2021-07-16 12:22:35 +02:00
|
|
|
/* USART configuration */
|
2022-05-27 02:17:19 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
return HAL_UART_Init(huart);
|
2021-07-16 12:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
int32_t ret = BSP_ERROR_NONE;
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if (COM >= COMn) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_WRONG_PARAM;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
2021-07-16 12:22:35 +02:00
|
|
|
__HAL_UART_RESET_HANDLE_STATE(&hcom_uart[COM]);
|
|
|
|
|
|
|
|
/* Register default MspInit/MspDeInit Callback */
|
2022-05-27 02:17:19 +02:00
|
|
|
if (HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPINIT_CB_ID,
|
|
|
|
COM1_MspInit) != HAL_OK) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_PERIPH_FAILURE;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else if (HAL_UART_RegisterCallback(&hcom_uart[COM],
|
|
|
|
HAL_UART_MSPDEINIT_CB_ID,
|
|
|
|
COM1_MspDeInit) != HAL_OK) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_PERIPH_FAILURE;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
2021-07-16 12:22:35 +02:00
|
|
|
IsComMspCbValid[COM] = 1U;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* BSP status */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
int32_t ret = BSP_ERROR_NONE;
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
if (COM >= COMn) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_WRONG_PARAM;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
2021-07-16 12:22:35 +02:00
|
|
|
__HAL_UART_RESET_HANDLE_STATE(&hcom_uart[COM]);
|
|
|
|
|
|
|
|
/* Register MspInit/MspDeInit Callbacks */
|
2022-05-27 02:17:19 +02:00
|
|
|
if (HAL_UART_RegisterCallback(&hcom_uart[COM], HAL_UART_MSPINIT_CB_ID,
|
|
|
|
Callback->pMspInitCb) != HAL_OK) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_PERIPH_FAILURE;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else if (HAL_UART_RegisterCallback(&hcom_uart[COM],
|
|
|
|
HAL_UART_MSPDEINIT_CB_ID,
|
|
|
|
Callback->pMspDeInitCb) != HAL_OK) {
|
2021-07-16 12:22:35 +02:00
|
|
|
ret = BSP_ERROR_PERIPH_FAILURE;
|
2022-05-27 02:17:19 +02:00
|
|
|
} else {
|
2021-07-16 12:22:35 +02:00
|
|
|
IsComMspCbValid[COM] = 1U;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* BSP status */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
|
|
|
|
|
|
|
|
#if (USE_COM_LOG > 0)
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @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) {
|
2021-07-16 12:22:35 +02:00
|
|
|
COM_ActiveLogPort = COM;
|
|
|
|
}
|
|
|
|
return BSP_ERROR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @brief Redirect console output to COM
|
|
|
|
*/
|
|
|
|
#ifdef __GNUC__
|
|
|
|
int __io_putchar(int ch)
|
|
|
|
#else
|
|
|
|
int fputc(int ch, FILE *f)
|
|
|
|
#endif /* __GNUC__ */
|
2021-07-16 12:22:35 +02:00
|
|
|
{
|
2022-05-27 02:17:19 +02:00
|
|
|
HAL_UART_Transmit(&hcom_uart[COM_ActiveLogPort], (uint8_t *)&ch, 1,
|
|
|
|
COM_POLL_TIMEOUT);
|
2021-07-16 12:22:35 +02:00
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
#endif /* USE_COM_LOG */
|
|
|
|
#endif /* USE_BSP_COM_FEATURE */
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
/** @defgroup STM32H7XX_NUCLEO_LOW_LEVEL_Private_Functions LOW LEVEL Private
|
|
|
|
* functions
|
|
|
|
* @{
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @brief Key EXTI line detection callbacks.
|
|
|
|
* @retval BSP status
|
|
|
|
*/
|
|
|
|
static void BUTTON_USER_EXTI_Callback(void) { BSP_PB_Callback(BUTTON_USER); }
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
#if (USE_BSP_COM_FEATURE > 0)
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @brief Initializes UART MSP.
|
|
|
|
* @param huart UART handle
|
|
|
|
* @retval BSP status
|
|
|
|
*/
|
|
|
|
static void COM1_MspInit(UART_HandleTypeDef *huart) {
|
2021-07-16 12:22:35 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @brief Initialize USART3 Msp part
|
|
|
|
* @param huart UART handle
|
|
|
|
* @retval BSP status
|
|
|
|
*/
|
|
|
|
static void COM1_MspDeInit(UART_HandleTypeDef *huart) {
|
|
|
|
GPIO_InitTypeDef gpio_init_structure;
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
/* Prevent unused argument(s) compilation warning */
|
|
|
|
UNUSED(huart);
|
|
|
|
|
|
|
|
/* COM GPIO pin configuration */
|
2022-05-27 02:17:19 +02:00
|
|
|
gpio_init_structure.Pin = COM1_TX_PIN;
|
2021-07-16 12:22:35 +02:00
|
|
|
HAL_GPIO_DeInit(COM1_TX_GPIO_PORT, gpio_init_structure.Pin);
|
|
|
|
|
2022-05-27 02:17:19 +02:00
|
|
|
gpio_init_structure.Pin = COM1_RX_PIN;
|
2021-07-16 12:22:35 +02:00
|
|
|
HAL_GPIO_DeInit(COM1_RX_GPIO_PORT, gpio_init_structure.Pin);
|
|
|
|
|
|
|
|
/* Disable USART clock */
|
|
|
|
COM1_CLK_DISABLE();
|
|
|
|
}
|
|
|
|
#endif /* USE_BSP_COM_FEATURE */
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
/**
|
2022-05-27 02:17:19 +02:00
|
|
|
* @}
|
|
|
|
*/
|
2021-07-16 12:22:35 +02:00
|
|
|
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|