在 rt-thread studio中新建工程
可以控制台串口,发送角和接收脚
但是我的发送和接收需要进行引脚复用,之前测试可用的的keil 工程代码如下
使用的是PA0到UART4和PA6到USART2 这种设置在Studio中如何配置
void Uart_A72_PortInit(void) {
//初始化串口需要配置使用的 IO 端口、微控制器内部串口的设置、串口接收的中断优先级分配
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_TypeDefStructure;
//开启外设时钟 GPIOA,GPIOD,GPIOI
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOI, ENABLE);
//开启外设时钟 USART2或者UART4
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 | RCC_APB1Periph_UART4, ENABLE);
//配置发送脚脚和接收脚
GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_UART4);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOI, &GPIO_InitStructure);
Hard_Uart_MurtSel(0); //选择与A72相连的端口
//__________________________________________________________________________
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_Tx;
USART_Init(UART4, &USART_InitStructure);
USART_Cmd(UART4, ENABLE);
NVIC_TypeDefStructure.NVIC_IRQChannel = UART4_IRQn;
NVIC_TypeDefStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_TypeDefStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_TypeDefStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_TypeDefStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_Mode = USART_Mode_Rx;
USART_Init(USART2, &USART_InitStructure);
NVIC_TypeDefStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_TypeDefStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_TypeDefStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_TypeDefStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_TypeDefStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_Cmd(USART2, ENABLE);
}