Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
RT-Thread移植
rt_kprintf
GD32
GD32F350G上移植RT-thread,rt_kprintf不能输出打印信息
发布于 2023-09-12 22:58:00 浏览:928
订阅该版
我自己根据网上的步骤在GD32F350G8裸机上移植RT_thread,程序可以跑进main函数,但是用rt_kprintf不能输出打印信息。平台Keil uVision5,我自己搞了一星期还是解决不了,请帮帮我,谢谢。附件是完整的工程文件。 [GD32F350-GD-EVAL.zip](https://club.rt-thread.org/file_download/e88174acd60933a0) ```c /* * File : drv_usart.c * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2009, RT-Thread Development Team * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://www.rt-thread.org/license/LICENSE * * Change Logs: * Date Author Notes * 2009-01-05 Bernard the first version * 2018-04-19 misonyo Porting for gd32f30x */ #include
#include
#include
#include "gd32f3x0.h" #ifdef RT_USING_SERIAL #define UART_ENABLE_IRQ(n) NVIC_EnableIRQ((n)) #define UART_DISABLE_IRQ(n) NVIC_DisableIRQ((n)) #if !defined(RT_USING_USART0) && !defined(RT_USING_USART1) && \ !defined(RT_USING_USART2) && !defined(RT_USING_UART3) && \ !defined(RT_USING_UART4) #error "Please define at least one UARTx" #endif #include
/* GD32 uart driver */ // Todo: compress uart info struct gd32_uart { uint32_t uart_periph; IRQn_Type irqn; rcu_periph_enum per_clk; rcu_periph_enum tx_gpio_clk; rcu_periph_enum rx_gpio_clk; uint32_t tx_port; uint16_t tx_pin; uint32_t rx_port; uint16_t rx_pin; struct rt_serial_device * serial; char *device_name; }; static void uart_isr(struct rt_serial_device *serial); #if defined(RT_USING_USART0) struct rt_serial_device serial0; void USART0_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); uart_isr(&serial0); /* leave interrupt */ rt_interrupt_leave(); } #endif /* RT_USING_USART0 */ #if defined(RT_USING_USART1) struct rt_serial_device serial1; void USART1_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); uart_isr(&serial1); /* leave interrupt */ rt_interrupt_leave(); } #endif /* RT_USING_UART1 */ #if defined(RT_USING_USART2) struct rt_serial_device serial2; void USART2_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); uart_isr(&serial2); /* leave interrupt */ rt_interrupt_leave(); } #endif /* RT_USING_UART2 */ #if defined(RT_USING_UART3) struct rt_serial_device serial3; void UART3_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); uart_isr(&serial3); /* leave interrupt */ rt_interrupt_leave(); } #endif /* RT_USING_UART3 */ #if defined(RT_USING_UART4) struct rt_serial_device serial4; void UART4_IRQHandler(void) { /* enter interrupt */ rt_interrupt_enter(); uart_isr(&serial4); /* leave interrupt */ rt_interrupt_leave(); } #endif /* RT_USING_UART4 */ static const struct gd32_uart uarts[] = { #ifdef RT_USING_USART0 { USART0, // uart peripheral index USART0_IRQn, // uart iqrn RCU_USART0, RCU_GPIOA, RCU_GPIOA, // periph clock, tx gpio clock, rt gpio clock GPIOA, GPIO_PIN_9, // tx port, tx pin GPIOA, GPIO_PIN_10, // rx port, rx pin &serial0, "uart0", }, #endif #ifdef RT_USING_USART1 { USART0, // uart peripheral index USART1_IRQn, // uart iqrn RCU_USART1, RCU_GPIOA, RCU_GPIOA, // periph clock, tx gpio clock, rt gpio clock GPIOA, GPIO_PIN_2, // tx port, tx pin GPIOA, GPIO_PIN_3, // rx port, rx pin &serial1, "uart1", }, #endif #ifdef RT_USING_USART2 { USART2, // uart peripheral index USART2_IRQn, // uart iqrn RCU_USART2, RCU_GPIOB, RCU_GPIOB, // periph clock, tx gpio clock, rt gpio clock GPIOB, GPIO_PIN_10, // tx port, tx alternate, tx pin GPIOB, GPIO_PIN_11, // rx port, rx alternate, rx pin &serial2, "uart2", }, #endif #ifdef RT_USING_UART3 { UART3, // uart peripheral index UART3_IRQn, // uart iqrn RCU_UART3, RCU_GPIOC, RCU_GPIOC, // periph clock, tx gpio clock, rt gpio clock GPIOC, GPIO_PIN_10, // tx port, tx alternate, tx pin GPIOC, GPIO_PIN_11, // rx port, rx alternate, rx pin &serial3, "uart3", }, #endif #ifdef RT_USING_UART4 { UART4, // uart peripheral index UART4_IRQn, // uart iqrn RCU_UART4, RCU_GPIOC, RCU_GPIOD, // periph clock, tx gpio clock, rt gpio clock GPIOC, GPIO_PIN_12, // tx port, tx alternate, tx pin GPIOD, GPIO_PIN_2, // rx port, rx alternate, rx pin &serial4, "uart4", }, #endif }; /** * @brief UART MSP Initialization * This function configures the hardware resources used in this example: * - Peripheral's clock enable * - Peripheral's GPIO Configuration * - NVIC configuration for UART interrupt request enable * @param uart: UART handle pointer * @retval None */ void gd32_uart_gpio_init(struct gd32_uart *uart) { /* enable USART clock */ rcu_periph_clock_enable(uart->tx_gpio_clk); rcu_periph_clock_enable(uart->rx_gpio_clk); rcu_periph_clock_enable(uart->per_clk); /* connect port to USARTx_Tx */ //gpio_init(uart->tx_port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, uart->tx_pin); gpio_mode_set(uart->tx_port, GPIO_MODE_AF, GPIO_PUPD_PULLUP, uart->tx_pin); gpio_output_options_set(uart->tx_port, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, uart->tx_pin); /* connect port to USARTx_Rx */ //gpio_init(uart->rx_port, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, uart->rx_pin); gpio_mode_set(uart->rx_port, GPIO_MODE_AF, GPIO_PUPD_PULLUP, uart->rx_pin); gpio_output_options_set(uart->rx_port, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, uart->rx_pin); NVIC_SetPriority(uart->irqn, 0); NVIC_EnableIRQ(uart->irqn); } static rt_err_t gd32_configure(struct rt_serial_device *serial, struct serial_configure *cfg) { struct gd32_uart *uart; RT_ASSERT(serial != RT_NULL); RT_ASSERT(cfg != RT_NULL); uart = (struct gd32_uart *)serial->parent.user_data; gd32_uart_gpio_init(uart); usart_baudrate_set(uart->uart_periph, cfg->baud_rate); switch (cfg->data_bits) { case DATA_BITS_9: usart_word_length_set(uart->uart_periph, USART_WL_9BIT); break; default: usart_word_length_set(uart->uart_periph, USART_WL_8BIT); break; } switch (cfg->stop_bits) { case STOP_BITS_2: usart_stop_bit_set(uart->uart_periph, USART_STB_2BIT); break; default: usart_stop_bit_set(uart->uart_periph, USART_STB_1BIT); break; } switch (cfg->parity) { case PARITY_ODD: usart_parity_config(uart->uart_periph, USART_PM_ODD); break; case PARITY_EVEN: usart_parity_config(uart->uart_periph, USART_PM_EVEN); break; default: usart_parity_config(uart->uart_periph, USART_PM_NONE); break; } usart_receive_config(uart->uart_periph, USART_RECEIVE_ENABLE); usart_transmit_config(uart->uart_periph, USART_TRANSMIT_ENABLE); usart_enable(uart->uart_periph); return RT_EOK; } static rt_err_t gd32_control(struct rt_serial_device *serial, int cmd, void *arg) { struct gd32_uart *uart; RT_ASSERT(serial != RT_NULL); uart = (struct gd32_uart *)serial->parent.user_data; switch (cmd) { case RT_DEVICE_CTRL_CLR_INT: /* disable rx irq */ NVIC_DisableIRQ(uart->irqn); /* disable interrupt */ usart_interrupt_disable(uart->uart_periph, USART_INT_RBNE); break; case RT_DEVICE_CTRL_SET_INT: /* enable rx irq */ NVIC_EnableIRQ(uart->irqn); /* enable interrupt */ usart_interrupt_enable(uart->uart_periph, USART_INT_RBNE); break; } return RT_EOK; } static int gd32_putc(struct rt_serial_device *serial, char ch) { struct gd32_uart *uart; RT_ASSERT(serial != RT_NULL); uart = (struct gd32_uart *)serial->parent.user_data; usart_data_transmit(uart->uart_periph, ch); while((usart_flag_get(uart->uart_periph, USART_FLAG_TC) == RESET)); return 1; } static int gd32_getc(struct rt_serial_device *serial) { int ch; struct gd32_uart *uart; RT_ASSERT(serial != RT_NULL); uart = (struct gd32_uart *)serial->parent.user_data; ch = -1; if (usart_flag_get(uart->uart_periph, USART_FLAG_RBNE) != RESET) ch = usart_data_receive(uart->uart_periph); return ch; } /** * Uart common interrupt process. This need add to uart ISR. * * @param serial serial device */ static void uart_isr(struct rt_serial_device *serial) { struct gd32_uart *uart = (struct gd32_uart *) serial->parent.user_data; RT_ASSERT(uart != RT_NULL); /* UART in mode Receiver */ if ((usart_interrupt_flag_get(uart->uart_periph, USART_INT_FLAG_RBNE) != RESET) && (usart_flag_get(uart->uart_periph, USART_FLAG_RBNE) != RESET)) { rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND); /* Clear RXNE interrupt flag */ usart_flag_clear(uart->uart_periph, USART_FLAG_RBNE); } } static const struct rt_uart_ops gd32_uart_ops = { gd32_configure, gd32_control, gd32_putc, gd32_getc }; int gd32_hw_usart_init(void) { struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; int i; for (i = 0; i < sizeof(uarts) / sizeof(uarts[0]); i++) { uarts[i].serial->ops = &gd32_uart_ops; uarts[i].serial->config = config; /* register UART device */ rt_hw_serial_register(uarts[i].serial, uarts[i].device_name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, (void *)&uarts[i]); } return 0; } INIT_BOARD_EXPORT(gd32_hw_usart_init); #endif ```
查看更多
5
个回答
默认排序
按发布时间排序
张世争
2023-09-13
学以致用
能 debug 调试吗,看看终端与串口设备是否对应
weimo
2023-09-13
这家伙很懒,什么也没写!
可能原因1:console使用的设备名称可能错了,在menuconfig里面修改一下 ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20230913/1bc09a9dcec8475be76d94b1d62cd747.png) 可能原因2:uart驱动的引脚没配好,需要查原理图 ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20230913/5079602cb587e6ba2c6536e797713906.png)
道友
2023-09-13
这家伙很懒,什么也没写!
参考一下第10步,希望对你有帮助 【手把手教你移植RT-Thread系统 - CSDN App】http://t.csdn.cn/CIQbU
CrazyH
2023-09-19
这家伙很懒,什么也没写!
检查下串口驱动吧
qzx198888
2023-11-23
这家伙很懒,什么也没写!
我用的华芯微特的 也遇到了一样的问题 ,可以输出rt -thread图像,但是用rk_printf就是不能打出日志
撰写答案
登录
注册新账号
关注者
0
被浏览
928
关于作者
彼岸牧风
这家伙很懒,什么也没写!
提问
7
回答
1
被采纳
0
关注TA
发私信
相关问题
1
rt_kprintf问题,拔掉串口系统就不运行了么?
2
rt_kprintf打印异常
3
开启C++功能后,rt_kprintf和单步调试功能无法使用
4
大家有什么好用的方法开关串口打印吗
5
rt_kprintf 格式描述符
6
怎么实现printf函数打印浮点数?
7
rt_kprintf串口打印信息有时出现乱码,有时候又是正常的
8
GD32E230k开发板,打开终端窗口中最后一行是这样的,是什么问题,怎么解决?
9
rt_thread studio rt_kprintf输出中文乱码?
10
关于rt_kprintf无法显示浮点数
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
【RT-Thread】【ci】【scons】将ci.attachconfig.yml和scons结合使用
2
Rt-thread中OTA下载后,bootloader不搬程序
3
ulog 日志 LOG_HEX 输出时间改为本地日期时间
4
在RT-Thread Studio中构建前执行python命令
5
研究一了一段时间RTT,直接标准版上手太难,想用nano,但又舍不得组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
I2C_IIC
ESP8266
UART
WIZnet_W5500
ota在线升级
cubemx
PWM
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
SFUD
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
xusiwei1236
8
个答案
2
次被采纳
踩姑娘的小蘑菇
1
个答案
2
次被采纳
用户名由3_15位
9
个答案
1
次被采纳
bernard
4
个答案
1
次被采纳
RTT_逍遥
3
个答案
1
次被采纳
本月文章贡献
聚散无由
2
篇文章
15
次点赞
catcatbing
2
篇文章
5
次点赞
Wade
2
篇文章
4
次点赞
Ghost_Girls
1
篇文章
7
次点赞
xiaorui
1
篇文章
2
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部