STM32
直播中

王银喜

7年用户 2317经验值
私信 关注
[问答]

请问一下stm32串口4要怎样才能进入HardFault_Handler中断呢

请问一下STM32串口4要怎样才能进入HardFault_Handler中断呢?

回帖(1)

王鹏

2021-12-9 14:39:02
把工程包含的文件startup_stm32f10x_md.s替换成startup_stm32f10x_hd.s就行了
前提是初始化函数没有问题  

void USART4_config(unsigned int BaudRate)
{
        GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  USART_InitTypeDef USART_InitStructure;
   
  /* Enable the USART2 Pins Software Remapping */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
   
   
  /* Configure USART2 Rx (PC.11) as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;   
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
   
  /* Configure USART2 Tx (PC.10) as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
   
  /* Enable the USART2 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = 52;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);   
   
  USART_InitStructure.USART_BaudRate = BaudRate;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;          
   
  USART_Init(UART4, &USART_InitStructure);
  USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);

  USART_Cmd(UART4, ENABLE);
}
举报

更多回帖

发帖
×
20
完善资料,
赚取积分