Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
Hardfault
RT-AK_AI-Kit_人工智能
STM32U系列
10
CubeAI部署rtt后使用
发布于 2023-09-02 19:04:51 浏览:5345
订阅该版
[tocm] ## 硬件 stm32u575 ## 环境 RT-Thread Studio ## 程序: 使用CubeIDE成功的:https://github.com/Hengbote/CubeIDE_use_Cubeai 使用rtt成功的:https://github.com/Hengbote/RT_Thread_use_Cubeai ## 流程 使用Cubemx添加了Cube-ai加入了模型并验证通过 ![0da6f452f9467570495949ed05363bc5.png](https://oss-club.rt-thread.org/uploads/20230902/0da6f452f9467570495949ed05363bc5.png.webp) 把生成的文件(network.c等)加入构建,添加(cubemx-Middlewares-ST-AI-lnc)头文件路径. 添加库(`cubemx-Middlewares-ST-AI-Lib-NetworkRuntime810_CM33_GCC.a`) ~~在这里本身生成的是NetworkRuntime810_CM33_IAR.a但是不能使用IAR. 所以我就换成了在CubeIDE成功的例子中生成的GCC.a~~ 开发环境选stm32CubeIDE会生成gcc文件 ![{984CF4D2-BB89-42bb-A99B-10ABA0511D2B}.png](https://oss-club.rt-thread.org/uploads/20230907/2e786f92908f74ad00e82ae102456168.png) 然后打开硬浮点 最后修改程序编译通过, 下载进板子运行失败,debug也会直接输出相同的错误 ```c #include
#include
/* 模型头文件 */ #include "ai_datatypes_defines.h" #include "ai_platform.h" #include "network_data.h" #include "network.h" #include "main.h" #define DBG_TAG "main" #define DBG_LVL DBG_LOG #include
/* 模型句柄 */ static ai_handle network = AI_HANDLE_NULL; /* 神经网络中间值 (激活缓冲区 ) */ AI_ALIGNED(32) static ai_u8 activations[AI_NETWORK_DATA_ACTIVATIONS_SIZE]; /* 输入张量的缓冲区 */ AI_ALIGNED(32) static ai_float in_data[AI_NETWORK_IN_1_SIZE]; // static ai_u8 in_data[AI_NETWORK_IN_1_SIZE_BYTES]; /* 输出张量的缓冲区 */ AI_ALIGNED(32) static ai_float out_data[AI_NETWORK_OUT_1_SIZE]; // static ai_u8 out_data[AI_NETWORK_OUT_1_SIZE_BYTES]; /* 模型输入输出张量指针 */ static ai_buffer *ai_input; static ai_buffer *ai_output; rt_mutex_t lock; //互斥量 //测试输入 uint8_t data[AI_NETWORK_IN_1_SIZE] = { 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 239,239,239, 91, 91, 91, 80, 80, 80, 80, 80, 80, 80, 80, 80, 252,252,252, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 104,104,104, 7, 7, 7, 7, 7, 7, 4, 4, 4, 0, 0, 0, 124,124,124, 254,254,254, 254,254,254, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 254,254,254, 157,157,157, 3, 3, 3, 32, 32, 32, 116,116,116, 116,116,116, 21, 21, 21, 14, 14, 14, 176,176,176, 254,254,254, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 202,202,202, 22, 22, 22, 8, 8, 8, 129,129,129, 252,252,252, 255,255,255, 109,109,109, 0, 0, 0, 52, 52, 52, 215,215,215, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 87, 87, 87, 2, 2, 2, 67, 67, 67, 252,252,252, 255,255,255, 255,255,255, 248,248,248, 43, 43, 43, 0, 0, 0, 127,127,127, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 78, 78, 78, 0, 0, 0, 250,250,250, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 229,229,229, 0, 0, 0, 127,127,127, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 76, 76, 76, 0, 0, 0, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 230,230,230, 3, 3, 3, 127,127,127, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 83, 83, 83, 1, 1, 1, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 229,229,229, 1, 1, 1, 127,127,127, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 79, 79, 79, 0, 0, 0, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 229,229,229, 0, 0, 0, 127,127,127, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 76, 76, 76, 0, 0, 0, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 229,229,229, 0, 0, 0, 127,127,127, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 76, 76, 76, 0, 0, 0, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 229,229,229, 0, 0, 0, 127,127,127, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 83, 83, 83, 1, 1, 1, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 229,229,229, 0, 0, 0, 127,127,127, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 98, 98, 98, 3, 3, 3, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 229,229,229, 1, 1, 1, 127,127,127, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 92, 92, 92, 2, 2, 2, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 230,230,230, 4, 4, 4, 128,128,128, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 77, 77, 77, 0, 0, 0, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 229,229,229, 1, 1, 1, 128,128,128, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 85, 85, 85, 3, 3, 3, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 230,230,230, 1, 1, 1, 128,128,128, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 83, 83, 83, 1, 1, 1, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 229,229,229, 0, 0, 0, 127,127,127, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 79, 79, 79, 0, 0, 0, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 229,229,229, 0, 0, 0, 127,127,127, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 76, 76, 76, 0, 0, 0, 250,250,250, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 229,229,229, 0, 0, 0, 127,127,127, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 78, 78, 78, 1, 1, 1, 182,182,182, 254,254,254, 255,255,255, 255,255,255, 253,253,253, 164,164,164, 0, 0, 0, 128,128,128, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 114,114,114, 8, 8, 8, 36, 36, 36, 221,221,221, 255,255,255, 255,255,255, 207,207,207, 21, 21, 21, 17, 17, 17, 153,153,153, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 53, 53, 53, 4, 4, 4, 85, 85, 85, 238,238,238, 239,239,239, 24, 24, 24, 19, 19, 19, 97, 97, 97, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 241,241,241, 26, 26, 26, 8, 8, 8, 20, 20, 20, 18, 18, 18, 2, 2, 2, 38, 38, 38, 244,244,244, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 193,193,193, 10, 10, 10, 1, 1, 1, 0, 0, 0, 3, 3, 3, 214,214,214, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 247,247,247, 179,179,179, 175,175,175, 175,175,175, 176,176,176, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255, }; static int aiInit(void); static int aiRun(const void *in_data, void *out_data); int main(void) { // uint32_t timestamp; // uint32_t timestamp1; float y_val[10]; float y_vall[10]; int y_valll[10]; float min, max, Radius; lock = rt_mutex_create("mutex_AI", RT_IPC_FLAG_FIFO); //创建摄像头互斥锁 if(lock == RT_NULL) LOG_E("无法创建互斥锁"); MX_CRC_Init(); /* 启用CRC IP时钟以使用神经网络运行时库 */ __HAL_RCC_CRC_CLK_ENABLE(); /* 初始化推理 */ aiInit(); while (1) { // 填充输入缓冲区 */ for (uint32_t i = 0; i < AI_NETWORK_IN_1_SIZE; i++) { ((ai_float *)in_data)[i] = data[i]; } // /* 获取当前时间戳 */ // timestamp = htim16.Instance->CNT; /* 运行推理 */ aiRun(in_data, out_data); // /* 获取当前时间戳 */ // timestamp1 = htim16.Instance->CNT; // // if(timestamp > timestamp1) // timestamp1 = timestamp1 + 65535 - timestamp; // else // timestamp1 = timestamp1 - timestamp; // // /* 输出推理时间 (微秒) */ // LOG_I("duration: %lu us\r\n", // timestamp1); /* 读取神经网络的输出 */ for(int i = 0; i < AI_NETWORK_OUT_1_SIZE; i++) y_val[i] = ((float *)out_data)[i]; min = y_val[0]; max = y_val[0]; for (int i = 0; i < AI_NETWORK_OUT_1_SIZE; i++) { if (y_val[i] < min) min = y_val[i]; if (y_val[i] > max) max = y_val[i]; } Radius = max - min; for (int i = 0; i < AI_NETWORK_OUT_1_SIZE; i ++) { y_vall[i] = (y_val[i] - min) / Radius; y_valll[i] = (int)(y_vall[i]*1000*100); LOG_I("number: %d output: %6d\r\n", i, y_valll[i]); } // LOG_D("Hello"); // rt_thread_mdelay(1000); } return RT_EOK; } /* * 初始化推理 */ int aiInit(void) { ai_error err; /* 创建和初始化模型 */ const ai_handle acts[] = { activations }; err = ai_network_create_and_init(&network, acts, NULL); if (err.type != AI_ERROR_NONE) { LOG_I("Error: could not create NN instance or initialize\r\n"); while(1); }; /* 获取指向模型的输入/输出张量的指针 */ ai_input = ai_network_inputs_get(network, NULL); ai_output = ai_network_outputs_get(network, NULL); return 0; } /* * 运行推理 */ int aiRun(const void *in_data, void *out_data) { ai_i32 n_batch; ai_error err; /* 1 - 更新输入和输出缓冲区的数据指针 */ ai_input[0].data = AI_HANDLE_PTR(in_data); ai_output[0].data = AI_HANDLE_PTR(out_data); /* 2 - 使用神经网络进行推理 */ if(rt_mutex_take(lock, RT_WAITING_FOREVER) != RT_EOK) //上锁 LOG_E("获取互斥量失败\r\n"); n_batch = ai_network_run(network, &ai_input[0], &ai_output[0]); rt_mutex_release(lock); //解锁 if (n_batch != 1) { err = ai_network_get_error(network); LOG_I("Error: could not run inference because of %d\r\n", err.type); }; return 0; } ``` 报错输出: ``` \ | / - RT - Thread Operating System / | \ 4.1.1 build Sep 2 2023 16:59:42 2006 - 2022 Copyright by RT-Thread team psr: 0x21000000 r00: 0x00000001 r01: 0x00000210 r02: 0x00000ab4 r03: 0x28167670 r04: 0xdeadbeef r05: 0xdeadbeef r06: 0xdeadbeef r07: 0x2002f5c0 r08: 0xdeadbeef r09: 0xdeadbeef r10: 0xdeadbeef r11: 0xdeadbeef r12: 0x00000000 lr: 0x08002979 pc: 0x08002a48 hard fault on thread: main thread pri status sp stack size max used left tick error -------- --- ------- ---------- ---------- ------ ---------- --- tidle0 31 ready 0x00000044 0x00000100 26% 0x00000020 OK timer 4 suspend 0x0000007c 0x00000200 24% 0x00000009 OK main 10 running 0x00000040 0x00000800 10% 0x00000014 OK bus fault: SCB_CFSR_BFSR:0x82 PRECISERR SCB->BFAR:28167678 ``` ## 其他尝试: 我在CubeIDE上使用该程序可以成功 通过反汇编发现出错的位置在`rt_smem_alloc()` lr指向`RT_ASSERT(rt_object_is_systemobject(&m->parent));` pc指向`((struct rt_small_mem_item *)&small_mem->heap_ptr[mem2->next])->prev = ptr2;` 这是堆栈溢出了吗,是不是因为我任务堆栈太小了
查看更多
2
个回答
默认排序
按发布时间排序
小黑兹
2023-09-04
这家伙很懒,什么也没写!
~~额没人回答,已经解决了.起码单独使用没有问题了 系统内存管理方式使用slab algorithm for large memory就ok了 优化要开到-O3~~ 上面的这个方法还是有些问题,会在任务调度的时候出问题. 改用以下方法: 不需要更改内存算法,使用初始的small内存算法就行. 也不用改优化 我们需要注意两个关键的地方. 1.关注FPU,不同的芯片可能设置不同. 我stm32u575要用fpv4-sp-d16 ![{0E29E55A-ABD9-44e1-BA09-18F680766C17}.png](https://oss-club.rt-thread.org/uploads/20230907/1f57adf45774c0f53571d0b847468297.png) 2.注意芯片内核与编译器 在设置修改arm后工程中rtthread-libcpu-arm文件夹下并没有自动更改内核文件夹,需要我们手动添加/排除构建 ![{41F26C64-59BA-4425-B3C8-67AEFCEA2860}.png](https://oss-club.rt-thread.org/uploads/20230907/5cec1b1cadcad2d8444f59e44b949548.png)
梦笑真美
2023-09-13
这家伙很懒,什么也没写!
ai都用上了,高级
撰写答案
登录
注册新账号
关注者
0
被浏览
5.3k
关于作者
小黑兹
这家伙很懒,什么也没写!
提问
3
回答
2
被采纳
0
关注TA
发私信
相关问题
1
RTT1.0,STM32调试时会跑到HardFault【已解决】,出现新问题
2
新手请教关于hardfault怎么查
3
github最新版本库中stm32f0X分支,运行切换任务时候出现hardfault[已解决]
4
实现iap功能,bootloader使用了rtt操作系统,在跳转到app代码的时候提示出现hardfault的问题
5
ymodem在on_begin内发送can无法断开连接,而且RTT会报hardfault
6
挂载UFFS文件系统执行到退出_BuildTreeStepOne函数时hardfault异常
7
STM32F1+RTT串口接收中断进入hardfault
8
STM32F746NG随机进入hardfault(已解决)
9
[已解决]自已建了个STM32F103的MDK工程,初始化时总是进入HardFault,求教!
10
将 Cortex M3 的 hardfault 处理与 M4、M7、M0 保持一致?
推荐文章
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
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
2
RT-Thread 发布 EtherKit开源以太网硬件!
3
rt-thread使用cherryusb实现虚拟串口
4
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
5
《原子操作:程序世界里的“最小魔法单位”解析》
热门标签
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
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
ulog
C++_cpp
at_device
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
a1012112796
13
个答案
2
次被采纳
张世争
9
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
11
个答案
1
次被采纳
本月文章贡献
程序员阿伟
8
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
3
次点赞
ThinkCode
1
篇文章
1
次点赞
Betrayer
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部