/** ****************************************************************************** * @file py32f040_hal_msp.c * @author MCU Application Team * @brief This file provides code for the MSP Initialization * and de-Initialization codes. ****************************************************************************** * @attention * *

© Copyright (c) 2023 Puya Semiconductor Co. * All rights reserved.

* * This software component is licensed by Puya 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 * ****************************************************************************** * @attention * *

© Copyright (c) 2016 STMicroelectronics. * All rights reserved.

* * 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 * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* External functions --------------------------------------------------------*/ /** * @brief Initialize global MSP. */ void HAL_MspInit(void) { __HAL_RCC_SYSCFG_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE(); } /** * @brief UART MSP 初始化 * @param huart UART 句柄 * @retval None * @note USART3: PB10=TX(AF4), PB11=RX(AF4) — 见 PY32F040 手册 PortB AF 表 */ void HAL_UART_MspInit(UART_HandleTypeDef *huart) { GPIO_InitTypeDef gpio_init = {0}; if (huart->Instance == JB_USART) { JB_USART_CLK_ENABLE(); JB_USART_TX_GPIO_CLK_ENABLE(); JB_USART_RX_GPIO_CLK_ENABLE(); /* PB10 ------> USART3_TX */ gpio_init.Pin = JB_USART_TX_PIN; gpio_init.Mode = GPIO_MODE_AF_PP; gpio_init.Pull = GPIO_PULLUP; gpio_init.Speed = GPIO_SPEED_FREQ_HIGH; gpio_init.Alternate = JB_USART_TX_AF; HAL_GPIO_Init(JB_USART_TX_GPIO_PORT, &gpio_init); /* PB11 ------> USART3_RX */ gpio_init.Pin = JB_USART_RX_PIN; gpio_init.Alternate = JB_USART_RX_AF; HAL_GPIO_Init(JB_USART_RX_GPIO_PORT, &gpio_init); HAL_NVIC_SetPriority(JB_USART_IRQn, 1, 0); HAL_NVIC_EnableIRQ(JB_USART_IRQn); } } /** * @brief UART MSP 反初始化 * @param huart UART 句柄 * @retval None */ void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) { if (huart->Instance == JB_USART) { __HAL_RCC_USART3_CLK_DISABLE(); HAL_GPIO_DeInit(JB_USART_TX_GPIO_PORT, JB_USART_TX_PIN); HAL_GPIO_DeInit(JB_USART_RX_GPIO_PORT, JB_USART_RX_PIN); HAL_NVIC_DisableIRQ(JB_USART_IRQn); } } /** * @brief TIM Base MSP 初始化 * @param htim TIM 句柄 * @retval None * @note TIM6 用作协议层 1ms 节拍 */ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) { if (htim->Instance == JB_TIMER) { JB_TIMER_CLK_ENABLE(); HAL_NVIC_SetPriority(JB_TIMER_IRQn, 2, 0); HAL_NVIC_EnableIRQ(JB_TIMER_IRQn); } } /** * @brief TIM Base MSP 反初始化 * @param htim TIM 句柄 * @retval None */ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim) { if (htim->Instance == JB_TIMER) { __HAL_RCC_TIM6_CLK_DISABLE(); HAL_NVIC_DisableIRQ(JB_TIMER_IRQn); } } /************************ (C) COPYRIGHT Puya *****END OF FILE******************/