如何创建工程我的其他文中你面有可以进去查看
1创建线程(以动态方式实现)
1-2创建函数入口

1-2启动函数

main.c文件源码
/*
 * Copyright (c) 2006-2024, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-06-26     RT-Thread    first version
 */
#include <rtthread.h>
#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
#include "main.h"
#include "usart.h"
#include "gpio.h"
// 线程入口函数
static void thread1_entry(void *parameter)
{
    rt_uint32_t count = 0;
    while (1)
    {
        // 线程执行的代码
        HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
        rt_kprintf("Thread count: %d\n", count++);
        rt_thread_delay(500); // 线程延时,单位为毫秒
    }
}
// 线程入口函数
static void thread2_entry(void *parameter)
{
    rt_uint32_t count = 0;
    while (1)
    {
        // 线程执行的代码
        HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_5);
        rt_kprintf("Thread count: %d\n", count++);
        rt_thread_delay(1000); // 线程延时,单位为毫秒
    }
}
int main(void)
{
    int count = 1;
    HAL_Init();
    MX_GPIO_Init();
    MX_USART1_UART_Init();
    //定义线程控制块
            rt_thread_t tid1 = RT_NULL;
            // 动态创建线程
            tid1 = rt_thread_create("dynamic1_thread",
                                   thread1_entry, // 线程入口函数
                                   RT_NULL,     // 线程入口参数
                                   512,         // 线程栈大小
                                   20,          // 线程优先级
                                   5);         // 线程时间片
            if (tid1 != RT_NULL)//判断是否成功创建
            {
                // 启动线程
                rt_thread_startup(tid1);
            }
       //定义线程控制块
       rt_thread_t tid2 = RT_NULL;
       // 动态创建线程
       tid2 = rt_thread_create("dynamic2_thread",
                             thread2_entry, // 线程入口函数
                              RT_NULL,     // 线程入口参数
                              512,         // 线程栈大小
                              25,          // 线程优先级
                              5);         // 线程时间片
       if (tid2 != RT_NULL)//判断是否成功创建
            {
                 // 启动线程
                 rt_thread_startup(tid2);
            }
    while (count++)
    {
        //串口输出
        LOG_D("Hello RT-Thread!");
        //延迟,在延迟期间使用权在内核,由内核分配
        rt_thread_mdelay(1000);
    }
    return RT_EOK;
}
 
效果
串口输出哪一个线程在运行
LED交替闪烁一个1秒闪烁,一个0.5秒闪烁
下面是串口的效果




















