66import re
77import sys
88import textwrap
9- from xml .dom import minidom
109from xml .dom .minidom import parse , Node
1110from argparse import RawTextHelpFormatter
1211
@@ -64,7 +63,7 @@ def get_gpio_af_num(pintofind, iptofind):
6463 if m .nodeType == Node .ELEMENT_NODE :
6564 for secondlevel in m .attributes .items ():
6665 k += 1
67- # if 'I2C1_SDA' in secondlevel:
66+ # if 'I2C1_SDA' in secondlevel:
6867 if iptofind in secondlevel :
6968 # DBG print (i, j, m.attributes.items())
7069 # m = IP node found
@@ -115,22 +114,22 @@ def get_gpio_af_numF1(pintofind, iptofind):
115114 for secondlevel in m .attributes .items ():
116115 # print ('secondlevel ' , i, j, k , secondlevel)
117116 k += 1
118- # if 'I2C1_SDA' in secondlevel:
117+ # if 'I2C1_SDA' in secondlevel:
119118 if iptofind in secondlevel :
120119 # m = IP node found
121120 # print (i, j, m.attributes.items())
122121 for p in m .childNodes :
123122 # p node 'RemapBlock'
124123 if (
125124 p .nodeType == Node .ELEMENT_NODE
126- and p .hasChildNodes () == False
125+ and p .hasChildNodes () is False
127126 ):
128127 mygpioaf += " AFIO_NONE"
129128 else :
130129 for s in p .childNodes :
131130 if s .nodeType == Node .ELEMENT_NODE :
132131 # s node 'Specific parameter'
133- # DBG print (i,j,k,p.attributes.items())
132+ # print (i,j,k,p.attributes.items())
134133 for myc in s .childNodes :
135134 # DBG print (myc)
136135 if (
@@ -282,7 +281,7 @@ def print_header():
282281""" % (
283282 datetime .datetime .now ().year ,
284283 os .path .basename (input_file_name ),
285- re .sub ("\.c$" , "" , out_c_filename ),
284+ re .sub ("\\ .c$" , "" , out_c_filename ),
286285 )
287286 out_c_file .write (s )
288287
@@ -427,8 +426,8 @@ def print_dac():
427426 )
428427
429428
430- def print_i2c (l ):
431- for p in l :
429+ def print_i2c (lst ):
430+ for p in lst :
432431 result = get_gpio_af_num (p [1 ], p [2 ])
433432 if result != "NOTFOUND" :
434433 s1 = "%-12s" % (" {" + p [0 ] + "," )
@@ -481,15 +480,15 @@ def print_pwm():
481480 )
482481
483482
484- def print_uart (l ):
485- for p in l :
483+ def print_uart (lst ):
484+ for p in lst :
486485 result = get_gpio_af_num (p [1 ], p [2 ])
487486 if result != "NOTFOUND" :
488487 s1 = "%-12s" % (" {" + p [0 ] + "," )
489488 # 2nd element is the UART_XX signal
490489 b = p [2 ].split ("_" )[0 ]
491490 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 :
493492 s1 += "STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, "
494493 else :
495494 s1 += "STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
@@ -505,8 +504,8 @@ def print_uart(l):
505504 )
506505
507506
508- def print_spi (l ):
509- for p in l :
507+ def print_spi (lst ):
508+ for p in lst :
510509 result = get_gpio_af_num (p [1 ], p [2 ])
511510 if result != "NOTFOUND" :
512511 s1 = "%-12s" % (" {" + p [0 ] + "," )
@@ -525,17 +524,16 @@ def print_spi(l):
525524 )
526525
527526
528- def print_can (l ):
529- for p in l :
530- b = p [2 ]
527+ def print_can (lst ):
528+ for p in lst :
531529 result = get_gpio_af_num (p [1 ], p [2 ])
532530 if result != "NOTFOUND" :
533531 s1 = "%-12s" % (" {" + p [0 ] + "," )
534532 # 2nd element is the CAN_XX signal
535533 instance = p [2 ].split ("_" )[0 ].replace ("CAN" , "" )
536534 if len (instance ) == 0 :
537535 instance = "1"
538- if "STM32F10" in mcu_file and l == canrd_list :
536+ if "STM32F10" in mcu_file and lst == canrd_list :
539537 s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, "
540538 else :
541539 s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, "
@@ -807,9 +805,9 @@ def parse_pins():
807805args = parser .parse_args ()
808806
809807if 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. " )
811809 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. "
813811 % config_filename
814812 )
815813 quit ()
@@ -819,10 +817,10 @@ def parse_pins():
819817if args .mcu :
820818 # check input file exists
821819 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" )
824822 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"
826824 )
827825 quit ()
828826 mcu_list .append (args .mcu )
@@ -848,11 +846,9 @@ def parse_pins():
848846
849847 # open output file
850848 if os .path .isfile (output_c_filename ):
851- # print (" * Requested %s file already exists and will be overwritten" % out_c_filename)
852849 os .remove (output_c_filename )
853850 out_c_file = open (output_c_filename , "w" )
854851 if os .path .isfile (output_h_filename ):
855- # print (" * Requested %s file already exists and will be overwritten" % out_h_filename)
856852 os .remove (output_h_filename )
857853 out_h_file = open (output_h_filename , "w" )
858854
0 commit comments