Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
Kernel
【急】我在使用信号量的时候遇到了问题,谁可以帮我解...
发布于 2018-01-11 11:47:15 浏览:2201
订阅该版
代码如下: ```static void led0_thread_entry(void *parameter) { uint8_t flag = 1; while(1) { rt_sem_take(&sem, RT_WAITING_FOREVER); if(flag) { HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, GPIO_PIN_SET); flag = 0; } else { HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, GPIO_PIN_RESET); flag = 1; } } } static void print_thread_entry(void *parameter){ uint32_t times = 0; while(1) { rt_sem_release(&sem); rt_kprintf("times = %u
", times++); rt_thread_delay(500); } }```调试信息: > thread led0 take sem:sem, which value is: 0 sem take: suspend thread - led0 thread print releases sem:sem, which value is: 0 resume thread:led0 times = 0 thread led0 take sem:sem, which value is: 0 sem take: suspend thread - led0 psr: 0x01000000 r00: 0x20000e58 r01: 0x10000000 r02: 0xf0f00000 r03: 0x00000410 r04: 0x20000ea8 r05: 0x00000001 r06: 0xdeadbeef r07: 0xdeadbeef r08: 0xdeadbeef r09: 0xdeadbeef r10: 0xdeadbeef r11: 0xdeadbeef r12: 0xfffffffe lr: 0x08003833 pc: 0x08003832 hard fault on thread: tidle
查看更多
6
个回答
默认排序
按发布时间排序
aozima
2018-01-11
调网络不抓包,调I2C等时序不上逻辑分析仪,就像电工不用万用表!多用整理的好的文字,比截图更省流量,还能在整理过程中思考。
代码没贴全,没看到sem初始化,以及你贴出日志的打印部分。 贴出的部分初看没发现问题。
z4b4@qq.com
2018-01-11
这家伙很懒,什么也没写!
>代码没贴全,没看到sem初始化,以及你贴出日志的打印部分。 > >贴出的部分初看没发现问题。 ... --- ``` static rt_thread_t print_tid = RT_NULL; static struct rt_thread led0_thread; /* 指向信号量的指针 */ struct rt_semaphore sem; ALIGN(RT_ALIGN_SIZE) static uint8_t rt_led0_thread_stack[512]; static void led0_thread_entry(void *parameter) { uint8_t flag = 1; while(1) { rt_sem_take(&sem, RT_WAITING_FOREVER); if(flag) { HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, GPIO_PIN_SET); flag = 0; } else { HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, GPIO_PIN_RESET); flag = 1; } } } static void print_thread_entry(void *parameter){ uint32_t times = 0; while(1) { rt_sem_release(&sem); rt_kprintf("times = %u\n", times++); rt_thread_delay(500); } } int main(void) { rt_sem_init(&sem , "sem", 0, RT_IPC_FLAG_FIFO); rt_thread_init(&led0_thread, "led0", led0_thread_entry, RT_NULL, &rt_led0_thread_stack[0], sizeof(rt_led0_thread_stack), 2, 20); print_tid = rt_thread_create("print", print_thread_entry, RT_NULL, 512, 1, 20); rt_thread_startup(&led0_thread); rt_thread_startup(print_tid); } ```
z4b4@qq.com
2018-01-11
这家伙很懒,什么也没写!
> --- >\ | / >- RT - Thread Operating System > / | \ 2.1.0 build Jan 11 2018 > 2006 - 2017 Copyright by rt-thread team >thread (NULL) take sem:heap, which value is: 1 >thread heap releases sem:heap, which value is: 0 >thread heap take sem:heap, which value is: 1 >thread heap releases sem:heap, which value is: 0 >thread main take sem:heap, which value is: 1 >thread main releases sem:heap, which value is: 0 >thread main take sem:heap, which value is: 1 >thread main releases sem:heap, which value is: 0 >thread led0 take sem:sem, which value is: 0 >sem take: suspend thread - led0 >thread print releases sem:sem, which value is: 0 >resume thread:led0 >times = 0 >thread led0 take sem:sem, which value is: 0 >sem take: suspend thread - led0 >psr: 0x01000000 >r00: 0x20000e58 >r01: 0x10000000 >r02: 0xf0f00000 >r03: 0x00000410 >r04: 0x20000ea8 >r05: 0x00000001 >r06: 0xdeadbeef >r07: 0xdeadbeef >r08: 0xdeadbeef >r09: 0xdeadbeef >r10: 0xdeadbeef >r11: 0xdeadbeef >r12: 0xfffffffe > lr: 0x08003833 > pc: 0x08003832 >hard fault on thread: tidle ---
z4b4@qq.com
2018-01-11
这家伙很懒,什么也没写!
> --- >\ | / >- RT - Thread Operating System > / | \ 2.1.0 build Jan 11 2018 > 2006 - 2017 Copyright by rt-thread team >thread (NULL) take sem:heap, which value is: 1 >thread heap releases sem:heap, which value is: 0 >thread heap take sem:heap, which value is: 1 >thread heap releases sem:heap, which value is: 0 >thread main take sem:heap, which value is: 1 >thread main releases sem:heap, which value is: 0 >thread main take sem:heap, which value is: 1 >thread main releases sem:heap, which value is: 0 >thread led0 take sem:sem, which value is: 0 >sem take: suspend thread - led0 >thread print releases sem:sem, which value is: 0 >resume thread:led0 >times = 0 >thread led0 take sem:sem, which value is: 0 >sem take: suspend thread - led0 >psr: 0x01000000 >r00: 0x20000e58 >r01: 0x10000000 >r02: 0xf0f00000 >r03: 0x00000410 >r04: 0x20000ea8 >r05: 0x00000001 >r06: 0xdeadbeef >r07: 0xdeadbeef >r08: 0xdeadbeef >r09: 0xdeadbeef >r10: 0xdeadbeef >r11: 0xdeadbeef >r12: 0xfffffffe > lr: 0x08003833 > pc: 0x08003832 >hard fault on thread: tidle ---
z4b4@qq.com
2018-01-11
这家伙很懒,什么也没写!
> --- 这是完整的代码,日志在楼下,大佬帮看看
z4b4@qq.com
2018-01-11
这家伙很懒,什么也没写!
好吧,我解决了,应该时rtconfig.h配置的问题
撰写答案
登录
注册新账号
关注者
0
被浏览
2.2k
关于作者
z4b4@qq.com
这家伙很懒,什么也没写!
提问
1
回答
5
被采纳
0
关注TA
发私信
相关问题
1
请教cpu使用率分析
2
选择FreeRTOS, 还是RT-Thread。
3
thread heap stack overflow ?
4
rtt消息队列delay问题
5
释放被删除线程的内存地方在哪里啊
6
请教:各线程结束后,释放其中的内存的连续性问题
7
STM32F103中断关于信号量、邮箱问题
8
RTT中的线程栈大小如何控制
9
关于线程由执行态变为挂起态的代码实现,,,
10
rt_malloc(rt_size_t size)内存分配函数最小分配尺寸问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
CherryUSB的bootuf2配置
2
在用clangd开发RTT吗,快来试试如何简单获得清晰干净的工作区
3
GD32F450 片内 flash驱动适配
4
STM32H7R7运行CherryUSB
5
RT-Smart首次线下培训,锁定2024 RT-Thread开发者大会!
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
UART
WIZnet_W5500
ota在线升级
PWM
freemodbus
flash
cubemx
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
中断
编译报错
Debug
SFUD
rt_mq_消息队列_msg_queue
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
a1012112796
12
个答案
1
次被采纳
踩姑娘的小蘑菇
4
个答案
1
次被采纳
红枫
4
个答案
1
次被采纳
张世争
4
个答案
1
次被采纳
Ryan_CW
4
个答案
1
次被采纳
本月文章贡献
catcatbing
3
篇文章
6
次点赞
YZRD
2
篇文章
5
次点赞
lizimu
2
篇文章
5
次点赞
qq1078249029
2
篇文章
2
次点赞
xnosky
2
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部