@@ -50,13 +50,13 @@ def get_gpio_af_num(pintofind, iptofind):
50
50
return get_gpio_af_numF1 (pintofind , iptofind )
51
51
# DBG print ('pin to find ' + pintofind)
52
52
i = 0
53
- mygpioaf = "NOTFOUND "
53
+ mygpioaf = ""
54
54
for n in xml_gpio .documentElement .childNodes :
55
55
i += 1
56
56
j = 0
57
57
if n .nodeType == Node .ELEMENT_NODE :
58
58
for firstlevel in n .attributes .items ():
59
- # if 'PB7' in firstlevel:
59
+ # if 'PB7' in firstlevel:
60
60
if pintofind == firstlevel [1 ]:
61
61
# DBG print (i , firstlevel)
62
62
# n = pin node found
@@ -79,27 +79,20 @@ def get_gpio_af_num(pintofind, iptofind):
79
79
if myc .nodeType == Node .ELEMENT_NODE :
80
80
# myc = node of ALTERNATE
81
81
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
85
86
# 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
97
90
98
91
99
92
def get_gpio_af_numF1 (pintofind , iptofind ):
100
93
# print ('pin to find ' + pintofind + ' ip to find ' + iptofind)
101
94
i = 0
102
- mygpioaf = "NOTFOUND "
95
+ mygpioaf = ""
103
96
for n in xml_gpio .documentElement .childNodes :
104
97
i += 1
105
98
j = 0
@@ -127,7 +120,9 @@ def get_gpio_af_numF1(pintofind, iptofind):
127
120
p .nodeType == Node .ELEMENT_NODE
128
121
and p .hasChildNodes () is False
129
122
):
130
- mygpioaf += " AFIO_NONE"
123
+ if mygpioaf != "" :
124
+ mygpioaf += " "
125
+ mygpioaf += "AFIO_NONE"
131
126
else :
132
127
for s in p .childNodes :
133
128
if s .nodeType == Node .ELEMENT_NODE :
@@ -143,24 +138,17 @@ def get_gpio_af_numF1(pintofind, iptofind):
143
138
for (
144
139
mygpioaflist
145
140
) in myc .childNodes :
146
- mygpioaf += " " + mygpioaflist .data .replace (
141
+ if mygpioaf != "" :
142
+ mygpioaf += " "
143
+ mygpioaf += mygpioaflist .data .replace (
147
144
"__HAL_" , ""
148
145
).replace (
149
146
"_REMAP" , ""
150
147
)
151
148
# 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 == "" :
162
150
mygpioaf = "AFIO_NONE"
163
- return mygpioaf . replace ( "NOTFOUND " , "" )
151
+ return mygpioaf
164
152
165
153
166
154
def store_pin (pin , name ):
@@ -462,19 +450,18 @@ def print_dac():
462
450
def print_i2c (lst ):
463
451
for p in lst :
464
452
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 )
478
465
out_c_file .write (
479
466
""" {NC, NP, 0}
480
467
};
@@ -486,25 +473,24 @@ def print_i2c(lst):
486
473
def print_pwm ():
487
474
for p in pwm_list :
488
475
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 )
508
494
out_c_file .write (
509
495
""" {NC, NP, 0}
510
496
};
@@ -516,19 +502,18 @@ def print_pwm():
516
502
def print_uart (lst ):
517
503
for p in lst :
518
504
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 )
532
517
out_c_file .write (
533
518
""" {NC, NP, 0}
534
519
};
@@ -540,15 +525,14 @@ def print_uart(lst):
540
525
def print_spi (lst ):
541
526
for p in lst :
542
527
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 )
552
536
out_c_file .write (
553
537
""" {NC, NP, 0}
554
538
};
@@ -560,20 +544,19 @@ def print_spi(lst):
560
544
def print_can (lst ):
561
545
for p in lst :
562
546
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 )
577
560
out_c_file .write (
578
561
""" {NC, NP, 0}
579
562
};
@@ -586,19 +569,18 @@ def print_eth():
586
569
prev_s = ""
587
570
for p in eth_list :
588
571
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 )
602
584
out_c_file .write (
603
585
"""\n {NC, NP, 0}
604
586
};
@@ -611,19 +593,18 @@ def print_qspi():
611
593
prev_s = ""
612
594
for p in qspi_list :
613
595
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 )
627
608
out_c_file .write (
628
609
"""\n {NC, NP, 0}
629
610
};
0 commit comments