完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
在 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); } |
|
相关推荐
3个回答
|
|
cubeMX重新配置一下各个串口及其复用引脚即可
|
|
|
|
需要使用stm32cubemx进行芯片针脚配置。
|
|
|
|
如果你想设置控制台的串口和引脚,可以直接在创建工程的时候,修改成你实际的引脚即可。
如果你是在程序中使用UART设备的时候,想复用引脚,直接在studio中打开cubemx工程进行串口引脚配置,保存生成代码即可正常使用,不用自己再写配置代码。 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
AI模型部署边缘设备的奇妙之旅:边缘端设备的局域网视频流传输方案
1734 浏览 0 评论
1591 浏览 0 评论
AI模型部署边缘设备的奇妙之旅:如何在边缘端部署OpenCV
6885 浏览 0 评论
tms320280021 adc采样波形,为什么adc采样频率上来波形就不好了?
1914 浏览 0 评论
5229 浏览 0 评论
79794 浏览 21 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-2-24 20:25 , Processed in 0.418425 second(s), Total 41, Slave 36 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191