81
81
82
82
let resp = & mut ResponseWriter :: new ( req. command , rbuf) ;
83
83
84
- // defmt:: trace!("Dap command: {}", req.command);
84
+ trace ! ( "Dap command: {}" , req. command) ;
85
85
86
86
match req. command {
87
87
Command :: DAP_Info => self . process_info ( req, resp, version) ,
@@ -227,12 +227,12 @@ where
227
227
}
228
228
} ;
229
229
230
- // defmt:: info!(
231
- // "DAP connect: {}, SWD: {}, JTAG: {}",
232
- // port,
233
- // SWD::AVAILABLE,
234
- // JTAG::AVAILABLE
235
- // );
230
+ info ! (
231
+ "DAP connect: {}, SWD: {}, JTAG: {}" ,
232
+ port,
233
+ SWD :: AVAILABLE ,
234
+ JTAG :: AVAILABLE
235
+ ) ;
236
236
237
237
match ( SWD :: AVAILABLE , JTAG :: AVAILABLE , port) {
238
238
// SWD
@@ -386,31 +386,33 @@ where
386
386
387
387
resp. write_ok ( ) ; // assume ok until we finish
388
388
let sequence_count = req. next_u8 ( ) ;
389
- let success = ( 0 ..sequence_count) . map ( |_| {
390
- // parse the seqnence info
391
- let sequence_info = req. next_u8 ( ) ;
392
- let nbits: usize = match sequence_info & 0x3F {
393
- // CMSIS-DAP says 0 means 64 bits
394
- 0 => 64 ,
395
- // Other integers are normal.
396
- n => n as usize ,
397
- } ;
398
- let nbytes = ( nbits + 7 ) / 8 ;
399
- let output = ( sequence_info & 0x80 ) == 0 ;
400
-
401
- if output {
402
- let output_data = req. data . get ( ..nbytes) . ok_or ( ( ) ) ?;
403
- swd. write_sequence ( nbits, output_data) . or ( Err ( ( ) ) ) ?;
404
- req. consume ( nbytes) ;
405
- Ok ( 0 )
406
- } else {
407
- let input_data = resp. remaining ( ) . get_mut ( ..nbytes) . ok_or ( ( ) ) ?;
408
- swd. read_sequence ( nbits, input_data) . or ( Err ( ( ) ) ) ?;
409
- resp. skip ( nbytes) ;
410
- Ok ( nbytes)
411
- }
412
- } ) . all ( |r : Result < usize , ( ) > | r. is_ok ( ) ) ;
413
-
389
+ let success = ( 0 ..sequence_count)
390
+ . map ( |_| {
391
+ // parse the seqnence info
392
+ let sequence_info = req. next_u8 ( ) ;
393
+ let nbits: usize = match sequence_info & 0x3F {
394
+ // CMSIS-DAP says 0 means 64 bits
395
+ 0 => 64 ,
396
+ // Other integers are normal.
397
+ n => n as usize ,
398
+ } ;
399
+ let nbytes = ( nbits + 7 ) / 8 ;
400
+ let output = ( sequence_info & 0x80 ) == 0 ;
401
+
402
+ if output {
403
+ let output_data = req. data . get ( ..nbytes) . ok_or ( ( ) ) ?;
404
+ swd. write_sequence ( nbits, output_data) . or ( Err ( ( ) ) ) ?;
405
+ req. consume ( nbytes) ;
406
+ Ok ( 0 )
407
+ } else {
408
+ let input_data = resp. remaining ( ) . get_mut ( ..nbytes) . ok_or ( ( ) ) ?;
409
+ swd. read_sequence ( nbits, input_data) . or ( Err ( ( ) ) ) ?;
410
+ resp. skip ( nbytes) ;
411
+ Ok ( nbytes)
412
+ }
413
+ } )
414
+ . all ( |r : Result < usize , ( ) > | r. is_ok ( ) ) ;
415
+
414
416
if !success {
415
417
resp. write_u8_at ( 0 , 0xFF ) ;
416
418
}
@@ -994,17 +996,26 @@ mod test {
994
996
) ;
995
997
996
998
// write 8 bits, read 5 bits, write 33 bits
997
- let report = [ 0x1Du8 , 3 , 8 , 0b10111101 , 0x80 | 5 , 33 , 0x56 , 0x83 , 0xAB , 0x32 , 0x01 ] ;
999
+ let report = [
1000
+ 0x1Du8 ,
1001
+ 3 ,
1002
+ 8 ,
1003
+ 0b10111101 ,
1004
+ 0x80 | 5 ,
1005
+ 33 ,
1006
+ 0x56 ,
1007
+ 0x83 ,
1008
+ 0xAB ,
1009
+ 0x32 ,
1010
+ 0x01 ,
1011
+ ] ;
998
1012
let mut rbuf = [ 0u8 ; 64 ] ;
999
1013
dap. state . to_swd ( ) ;
1000
1014
match & mut dap. state {
1001
1015
State :: Swd ( swd) => {
1002
1016
swd. expect_write_sequence ( )
1003
1017
. once ( )
1004
- . with (
1005
- eq ( 8 ) ,
1006
- eq ( [ 0b10111101u8 ] ) ,
1007
- )
1018
+ . with ( eq ( 8 ) , eq ( [ 0b10111101u8 ] ) )
1008
1019
. return_const ( Ok ( ( ) ) ) ;
1009
1020
swd. expect_read_sequence ( )
1010
1021
. once ( )
@@ -1015,19 +1026,13 @@ mod test {
1015
1026
} ) ;
1016
1027
swd. expect_write_sequence ( )
1017
1028
. once ( )
1018
- . with (
1019
- eq ( 33 ) ,
1020
- eq ( [ 0x56 , 0x83 , 0xAB , 0x32 , 0x01 ] ) ,
1021
- )
1029
+ . with ( eq ( 33 ) , eq ( [ 0x56 , 0x83 , 0xAB , 0x32 , 0x01 ] ) )
1022
1030
. return_const ( Ok ( ( ) ) ) ;
1023
1031
}
1024
1032
_ => assert ! ( false , "can't switch to swd" ) ,
1025
1033
}
1026
1034
let rsize = dap. process_command ( & report, & mut rbuf, DapVersion :: V2 ) ;
1027
1035
assert_eq ! ( rsize, 3 ) ;
1028
- assert_eq ! (
1029
- & rbuf[ ..3 ] ,
1030
- & [ 0x1Du8 , 0x00 , 0x1F ]
1031
- )
1036
+ assert_eq ! ( & rbuf[ ..3 ] , & [ 0x1Du8 , 0x00 , 0x1F ] )
1032
1037
}
1033
1038
}
0 commit comments