6
6
import re
7
7
import sys
8
8
import textwrap
9
- from xml .dom import minidom
10
9
from xml .dom .minidom import parse , Node
11
10
from argparse import RawTextHelpFormatter
12
11
@@ -64,7 +63,7 @@ def get_gpio_af_num(pintofind, iptofind):
64
63
if m .nodeType == Node .ELEMENT_NODE :
65
64
for secondlevel in m .attributes .items ():
66
65
k += 1
67
- # if 'I2C1_SDA' in secondlevel:
66
+ # if 'I2C1_SDA' in secondlevel:
68
67
if iptofind in secondlevel :
69
68
# DBG print (i, j, m.attributes.items())
70
69
# m = IP node found
@@ -115,22 +114,22 @@ def get_gpio_af_numF1(pintofind, iptofind):
115
114
for secondlevel in m .attributes .items ():
116
115
# print ('secondlevel ' , i, j, k , secondlevel)
117
116
k += 1
118
- # if 'I2C1_SDA' in secondlevel:
117
+ # if 'I2C1_SDA' in secondlevel:
119
118
if iptofind in secondlevel :
120
119
# m = IP node found
121
120
# print (i, j, m.attributes.items())
122
121
for p in m .childNodes :
123
122
# p node 'RemapBlock'
124
123
if (
125
124
p .nodeType == Node .ELEMENT_NODE
126
- and p .hasChildNodes () == False
125
+ and p .hasChildNodes () is False
127
126
):
128
127
mygpioaf += " AFIO_NONE"
129
128
else :
130
129
for s in p .childNodes :
131
130
if s .nodeType == Node .ELEMENT_NODE :
132
131
# s node 'Specific parameter'
133
- # DBG print (i,j,k,p.attributes.items())
132
+ # print (i,j,k,p.attributes.items())
134
133
for myc in s .childNodes :
135
134
# DBG print (myc)
136
135
if (
@@ -282,7 +281,7 @@ def print_header():
282
281
""" % (
283
282
datetime .datetime .now ().year ,
284
283
os .path .basename (input_file_name ),
285
- re .sub ("\.c$" , "" , out_c_filename ),
284
+ re .sub ("\\ .c$" , "" , out_c_filename ),
286
285
)
287
286
out_c_file .write (s )
288
287
@@ -427,8 +426,8 @@ def print_dac():
427
426
)
428
427
429
428
430
- def print_i2c (l ):
431
- for p in l :
429
+ def print_i2c (lst ):
430
+ for p in lst :
432
431
result = get_gpio_af_num (p [1 ], p [2 ])
433
432
if result != "NOTFOUND" :
434
433
s1 = "%-12s" % (" {" + p [0 ] + "," )
@@ -481,15 +480,15 @@ def print_pwm():
481
480
)
482
481
483
482
484
- def print_uart (l ):
485
- for p in l :
483
+ def print_uart (lst ):
484
+ for p in lst :
486
485
result = get_gpio_af_num (p [1 ], p [2 ])
487
486
if result != "NOTFOUND" :
488
487
s1 = "%-12s" % (" {" + p [0 ] + "," )
489
488
# 2nd element is the UART_XX signal
490
489
b = p [2 ].split ("_" )[0 ]
491
490
s1 += "%-9s" % (b [: len (b ) - 1 ] + b [len (b ) - 1 :] + "," )
492
- if "STM32F10" in mcu_file and l == uartrx_list :
491
+ if "STM32F10" in mcu_file and lst == uartrx_list :
493
492
s1 += "STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, "
494
493
else :
495
494
s1 += "STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
@@ -505,8 +504,8 @@ def print_uart(l):
505
504
)
506
505
507
506
508
- def print_spi (l ):
509
- for p in l :
507
+ def print_spi (lst ):
508
+ for p in lst :
510
509
result = get_gpio_af_num (p [1 ], p [2 ])
511
510
if result != "NOTFOUND" :
512
511
s1 = "%-12s" % (" {" + p [0 ] + "," )
@@ -525,17 +524,16 @@ def print_spi(l):
525
524
)
526
525
527
526
528
- def print_can (l ):
529
- for p in l :
530
- b = p [2 ]
527
+ def print_can (lst ):
528
+ for p in lst :
531
529
result = get_gpio_af_num (p [1 ], p [2 ])
532
530
if result != "NOTFOUND" :
533
531
s1 = "%-12s" % (" {" + p [0 ] + "," )
534
532
# 2nd element is the CAN_XX signal
535
533
instance = p [2 ].split ("_" )[0 ].replace ("CAN" , "" )
536
534
if len (instance ) == 0 :
537
535
instance = "1"
538
- if "STM32F10" in mcu_file and l == canrd_list :
536
+ if "STM32F10" in mcu_file and lst == canrd_list :
539
537
s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, "
540
538
else :
541
539
s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, "
@@ -807,9 +805,9 @@ def parse_pins():
807
805
args = parser .parse_args ()
808
806
809
807
if not (os .path .isdir (cubemxdir )):
810
- print ("\n ! ! ! Cube Mx seems not to be installed or not at the requested location" )
808
+ print ("\n Cube Mx seems not to be installed or not at the requested location. " )
811
809
print (
812
- "\n ! ! ! please check the value you set for 'CUBEMX_DIRECTORY' in '%s' file"
810
+ "\n Please check the value you set for 'CUBEMX_DIRECTORY' in '%s' file. "
813
811
% config_filename
814
812
)
815
813
quit ()
@@ -819,10 +817,10 @@ def parse_pins():
819
817
if args .mcu :
820
818
# check input file exists
821
819
if not (os .path .isfile (os .path .join (cubemxdir , args .mcu ))):
822
- print ("\n ! ! ! " + args .mcu + " file not found" )
823
- print ("\n ! ! ! Check in " + cubemxdir + " the correct name of this file" )
820
+ print ("\n " + args .mcu + " file not found" )
821
+ print ("\n Check in " + cubemxdir + " the correct name of this file" )
824
822
print (
825
- "\n ! ! ! You may use double quotes for this file if it contains special characters"
823
+ "\n You may use double quotes for file containing special characters"
826
824
)
827
825
quit ()
828
826
mcu_list .append (args .mcu )
@@ -848,11 +846,9 @@ def parse_pins():
848
846
849
847
# open output file
850
848
if os .path .isfile (output_c_filename ):
851
- # print (" * Requested %s file already exists and will be overwritten" % out_c_filename)
852
849
os .remove (output_c_filename )
853
850
out_c_file = open (output_c_filename , "w" )
854
851
if os .path .isfile (output_h_filename ):
855
- # print (" * Requested %s file already exists and will be overwritten" % out_h_filename)
856
852
os .remove (output_h_filename )
857
853
out_h_file = open (output_h_filename , "w" )
858
854
0 commit comments