@@ -294,7 +294,9 @@ int model_deinit(kpu_task_t *task)
294
294
295
295
STATIC mp_obj_t py_kpu_class_load (uint n_args , const mp_obj_t * pos_args , mp_map_t * kw_args )
296
296
{
297
- int err = 0 ;
297
+ // int err = 0;
298
+ char * err = NULL ;
299
+
298
300
py_kpu_net_obj_t * o = m_new_obj (py_kpu_net_obj_t );
299
301
300
302
uint8_t * model_data = NULL ;
@@ -304,7 +306,8 @@ STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_
304
306
kpu_task = (uint8_t * )malloc (sizeof (kpu_model_context_t ));
305
307
if (kpu_task == NULL )
306
308
{
307
- err = -1 ;//malloc error
309
+ // err = -1;//malloc error
310
+ err = "malloc error 0" ;
308
311
goto error ;
309
312
}
310
313
@@ -326,28 +329,32 @@ STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_
326
329
327
330
if (model_size < 0 )
328
331
{
329
- err = -2 ;//read error
332
+ // err = -2;//read error
333
+ err = "read model size error 1" ;
330
334
goto error ;
331
335
}
332
336
mp_printf (& mp_plat_print , "model_size=%d\r\n" ,model_size );
333
337
334
338
model_data = (uint8_t * )malloc (model_size * sizeof (uint8_t ));
335
339
if (model_data == NULL )
336
340
{
337
- err = -1 ;//malloc error
341
+ // err = -1;//malloc error
342
+ err = "malloc error 1" ;
338
343
goto error ;
339
344
}
340
345
341
346
status = w25qxx_read_data_dma (model_addr , model_data , model_size , W25QXX_QUAD_FAST );
342
347
if (status != W25QXX_OK )
343
348
{
344
- err = -2 ;//read error
349
+ // err = -2;//read error
350
+ err = "read model data error 1" ;
345
351
goto error ;
346
352
}
347
353
int ret = kpu_load_kmodel (kpu_task , model_data );
348
354
if (ret != 0 )
349
355
{
350
- err = -3 ; //load error
356
+ // err = -3; //load error
357
+ err = "load model data error 1" ;
351
358
goto error ;
352
359
}
353
360
}
@@ -364,6 +371,7 @@ STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_
364
371
if ( err != 0 )
365
372
{
366
373
model_deinit (kpu_task );
374
+ err = "model init error 2" ;
367
375
goto error ;
368
376
}
369
377
@@ -382,15 +390,17 @@ STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_
382
390
383
391
if (model_size <= 0 )
384
392
{
385
- err = -2 ;//read error
393
+ // err = -2;//read error
394
+ err = "read model size error 2" ;
386
395
vfs_internal_close (file , & ferr );
387
396
goto error ;
388
397
}
389
398
390
399
model_data = (uint8_t * )malloc (model_size * sizeof (uint8_t ));
391
400
if (model_data == NULL )
392
401
{
393
- err = -1 ;//malloc error
402
+ // err = -1;//malloc error
403
+ err = "malloc error 2" ;
394
404
goto error ;
395
405
}
396
406
@@ -409,7 +419,8 @@ STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_
409
419
int ret = kpu_load_kmodel (kpu_task , model_data );
410
420
if (ret != 0 )
411
421
{
412
- err = -3 ; //load error
422
+ // err = -3; //load error
423
+ err = "load model data error 2" ;
413
424
goto error ;
414
425
}
415
426
@@ -450,7 +461,7 @@ STATIC mp_obj_t py_kpu_class_load(uint n_args, const mp_obj_t *pos_args, mp_map_
450
461
m_del (py_kpu_net_obj_t , o ,sizeof (py_kpu_net_obj_t ));
451
462
452
463
char msg [50 ];
453
- sprintf (msg ,"[MAIXPY]kpu: load error %d " , err );
464
+ sprintf (msg ,"[MAIXPY]:kpu load error: %s " , err );
454
465
mp_raise_ValueError (msg );
455
466
return mp_const_false ;
456
467
}
0 commit comments