【GD32L233C-START】13、RT-Thread移植到GD32L233

1、安装RT-Thread keil Pack

在这里插入图片描述
或者离线下载安装:
https://www.rt-thread.org/download/mdk/RealThread.RT-Thread.3.1.5.pack
在这里插入图片描述

2、在工程中勾选RTOS中的kernel 和 shell

在这里插入图片描述

3、编译报错

在这里插入图片描述

4、配置时钟#error “TODO 1: OS Tick Configuration.”

//   #error "TODO 1: OS Tick Configuration."
	  
	SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
	NVIC_SetPriority(SysTick_IRQn, 0x00U);
void SysTick_Handler(void)
{
	void rt_os_tick_callback(void);
	rt_os_tick_callback();
}

5、配置串口#error “TODO 2: Enable the hardware uart and config baudrate.”

//#error "TODO 2: Enable the hardware uart and config baudrate."
	
	extern	void SerialInit(void);
    SerialInit();
void SerialInit(void)
{
	/* enable COM GPIO clock */
    rcu_periph_clock_enable(RCU_GPIOA);
    /* enable USART clock */
    rcu_periph_clock_enable(RCU_USART0);

    /* connect port to USART TX */
    gpio_af_set(GPIOA, GPIO_AF_7, GPIO_PIN_9);
    /* connect port to USART RX */
    gpio_af_set(GPIOA, GPIO_AF_7, GPIO_PIN_10);

    /* configure USART TX as alternate function push-pull */
    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_9);
    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_10);

    /* configure USART RX as alternate function push-pull */
    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_10);
    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_10);

    /* USART configure */
    usart_deinit(USART0);
    usart_word_length_set(USART0, USART_WL_8BIT);
    usart_stop_bit_set(USART0, USART_STB_1BIT);
    usart_parity_config(USART0, USART_PM_NONE);
    usart_baudrate_set(USART0, 115200U);
    usart_receive_config(USART0, USART_RECEIVE_ENABLE);
    usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);

    usart_enable(USART0);
}

6、串口输出#error “TODO 3: Output the string ‘str’ through the uart.”

//#error "TODO 3: Output the string 'str' through the uart."
	extern void _rt_hw_console_output( const char *str );
	_rt_hw_console_output(str);
void _rt_hw_console_output( const char *str )
{
	rt_size_t i = 0, size = 0;
    char a = '\r';
    
    size = rt_strlen(str);

    for (i = 0; i < size; i++)
    {
        if (*(str + i) == '\n')
        {
            usart_data_transmit(USART0, (uint32_t )a);
            while((usart_flag_get(USART0, USART_FLAG_TC) == RESET));
        }
        usart_data_transmit(USART0, (uint32_t)*(str + i));
        while((usart_flag_get(USART0, USART_FLAG_TC) == RESET));
    }
}

7、串口输入#error “TODO 4: Read a char from the uart and assign it to ‘ch’.”

//#error "TODO 4: Read a char from the uart and assign it to 'ch'."
	
	extern char _rt_hw_console_getchar(void);
    ch= _rt_hw_console_getchar();
char _rt_hw_console_getchar(void)
{
    /* the initial value of ch must < 0 */
    int ch = -1;

    if (usart_flag_get(USART0, USART_FLAG_RBNE) != RESET)
    {
        ch = usart_data_receive(USART0);
    }
    else
    {
        rt_thread_mdelay(10);
    }
    return ch;
}

8、PendSV_Handler和HardFault_Handler重复定义

在这里插入图片描述
PendSV_HandlerHardFault_Handler两个中断,RT-Thread系统处理,屏蔽掉gd32l23x_it.c中的即可。

9、finsh_config.h未包含

在这里插入图片描述
在rtconfig.h中包含finsh_config.h。

10、创建led线程

static rt_thread_t led_thread = RT_NULL;

void LedInit(void)
{
	/* enable the LED GPIO clock */
    rcu_periph_clock_enable(RCU_GPIOA);
    /* configure LED GPIO pin */
    gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_7 | GPIO_PIN_8);
    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7 | GPIO_PIN_8);

    /* reset LED GPIO pin */
    gpio_bit_reset(GPIOA, GPIO_PIN_7 | GPIO_PIN_8);
}

static void led_thread_entry(void *parameter)
{
    while (1)
    {
		gpio_bit_toggle(GPIOA, GPIO_PIN_7|GPIO_PIN_8);
        rt_thread_mdelay(1000);
		rt_kprintf("led blink\r\n");
    }
}

void LedThreadStart(void)
{
	led_thread = rt_thread_create( "led",     /*线程名字*/                    
									  led_thread_entry,/*线程入口函数*/
									  RT_NULL,/*线程入口函数参数*/
									  256,    /*线程栈大小*/
									  4 ,    /*线程优先级*/
									  20);   /*线程时间片*/
	rt_thread_startup (led_thread);
}

11、硬件初始化

在这里插入图片描述
在rt_hw_board_init函数中包含led初始化函数。

12、在main函数中调用启动led线程

int main(void)
{
    LedThreadStart();

    return 0;
}

13、现象

在这里插入图片描述

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

freemote

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值