打印
[MM32软件]

灵动芯片32L373移植了RT-THREAD后,建多个任务为何死机?

[复制链接]
637|19
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ningling_21|  楼主 | 2020-6-29 08:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如题:
有main任务,又新建2个任务,只是闪灯,运行2秒就进入rt_hw_hard_fault_exception

使用特权

评论回复
沙发
zhu^zhu| | 2020-6-29 08:39 | 只看该作者
这应该是纯软件的问题。最好是把代码贴出来,应该很容易分析问题所在。

使用特权

评论回复
板凳
ningling_21|  楼主 | 2020-6-29 10:24 | 只看该作者
本帖最后由 ningling_21 于 2020-7-1 22:16 编辑
#include <rtthread.h>
#include <rtdevice.h>
#include "HAL_device.h"
#include "drv_uart.h"
//#include "can.h"
#include "HAL_can.h"

/* defined the LED pin: PA15 */
#define LED_PIN    38
#define LED2_PIN   39
#define LED3_PIN   40
#define LED4_PIN   41
static rt_uint8_t led_1_stack[128];
static struct rt_thread led_1_thread;

static rt_uint8_t led_2_stack[128];
static struct rt_thread led_2_thread;


//--------------------------------------------------------------------------------------------------
static void led_1_thread_entry(void * parameter)//线程1入口
{
        u8  led_stat_led=0;
        //rt_hw_led_init();       
        //rt_hw_usart_init();
        rt_pin_mode(LED4_PIN, PIN_MODE_OUTPUT);
       
        while(1)
        {
               
                if(led_stat_led==0)
                {
                        led_stat_led=1;
                       
                        rt_pin_write(LED4_PIN, PIN_LOW);
                }
                else
                {
                        led_stat_led=0;
                       
                        rt_pin_write(LED4_PIN, PIN_HIGH);
                       
                        //mm32_uart_putc(UART1,0x55);
                }
        rt_thread_delay( 200 );
        }
}
static void led_2_thread_entry(void * parameter)//线程2入口
{
        u8  led_stat_led=0;
        //rt_hw_led_init();       
        //rt_hw_usart_init();
        rt_pin_mode(LED3_PIN, PIN_MODE_OUTPUT);

        while(1)
        {

                if(led_stat_led==0)
                {
                        led_stat_led=1;
                       
                        rt_pin_write(LED3_PIN, PIN_LOW);
                }
                else
                {
                        led_stat_led=0;
                       
                        rt_pin_write(LED3_PIN, PIN_HIGH);
                }
        rt_thread_delay( 100 );
        }
}
int main(void)
{
        u16  run_cnt=0;
        u8  led_stat_led=0;
        u8  flag_rt_thread=0;
        rt_err_t result;
    int count = 1;
    /* set LED4 pin mode to output */
    rt_pin_mode(LED_PIN,  PIN_MODE_OUTPUT);
        rt_pin_mode(LED2_PIN, PIN_MODE_OUTPUT);
        //rt_pin_mode(LED3_PIN, PIN_MODE_OUTPUT);

        rt_hw_uart_init();         
    while (count)
    {
        run_cnt++;
                if(led_stat_led==0)
                {
                        led_stat_led=1;
                        rt_pin_write(LED_PIN, PIN_HIGH);
                        rt_pin_write(LED2_PIN, PIN_LOW);
                        //rt_pin_write(LED3_PIN, PIN_HIGH);
                        //rt_pin_write(LED4_PIN, PIN_LOW);
                }
                else
                {
                        led_stat_led=0;
                        rt_pin_write(LED_PIN, PIN_LOW);                       
                        rt_pin_write(LED2_PIN, PIN_HIGH);
                        //rt_pin_write(LED3_PIN, PIN_LOW);
                        //rt_pin_write(LED4_PIN, PIN_HIGH);
                }
               
                rt_thread_mdelay(100);
               
                //rt_kprintf("run_count=%d\r\n",run_cnt);
                if(run_cnt>=20)
                {
                        run_cnt=0;
                        if(flag_rt_thread==0)
                        {
                                flag_rt_thread=1;
                                //rt_thread_create()
                                result = rt_thread_init(&led_1_thread,
                            "led",
                            led_1_thread_entry,
                            RT_NULL,
                            (rt_uint8_t*)&led_1_stack[0],                //堆栈起始
                            sizeof(led_1_stack),                                //堆栈大小
                            21,                                                                //线程优先级
                            10);                                                                //时间片数
       
                                if (result == RT_EOK)
                                {
                                        rt_thread_startup(&led_1_thread);
                                }
                                rt_kprintf("led1_thread ok.\n");
                               
                                result = rt_thread_init(&led_2_thread,
                            "led",
                            led_2_thread_entry,
                            RT_NULL,
                            (rt_uint8_t*)&led_2_stack[0],                //堆栈起始
                            sizeof(led_2_stack),                                //堆栈大小
                            22,                                                                //线程优先级
                            5);                                                                //时间片数
       
                                if (result == RT_EOK)
                                {
                                        rt_thread_startup(&led_2_thread);
                                }
                        }
                       
                       
                }
    }
    return RT_EOK;
}

使用特权

评论回复
地板
zeshoufx| | 2020-6-29 20:25 | 只看该作者

使用特权

评论回复
5
ningling_21|  楼主 | 2020-6-29 21:23 | 只看该作者

使用特权

评论回复
6
qjp1988113| | 2020-6-30 08:21 | 只看该作者
很混乱,你不觉得你的所谓的MAIN任务很奇怪么。一个程序必须有一个main函数,作为主程序的入口。既然用到了RT-THREAD,最好就把所以动作都做成TASK子程序。main函数的while里面就不要放东西了。

使用特权

评论回复
7
huangzushuimd| | 2020-6-30 09:26 | 只看该作者
有main任务,又新建2个任务,只是闪灯,运行2秒就进入rt_hw_hard_fault_exception
这个建立任务应该在while的外面,确保只运行一次;不然的话,可能会建立任务很多次;
具体使用请参考:
https://www.rt-thread.org/document/site/um4003-rtthread-programming-manual.pdf
https://www.rt-thread.org/document/site/tutorial/iot_board_tutorial.pdf

使用特权

评论回复
8
ningling_21|  楼主 | 2020-6-30 09:51 | 只看该作者
huangzushuimd 发表于 2020-6-30 09:26
有main任务,又新建2个任务,只是闪灯,运行2秒就进入rt_hw_hard_fault_exception
这个建立任务应该在while ...

确实只建立一次,有标志位控制,在建立的时就异常

使用特权

评论回复
9
zeshoufx| | 2020-6-30 18:36 | 只看该作者
ningling_21 发表于 2020-6-30 09:51
确实只建立一次,有标志位控制,在建立的时就异常

mian函数里面的循环能不能作为一个独立的任务,,,一般系统下的mian函数不放循环的吧

使用特权

评论回复
评论
suncl110 2020-7-2 09:19 回复TA
RT Thread main被包装成一个普通任务了. 
10
ningling_21|  楼主 | 2020-6-30 19:06 | 只看该作者
zeshoufx 发表于 2020-6-30 18:36
mian函数里面的循环能不能作为一个独立的任务,,,一般系统下的mian函数不放循环的吧 ...

这里的main 也是一个任务

使用特权

评论回复
11
suncl110| | 2020-7-2 09:21 | 只看该作者
rt_hw_hard_fault_exception 一般是寻址失败,栈溢出的可能性比较大.

使用特权

评论回复
12
晓伍| | 2020-7-7 15:53 | 只看该作者
知道是死在哪里了吗

使用特权

评论回复
13
八层楼| | 2020-7-7 15:53 | 只看该作者
真是看不太好

使用特权

评论回复
14
观海| | 2020-7-7 16:00 | 只看该作者
单个任务不死机吗

使用特权

评论回复
15
guanjiaer| | 2020-7-7 16:00 | 只看该作者
帮楼主顶一下

使用特权

评论回复
16
heimaojingzhang| | 2020-7-7 16:00 | 只看该作者
楼主问题解决了吗

使用特权

评论回复
17
ningling_21|  楼主 | 2020-7-7 20:47 | 只看该作者

删除第3个任务就可以

使用特权

评论回复
18
ningling_21|  楼主 | 2020-7-7 20:47 | 只看该作者
观海 发表于 2020-7-7 16:00
单个任务不死机吗

单个任务不会

使用特权

评论回复
19
ningling_21|  楼主 | 2020-7-7 20:48 | 只看该作者
晓伍 发表于 2020-7-7 15:53
知道是死在哪里了吗

创建第3个任务时

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5013

主题

17706

帖子

51

粉丝