12
12
mcu_file = ""
13
13
mcu_list = [] # 'name'
14
14
io_list = [] # 'PIN','name'
15
+ alt_list = [] # 'PIN','name'
15
16
adclist = [] # 'PIN','name','ADCSignal'
16
17
daclist = [] # 'PIN','name','DACSignal'
17
18
i2cscl_list = [] # 'PIN','name','I2CSCLSignal'
@@ -167,13 +168,13 @@ def isPinAndSignalInList(pin, signal, lst):
167
168
return len ([item for item in lst if item [0 ] == pin and item [2 ] == signal ])
168
169
169
170
170
- def store_pin (pin , name ):
171
- if pin in [p [0 ] for p in io_list ]:
171
+ def store_pin (pin , name , dest_list ):
172
+ if pin in [p [0 ] for p in dest_list ]:
172
173
return
173
174
# store pin I/O
174
175
p = [pin , name ]
175
- if p not in io_list :
176
- io_list .append (p )
176
+ if p not in dest_list :
177
+ dest_list .append (p )
177
178
178
179
179
180
# function to store ADC list
@@ -349,8 +350,14 @@ def print_header():
349
350
#include "%s.h"
350
351
351
352
/* =====
352
- * Note: Commented lines are alternative possibilities which are not used per default.
353
- * If you change them, you will have to know what you do
353
+ * Notes:
354
+ * - The pins mentioned Px_y_ALTz are alternative possibilities which use other
355
+ * HW peripheral instances. You can use them the same way as any other "normal"
356
+ * pin (i.e. analogWrite(PA7_ALT0, 128);). These pins are not available thanks
357
+ * pin number (Dx or x).
358
+ *
359
+ * - Commented lines are alternative possibilities which are not used per default.
360
+ * If you change them, you will have to know what you do
354
361
* =====
355
362
*/
356
363
""" % (
@@ -444,6 +451,7 @@ def print_all_lists():
444
451
if print_list_header ("SD" , "SD" , "SD" , sd_list ):
445
452
print_sd ()
446
453
# Print specific PinNames in header file
454
+ print_alt_h ()
447
455
print_syswkup_h ()
448
456
print_usb_h ()
449
457
@@ -500,9 +508,19 @@ def print_adc():
500
508
s_pin_data += "_ADC_CONTROL"
501
509
s_pin_data += ", GPIO_NOPULL, 0, "
502
510
511
+ prev_p = ""
512
+ alt_index = 0
513
+
503
514
for p in adclist :
504
515
if "IN" in p [2 ]:
505
- s1 = "%-10s" % (" {" + p [0 ] + "," )
516
+ if p [0 ] == prev_p :
517
+ p [0 ] += "_ALT%d" % alt_index
518
+ alt_index += 1
519
+ store_pin (p [0 ], p [1 ], alt_list )
520
+ else :
521
+ prev_p = p [0 ]
522
+ alt_index = 0
523
+ s1 = "%-15s" % (" {" + p [0 ] + "," )
506
524
a = p [2 ].split ("_" )
507
525
inst = a [0 ].replace ("ADC" , "" )
508
526
if len (inst ) == 0 :
@@ -553,9 +571,18 @@ def print_dac():
553
571
554
572
555
573
def print_i2c (lst ):
574
+ prev_p = ""
575
+ alt_index = 0
556
576
for p in lst :
557
577
result = get_gpio_af_num (p [1 ], p [2 ])
558
- s1 = "%-10s" % (" {" + p [0 ] + "," )
578
+ if p [0 ] == prev_p :
579
+ p [0 ] += "_ALT%d" % alt_index
580
+ store_pin (p [0 ], p [1 ], alt_list )
581
+ alt_index += 1
582
+ else :
583
+ prev_p = p [0 ]
584
+ alt_index = 0
585
+ s1 = "%-15s" % (" {" + p [0 ] + "," )
559
586
# 2nd element is the I2C XXX signal
560
587
b = p [2 ].split ("_" )[0 ]
561
588
s1 += (
@@ -576,9 +603,18 @@ def print_i2c(lst):
576
603
577
604
578
605
def print_pwm ():
606
+ prev_p = ""
607
+ alt_index = 0
579
608
for p in pwm_list :
580
609
result = get_gpio_af_num (p [1 ], p [2 ])
581
- s1 = "%-10s" % (" {" + p [0 ] + "," )
610
+ if p [0 ] == prev_p :
611
+ p [0 ] += "_ALT%d" % alt_index
612
+ store_pin (p [0 ], p [1 ], alt_list )
613
+ alt_index += 1
614
+ else :
615
+ prev_p = p [0 ]
616
+ alt_index = 0
617
+ s1 = "%-15s" % (" {" + p [0 ] + "," )
582
618
# 2nd element is the PWM signal
583
619
a = p [2 ].split ("_" )
584
620
inst = a [0 ]
@@ -605,9 +641,18 @@ def print_pwm():
605
641
606
642
607
643
def print_uart (lst ):
644
+ prev_p = ""
645
+ alt_index = 0
608
646
for p in lst :
609
647
result = get_gpio_af_num (p [1 ], p [2 ])
610
- s1 = "%-10s" % (" {" + p [0 ] + "," )
648
+ if p [0 ] == prev_p :
649
+ p [0 ] += "_ALT%d" % alt_index
650
+ store_pin (p [0 ], p [1 ], alt_list )
651
+ alt_index += 1
652
+ else :
653
+ prev_p = p [0 ]
654
+ alt_index = 0
655
+ s1 = "%-15s" % (" {" + p [0 ] + "," )
611
656
# 2nd element is the UART_XX signal
612
657
b = p [2 ].split ("_" )[0 ]
613
658
s1 += "%-9s" % (b [: len (b ) - 1 ] + b [len (b ) - 1 :] + "," )
@@ -628,9 +673,18 @@ def print_uart(lst):
628
673
629
674
630
675
def print_spi (lst ):
676
+ prev_p = ""
677
+ alt_index = 0
631
678
for p in lst :
632
679
result = get_gpio_af_num (p [1 ], p [2 ])
633
- s1 = "%-10s" % (" {" + p [0 ] + "," )
680
+ if p [0 ] == prev_p :
681
+ p [0 ] += "_ALT%d" % alt_index
682
+ store_pin (p [0 ], p [1 ], alt_list )
683
+ alt_index += 1
684
+ else :
685
+ prev_p = p [0 ]
686
+ alt_index = 0
687
+ s1 = "%-15s" % (" {" + p [0 ] + "," )
634
688
# 2nd element is the SPI_XXXX signal
635
689
instance = p [2 ].split ("_" )[0 ].replace ("SPI" , "" )
636
690
s1 += "SPI" + instance + ", STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, "
@@ -804,6 +858,23 @@ def print_usb(lst):
804
858
)
805
859
806
860
861
+ def print_alt_h ():
862
+ if len (alt_list ) == 0 :
863
+ out_h_file .write ("/* No alternate */\n " )
864
+ else :
865
+ out_h_file .write ("/* Alternate pin name */\n " )
866
+ # print pin name under switch
867
+ for p in alt_list :
868
+ if "_ALT" in p [0 ]:
869
+ s1 = " %-10s = %-5s | %s,\n " % (
870
+ p [0 ],
871
+ p [0 ].split ("_A" )[0 ],
872
+ p [0 ].split ("_" )[2 ],
873
+ )
874
+ out_h_file .write (s1 )
875
+ out_h_file .write ("\n " )
876
+
877
+
807
878
def print_syswkup_h ():
808
879
if len (syswkup_list ) == 0 :
809
880
out_h_file .write ("/* NO SYS_WKUP */\n " )
@@ -863,6 +934,8 @@ def natural_sortkey2(list_2_elem):
863
934
864
935
865
936
def sort_my_lists ():
937
+ io_list .sort (key = natural_sortkey )
938
+ alt_list .sort (key = natural_sortkey )
866
939
adclist .sort (key = natural_sortkey )
867
940
daclist .sort (key = natural_sortkey )
868
941
i2cscl_list .sort (key = natural_sortkey )
@@ -895,6 +968,7 @@ def sort_my_lists():
895
968
896
969
def clean_all_lists ():
897
970
del io_list [:]
971
+ del alt_list [:]
898
972
del adclist [:]
899
973
del daclist [:]
900
974
del i2cscl_list [:]
@@ -939,7 +1013,7 @@ def parse_pins():
939
1013
pin = m .group (0 )[:3 ] + "_" + m .group (0 )[3 :]
940
1014
name = s .attributes ["Name" ].value .strip () # full name: "PF0 / OSC_IN"
941
1015
if s .attributes ["Type" ].value in ["I/O" , "MonoIO" ]:
942
- store_pin (pin , name )
1016
+ store_pin (pin , name , io_list )
943
1017
else :
944
1018
continue
945
1019
siglist = s .getElementsByTagName ("Signal" )
@@ -1110,12 +1184,15 @@ def parse_pins():
1110
1184
print_header ()
1111
1185
print_all_lists ()
1112
1186
1113
- nb_pin = len (io_list )
1114
- print (" * I/O pins found: %i" % nb_pin )
1187
+ print (
1188
+ " * Total I/O pins found: {} ({} + {} ALT I/O pins)\n " .format (
1189
+ (len (io_list ) + len (alt_list )), len (io_list ), len (alt_list )
1190
+ )
1191
+ )
1115
1192
# io_list.sort(key=natural_sortkey)
1116
1193
# for io in io_list:
1117
1194
# print(io[0] + ", " + io[1])
1118
- print ( "done \n " )
1195
+
1119
1196
clean_all_lists ()
1120
1197
1121
1198
out_c_file .close ()
0 commit comments