@@ -50,13 +50,13 @@ def get_gpio_af_num(pintofind, iptofind):
5050 return get_gpio_af_numF1 (pintofind , iptofind )
5151 # DBG print ('pin to find ' + pintofind)
5252 i = 0
53- mygpioaf = "NOTFOUND "
53+ mygpioaf = ""
5454 for n in xml_gpio .documentElement .childNodes :
5555 i += 1
5656 j = 0
5757 if n .nodeType == Node .ELEMENT_NODE :
5858 for firstlevel in n .attributes .items ():
59- # if 'PB7' in firstlevel:
59+ # if 'PB7' in firstlevel:
6060 if pintofind == firstlevel [1 ]:
6161 # DBG print (i , firstlevel)
6262 # n = pin node found
@@ -79,27 +79,20 @@ def get_gpio_af_num(pintofind, iptofind):
7979 if myc .nodeType == Node .ELEMENT_NODE :
8080 # myc = node of ALTERNATE
8181 for mygpioaflist in myc .childNodes :
82- mygpioaf += (
83- " " + mygpioaflist .data
84- )
82+ if mygpioaflist .data not in mygpioaf :
83+ if mygpioaf != "" :
84+ mygpioaf += " "
85+ mygpioaf += mygpioaflist .data
8586 # print (mygpioaf)
86- if mygpioaf == "NOTFOUND" :
87- print (
88- "GPIO AF not found in "
89- + gpiofile
90- + " for "
91- + pintofind
92- + " and the IP "
93- + iptofind
94- )
95- # quit()
96- return mygpioaf .replace ("NOTFOUND " , "" )
87+ if mygpioaf == "" :
88+ mygpioaf = "GPIO_AF_NONE"
89+ return mygpioaf
9790
9891
9992def get_gpio_af_numF1 (pintofind , iptofind ):
10093 # print ('pin to find ' + pintofind + ' ip to find ' + iptofind)
10194 i = 0
102- mygpioaf = "NOTFOUND "
95+ mygpioaf = ""
10396 for n in xml_gpio .documentElement .childNodes :
10497 i += 1
10598 j = 0
@@ -127,7 +120,9 @@ def get_gpio_af_numF1(pintofind, iptofind):
127120 p .nodeType == Node .ELEMENT_NODE
128121 and p .hasChildNodes () is False
129122 ):
130- mygpioaf += " AFIO_NONE"
123+ if mygpioaf != "" :
124+ mygpioaf += " "
125+ mygpioaf += "AFIO_NONE"
131126 else :
132127 for s in p .childNodes :
133128 if s .nodeType == Node .ELEMENT_NODE :
@@ -143,24 +138,17 @@ def get_gpio_af_numF1(pintofind, iptofind):
143138 for (
144139 mygpioaflist
145140 ) in myc .childNodes :
146- mygpioaf += " " + mygpioaflist .data .replace (
141+ if mygpioaf != "" :
142+ mygpioaf += " "
143+ mygpioaf += mygpioaflist .data .replace (
147144 "__HAL_" , ""
148145 ).replace (
149146 "_REMAP" , ""
150147 )
151148 # print mygpioaf
152- if mygpioaf == "NOTFOUND" :
153- print (
154- "GPIO AF not found in "
155- + gpiofile
156- + " for "
157- + pintofind
158- + " and the IP "
159- + iptofind
160- + " set as AFIO_NONE"
161- )
149+ if mygpioaf == "" :
162150 mygpioaf = "AFIO_NONE"
163- return mygpioaf . replace ( "NOTFOUND " , "" )
151+ return mygpioaf
164152
165153
166154def store_pin (pin , name ):
@@ -462,19 +450,18 @@ def print_dac():
462450def print_i2c (lst ):
463451 for p in lst :
464452 result = get_gpio_af_num (p [1 ], p [2 ])
465- if result != "NOTFOUND" :
466- s1 = "%-10s" % (" {" + p [0 ] + "," )
467- # 2nd element is the I2C XXX signal
468- b = p [2 ].split ("_" )[0 ]
469- s1 += (
470- b [: len (b ) - 1 ]
471- + b [len (b ) - 1 ]
472- + ", STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, "
473- )
474- r = result .split (" " )
475- for af in r :
476- s2 = s1 + af + ")},\n "
477- out_c_file .write (s2 )
453+ s1 = "%-10s" % (" {" + p [0 ] + "," )
454+ # 2nd element is the I2C XXX signal
455+ b = p [2 ].split ("_" )[0 ]
456+ s1 += (
457+ b [: len (b ) - 1 ]
458+ + b [len (b ) - 1 ]
459+ + ", STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, "
460+ )
461+ r = result .split (" " )
462+ for af in r :
463+ s2 = s1 + af + ")},\n "
464+ out_c_file .write (s2 )
478465 out_c_file .write (
479466 """ {NC, NP, 0}
480467};
@@ -486,25 +473,24 @@ def print_i2c(lst):
486473def print_pwm ():
487474 for p in pwm_list :
488475 result = get_gpio_af_num (p [1 ], p [2 ])
489- if result != "NOTFOUND" :
490- s1 = "%-10s" % (" {" + p [0 ] + "," )
491- # 2nd element is the PWM signal
492- a = p [2 ].split ("_" )
493- inst = a [0 ]
494- if len (inst ) == 3 :
495- inst += "1"
496- s1 += "%-8s" % (inst + "," )
497- chan = a [1 ].replace ("CH" , "" )
498- if chan .endswith ("N" ):
499- neg = ", 1"
500- chan = chan .strip ("N" )
501- else :
502- neg = ", 0"
503- s1 += "STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, "
504- r = result .split (" " )
505- for af in r :
506- s2 = s1 + af + ", " + chan + neg + ")}, // " + p [2 ] + "\n "
507- out_c_file .write (s2 )
476+ s1 = "%-10s" % (" {" + p [0 ] + "," )
477+ # 2nd element is the PWM signal
478+ a = p [2 ].split ("_" )
479+ inst = a [0 ]
480+ if len (inst ) == 3 :
481+ inst += "1"
482+ s1 += "%-8s" % (inst + "," )
483+ chan = a [1 ].replace ("CH" , "" )
484+ if chan .endswith ("N" ):
485+ neg = ", 1"
486+ chan = chan .strip ("N" )
487+ else :
488+ neg = ", 0"
489+ s1 += "STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, "
490+ r = result .split (" " )
491+ for af in r :
492+ s2 = s1 + af + ", " + chan + neg + ")}, // " + p [2 ] + "\n "
493+ out_c_file .write (s2 )
508494 out_c_file .write (
509495 """ {NC, NP, 0}
510496};
@@ -516,19 +502,18 @@ def print_pwm():
516502def print_uart (lst ):
517503 for p in lst :
518504 result = get_gpio_af_num (p [1 ], p [2 ])
519- if result != "NOTFOUND" :
520- s1 = "%-10s" % (" {" + p [0 ] + "," )
521- # 2nd element is the UART_XX signal
522- b = p [2 ].split ("_" )[0 ]
523- s1 += "%-9s" % (b [: len (b ) - 1 ] + b [len (b ) - 1 :] + "," )
524- if "STM32F10" in mcu_file and lst == uartrx_list :
525- s1 += "STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, "
526- else :
527- s1 += "STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
528- r = result .split (" " )
529- for af in r :
530- s2 = s1 + af + ")},\n "
531- out_c_file .write (s2 )
505+ s1 = "%-10s" % (" {" + p [0 ] + "," )
506+ # 2nd element is the UART_XX signal
507+ b = p [2 ].split ("_" )[0 ]
508+ s1 += "%-9s" % (b [: len (b ) - 1 ] + b [len (b ) - 1 :] + "," )
509+ if "STM32F10" in mcu_file and lst == uartrx_list :
510+ s1 += "STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, "
511+ else :
512+ s1 += "STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
513+ r = result .split (" " )
514+ for af in r :
515+ s2 = s1 + af + ")},\n "
516+ out_c_file .write (s2 )
532517 out_c_file .write (
533518 """ {NC, NP, 0}
534519};
@@ -540,15 +525,14 @@ def print_uart(lst):
540525def print_spi (lst ):
541526 for p in lst :
542527 result = get_gpio_af_num (p [1 ], p [2 ])
543- if result != "NOTFOUND" :
544- s1 = "%-10s" % (" {" + p [0 ] + "," )
545- # 2nd element is the SPI_XXXX signal
546- instance = p [2 ].split ("_" )[0 ].replace ("SPI" , "" )
547- s1 += "SPI" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
548- r = result .split (" " )
549- for af in r :
550- s2 = s1 + af + ")},\n "
551- out_c_file .write (s2 )
528+ s1 = "%-10s" % (" {" + p [0 ] + "," )
529+ # 2nd element is the SPI_XXXX signal
530+ instance = p [2 ].split ("_" )[0 ].replace ("SPI" , "" )
531+ s1 += "SPI" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
532+ r = result .split (" " )
533+ for af in r :
534+ s2 = s1 + af + ")},\n "
535+ out_c_file .write (s2 )
552536 out_c_file .write (
553537 """ {NC, NP, 0}
554538};
@@ -560,20 +544,19 @@ def print_spi(lst):
560544def print_can (lst ):
561545 for p in lst :
562546 result = get_gpio_af_num (p [1 ], p [2 ])
563- if result != "NOTFOUND" :
564- s1 = "%-10s" % (" {" + p [0 ] + "," )
565- # 2nd element is the CAN_XX signal
566- instance = p [2 ].split ("_" )[0 ].replace ("CAN" , "" )
567- if len (instance ) == 0 :
568- instance = "1"
569- if "STM32F10" in mcu_file and lst == canrd_list :
570- s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, "
571- else :
572- s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, "
573- r = result .split (" " )
574- for af in r :
575- s2 = s1 + af + ")},\n "
576- out_c_file .write (s2 )
547+ s1 = "%-10s" % (" {" + p [0 ] + "," )
548+ # 2nd element is the CAN_XX signal
549+ instance = p [2 ].split ("_" )[0 ].replace ("CAN" , "" )
550+ if len (instance ) == 0 :
551+ instance = "1"
552+ if "STM32F10" in mcu_file and lst == canrd_list :
553+ s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, "
554+ else :
555+ s1 += "CAN" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, "
556+ r = result .split (" " )
557+ for af in r :
558+ s2 = s1 + af + ")},\n "
559+ out_c_file .write (s2 )
577560 out_c_file .write (
578561 """ {NC, NP, 0}
579562};
@@ -586,19 +569,18 @@ def print_eth():
586569 prev_s = ""
587570 for p in eth_list :
588571 result = get_gpio_af_num (p [1 ], p [2 ])
589- if result != "NOTFOUND" :
590- s1 = "%-10s" % (" {" + p [0 ] + "," )
591- # 2nd element is the ETH_XXXX signal
592- s1 += "ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, " + result + ")},"
593- # check duplicated lines, only signal differs
594- if prev_s == s1 :
595- s1 = "|" + p [2 ]
596- else :
597- if len (prev_s ) > 0 :
598- out_c_file .write ("\n " )
599- prev_s = s1
600- s1 += " // " + p [2 ]
601- out_c_file .write (s1 )
572+ s1 = "%-10s" % (" {" + p [0 ] + "," )
573+ # 2nd element is the ETH_XXXX signal
574+ s1 += "ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, " + result + ")},"
575+ # check duplicated lines, only signal differs
576+ if prev_s == s1 :
577+ s1 = "|" + p [2 ]
578+ else :
579+ if len (prev_s ) > 0 :
580+ out_c_file .write ("\n " )
581+ prev_s = s1
582+ s1 += " // " + p [2 ]
583+ out_c_file .write (s1 )
602584 out_c_file .write (
603585 """\n {NC, NP, 0}
604586};
@@ -611,19 +593,18 @@ def print_qspi():
611593 prev_s = ""
612594 for p in qspi_list :
613595 result = get_gpio_af_num (p [1 ], p [2 ])
614- if result != "NOTFOUND" :
615- s1 = "%-10s" % (" {" + p [0 ] + "," )
616- # 2nd element is the QUADSPI_XXXX signal
617- s1 += "QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, " + result + ")},"
618- # check duplicated lines, only signal differs
619- if prev_s == s1 :
620- s1 = "|" + p [2 ]
621- else :
622- if len (prev_s ) > 0 :
623- out_c_file .write ("\n " )
624- prev_s = s1
625- s1 += " // " + p [2 ]
626- out_c_file .write (s1 )
596+ s1 = "%-10s" % (" {" + p [0 ] + "," )
597+ # 2nd element is the QUADSPI_XXXX signal
598+ s1 += "QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, " + result + ")},"
599+ # check duplicated lines, only signal differs
600+ if prev_s == s1 :
601+ s1 = "|" + p [2 ]
602+ else :
603+ if len (prev_s ) > 0 :
604+ out_c_file .write ("\n " )
605+ prev_s = s1
606+ s1 += " // " + p [2 ]
607+ out_c_file .write (s1 )
627608 out_c_file .write (
628609 """\n {NC, NP, 0}
629610};
0 commit comments