45
45
#include "usb_dfu.h"
46
46
47
47
48
- #define SYS_LOG_LEVEL CONFIG_SYS_LOG_USB_DFU_LEVEL
49
- #include <misc/sys_log.h>
48
+ #ifndef CONFIG_USB_DFU_DEBUG
49
+ #define DBG (...) { ; }
50
+ #else
51
+ #if defined(CONFIG_STDOUT_CONSOLE )
52
+ #include <stdio.h>
53
+ #define DBG printf
54
+ #else
55
+ #define DBG printk
56
+ #endif /* CONFIG_STDOUT_CONSOLE */
57
+ #endif /* CONFIG_USB_DFU_DEBUG */
50
58
51
59
/* Alternate settings are used to access additional memory segments.
52
60
* This example uses the alternate settings as an offset into flash.
@@ -338,7 +346,7 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
338
346
339
347
switch (pSetup -> bRequest ) {
340
348
case DFU_GETSTATUS :
341
- SYS_LOG_DBG ("DFU_GETSTATUS: status %d, state %d" ,
349
+ DBG ("DFU_GETSTATUS: status %d, state %d\n " ,
342
350
dfu_data .status , dfu_data .state );
343
351
344
352
if (dfu_data .state == dfuMANIFEST_SYNC )
@@ -354,13 +362,13 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
354
362
break ;
355
363
356
364
case DFU_GETSTATE :
357
- SYS_LOG_DBG ("DFU_GETSTATE" );
365
+ DBG ("DFU_GETSTATE\n " );
358
366
(* data )[0 ] = dfu_data .state ;
359
367
* data_len = 1 ;
360
368
break ;
361
369
362
370
case DFU_ABORT :
363
- SYS_LOG_DBG ("DFU_ABORT" );
371
+ DBG ("DFU_ABORT\n " );
364
372
365
373
if (dfu_check_app_state ())
366
374
return - EINVAL ;
@@ -371,7 +379,7 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
371
379
break ;
372
380
373
381
case DFU_CLRSTATUS :
374
- SYS_LOG_DBG ("DFU_CLRSTATUS" );
382
+ DBG ("DFU_CLRSTATUS\n " );
375
383
376
384
if (dfu_check_app_state ())
377
385
return - EINVAL ;
@@ -381,7 +389,7 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
381
389
break ;
382
390
383
391
case DFU_DNLOAD :
384
- SYS_LOG_DBG ("DFU_DNLOAD block %d, len %d, state %d" ,
392
+ DBG ("DFU_DNLOAD block %d, len %d, state %d\n " ,
385
393
pSetup -> wValue , pSetup -> wLength , dfu_data .state );
386
394
387
395
if (dfu_check_app_state ())
@@ -390,7 +398,7 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
390
398
switch (dfu_data .state ) {
391
399
case dfuIDLE :
392
400
dfu_reset_counters ();
393
- SYS_LOG_DBG ("DFU_DNLOAD start" );
401
+ DBG ("DFU_DNLOAD start\n " );
394
402
case dfuDNLOAD_IDLE :
395
403
if (pSetup -> wLength != 0 ) {
396
404
/* Download has started */
@@ -402,13 +410,12 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
402
410
DFU_FLASH_ADDR +
403
411
dfu_data .bytes_rcvd ,
404
412
dfu_data .flash_page_size );
405
- SYS_LOG_DBG ("Flash erase" );
413
+ DBG ("Flash erase\n " );
406
414
if (ret ) {
407
415
dfu_data .state = dfuERROR ;
408
416
dfu_data .status = errERASE ;
409
- SYS_LOG_ERR ("DFU flash erase "
410
- "error, ret %d" ,
411
- ret );
417
+ DBG ("DFU flash erase error, "
418
+ "ret %d\n" , ret );
412
419
}
413
420
}
414
421
@@ -421,8 +428,8 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
421
428
if (ret ) {
422
429
dfu_data .state = dfuERROR ;
423
430
dfu_data .status = errWRITE ;
424
- SYS_LOG_ERR ("DFU flash write error, "
425
- "ret %d" , ret );
431
+ DBG ("DFU flash write error, ret %d\n" ,
432
+ ret );
426
433
} else
427
434
dfu_data .bytes_rcvd += pSetup -> wLength ;
428
435
} else {
@@ -432,16 +439,15 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
432
439
}
433
440
break ;
434
441
default :
435
- SYS_LOG_ERR ("DFU_DNLOAD wrong state %d" ,
436
- dfu_data .state );
442
+ DBG ("DFU_DNLOAD wrong state %d\n" , dfu_data .state );
437
443
dfu_data .state = dfuERROR ;
438
444
dfu_data .status = errUNKNOWN ;
439
445
dfu_reset_counters ();
440
446
return - EINVAL ;
441
447
}
442
448
break ;
443
449
case DFU_UPLOAD :
444
- SYS_LOG_DBG ("DFU_UPLOAD block %d, len %d, state %d" ,
450
+ DBG ("DFU_UPLOAD block %d, len %d, state %d\n " ,
445
451
pSetup -> wValue , pSetup -> wLength , dfu_data .state );
446
452
447
453
if (dfu_check_app_state ())
@@ -450,12 +456,12 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
450
456
switch (dfu_data .state ) {
451
457
case dfuIDLE :
452
458
dfu_reset_counters ();
453
- SYS_LOG_DBG ("DFU_UPLOAD start" );
459
+ DBG ("DFU_UPLOAD start\n " );
454
460
case dfuUPLOAD_IDLE :
455
461
if (!pSetup -> wLength ||
456
462
dfu_data .block_nr != pSetup -> wValue ) {
457
- SYS_LOG_ERR ("DFU_UPLOAD block %d, expected "
458
- "%d, len %d" , pSetup -> wValue ,
463
+ DBG ("DFU_UPLOAD block %d, expected %d, "
464
+ "len %d\n " , pSetup -> wValue ,
459
465
dfu_data .block_nr , pSetup -> wLength );
460
466
dfu_data .state = dfuERROR ;
461
467
dfu_data .status = errUNKNOWN ;
@@ -498,16 +504,15 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
498
504
499
505
break ;
500
506
default :
501
- SYS_LOG_ERR ("DFU_UPLOAD wrong state %d" ,
502
- dfu_data .state );
507
+ DBG ("DFU_UPLOAD wrong state %d\n" , dfu_data .state );
503
508
dfu_data .state = dfuERROR ;
504
509
dfu_data .status = errUNKNOWN ;
505
510
dfu_reset_counters ();
506
511
return - EINVAL ;
507
512
}
508
513
break ;
509
514
case DFU_DETACH :
510
- SYS_LOG_DBG ("DFU_DETACH timeout %d, state %d" ,
515
+ DBG ("DFU_DETACH timeout %d, state %d\n " ,
511
516
pSetup -> wValue , dfu_data .state );
512
517
513
518
if (dfu_data .state != appIDLE ) {
@@ -528,7 +533,7 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
528
533
usb_set_config (& dfu_config );
529
534
break ;
530
535
default :
531
- SYS_LOG_ERR ("DFU UNKNOWN STATE: %d" , pSetup -> bRequest );
536
+ DBG ("DFU UNKNOWN STATE: %d\n " , pSetup -> bRequest );
532
537
return - EINVAL ;
533
538
}
534
539
@@ -547,33 +552,32 @@ static void dfu_status_cb(enum usb_dc_status_code status)
547
552
/* Check the USB status and do needed action if required */
548
553
switch (status ) {
549
554
case USB_DC_ERROR :
550
- SYS_LOG_ERR ("USB device error" );
555
+ DBG ("USB device error\n " );
551
556
break ;
552
557
case USB_DC_RESET :
553
- SYS_LOG_DBG ("USB device reset detected, state %d" ,
554
- dfu_data .state );
558
+ DBG ("USB device reset detected, state %d\n" , dfu_data .state );
555
559
if (dfu_data .state == appDETACH ) {
556
560
dfu_data .state = dfuIDLE ;
557
561
}
558
562
break ;
559
563
case USB_DC_CONNECTED :
560
- SYS_LOG_DBG ("USB device connected" );
564
+ DBG ("USB device connected\n " );
561
565
break ;
562
566
case USB_DC_CONFIGURED :
563
- SYS_LOG_DBG ("USB device configured" );
567
+ DBG ("USB device configured\n " );
564
568
break ;
565
569
case USB_DC_DISCONNECTED :
566
- SYS_LOG_DBG ("USB device disconnected" );
570
+ DBG ("USB device disconnected\n " );
567
571
break ;
568
572
case USB_DC_SUSPEND :
569
- SYS_LOG_DBG ("USB device supended" );
573
+ DBG ("USB device supended\n " );
570
574
break ;
571
575
case USB_DC_RESUME :
572
- SYS_LOG_DBG ("USB device resumed" );
576
+ DBG ("USB device resumed\n " );
573
577
break ;
574
578
case USB_DC_UNKNOWN :
575
579
default :
576
- SYS_LOG_WRN ("USB unknown state" );
580
+ DBG ("USB unknown state\n " );
577
581
break ;
578
582
}
579
583
}
@@ -596,12 +600,11 @@ static int dfu_custom_handle_req(struct usb_setup_packet *pSetup,
596
600
if (REQTYPE_GET_RECIP (pSetup -> bmRequestType ) ==
597
601
REQTYPE_RECIP_INTERFACE ) {
598
602
if (pSetup -> bRequest == REQ_SET_INTERFACE ) {
599
- SYS_LOG_DBG ("DFU alternate setting %d" ,
600
- pSetup -> wValue );
603
+ DBG ("DFU alternate setting %d\n" , pSetup -> wValue );
601
604
602
605
if (pSetup -> wValue >= DFU_MODE_ALTERNATE_SETTINGS ) {
603
- SYS_LOG_DBG ("Invalid DFU alternate setting "
604
- "(%d)" , pSetup -> wValue );
606
+ DBG ("Invalid DFU alternate setting (%d)\n" ,
607
+ pSetup -> wValue );
605
608
} else {
606
609
dfu_data .alt_setting = pSetup -> wValue ;
607
610
}
@@ -652,14 +655,14 @@ int dfu_start(struct device *flash_dev, uint32_t flash_base_addr,
652
655
/* Initialize the USB driver with the right configuration */
653
656
ret = usb_set_config (& dfu_config );
654
657
if (ret < 0 ) {
655
- SYS_LOG_ERR ("Failed to config USB" );
658
+ DBG ("Failed to config USB\n " );
656
659
return ret ;
657
660
}
658
661
659
662
/* Enable USB driver */
660
663
ret = usb_enable (& dfu_config );
661
664
if (ret < 0 ) {
662
- SYS_LOG_ERR ("Failed to enable USB" );
665
+ DBG ("Failed to enable USB\n " );
663
666
return ret ;
664
667
}
665
668
0 commit comments