单片机学习小组
直播中

吴湛

9年用户 896经验值
擅长:可编程逻辑
私信 关注

RT_Thread Nano如何添加控制台?

RT_Thread Nano如何添加控制台?

回帖(1)

潘千

2022-2-16 10:59:16
前言:

上一节,我们完成了GD32VF103在RT_Thread Nano上的移植,本节我们为其增加控制台输出功能,以及通过FinSH组件和用户交互功能。
一、基础知识

1.FinS H简介
RT-Thread FinSH 是 RT-Thread 的命令行组件(shell),提供一套供用户在命令行调用的操作接口,主要用于调试或查看系统信息。它可以使用串口 / 以太网 / USB 等与 PC 机进行通信,使用 FinSH 组件基本命令的效果图如下所示:
二、添加步骤

1.导入工程
将上一节内容进行复制,修改.project中工程名字为lesson3

重新import进来新的工程

2.控制台输出
适配号控制台输出,就可以使用RT_Thread中rt_kprintf()函数进行串口信息的打印,方便调试Bug、获取系统当前运行状态。
(1) 串口初始化
在gd32vf102c_start.c中定义调试串口初始化函数void uart_debug_init(void),同时在gd32vf103c_start.h中声明。

然后再board.c中rt_hw_board_init()函数中调用uart_debug_init()。


(2) 实现 rt_hw_console_output


在gd32vf102c_start.c文件中,实现rt_hw_console_output如下:


void rt_hw_console_output(const char str)
{
    rt_enter_critical();
    while(str != '')
    {
        if ('n' == *str)
        {
            usart_data_transmit(EVAL_COM0, 'r' );
            while ( usart_flag_get(EVAL_COM0, USART_FLAG_TBE)== RESET);
        }
        usart_data_transmit(EVAL_COM0, (uint8_t) *str++ );
        while ( usart_flag_get(EVAL_COM0, USART_FLAG_TBE)== RESET);
    }
    rt_exit_critical();
}


(3) 修改main.c中led_process_thread_entry函数


void led_process_thread_entry(void parameter)
{
    rt_err_t ret = RT_EOK;
    while(1)
    {
        / insert 500 ms delay /
        rt_thread_mdelay(500);
        / toggle the LED /
        gpio_bit_write(GPIOA, GPIO_PIN_1, (bit_status)(1-gpio_input_bit_get(GPIOA, GPIO_PIN_1)));
        rt_kprintf("toggle the LEDrn");
        / insert 500 ms delay */
        rt_thread_mdelay(500);
    }
}


函数,每隔1S打印一次数据。
三、运行结果

运行结果如下所示
举报

更多回帖

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