Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
未定义错误
neon
线程内部定义数组并初始化就出现未定义错误
发布于 2020-10-02 22:43:35 浏览:1099
订阅该版
[tocm] 在线程处理函数当中定义一个数组并初始化。那么久会出现未定义错误,如果数组屏蔽掉,就能正常运行,而当数组定义但未被初始化也能正常运行。后来在经过编译选项的处理分别出现如下: 1:线程处理函数中定义并初始化(`char buf[10] ={1};`),这个时候编译优化选项选择-O0那么就出现未定义错误,而如果把编译优化选项更改-O2或者-Os那么就能正常运行。如下是出现错误的现象: ``` \ | / - RT - Thread Operating System / | \ 4.0.2 build Sep 30 2020 2006 - 2019 Copyright by rt-thread team msh >undefined instruction: Execption: r00:0x00000000 r01:0xdeadbeef r02:0xdeadbeef r03:0x9ff9c318 r04:0xdeadbeef r05:0xdeadbeef r06:0xdeadbeef r07:0xdeadbeef r08:0xdeadbeef r09:0xdeadbeef r10:0xdeadbeef fp :0x9ff9c32c ip :0xdeadbeef sp :0x9ff9c310 lr :0x9ff8e5c4 pc :0x9ff8f848 cpsr:0x00000013 thread pri status sp stack size max used left tick error -------- --- ------- ---------- ---------- ------ ---------- --- thread2 25 running 0x00000048 0x00000200 14% 0x00000019 000 tshell 20 suspend 0x000000c8 0x00001000 05% 0x00000009 000 tidle0 31 ready 0x00000048 0x00000100 28% 0x00000020 000 main 10 close 0x00000074 0x00000800 11% 0x00000012 000 shutdown... (0) assertion failed at function:rt_hw_cpu_shutdown, line number:85 ``` 处理函数代码: ```c /* 线程 2 入口 */ void thread2_entry(void* parameter) { int count = 0; char buf[10] ={1}; while (1) { rt_kprintf("xxxxxxxxxxxxThread2 count:%d\n", ++count); /* 延时 50ms */ rt_thread_mdelay(500); } } /* 线程例程初始化 */ int thread_sample_init() { rt_thread_t thread2_ptr; rt_err_t result; #if 0 /* 初始化线程 1 */ /* 线程的入口是 thread1_entry,参数是 RT_NULL * 线程栈是 thread1_stack * 优先级是 20,时间片是 10 个 OS Tick */ result = rt_thread_init(&thread1, "thread1", thread1_entry, RT_NULL, &thread1_stack[0], sizeof(thread1_stack), 20, 10); /* 启动线程 */ if (result == RT_EOK) rt_thread_startup(&thread1); #endif /* 创建线程 2 */ /* 线程的入口是 thread2_entry, 参数是 RT_NULL * 栈空间是 512,优先级是 25,时间片是 25 个 OS Tick */ thread2_ptr = rt_thread_create("thread2", thread2_entry, RT_NULL, 512, 25, 25); /* 启动线程 */ if (thread2_ptr != RT_NULL) rt_thread_startup(thread2_ptr); return 0; } ``` 处理函数汇编代码: ``` thread2_entry 0x9FF8F828: PUSH {r11,lr} 0x9FF8F82C: ADD r11,sp,#4 0x9FF8F830: SUB sp,sp,#0x18 0x9FF8F834: STR r0,[r11,#-0x18] 0x9FF8F838: MOV r3,#0 0x9FF8F83C: STR r3,[r11,#-8] 0x9FF8F840: SUB r3,r11,#0x14 0x9FF8F844: VMOV.I32 d16,#0 0x9FF8F848: VSTR d16,[r3,#0] 0x9FF8F84C: ADD r3,r3,#2 0x9FF8F850: VST1.8 {d16},[r3] 0x9FF8F854: MOV r3,#1 0x9FF8F858: STRB r3,[r11,#-0x14] 0x9FF8F85C: LDR r3,[r11,#-8] 0x9FF8F860: ADD r3,r3,#1 0x9FF8F864: STR r3,[r11,#-8] 0x9FF8F868: LDR r1,[r11,#-8] 0x9FF8F86C: MOV r0,#0x1614 0x9FF8F870: MOVT r0,#0x9ff9 0x9FF8F874: BL {pc}-0x2f48 ; 0x9ff8c92c 0x9FF8F878: MOV r0,#0x1f4 0x9FF8F87C: BL {pc}-0xbf8 ; 0x9ff8ec84 0x9FF8F880: B {pc}-0x24 ; 0x9ff8f85c ``` 2:当线程处理函数当中当中不定义数组或者定义数组未被初始化,那么不论编译优化选项-O0还是O2都能正常运行 。 ```c /* 线程 2 入口 */ void thread2_entry(void* parameter) { int count = 0; int i; char buf[10]; for(i = 0; i< 10;i++) buf[i] = i; while (1) { rt_kprintf("xxxxxxxxxxxxThread2 count:%d\n", ++count); /* 延时 50ms */ rt_thread_mdelay(500); } } /* 线程例程初始化 */ int thread_sample_init() { rt_thread_t thread2_ptr; rt_err_t result; #if 0 /* 初始化线程 1 */ /* 线程的入口是 thread1_entry,参数是 RT_NULL * 线程栈是 thread1_stack * 优先级是 20,时间片是 10 个 OS Tick */ result = rt_thread_init(&thread1, "thread1", thread1_entry, RT_NULL, &thread1_stack[0], sizeof(thread1_stack), 20, 10); /* 启动线程 */ if (result == RT_EOK) rt_thread_startup(&thread1); #endif /* 创建线程 2 */ /* 线程的入口是 thread2_entry, 参数是 RT_NULL * 栈空间是 512,优先级是 25,时间片是 25 个 OS Tick */ thread2_ptr = rt_thread_create("thread2", thread2_entry, RT_NULL, 512, 25, 25); /* 启动线程 */ if (thread2_ptr != RT_NULL) rt_thread_startup(thread2_ptr); return 0; } ``` ```python rtconfig.py: import os # toolchains options ARCH='arm' CPU='cortex-a' CROSS_TOOL='gcc' if os.getenv('RTT_CC'): CROSS_TOOL = os.getenv('RTT_CC') # only support GNU GCC compiler. PLATFORM = 'gcc' EXEC_PATH = '/home/linuxsir/gcc-arm-none-eabi-6_2-2016q4/bin' if os.getenv('RTT_EXEC_PATH'): EXEC_PATH = os.getenv('RTT_EXEC_PATH') BUILD = 'debug' if PLATFORM == 'gcc': # toolchains PREFIX = 'arm-none-eabi-' CC = PREFIX + 'gcc' CXX = PREFIX + 'g++' AS = PREFIX + 'gcc' AR = PREFIX + 'ar' LINK = PREFIX + 'gcc' TARGET_EXT = 'elf' SIZE = PREFIX + 'size' OBJDUMP = PREFIX + 'objdump' OBJCPY = PREFIX + 'objcopy' DEVICE = ' -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 ' CFLAGS = DEVICE + ' -Wall' AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -D__ASSEMBLY__' LINK_SCRIPT = ' wokoo.lds' LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-wokoo.map'+\ ' -T %s' % LINK_SCRIPT CPATH = '' LPATH = '' # generate debug info in all cases if BUILD == 'debug': CFLAGS += ' -O0 -gdwarf-2' AFLAGS += ' -gdwarf-2' else: CFLAGS += ' -O2' POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' +\ SIZE + ' $TARGET \n' ``` rtconfig.h: ```c #ifndef RT_CONFIG_H__ #define RT_CONFIG_H__ /* Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) */ /* RT-Thread Kernel */ #define RT_USING_FPU #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 1000 #define RT_USING_OVERFLOW_CHECK #define RT_USING_HOOK #define RT_USING_IDLE_HOOK #define RT_IDLE_HOOK_LIST_SIZE 4 #define IDLE_THREAD_STACK_SIZE 256 #define RT_USING_TIMER_SOFT #define RT_TIMER_THREAD_PRIO 4 #define RT_TIMER_THREAD_STACK_SIZE 512 #define RT_DEBUG #define RT_DEBUG_COLOR /* Inter-Thread communication */ #define RT_USING_SEMAPHORE #define RT_USING_MUTEX #define RT_USING_EVENT #define RT_USING_MAILBOX #define RT_USING_MESSAGEQUEUE /* end of Inter-Thread communication */ /* Memory Management */ #define RT_USING_MEMPOOL #define RT_USING_SMALL_MEM #define RT_USING_HEAP /* end of Memory Management */ /* Kernel Device Object */ #define RT_USING_DEVICE #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 1024 #define RT_CONSOLE_DEVICE_NAME "uart0" /* end of Kernel Device Object */ #define RT_VER_NUM 0x40002 /* end of RT-Thread Kernel */ #define ARCH_ARM //#define RT_USING_CPU_FFS #define ARCH_ARM_CORTEX_A #define ARCH_ARM_CORTEX_A7 /* 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 */ /* end of C++ features */ /* Command shell */ //#define RT_USING_NEWLIB //#define RT_USING_MINILIBC #define HAVE_SIGINFO #define HAVE_SIGVAL #define HAVE_SIGEVENT #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_USING_MSH_ONLY #define FINSH_ARG_MAX 10 /* end of Command shell */ /* Device virtual file system */ /* end of Device virtual file system */ /* Device Drivers */ #define RT_USING_DEVICE_IPC #define RT_PIPE_BUFSZ 512 #define RT_USING_SERIAL #define RT_SERIAL_RB_BUFSZ 64 #define RT_USING_PIN /* Using USB */ /* end of Using USB */ /* end of Device Drivers */ /* POSIX layer and C standard library */ #define RT_LIBC_USING_TIME /* end of POSIX layer and C standard library */ /* Network */ /* Socket abstraction layer */ /* end of Socket abstraction layer */ /* Network interface device */ /* end of Network interface device */ /* light weight TCP/IP stack */ /* end of light weight TCP/IP stack */ /* AT commands */ /* end of AT commands */ /* end of Network */ /* VBUS(Virtual Software BUS) */ /* end of VBUS(Virtual Software BUS) */ /* Utilities */ /* end of Utilities */ /* end of RT-Thread Components */ /* RT-Thread online packages */ /* IoT - internet of things */ /* Wi-Fi */ /* Marvell WiFi */ /* end of Marvell WiFi */ /* Wiced WiFi */ /* end of Wiced WiFi */ /* end of Wi-Fi */ /* IoT Cloud */ /* end of IoT Cloud */ /* end of IoT - internet of things */ /* security packages */ /* end of security packages */ /* language packages */ /* end of language packages */ /* multimedia packages */ /* end of multimedia packages */ /* tools packages */ /* end of tools packages */ /* system packages */ /* end of system packages */ /* peripheral libraries and drivers */ /* end of peripheral libraries and drivers */ /* miscellaneous packages */ /* samples: kernel and components samples */ /* end of samples: kernel and components samples */ /* end of miscellaneous packages */ /* end of RT-Thread online packages */ /* samples: kernel and components samples */ /* end of samples: kernel and components samples */ //#define RT_STUDIO_BUILT_IN #endif ```
查看更多
2
个回答
默认排序
按发布时间排序
aozima
2020-10-07
调网络不抓包,调I2C等时序不上逻辑分析仪,就像电工不用万用表!多用整理的好的文字,比截图更省流量,还能在整理过程中思考。
几个想法,可以尝试下 * buf的地址打印一下 * 汇编代码的调试信息开一下,这样能看到源代码,虽然优化后不一定对得上,但大体上是对的。 * while中最好能对buf做一下引用,不然优化会有直接丢弃所有buf相关的操作。 * 从经验上看,很可能是buf是char型号,地址不对齐,然后编译器赋值用的memset或是FPU指令。 * 报错应该应该是数据异常才是,但这里是非法指令,建议对PC和LR做一下定位 * 编译器对某些指令做得不好,有bUG,也是有可能的,
EEZK_1546
2020-10-08
这家伙很懒,什么也没写!
buf地址无法打印出来,因为到char buf就已经出现未定义错误,程序就执行不下去了 ```c void thread2_entry(void* parameter) { int count = 0; char buf[64]= {10,10,12,13,14}; rt_kprintf("buf addr :%p\n",buf); while (1) { rt_kprintf("xxxxxxxxxxxxThread2 count:%d\n", buf[0]); buf[1] = 0; /* 延时 50ms */ rt_thread_mdelay(3000); } } ``` 现象: ``` msh >undefined instruction: Execption: r00:0x00000000 r01:0xdeadbeef r02:0xdeadbeef r03:0x0002c60c r04:0xdeadbeef r05:0xdeadbeef r06:0xdeadbeef r07:0xdeadbeef r08:0xdeadbeef r09:0xdeadbeef r10:0xdeadbeef fp :0x0002c654 ip :0xdeadbeef sp :0x0002c600 lr :0x0001297c pc :0x000091a8 cpsr:0x00000013 thread pri status sp stack size max used left tick error -------- --- ------- ---------- ---------- ------ ---------- --- thread2 25 running 0x00000044 0x00000200 16% 0x00000018 000 tshell 20 suspend 0x000000cc 0x00001000 05% 0x0000000a 000 tidle0 31 ready 0x00000044 0x00000100 26% 0x00000020 000 main 10 close 0x00000080 0x00000800 14% 0x0000000d 000 shutdown... (0) assertion failed at function:rt_hw_cpu_shutdown, line number:85 ``` 但是当如果buf大小定义到100数据组,那么久能正常 ``` \ | / - RT - Thread Operating System / | \ 4.0.3 build Oct 7 2020 2006 - 2020 Copyright by rt-thread team Codefair Wokoo Platform SDK init start msh >buf addr :0002c5e8 xxxxxxxxxxxxThread2 count:4 xxxxxxxxxxxxThread2 count:4 xxxxxxxxxxxxThread2 count:4 ```
撰写答案
登录
注册新账号
关注者
0
被浏览
1.1k
关于作者
EEZK_1546
这家伙很懒,什么也没写!
提问
10
回答
2
被采纳
0
关注TA
发私信
相关问题
1
board.c:91: undefined reference to `Image$$RW_IRAM1$$Base'
2
复制的新手教程,为什么定义丢失了
3
cortex-a7支持fpu问题
4
关于RT-Thread和NEON兼容编译的问题
5
undefined instruction 错误
6
libcpu中arm的cortex-a 的文件使能浮点宏后存在问题
推荐文章
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
如何在master上的BSP中添加配置yml文件
2
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
3
RT-Thread 发布 EtherKit开源以太网硬件!
4
rt-thread使用cherryusb实现虚拟串口
5
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
热门标签
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
14
个答案
2
次被采纳
张世争
9
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
13
个答案
1
次被采纳
本月文章贡献
程序员阿伟
9
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
5
次点赞
RTT_逍遥
1
篇文章
2
次点赞
ThinkCode
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部