基础库移植
首先移植一下基础结构,按照SDK的结构编辑修改。把头文件放置于include/tinymaix
文件夹里
源文件放置于 src/tinymaix
文件夹里
编辑 Makefile
增加引索
#
# Rules for building library
#
# ----------------------------------------------------------------------------
# common rules
# ----------------------------------------------------------------------------
ROOT_PATH := ../..
include $(ROOT_PATH)/gcc.mk
# ----------------------------------------------------------------------------
# library and objects
# ----------------------------------------------------------------------------
LIBS := libtinymaix.a
DIRS := .
SRCS := $(sort $(basename $(foreach dir,$(DIRS),$(wildcard $(dir)/*.[csS]))))
OBJS := $(addsuffix .o,$(SRCS))
CC_FLAGS += -Wno-unused-variable -Wno-error=unused-but-set-variable -Wno-error=multichar -Wno-unused-but-set-variable -Wno-multichar
# library make rules
include $(LIB_MAKE_RULES)
在 project/Kconfig
里增加 Kconfig
引索
# Sipeed lib TinyMaix
config TINYMAIX
bool "TinyMaix is a tiny inference library for microcontrollers (TinyML)."
default n
help
set y to build library tinymaix.
同样吧project/project.mk
加入引索
mnist demo 移植
先复制一份hello_world
,重命名为 tinymaix_mnist
在 defconfig
里加入使用的包
运行错误,exception:6 happen!!
烧录板子上运行之后发现不能正常使用,报错如下:
use default flash chip mJedec 0x0
[FD I]: mode: 0x10, freq: 96000000Hz, drv: 0
[FD I]: jedec: 0x0, suspend_support: 1
mode select:e
platform information ===============================================
XR806 SDK v1.2.1 Sep 19 2022 20:46:25 62800400
heap space [0x209818, 0x24bc00), size 271336
cpu clock 160000000 Hz
HF clock 40000000 Hz
sdk option:
XIP : enable
INT LF OSC : enable
INT LDO : select
ILDO/EPWR : enable
SIP flash : enable
====================================================================
mnist demo
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,116,125,171,255,255,150, 93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,169,253,253,253,253,253,253,218, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,169,253,253,253,213,142,176,253,253,122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 52,250,253,210, 32, 12, 0, 6,206,253,140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 77,251,210, 25, 0, 0, 0,122,248,253, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 31, 18, 0, 0, 0, 0,209,253,253, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,117,247,253,198, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 76,247,253,231, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128,253,253,144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,176,246,253,159, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,234,253,233, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,198,253,253,141, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 78,248,253,189, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 19,200,253,253,141, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,134,253,253,173, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,248,253,253, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,248,253,253, 43, 20, 20, 20, 20, 5, 0, 5, 20, 20, 37,150,150,150,147, 10, 0,
0, 0, 0, 0, 0, 0, 0, 0,248,253,253,253,253,253,253,253,168,143,166,253,253,253,253,253,253,253,123, 0,
0, 0, 0, 0, 0, 0, 0, 0,174,253,253,253,253,253,253,253,253,253,253,253,249,247,247,169,117,117, 57, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,118,123,123,123,166,253,253,253,155,123,123, 41, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
================================ model stat ================================
mdl_type=0 (int8))
out_deq=1
input_cnt=1, output_cnt=1, layer_cnt=6
input 3dims: (28, 28, 1)
output 1dims: (1, 1, 10)
exception:6 happen!!
appos pstack:0x20a0e0 msp:0x24bfe0 psp:0x20a100
msplim:0x0 psplim:0x209a58
usage fault happen, UFSR:0x100
CPU registers:
R00:[0x20a100]: 0x00000019
R01:[0x20a104]: 0x00000003
R02:[0x20a108]: 0x00000000
R03:[0x20a10c]: 0x00000000
R04:[0x20a0e0]: 0x0020a1f8
R05:[0x20a0e4]: 0x002056c5
R06:[0x20a0e8]: 0x0000001c
R07:[0x20a0ec]: 0x00000000
R08:[0x20a0f0]: 0x08080808
R09:[0x20a0f4]: 0x09090909
R10:[0x20a0f8]: 0x10101010
R11:[0x20a0fc]: 0x11111111
R12:[0x20a110]: 0x00209413
R14(LR):[0x20a114]: 0x00204063
R15(PC):[0x20a118]: 0x00204062
xPSR:[0x20a11c]: 0x61100000
SHCSR:0x00070008 step:0
FPSCR:0xe000ed38
stack info:
[0x20a120]: 0x09090909 0x0001cd89 0x0020b9e0 0x00000019
[0x20a130]: 0x002093f8 0x00203315 0x00000000 0x00204da1
[0x20a140]: 0x00206cc9 0x0020a15c 0x00000001 0x0020a1f8
[0x20a150]: 0x002056c5 0x00204063 0x00206cc9 0x00000001
[0x20a160]: 0x00000001 0x00000001 0x0000000a 0x0001ca41
[0x20a170]: 0x00000001 0x0020b9e0 0x00000000 0x00000000
[0x20a180]: 0x00000000 0x0001cc81 0x0020a260 0x00000000
[0x20a190]: 0x0020b9e0 0xffffffff 0x00000000 0x0020b9e0
[0x20a1a0]: 0x0020a260 0x0000001c 0x00205647 0x08080808
[0x20a1b0]: 0x09090909 0x0001cd89 0x0020b9e0 0x0020a1f8
[0x20a1c0]: 0x0020a1ec 0x0000001c 0x00205647 0x08080808
[0x20a1d0]: 0x09090909 0x10101010 0x11111111 0x0020127d
[0x20a1e0]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x001c0003
[0x20a1f0]: 0x0001001c 0x00207114 0x001c0003 0x0001001c
[0x20a200]: 0x00000000 0xa5a5a5a5 0x00209a58 0xfffffffd
[0x20a210]: 0x04040404 0x05050505 0x06060606 0x07070707
[0x20a220]: 0x08080808 0x09090909 0x10101010 0x00000000
[0x20a230]: 0x00000000 0x04040404 0x05050505 0x06060606
[0x20a240]: 0x07070707 0x00201413 0x03030303 0x0002141d
[0x20a250]: 0xa5a5a5a5 0xa5a5a5a5 0x00000068 0xfffffffc
[0x20a260]: 0x0020a058 0x0000138c 0x00200900 0x00200900
[0x20a270]: 0x0020a260 0x002008f8 0x00000004 0x0020099c
[0x20a280]: 0x0020099c 0x0020a260 0x00000000 0x00000003
[0x20a290]: 0x00209a58 0x6e69616d 0x4418fe00 0x16dd06e6
[0x20a2a0]: 0x00fe4dbc 0x00000001 0x27d039ed 0x00000003
[0x20a2b0]: 0x00000000 0x00000000 0x00000000 0x9f7a9300
[0x20a2c0]: 0x00000208 0xfffffffc 0xa5a5a5a5 0xa5a5a5a5
[0x20a2d0]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a2e0]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a2f0]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a300]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a310]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a320]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a330]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a340]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a350]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a360]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a370]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a380]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a390]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a3a0]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a3b0]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a3c0]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a3d0]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a3e0]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a3f0]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a400]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a410]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a420]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a430]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a440]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a450]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a460]: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
[0x20a470]: 0xa5a5a5a5 0xa5a5a5a5 0x0020a2c8 0xfffffffd
[0x20a480]: 0x04040404 0x05050505 0x06060606 0x07070707
[0x20a490]: 0x08080808 0x09090909 0x10101010 0x11111111
[0x20a4a0]: 0x00000000 0x01010101 0x02020202 0x03030303
[0x20a4b0]: 0x12121212 0x0002141d 0x00203ad9 0x01000000
[0x20a4c0]: 0xa5a5a5a5 0xa5a5a5a5 0x00000068 0xfffffffc
[0x20a4d0]: 0x0020a478 0x310bfe93 0x002008c4 0x002008c4
[0x20a4e0]: 0x0020a4d0 0x002008bc 0x00000007 0xf668acd2
[0x20a4f0]: 0x504cf2d4 0x0020a4d0 0x00000000 0x00000000
[0x20a500]: 0x0020a2c8 0x454c4449 0x58e29900 0xe9499e84
[0x20a510]: 0x000f851c 0x00000002 0x88208fae 0x00000000
[LR]:0x204063
[0x203e60]: 0x83f0e8bd 0x68ab696c 0x4621b142 0xf85168a2
[0x203e70]: 0x441a0f10 0x92146849 0xc203aa12 0x68e246a1
[0x203e80]: 0x93174413 0x0f18f859 0xf8d9ab15 0xc3031004
[0x203e90]: 0x2b058823 0x80b7f200 0xf003e8df 0x7d695e03
[0x203ea0]: 0x6ae10388 0x2312e9d4 0x6aa19110 0x910f4423
[0x203eb0]: 0x44226a61 0x6a21910e 0x910da812 0x44216c61
[0x203ec0]: 0x6be1910c 0xf894910b 0x910a103b 0x103af894
[0x203ed0]: 0xf8949109 0x91081039 0x1038f894 0x8ee19107
[0x203ee0]: 0xf8949106 0x91051035 0x1034f894 0xf8949104
[0x203ef0]: 0x91031033 0x1032f894 0xf8949102 0x91011031
[0x203f00]: 0x1030f894 0xa9159100 0xfb60f000 0xd1a62800
[0x203f10]: 0xb113686b 0x46284621 0x88634798 0xfb08b1a3
[0x203f20]: 0xf8d9f206 0xeb073000 0x50bb0c02 0x3004f8d9
[0x203f30]: 0x3004f8cc 0x68a9682b 0x68e0795b 0xd1402b00
[0x203f40]: 0xf8cc4401 0x36011008 0x696b6862 0x616b4413
[0x203f50]: 0x33018a6b 0xe77c826b 0xa9156ae3 0x6aa39301
[0x203f60]: 0x9300a812 0x6a226a63 0xfd5af000 0x6ae1e7ce
[0x203f70]: 0x230de9d4 0x6aa19104 0x91034423 0x44226a61
[0x203f80]: 0x6a219102 0x9101a812 0x44216b21 0xa9159100
[0x203f90]: 0xfd92f000 0x6ae3e7ba 0x9301a915 0xa8126aa3
[0x203fa0]: 0x6a639300 0xf0006a22 0xe7affdcb 0xa9156ae3
[0x203fb0]: 0x6aa39301 0x9300a812 0x6a226a63 0xfe60f000
[0x203fc0]: 0x8ba2e7a4 0x43538b63 0x435a8be2 0x440b1883
[0x203fd0]: 0xf0233307 0x469e0307 0xeb034401 0x454b0982
[0x203fe0]: 0xf8ccd102 0xe7aee008 0x2b01f911 0xed946ae0
[0x203ff0]: 0x1a127a0a 0x2a90ee07 0x7ae7eef8 0x7a87ee67
[0x204000]: 0x7a01ece3 0x2005e7eb 0x0000e729 0x00000000
[0x204010]: 0x4ff0e92d 0x27004605 0x4897b095 0xfee6f000
[0x204020]: 0x79294b96 0xf8534896 0xf0002021 0x7969fea3
[0x204030]: 0xf0004894 0x896bfe9f 0x88e9892a 0xf0004892
[0x204040]: 0x8b6bfe99 0x93008aea 0x8b2b8aa9 0xf000488f
[0x204050]: 0x8c6bfe91 0x93008bea 0x8c2b8ba9 0xf000488c
[0x204060]: 0xe9d5fe89 0x488b1203 0xfe84f000 0xf000488a
[0x204070]: 0x488afebd 0xfebaf000 0x8b2a8ae9 0xfb028b6b
[0x204080]: 0x4358f001 0x48869000 0xfe74f000 0x46b846ba
[0x204090]: 0x9234f8df 0xb234f8df 0x0440f105 0x42bb896b
[0x2040a0]: 0x4640dc26 0xfb10f622 0x4b7e2200 0xfb76f622
[0x2040b0]: 0xe9d54606 0x44180303 0xf622460f 0x2200faf5
[0x2040c0]: 0xf6224b78 0xe9cdfb6b 0x46500102 0xfafcf622
[0x2040d0]: 0xe9d3a367 0xf6222300 0x4632fc8b 0x0100e9cd
[0x2040e0]: 0x4871463b 0xfe46f000 0xb0152000 0x8ff0e8bd
[0x2040f0]: 0x4648213f 0xfe3ef000 0x486c1b61 0xfe3af000
[0x204100]: 0x46482146 0xfe36f000 0x88626ae3 0x93108826
[0x204110]: 0x92136aa0 0xfaeaf622 0x010ee9cd 0x930c6a63
[0x204120]: 0xf6226a20 0xe9cdfae3 0x8be3010a 0x93099a13
[0x204130]: 0x46318ba3 0x8b639308 0x9307485d 0x93068b23
[0x204140]: 0x93058ae3 0x93048aa3 0x93038a63 0x93028a23
[0x204150]: 0x930168e3 0x930068a3 0xf0006863 0x8823fe0b
[0x204160]: 0xf2002b05 0x8b6180e9 0x8be68ba2 0x4372434a
[0x204170]: 0x68629213 0xf85b4490 0xeba82023 0x2b050802
[0x204180]: 0x80d8f200 0xf013e8df 0x003c0006 0x006f0042
[0x204190]: 0x00a400d6 0xf8949a13 0xf8943030 0x43536031
[0x2041a0]: 0x8ae64373 0x46482155 0xf000435e 0x6ce3fde3
[0x2041b0]: 0x930b4840 0x930a6ca3 0x93096c63 0x93086be3
[0x2041c0]: 0x303bf894 0xf8949307 0x9306303a 0x3039f894
[0x2041d0]: 0xf8949305 0x93043038 0x93038ee3 0x3035f894
[0x2041e0]: 0xf8949302 0x93013034 0x3033f894 0xf8949300
[0x2041f0]: 0xf8943032 0xf8942031 0xf0001030 0xe011fdbb
[0x204200]: 0x8a638aa6 0x8ae64373 0xe00b435e 0x215f8ae3
[0x204210]: 0x435e4648 0xfdaef000 0x230de9d4 0x48266b21
[0x204220]: 0xfda8f000 0x88229b13 0x68639305 0x1022f85b
[0x204230]: 0x1a5b4822 0x68e39304 0x93034921 0xf85168a3
[0x204240]: 0x93022022 0x46398be3 0x8ba39301 0x930044b2
[0x204250]: 0xf0008b63 0x4631fd8f 0xf000481a 0x6863fd8b
[PC]:0x204062
[0x203e60]: 0x83f0e8bd 0x68ab696c 0x4621b142 0xf85168a2
[0x203e70]: 0x441a0f10 0x92146849 0xc203aa12 0x68e246a1
[0x203e80]: 0x93174413 0x0f18f859 0xf8d9ab15 0xc3031004
[0x203e90]: 0x2b058823 0x80b7f200 0xf003e8df 0x7d695e03
[0x203ea0]: 0x6ae10388 0x2312e9d4 0x6aa19110 0x910f4423
[0x203eb0]: 0x44226a61 0x6a21910e 0x910da812 0x44216c61
[0x203ec0]: 0x6be1910c 0xf894910b 0x910a103b 0x103af894
[0x203ed0]: 0xf8949109 0x91081039 0x1038f894 0x8ee19107
[0x203ee0]: 0xf8949106 0x91051035 0x1034f894 0xf8949104
[0x203ef0]: 0x91031033 0x1032f894 0xf8949102 0x91011031
[0x203f00]: 0x1030f894 0xa9159100 0xfb60f000 0xd1a62800
[0x203f10]: 0xb113686b 0x46284621 0x88634798 0xfb08b1a3
[0x203f20]: 0xf8d9f206 0xeb073000 0x50bb0c02 0x3004f8d9
[0x203f30]: 0x3004f8cc 0x68a9682b 0x68e0795b 0xd1402b00
[0x203f40]: 0xf8cc4401 0x36011008 0x696b6862 0x616b4413
[0x203f50]: 0x33018a6b 0xe77c826b 0xa9156ae3 0x6aa39301
[0x203f60]: 0x9300a812 0x6a226a63 0xfd5af000 0x6ae1e7ce
[0x203f70]: 0x230de9d4 0x6aa19104 0x91034423 0x44226a61
[0x203f80]: 0x6a219102 0x9101a812 0x44216b21 0xa9159100
[0x203f90]: 0xfd92f000 0x6ae3e7ba 0x9301a915 0xa8126aa3
[0x203fa0]: 0x6a639300 0xf0006a22 0xe7affdcb 0xa9156ae3
[0x203fb0]: 0x6aa39301 0x9300a812 0x6a226a63 0xfe60f000
[0x203fc0]: 0x8ba2e7a4 0x43538b63 0x435a8be2 0x440b1883
[0x203fd0]: 0xf0233307 0x469e0307 0xeb034401 0x454b0982
[0x203fe0]: 0xf8ccd102 0xe7aee008 0x2b01f911 0xed946ae0
[0x203ff0]: 0x1a127a0a 0x2a90ee07 0x7ae7eef8 0x7a87ee67
[0x204000]: 0x7a01ece3 0x2005e7eb 0x0000e729 0x00000000
[0x204010]: 0x4ff0e92d 0x27004605 0x4897b095 0xfee6f000
[0x204020]: 0x79294b96 0xf8534896 0xf0002021 0x7969fea3
[0x204030]: 0xf0004894 0x896bfe9f 0x88e9892a 0xf0004892
[0x204040]: 0x8b6bfe99 0x93008aea 0x8b2b8aa9 0xf000488f
[0x204050]: 0x8c6bfe91 0x93008bea 0x8c2b8ba9 0xf000488c
[0x204060]: 0xe9d5fe89 0x488b1203 0xfe84f000 0xf000488a
[0x204070]: 0x488afebd 0xfebaf000 0x8b2a8ae9 0xfb028b6b
[0x204080]: 0x4358f001 0x48869000 0xfe74f000 0x46b846ba
[0x204090]: 0x9234f8df 0xb234f8df 0x0440f105 0x42bb896b
[0x2040a0]: 0x4640dc26 0xfb10f622 0x4b7e2200 0xfb76f622
[0x2040b0]: 0xe9d54606 0x44180303 0xf622460f 0x2200faf5
[0x2040c0]: 0xf6224b78 0xe9cdfb6b 0x46500102 0xfafcf622
[0x2040d0]: 0xe9d3a367 0xf6222300 0x4632fc8b 0x0100e9cd
[0x2040e0]: 0x4871463b 0xfe46f000 0xb0152000 0x8ff0e8bd
[0x2040f0]: 0x4648213f 0xfe3ef000 0x486c1b61 0xfe3af000
[0x204100]: 0x46482146 0xfe36f000 0x88626ae3 0x93108826
[0x204110]: 0x92136aa0 0xfaeaf622 0x010ee9cd 0x930c6a63
[0x204120]: 0xf6226a20 0xe9cdfae3 0x8be3010a 0x93099a13
[0x204130]: 0x46318ba3 0x8b639308 0x9307485d 0x93068b23
[0x204140]: 0x93058ae3 0x93048aa3 0x93038a63 0x93028a23
[0x204150]: 0x930168e3 0x930068a3 0xf0006863 0x8823fe0b
[0x204160]: 0xf2002b05 0x8b6180e9 0x8be68ba2 0x4372434a
[0x204170]: 0x68629213 0xf85b4490 0xeba82023 0x2b050802
[0x204180]: 0x80d8f200 0xf013e8df 0x003c0006 0x006f0042
[0x204190]: 0x00a400d6 0xf8949a13 0xf8943030 0x43536031
[0x2041a0]: 0x8ae64373 0x46482155 0xf000435e 0x6ce3fde3
[0x2041b0]: 0x930b4840 0x930a6ca3 0x93096c63 0x93086be3
[0x2041c0]: 0x303bf894 0xf8949307 0x9306303a 0x3039f894
[0x2041d0]: 0xf8949305 0x93043038 0x93038ee3 0x3035f894
[0x2041e0]: 0xf8949302 0x93013034 0x3033f894 0xf8949300
[0x2041f0]: 0xf8943032 0xf8942031 0xf0001030 0xe011fdbb
[0x204200]: 0x8a638aa6 0x8ae64373 0xe00b435e 0x215f8ae3
[0x204210]: 0x435e4648 0xfdaef000 0x230de9d4 0x48266b21
[0x204220]: 0xfda8f000 0x88229b13 0x68639305 0x1022f85b
[0x204230]: 0x1a5b4822 0x68e39304 0x93034921 0xf85168a3
[0x204240]: 0x93022022 0x46398be3 0x8ba39301 0x930044b2
[0x204250]: 0xf0008b63 0x4631fd8f 0xf000481a 0x6863fd8b
[text start]:0x200000
[0x200000]: 0x00200068 0x00207474 0x00207558 0x0020018c
[0x200010]: 0x00200010 0x00200010 0x00200018 0x00200018
[0x200020]: 0x0000fffc 0x0000000e 0x00000008 0xffffffff
[0x200030]: 0x00000fff 0x000001f4 0x002075c8 0x002075c8
[0x200040]: 0x00000000 0x00000000 0x00200150 0x00200170
[0x200050]: 0x00000000 0x0000d73a 0x0000d710 0x00000000
[0x200060]: 0x00000000 0x00000000 0x0020bb6c 0x00200000
[0x200070]: 0x00000000 0x0000dd94 0x0000dd78 0x00000000
[0x200080]: 0x0020b828 0x0020b828 0x0000006e 0x0000f489
[0x200090]: 0x0000000f 0x00000006 0x00000000 0x00000000
[0x2000a0]: 0x00201f01 0x00201f45 0x00000006 0x00000000
[0x2000b0]: 0x00000000 0x00200170 0x00209a38 0x00000000
[0x2000c0]: 0x00010eec 0x00010ea8 0x00000000 0x00000000
[0x2000d0]: 0x00000000 0x00000000 0x00000000 0x00000000
[0x2000e0]: 0x00011a00 0x000119e4 0x00000000 0x00000000
[0x2000f0]: 0x00000000 0x00000000 0x00000000 0x00000000
[0x200100]: 0x00011a05 0x000119e4 0x00000001 0x00000000
[0x200110]: 0x00000000 0x00000000 0x00000000 0x00000000
[0x200120]: 0x00011e3f 0x0020012c 0x00000000 0x00011e3f
[0x200130]: 0x00000000 0x00000000 0x00000000 0x00000000
[0x200140]: 0x00011ca5 0x00011c39 0x00000000 0x00000000
[0x200150]: 0x00207474 0x00200048 0x00000000 0x000127e8
[0x200160]: 0x000127cc 0x00000000 0x00000000 0x00000000
[0x200170]: 0x00200048 0x002000b4 0x00000000 0x00014551
[0x200180]: 0x00014528 0x00000000 0x00000038 0x00200008
[0x200190]: 0x00207558 0x00000000 0x00000000 0x00000000
[0x2001a0]: 0x00016374 0x00016378 0x00000000 0x00000006
[0x2001b0]: 0x00000000 0x00017079 0x00016f81 0x00016f7d
[0x2001c0]: 0x0017701c 0x00017399 0x000172a1 0x0001712d
[0x2001d0]: 0x00156085 0x00017635 0x00017419 0x00017415
[0x2001e0]: 0x00166085 0x00017635 0x00017419 0x00017415
[0x2001f0]: 0x00136085 0x00017635 0x00017419 0x00017415
[NVIC Pending]:0xe000e200
[0xe000e200]:0x00000000, 0x00000000, 0x00000000, 0x00000000
[0xe000e210]:0x00000000, 0x00000000, 0x00000000, 0x00000000
[0xe000e220]:0x00000000, 0x00000000, 0x00000000, 0x00000000
[0xe000e230]:0x00000000, 0x00000000, 0x00000000, 0x00000000
[NVIC Activing]:0xe000e300
[0xe000e300]:0x00000000, 0x00000000, 0x00000000, 0x00000000
[0xe000e310]:0x00000000, 0x00000000, 0x00000000, 0x00000000
[0xe000e320]:0x00000000, 0x00000000, 0x00000000, 0x00000000
[0xe000e330]:0x00000000, 0x00000000, 0x00000000, 0x00000000
Name State Pri Idx StkCur StkBot StkFree StkFreeMin
main ? 3 1 0x20a058 0x209a58 1536 1064
IDLE R 0 2 0x20a478 0x20a2c8 432 432
Tmr Svc B 6 3 0x20ada0 0x20a630 1904 1904
Looper B 4 5 0x20c580 0x20be48 1848 1848
console B 4 6 0x20ce90 0x20c738 1880 1880
pm B 3 4 0x20b6f0 0x20afb8 1848 1848
这里具体看这一部分
exception:6 happen!!
appos pstack:0x20a0e0 msp:0x24bfe0 psp:0x20a100
msplim:0x0 psplim:0x209a58
usage fault happen, UFSR:0x100
CPU registers:
R00:[0x20a100]: 0x00000019
R01:[0x20a104]: 0x00000003
R02:[0x20a108]: 0x00000000
R03:[0x20a10c]: 0x00000000
R04:[0x20a0e0]: 0x0020a1f8
R05:[0x20a0e4]: 0x002056c5
R06:[0x20a0e8]: 0x0000001c
R07:[0x20a0ec]: 0x00000000
R08:[0x20a0f0]: 0x08080808
R09:[0x20a0f4]: 0x09090909
R10:[0x20a0f8]: 0x10101010
R11:[0x20a0fc]: 0x11111111
R12:[0x20a110]: 0x00209413
R14(LR):[0x20a114]: 0x00204063
R15(PC):[0x20a118]: 0x00204062
xPSR:[0x20a11c]: 0x61100000
SHCSR:0x00070008 step:0
FPSCR:0xe000ed38
参考Arm® Cortex®-M33 Devices Generic User Guide,查阅到 exception:6
为 usage fault
继续追踪,查看 UFSR
寄存器定义,结合上面报错 usage fault happen, UFSR:0x100
可以得出这里的错误是 UNALIGNED
,也就是 Illegal unaligned load or store
对于 Cortex M33 平台,仅仅支持如下的部分访问方式,其他的访问方法均会触发UNALIGNED
错误
那么看一下是哪一行代码触发了这个错误,看最后一个PC指向的地址:0x00204062
位于 tm_stat.c
,看上去只是一行普普通通的 printf
,注释了看看效果。
虽然也出错了,但是代码已经运行到后面去了,现在继续上面的操作。
use default flash chip mJedec 0x0
[FD I]: mode: 0x10, freq: 96000000Hz, drv: 0
[FD I]: jedec: 0x0, suspend_support: 1
mode select:e
platform information ===============================================
XR806 SDK v1.2.1 Sep 19 2022 20:46:25 62800400
heap space [0x2097e8, 0x24bc00), size 271384
cpu clock 160000000 Hz
HF clock 40000000 Hz
sdk option:
XIP : enable
INT LF OSC : enable
INT LDO : select
ILDO/EPWR : enable
SIP flash : enable
====================================================================
mnist demo
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,116,125,171,255,255,150, 93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,169,253,253,253,253,253,253,218, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,169,253,253,253,213,142,176,253,253,122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 52,250,253,210, 32, 12, 0, 6,206,253,140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 77,251,210, 25, 0, 0, 0,122,248,253, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 31, 18, 0, 0, 0, 0,209,253,253, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,117,247,253,198, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 76,247,253,231, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128,253,253,144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,176,246,253,159, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,234,253,233, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,198,253,253,141, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 78,248,253,189, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 19,200,253,253,141, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,134,253,253,173, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,248,253,253, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,248,253,253, 43, 20, 20, 20, 20, 5, 0, 5, 20, 20, 37,150,150,150,147, 10, 0,
0, 0, 0, 0, 0, 0, 0, 0,248,253,253,253,253,253,253,253,168,143,166,253,253,253,253,253,253,253,123, 0,
0, 0, 0, 0, 0, 0, 0, 0,174,253,253,253,253,253,253,253,253,253,253,253,249,247,247,169,117,117, 57, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,118,123,123,123,166,253,253,253,155,123,123, 41, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
================================ model stat ================================
mdl_type=0 (int8))
out_deq=1
input_cnt=1, output_cnt=1, layer_cnt=6
input 3dims: (28, 28, 1)
output 1dims: (1, 1, 10)
//Note: PARAM is layer param size, include align padding
Idx Layer outshape inoft outoft PARAM MEMOUT OPS
--- Input 28, 28, 1 - 0 0 784 0
###L63: body oft = 64
###L70: type=0, is_out=0, size=152, in_oft=0, out_oft=784, in_dims=[3,28,28,1], out_dims=[3,13,13,4], in_s=0.004, in_zp=-128, out_s=0.016, out_zp=-128
###L85: Conv2d: kw=3, kh=3, sw=2, sh=2, dw=1, dh=1, act=1, pad=[0,0,0,0], dmul=0, ws_oft=80, w_oft=96, b_oft=136
000 Conv2D 13, 13, 4 0 784 72 676 6084
###L63: body oft = 216
###L70: type=0, is_out=0, size=432, in_oft=784, out_oft=0, in_dims=[3,13,13,4], out_dims=[3,6,6,8], in_s=0.016, in_zp=-128, out_s=0.016, out_zp=-128
###L85: Conv2d: kw=3, kh=3, sw=2, sh=2, dw=1, dh=1, act=1, pad=[0,0,0,0], dmul=0, ws_oft=80, w_oft=112, b_oft=400
001 Conv2D 6, 6, 8 784 0 352 288 10368
###L63: body oft = 648
###L70: type=0, is_out=0, size=1360, in_oft=0, out_oft=1400, in_dims=[3,6,6,8], out_dims=[3,2,2,16], in_s=0.016, in_zp=-128, out_s=0.057, out_zp=-128
###L85: Conv2d: kw=3, kh=3, sw=2, sh=2, dw=1, dh=1, act=1, pad=[0,0,0,0], dmul=0, ws_oft=80, w_oft=144, b_oft=1296
002 Conv2D 2, 2, 16 0 1400 1280 64 4608
###L63: body oft = 2008
###L70: type=1, is_out=0, size=48, in_oft=1400, out_oft=0, in_dims=[3,2,2,16], out_dims=[1,1,1,16], in_s=0.057, in_zp=-128, out_s=0.022, out_zp=-128
003 GAP 1, 1, 16 1400 0 0 16 64
###L63: body oft = 2056
###L70: type=2, is_out=0, size=304, in_oft=0, out_oft=1448, in_dims=[1,1,1,16], out_dims=[1,1,1,10], in_s=0.022, in_zp=-128, out_s=0.151, out_zp=42
###L95:
exception:6 happen!!
appos pstack:0x20a0b0 msp:0x24bfe0 psp:0x20a0d0
msplim:0x0 psplim:0x209a28
usage fault happen, UFSR:0x100
CPU registers:
R00:[0x20a0d0]: 0x00000008
R01:[0x20a0d4]: 0x00000003
R02:[0x20a0d8]: 0x00000000
R03:[0x20a0dc]: 0x00000000
R04:[0x20a0b0]: 0x00205ebd
R05:[0x20a0b4]: 0x002056b5
R06:[0x20a0b8]: 0x000000a0
R07:[0x20a0bc]: 0x00000004
R08:[0x20a0c0]: 0x00000798
R09:[0x20a0c4]: 0x00206d7c
R10:[0x20a0c8]: 0x00005284
R11:[0x20a0cc]: 0x00206f28
R12:[0x20a0e0]: 0x002093d2
R14(LR):[0x20a0e4]: 0x0020420f
R15(PC):[0x20a0e8]: 0x0020420e
xPSR:[0x20a0ec]: 0x61100000
SHCSR:0x00070008 step:0
FPSCR:0xe000ed38
找到 PC->0x0020420e
果然又是printf
注释掉
然后终于不是死在printf
上了,死在 switch
上了
这就没招了,询问群里大佬
那行,换一个编译器看看,换一个 gcc-arm-none-eabi-10.3-2021.07-x86_64-linux.tar.bz2
,测试完全正常。
Kconfig 增加选项
每一次修改模型类型,优化都要修改头文件,太不优雅了,加入 Kconfig
里直接配置比较好
编写 Kconfig
# Sipeed lib TinyMaix
config TINYMAIX
bool "TinyMaix is a tiny inference library for microcontrollers (TinyML)."
default n
help
set y to build library tinymaix.
choice
prompt "TinyMaix TM_MDL_TYPE"
depends on TINYMAIX
default TINYMAIX_TM_MDL_INT8
help
Select TinyMaix TM_MDL_TYPE, Support TM_MDL_INT8, TM_MDL_FP32
config TINYMAIX_TM_MDL_INT8
bool "Using TM_MDL_INT8"
help
Select TM_MDL_INT8.
config TINYMAIX_TM_MDL_FP32
bool "Using TM_MDL_FP32"
help
Select TM_MDL_FP32.
endchoice
choice
prompt "TinyMaix ARCH"
depends on TINYMAIX
default TINYMAIX_TM_ARCH_CPU
help
Select TinyMaix instruction set acceleration, Support ARCH_CPU, ARCH_ARM_SIMD
config TINYMAIX_TM_ARCH_CPU
bool "Pure cpu compute"
help
Pure cpu compute.
config TINYMAIX_TM_ARCH_ARM_SIMD
bool "Using ARM SIMD"
help
Using ARM SIMD.
endchoice
choice
prompt "TinyMaix OPT_LEVEL"
depends on TINYMAIX
default TINYMAIX_TM_ARCH_CPU
help
Select TinyMaix TM_OPT, Support TM_OPT0, TM_TM_OPT1
config TINYMAIX_TM_TM_OPT0
bool "TM_OPT0, least code and buf"
help
least code and buf.
config TINYMAIX_TM_TM_OPT1
bool "TM_OPT1, opt for speed, need more code and buf"
help
opt for speed, need more code and buf.
endchoice
头文件里加一下就ok了
#if defined(CONFIG_TINYMAIX_TM_ARCH_CPU)
#define TM_ARCH TM_ARCH_CPU
#elif defined(CONFIG_TINYMAIX_TM_ARCH_ARM_SIMD)
#define TM_ARCH TM_ARCH_ARM_SIMD
#else
#error "Unsupported TM_ARCH"
#endif
#if defined(CONFIG_TINYMAIX_TM_TM_OPT0)
#define TM_OPT_LEVEL TM_OPT0
#elif defined(CONFIG_TINYMAIX_TM_TM_OPT1)
#define TM_OPT_LEVEL TM_OPT1
#else
#error "Unsupported TM_OPT_LEVEL"
#endif
#if defined(CONFIG_TINYMAIX_TM_MDL_INT8)
#define TM_MDL_TYPE TM_MDL_INT8
#elif defined(CONFIG_TINYMAIX_TM_MDL_FP32)
#define TM_MDL_TYPE TM_MDL_FP32
#else
#error "Unsupported TM_MDL_TYPE"
#endif