我需要使用全部4个串口,串口1,2,3 没有问题,但是串口4只能发送,只要一接收到数据,就马上死机。
这是我的串口4配置。

void USART4_Init()

{

    GPIO_InitTypeDef  GPIO_InitStructure={0};

    USART_InitTypeDef USART_InitStructure={0};

    NVIC_InitTypeDef  NVIC_InitStructure={0};



    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);


   // GPIO_PinRemapConfig(GPIO_PartialRemap_USART4, ENABLE);



    GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;

    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;

    GPIO_Init(GPIOB,&GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1;

    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;

    GPIO_Init(GPIOB,&GPIO_InitStructure);



    USART_InitStructure.USART_BaudRate = 115200;

    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);



    NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);



    USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);

    USART_Cmd(UART4, ENABLE);

}

void UART4_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));

void UART4_IRQHandler(void)

{

    if(USART_GetITStatus(UART4, USART_IT_RXNE) != RESET)

    {
        //处理数据

    }

}


另外,我注意到数据手册上,这个芯片的PB0和PB1,既是 USART4_TX 和 UART4_RX ,又是UART4_TX_1和 UART4_RX_1,那我在不使用同步串口功能时,到底该不该重映射呢?已经尝试过重映射,串口4就完全不工作了。