#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)```修改rtconfig.h文件,用以完成对rtthread的配置 ```#ifndef RT_CONFIG_H__ #define RT_CONFIG_H__ /* Automatically generated file; DO NOT EDIT. */ /* RT-Thread Configuration */ /* RT-Thread Kernel */ #define RT_NAME_MAX 8 #define RT_ALIGN_SIZE 4 #define RT_THREAD_PRIORITY_32 #define RT_THREAD_PRIORITY_MAX 32 #define RT_TICK_PER_SECOND 100 #define RT_USING_OVERFLOW_CHECK #define RT_USING_HOOK #define RT_IDEL_HOOK_LIST_SIZE 4 #define IDLE_THREAD_STACK_SIZE 256 #define RT_DEBUG #define RT_DEBUG_INIT 1 /* Inter-Thread communication */ #define RT_USING_SEMAPHORE #define RT_USING_MUTEX #define RT_USING_EVENT #define RT_USING_MAILBOX #define RT_USING_MESSAGEQUEUE /* Memory Management */ //#define RT_USING_NOHEAP #define RT_USING_SMALL_MEM #define RT_USING_HEAP /* Kernel Device Object */ #define RT_USING_DEVICE #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 512 #define RT_CONSOLE_DEVICE_NAME "uart1" #define ARCH_ARM #define ARCH_ARM_CORTEX_M #define ARCH_ARM_CORTEX_M3 /* RT-Thread Components */ #define RT_USING_COMPONENTS_INIT #define RT_USING_USER_MAIN #define RT_MAIN_THREAD_STACK_SIZE 2048 #define RT_MAIN_THREAD_PRIORITY 10 /* C++ features */ /* Command shell */ #define RT_USING_FINSH #define FINSH_THREAD_NAME "tshell" #define FINSH_USING_HISTORY #define FINSH_HISTORY_LINES 5 #define FINSH_USING_SYMTAB #define FINSH_USING_DESCRIPTION #define FINSH_THREAD_PRIORITY 20 #define FINSH_THREAD_STACK_SIZE 4096 #define FINSH_CMD_SIZE 80 #define FINSH_USING_MSH #define FINSH_USING_MSH_DEFAULT #define FINSH_ARG_MAX 10 /* Device virtual file system */ /* Device Drivers */ #define RT_USING_DEVICE_IPC #define RT_PIPE_BUFSZ 512 #define RT_USING_SERIAL /* Using USB */ /* POSIX layer and C standard library */ /* Network */ /* Socket abstraction layer */ /* light weight TCP/IP stack */ /* Modbus master and slave stack */ /* AT commands */ /* VBUS(Virtual Software BUS) */ /* Utilities */ /* RT-Thread online packages */ /* IoT - internet of things */ /* Wi-Fi */ /* Marvell WiFi */ /* Wiced WiFi */ /* security packages */ /* language packages */ /* multimedia packages */ /* tools packages */ /* system packages */ /* peripheral libraries and drivers */ /* miscellaneous packages */ /* sample package */ /* example package: hello */ /* Privated Packages of RealThread */ /* Network Utilities */ /* Env config */ //#define SYS_PKGS_DOWNLOAD_ACCELERATE #define RT_USING_UART1 #endif ```下面即可在main文件中添加线程了 ``` #include "stm32f10x.h" #include "rtthread.h" struct rt_thread led1_thread; struct rt_thread led2_thread; rt_uint8_t led1_thread_stack[512]; rt_uint8_t led2_thread_stack[512]; void LedGPIO_Init(void) { GPIO_InitTypeDef LedInitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); LedInitStruct.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2; LedInitStruct.GPIO_Mode = GPIO_Mode_Out_PP; LedInitStruct.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init(GPIOA,&LedInitStruct); } void led1_thread_entry(void* parameter) { for(;;) { GPIO_SetBits(GPIOA,GPIO_Pin_1); rt_thread_delay(RT_TICK_PER_SECOND/2); GPIO_ResetBits(GPIOA,GPIO_Pin_1); rt_thread_delay(RT_TICK_PER_SECOND/2); } } void led2_thread_entry(void* parameter) { for(;;) { GPIO_SetBits(GPIOA,GPIO_Pin_2); rt_thread_delay(RT_TICK_PER_SECOND); GPIO_ResetBits(GPIOA,GPIO_Pin_2); rt_thread_delay(RT_TICK_PER_SECOND); } } int main(void) { LedGPIO_Init(); rt_thread_init(&led1_thread,"led1",led1_thread_entry,RT_NULL, led1_thread_stack,sizeof(led1_thread_stack),5,5); rt_thread_startup(&led1_thread); rt_thread_init(&led2_thread,"led2",led2_thread_entry,RT_NULL, led2_thread_stack,sizeof(led2_thread_stack),5,5); rt_thread_startup(&led2_thread); return 0; } ```连接好串口,或者软件仿真发现可以使用msh命令查看系统工作状态了 ![未命名1534478368.png](/uploads/201808/17/120045b301q09r1fxffu00.png)
查看更多
回到 顶部
发布 问题
分享 好友
手机 浏览
投诉 建议
回到 底部