@@ -52,6 +52,8 @@ struct port_options port_opts = {
52
52
.baudRate = SERIAL_BAUD_57600 ,
53
53
.serial_mode = "8e1" ,
54
54
.bus_addr = 0 ,
55
+ .rx_frame_max = STM32_MAX_RX_FRAME ,
56
+ .tx_frame_max = STM32_MAX_TX_FRAME ,
55
57
};
56
58
int rd = 0 ;
57
59
int wr = 0 ;
@@ -479,9 +481,12 @@ int main(int argc, char* argv[]) {
479
481
return ret ;
480
482
}
481
483
482
- int parse_options (int argc , char * argv []) {
484
+ int parse_options (int argc , char * argv [])
485
+ {
483
486
int c ;
484
- while ((c = getopt (argc , argv , "a:b:m:r:w:e:vn:g:jkfcChuos:S:i:R" )) != -1 ) {
487
+ char * pLen ;
488
+
489
+ while ((c = getopt (argc , argv , "a:b:m:r:w:e:vn:g:jkfcChuos:S:F:i:R" )) != -1 ) {
485
490
switch (c ) {
486
491
case 'a' :
487
492
port_opts .bus_addr = strtoul (optarg , NULL , 0 );
@@ -595,7 +600,6 @@ int parse_options(int argc, char *argv[]) {
595
600
fprintf (stderr , "ERROR: Invalid options, can't specify start page / num pages and start address/length\n" );
596
601
return 1 ;
597
602
} else {
598
- char * pLen ;
599
603
start_addr = strtoul (optarg , & pLen , 0 );
600
604
if (* pLen == ':' ) {
601
605
pLen ++ ;
@@ -607,6 +611,36 @@ int parse_options(int argc, char *argv[]) {
607
611
}
608
612
}
609
613
break ;
614
+ case 'F' :
615
+ port_opts .rx_frame_max = strtoul (optarg , & pLen , 0 );
616
+ if (* pLen == ':' ) {
617
+ pLen ++ ;
618
+ port_opts .tx_frame_max = strtoul (pLen , NULL , 0 );
619
+ }
620
+ if (port_opts .rx_frame_max < 0
621
+ || port_opts .tx_frame_max < 0 ) {
622
+ fprintf (stderr , "ERROR: Invalid negative value for option -F\n" );
623
+ return 1 ;
624
+ }
625
+ if (port_opts .rx_frame_max == 0 )
626
+ port_opts .rx_frame_max = STM32_MAX_RX_FRAME ;
627
+ if (port_opts .tx_frame_max == 0 )
628
+ port_opts .tx_frame_max = STM32_MAX_TX_FRAME ;
629
+ if (port_opts .rx_frame_max < 20
630
+ || port_opts .tx_frame_max < 5 ) {
631
+ fprintf (stderr , "ERROR: current code cannot work with small frames.\n" );
632
+ fprintf (stderr , "min(RX) = 20, min(TX) = 5\n" );
633
+ return 1 ;
634
+ }
635
+ if (port_opts .rx_frame_max > STM32_MAX_RX_FRAME ) {
636
+ fprintf (stderr , "WARNING: Ignore RX length in option -F\n" );
637
+ port_opts .rx_frame_max = STM32_MAX_RX_FRAME ;
638
+ }
639
+ if (port_opts .tx_frame_max > STM32_MAX_TX_FRAME ) {
640
+ fprintf (stderr , "WARNING: Ignore TX length in option -F\n" );
641
+ port_opts .tx_frame_max = STM32_MAX_TX_FRAME ;
642
+ }
643
+ break ;
610
644
case 'f' :
611
645
force_binary = 1 ;
612
646
break ;
@@ -676,6 +710,7 @@ void show_help(char *name) {
676
710
" -g address Start execution at specified address (0 = flash start)\n"
677
711
" -S address[:length] Specify start address and optionally length for\n"
678
712
" read/write/erase operations\n"
713
+ " -F RX_length[:TX_length] Specify the max length of RX and TX frame\n"
679
714
" -s start_page Flash at specified page (0 = flash start)\n"
680
715
" -f Force binary parser\n"
681
716
" -h Show this help\n"
0 commit comments