官方暂时未开放模型编译器,先移植下TinyMAXI,跑下手写题识别并用LCD显示。
1.移植下TinyMAXI
![image.png image.png](//file.elecfans.com/web2/M00/7D/50/pYYBAGN7K6qAB1ZoAAFNVTF6o9A455.jpg)
将TinyMAXI的文件放入src目录下,并添加修改到cmaklists.txt文件中,6011a支持smid指令,可加速运行神经网络。
测试代码如下
TM_DBGT_INIT()
TM_PRINTF("mnist demo\n")
tm_mdl_t mdl
for(int i=0
TM_PRINTF("%3d,", mnist_pic[i])
if(i%28==27)TM_PRINTF("\n")
}
tm_mat_t in_uint8 = {3,28,28,1, {(mtype_t*)mnist_pic}}
tm_mat_t in = {3,28,28,1, {NULL}}
tm_mat_t outs[1]
tm_err_t res
tm_stat((tm_mdlbin_t*)mdl_data)
res = tm_load(&mdl, mdl_data, NULL, layer_cb, &in)
if(res != TM_OK) {
TM_PRINTF("tm model load err %d\n", res)
return
}
#if (TM_MDL_TYPE == TM_MDL_INT8) || (TM_MDL_TYPE == TM_MDL_INT16)
res = tm_preprocess(&mdl, TMPP_UINT2INT, &in_uint8, &in)
#else
res = tm_preprocess(&mdl, TMPP_UINT2FP01, &in_uint8, &in)
#endif
//TM_DBGT_START()
res = tm_run(&mdl, &in, outs)
//TM_DBGT("tm_run")
if(res==TM_OK) parse_output(outs)
else TM_PRINTF("tm run error: %d\n", res)
tm_unload(&mdl)
串口输出结果如图
![image.png image.png](//file.elecfans.com/web2/M00/7D/50/pYYBAGN7K6mAMlFIAAGreyGs0WU331.jpg)
2.SPI LCD
首先prj.conf文件开启spi功能,设置CONFIG_SPI=y,然后,修改配置I/O口,6011a SPI1默认关闭,这里使用SPI0,如图管脚配置:
![image.png image.png](//file.elecfans.com/web2/M00/7C/C2/poYBAGN7K6mACdLfAAS197eZSZg157.jpg)
设备驱动代码如下:
spi速率可达到100M,非常快。
const struct device *dev0;
const struct device* dev1 ;
static struct spi_config spi_cfg = {
.operation = SPI_WORD_SET(8)| SPI_OP_MODE_MASTER|SPI_TRANSFER_MSB|SPI_LINES_SINGLE,
.slave = 0,
.frequency = 100000000U,
};
void LCD_GPIO_Init(void)
{
dev0=device_get_binding("GPIO_A");
dev1= device_get_binding("SPI_0");
if(dev1 == NULL){
printk("ERR: No Device Drivers!\n");
return;
}
if(!device_is_ready(dev1)){
printk("ERR: Device Was Not Ready - %s\n",dev1->name);
return;
}
(void)gpio_pin_configure(dev0,14,(GPIO_OUTPUT|GPIO_PULL_UP));
(void)gpio_pin_configure(dev0,15,(GPIO_OUTPUT|GPIO_PULL_UP));
(void)gpio_pin_configure(dev0,16,(GPIO_OUTPUT|GPIO_PULL_UP));
(void)gpio_pin_configure(dev0,13,(GPIO_OUTPUT|GPIO_PULL_UP));
}
原作者:zhai