You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

47 regels
1.1 KiB

  1. /**
  2. * @file stm32f4xx_hal_msp.c
  3. * @brief STM32 HAL 底层初始化实现。
  4. * @version 2.0
  5. * @author zengbingjie
  6. * @date 2026-07-29
  7. * @copyright 版权所有 (c) 2026 Xinje Electric。
  8. * @note 修改记录:2.0 配置 USART1 的 Modbus RTU 引脚和中断。
  9. */
  10. #include "main.h"
  11. /**
  12. * @brief 初始化全局 MSP 资源。
  13. */
  14. void HAL_MspInit(void)
  15. {
  16. __HAL_RCC_SYSCFG_CLK_ENABLE();
  17. __HAL_RCC_PWR_CLK_ENABLE();
  18. }
  19. /**
  20. * @brief 初始化 USART1 时钟、引脚和中断。
  21. * @param[in] uartHandle 待初始化的 UART 句柄。
  22. */
  23. void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle)
  24. {
  25. GPIO_InitTypeDef gpioConfig = {0};
  26. if ((uartHandle == NULL) || (uartHandle->Instance != USART1)) {
  27. return;
  28. }
  29. __HAL_RCC_USART1_CLK_ENABLE();
  30. __HAL_RCC_GPIOA_CLK_ENABLE();
  31. gpioConfig.Pin = GPIO_PIN_9 | GPIO_PIN_10;
  32. gpioConfig.Mode = GPIO_MODE_AF_PP;
  33. gpioConfig.Pull = GPIO_NOPULL;
  34. gpioConfig.Speed = GPIO_SPEED_FREQ_HIGH;
  35. gpioConfig.Alternate = GPIO_AF7_USART1;
  36. HAL_GPIO_Init(GPIOA, &gpioConfig);
  37. HAL_NVIC_SetPriority(USART1_IRQn, 6U, 0U);
  38. HAL_NVIC_EnableIRQ(USART1_IRQn);
  39. }