新手入门
- 积分
- 8
- 金钱
- 8
- 注册时间
- 2021-3-16
- 在线时间
- 1 小时
|
1金钱
各位大佬, 如题:
板子上有两个LED灯, 一个蓝色,一个红色, 我想在RT-Thread Nano OS的两个thread里, 循环点亮和熄灭LED灯, 但是运行到蓝色LED灯灭之后,LED灯的状态就不变了, 问题出现在哪里了呢?
【这个Nano里, 没有使用heap】
#include "stm32f10x_gpio.h"
#include "myFunctions.h"
#include "stm32f10x.h"
#include <rtthread.h>
#define THREAD_PRIORITY 1
#define THREAD_STACK_SIZE 100
#define THREAD_TIMESLICE 100
//ALIGN(RT_ALIGN_SIZE)
static char thread1_stack[100];
static struct rt_thread thread1;
/* 线程1入口 */
static void thread1_entry(void *param)
{
int count = 0;
while (1)
{
if(count == 0)
{
GPIO_SetBitx(GPIOA,GPIO_Pin_8); //Blue LED OFF
rt_thread_mdelay(1000);
count = 1;
}
else
{
GPIO_ResetBitx(GPIOA,GPIO_Pin_8); //Blue LED ON
rt_thread_mdelay(1000);
count = 0;
}
}
}
static char thread2_stack[100];
static struct rt_thread thread2;
/* 线程2入口 */
static void thread2_entry(void *param)
{
int count = 0;
while (1)
{
if(count == 0)
{
GPIO_SetBitx(GPIOD,GPIO_Pin_2); //Red LED OFF
rt_thread_mdelay(5000);
count = 1;
}
else
{
GPIO_ResetBitx(GPIOD,GPIO_Pin_2); //Red LED ON
rt_thread_mdelay(5000);
count = 0;
}
}
}
int main()
{
rt_err_t retValue= 0;
LED_GPIO_Init();
rt_thread_mdelay(1000);
GPIO_ResetBitx(GPIOA,GPIO_Pin_8); //Blue LED ON
GPIO_ResetBitx(GPIOD,GPIO_Pin_2); //Red LED ON
rt_thread_mdelay(1000);
rt_thread_mdelay(1000);
rt_thread_mdelay(1000);
/* 初始化线程1,名称是thread1,入口是thread1_entry */
retValue = rt_thread_init(&thread1,"thread1",thread1_entry,RT_NULL,&thread1_stack[0],sizeof(thread1_stack),THREAD_PRIORITY, THREAD_TIMESLICE);
retValue = rt_thread_startup(&thread1);
if(retValue == RT_EOK)
GPIO_SetBitx(GPIOA,GPIO_Pin_8); //Blue LED OFF //-------------------------》 程序运行到了这里, 蓝色灯也熄灭了。
/* 初始化线程2,名称是thread2,入口是thread2_entry */
retValue = rt_thread_init(&thread2, "thread2",thread2_entry,RT_NULL,&thread2_stack[0],sizeof(thread2_stack),THREAD_PRIORITY, THREAD_TIMESLICE);
retValue = rt_thread_startup(&thread2);
if(retValue == RT_EOK)
GPIO_SetBitx(GPIOD,GPIO_Pin_2); //Red LED OFF //-------------------------》 程序没有运行到了这里, 红色LED一直亮。
return 0;
}
编译没有错误,下载到板子上,也能运行。
。。。。。。。
compiling board.c...
linking...
Program Size: Code=6780 RO-data=644 RW-data=128 ZI-data=2888
FromELF: creating hex file...
".\Objects\LED_Test.axf" - 0 Error(s), 1 Warning(s).
Build Time Elapsed: 00:00:05
|
|