30
30
eth_list = [] #'PIN','name','ETH'
31
31
qspi_list = [] #'PIN','name','QUADSPI'
32
32
33
- def find_gpio_file (xmldoc ):
33
+ def find_gpio_file ():
34
34
res = 'ERROR'
35
- itemlist = xmldoc .getElementsByTagName ('IP' )
35
+ itemlist = xml_mcu .getElementsByTagName ('IP' )
36
36
for s in itemlist :
37
37
a = s .attributes ['Name' ].value
38
38
if "GPIO" in a :
39
39
res = s .attributes ['Version' ].value
40
40
return res
41
41
42
- def get_gpio_af_num (xml , pintofind , iptofind ):
42
+ def get_gpio_af_num (pintofind , iptofind ):
43
43
if 'STM32F10' in mcu_file :
44
- return get_gpio_af_numF1 (xml , pintofind , iptofind )
45
- # xml = parse('GPIO-STM32L051_gpio_v1_0_Modes.xml')
46
- #xml = parse(gpiofile)
44
+ return get_gpio_af_numF1 (pintofind , iptofind )
47
45
#DBG print ('pin to find ' + pintofind)
48
46
i = 0
49
47
mygpioaf = 'NOTFOUND'
50
- for n in xml .documentElement .childNodes :
48
+ for n in xml_gpio .documentElement .childNodes :
51
49
i += 1
52
50
j = 0
53
51
if n .nodeType == Node .ELEMENT_NODE :
@@ -82,11 +80,11 @@ def get_gpio_af_num(xml, pintofind, iptofind):
82
80
#quit()
83
81
return mygpioaf .replace ('NOTFOUND ' , '' )
84
82
85
- def get_gpio_af_numF1 (xml , pintofind , iptofind ):
83
+ def get_gpio_af_numF1 (pintofind , iptofind ):
86
84
#print ('pin to find ' + pintofind + ' ip to find ' + iptofind)
87
85
i = 0
88
86
mygpioaf = 'NOTFOUND'
89
- for n in xml .documentElement .childNodes :
87
+ for n in xml_gpio .documentElement .childNodes :
90
88
i += 1
91
89
j = 0
92
90
if n .nodeType == Node .ELEMENT_NODE :
@@ -240,35 +238,35 @@ def print_all_lists():
240
238
if print_list_header ("DAC" , "DAC" , daclist , "DAC" ):
241
239
print_dac ()
242
240
if print_list_header ("I2C" , "I2C_SDA" , i2csda_list , "I2C" ):
243
- print_i2c (xml , i2csda_list )
241
+ print_i2c (i2csda_list )
244
242
if print_list_header ("" , "I2C_SCL" , i2cscl_list , "I2C" ):
245
- print_i2c (xml , i2cscl_list )
243
+ print_i2c (i2cscl_list )
246
244
if print_list_header ("PWM" , "PWM" , pwm_list , "TIM" ):
247
- print_pwm (xml )
245
+ print_pwm ()
248
246
if print_list_header ("SERIAL" , "UART_TX" , uarttx_list , "UART" ):
249
- print_uart (xml , uarttx_list )
247
+ print_uart (uarttx_list )
250
248
if print_list_header ("" , "UART_RX" , uartrx_list , "UART" ):
251
- print_uart (xml , uartrx_list )
249
+ print_uart (uartrx_list )
252
250
if print_list_header ("" , "UART_RTS" , uartrts_list , "UART" ):
253
- print_uart (xml , uartrts_list )
251
+ print_uart (uartrts_list )
254
252
if print_list_header ("" , "UART_CTS" , uartcts_list , "UART" ):
255
- print_uart (xml , uartcts_list )
253
+ print_uart (uartcts_list )
256
254
if print_list_header ("SPI" , "SPI_MOSI" , spimosi_list , "SPI" ):
257
- print_spi (xml , spimosi_list )
255
+ print_spi (spimosi_list )
258
256
if print_list_header ("" , "SPI_MISO" , spimiso_list , "SPI" ):
259
- print_spi (xml , spimiso_list )
257
+ print_spi (spimiso_list )
260
258
if print_list_header ("" , "SPI_SCLK" , spisclk_list , "SPI" ):
261
- print_spi (xml , spisclk_list )
259
+ print_spi (spisclk_list )
262
260
if print_list_header ("" , "SPI_SSEL" , spissel_list , "SPI" ):
263
- print_spi (xml , spissel_list )
261
+ print_spi (spissel_list )
264
262
if print_list_header ("CAN" , "CAN_RD" , canrd_list , "CAN" ):
265
- print_can (xml , canrd_list )
263
+ print_can (canrd_list )
266
264
if print_list_header ("" , "CAN_TD" , cantd_list , "CAN" ):
267
- print_can (xml , cantd_list )
265
+ print_can (cantd_list )
268
266
if print_list_header ("ETHERNET" , "Ethernet" , eth_list , "ETH" ):
269
- print_eth (xml , eth_list )
267
+ print_eth ()
270
268
if print_list_header ("QUADSPI" , "QUADSPI" , qspi_list , "QSPI" ):
271
- print_qspi (xml , qspi_list )
269
+ print_qspi ()
272
270
273
271
def print_list_header (comment , name , l , switch ):
274
272
if len (l )> 0 :
@@ -330,9 +328,9 @@ def print_dac():
330
328
#endif
331
329
""" )
332
330
333
- def print_i2c (xml , l ):
331
+ def print_i2c (l ):
334
332
for p in l :
335
- result = get_gpio_af_num (xml , p [1 ], p [2 ])
333
+ result = get_gpio_af_num (p [1 ], p [2 ])
336
334
if result != 'NOTFOUND' :
337
335
s1 = "%-12s" % (" {" + p [0 ] + ',' )
338
336
#2nd element is the I2C XXX signal
@@ -347,9 +345,9 @@ def print_i2c(xml, l):
347
345
#endif
348
346
""" )
349
347
350
- def print_pwm (xml ):
348
+ def print_pwm ():
351
349
for p in pwm_list :
352
- result = get_gpio_af_num (xml , p [1 ], p [2 ])
350
+ result = get_gpio_af_num (p [1 ], p [2 ])
353
351
if result != 'NOTFOUND' :
354
352
s1 = "%-12s" % (" {" + p [0 ] + ',' )
355
353
#2nd element is the PWM signal
@@ -374,9 +372,9 @@ def print_pwm(xml):
374
372
#endif
375
373
""" )
376
374
377
- def print_uart (xml , l ):
375
+ def print_uart (l ):
378
376
for p in l :
379
- result = get_gpio_af_num (xml , p [1 ], p [2 ])
377
+ result = get_gpio_af_num (p [1 ], p [2 ])
380
378
if result != 'NOTFOUND' :
381
379
s1 = "%-12s" % (" {" + p [0 ] + ',' )
382
380
#2nd element is the UART_XX signal
@@ -395,9 +393,9 @@ def print_uart(xml, l):
395
393
#endif
396
394
""" )
397
395
398
- def print_spi (xml , l ):
396
+ def print_spi (l ):
399
397
for p in l :
400
- result = get_gpio_af_num (xml , p [1 ], p [2 ])
398
+ result = get_gpio_af_num (p [1 ], p [2 ])
401
399
if result != 'NOTFOUND' :
402
400
s1 = "%-12s" % (" {" + p [0 ] + ',' )
403
401
#2nd element is the SPI_XXXX signal
@@ -412,10 +410,10 @@ def print_spi(xml, l):
412
410
#endif
413
411
""" )
414
412
415
- def print_can (xml , l ):
413
+ def print_can (l ):
416
414
for p in l :
417
415
b = p [2 ]
418
- result = get_gpio_af_num (xml , p [1 ], p [2 ])
416
+ result = get_gpio_af_num (p [1 ], p [2 ])
419
417
if result != 'NOTFOUND' :
420
418
s1 = "%-12s" % (" {" + p [0 ] + ',' )
421
419
#2nd element is the CAN_XX signal
@@ -435,10 +433,10 @@ def print_can(xml, l):
435
433
#endif
436
434
""" )
437
435
438
- def print_eth (xml , l ):
436
+ def print_eth ():
439
437
prev_s = ''
440
- for p in l :
441
- result = get_gpio_af_num (xml , p [1 ], p [2 ])
438
+ for p in eth_list :
439
+ result = get_gpio_af_num (p [1 ], p [2 ])
442
440
if result != 'NOTFOUND' :
443
441
s1 = "%-12s" % (" {" + p [0 ] + ',' )
444
442
#2nd element is the ETH_XXXX signal
@@ -457,10 +455,10 @@ def print_eth(xml, l):
457
455
#endif
458
456
""" )
459
457
460
- def print_qspi (xml , l ):
458
+ def print_qspi ():
461
459
prev_s = ''
462
- for p in l :
463
- result = get_gpio_af_num (xml , p [1 ], p [2 ])
460
+ for p in qspi_list :
461
+ result = get_gpio_af_num (p [1 ], p [2 ])
464
462
if result != 'NOTFOUND' :
465
463
s1 = "%-12s" % (" {" + p [0 ] + ',' )
466
464
#2nd element is the QUADSPI_XXXX signal
@@ -503,8 +501,6 @@ def sort_my_lists():
503
501
eth_list .sort (key = natural_sortkey )
504
502
qspi_list .sort (key = natural_sortkey )
505
503
506
- return
507
-
508
504
def clean_all_lists ():
509
505
del io_list [:]
510
506
del adclist [:]
@@ -524,7 +520,42 @@ def clean_all_lists():
524
520
del canrd_list [:]
525
521
del eth_list [:]
526
522
del qspi_list [:]
527
-
523
+
524
+ def parse_pins ():
525
+ print (" * Getting pins per Ips..." )
526
+ pinregex = r'^(P[A-Z][0-9][0-5]?)'
527
+ itemlist = xml_mcu .getElementsByTagName ('Pin' )
528
+ for s in itemlist :
529
+ m = re .match (pinregex , s .attributes ['Name' ].value )
530
+ if m :
531
+ pin = m .group (0 )[:2 ] + '_' + m .group (0 )[2 :] # pin formatted P<port>_<number>: PF_O
532
+ name = s .attributes ['Name' ].value .strip () # full name: "PF0 / OSC_IN"
533
+ if s .attributes ['Type' ].value == "I/O" :
534
+ store_pin (pin , name )
535
+ else :
536
+ continue
537
+ siglist = s .getElementsByTagName ('Signal' )
538
+ for a in siglist :
539
+ sig = a .attributes ['Name' ].value .strip ()
540
+ if "ADC" in sig :
541
+ store_adc (pin , name , sig )
542
+ if all (["DAC" in sig , "_OUT" in sig ]):
543
+ store_dac (pin , name , sig )
544
+ if "I2C" in sig :
545
+ store_i2c (pin , name , sig )
546
+ if re .match ('^TIM' , sig ) is not None : #ignore HRTIM
547
+ store_pwm (pin , name , sig )
548
+ if re .match ('^(LPU|US|U)ART' , sig ) is not None :
549
+ store_uart (pin , name , sig )
550
+ if "SPI" in sig :
551
+ store_spi (pin , name , sig )
552
+ if "CAN" in sig :
553
+ store_can (pin , name , sig )
554
+ if "ETH" in sig :
555
+ store_eth (pin , name , sig )
556
+ if "QUADSPI" in sig :
557
+ store_qspi (pin , name , sig )
558
+
528
559
# main
529
560
cur_dir = os .getcwd ()
530
561
out_filename = 'PeripheralPins.c'
@@ -601,73 +632,35 @@ def clean_all_lists():
601
632
quit ()
602
633
603
634
for mcu_file in mcu_list :
604
- print ("Generate %s for '%s'" % (out_filename , mcu_file ))
635
+ print ("Generating %s for '%s'... " % (out_filename , mcu_file ))
605
636
input_file_name = os .path .join (cubemxdir , mcu_file )
606
637
out_path = os .path .join (cur_dir , 'Arduino' , os .path .splitext (mcu_file )[0 ])
607
638
output_filename = os .path .join (out_path , out_filename )
608
639
if not (os .path .isdir (out_path )):
609
640
os .makedirs (out_path )
610
641
611
- #open input file
612
- #print (" * * * Opening input file...")
613
- xmldoc = minidom .parse (input_file_name )
614
- itemlist = xmldoc .getElementsByTagName ('Pin' )
615
642
#open output file
616
643
if (os .path .isfile (output_filename )):
617
- #print (" * * * * Requested %s file already exists and will be overwritten" % out_filename)
644
+ #print (" * Requested %s file already exists and will be overwritten" % out_filename)
618
645
os .remove (output_filename )
619
-
620
646
out_file = open (output_filename , 'w' )
621
647
622
- gpiofile = find_gpio_file (xmldoc )
648
+ #open input file
649
+ xml_mcu = parse (input_file_name )
650
+ gpiofile = find_gpio_file ()
623
651
if gpiofile == 'ERROR' :
624
652
print ("Could not find GPIO file" )
625
653
quit ()
654
+ xml_gpio = parse (os .path .join (cubemxdirIP , 'GPIO-' + gpiofile + '_Modes.xml' ))
626
655
627
- xml = parse (os .path .join (cubemxdirIP , 'GPIO-' + gpiofile + '_Modes.xml' ))
628
- print (" * * * Getting pins and Ips for the xml file..." )
629
- pinregex = r'^(P[A-Z][0-9][0-5]?)'
630
- for s in itemlist :
631
- m = re .match (pinregex , s .attributes ['Name' ].value )
632
- if m :
633
- pin = m .group (0 )[:2 ] + '_' + m .group (0 )[2 :] # pin formatted P<port>_<number>: PF_O
634
- name = s .attributes ['Name' ].value .strip () # full name: "PF0 / OSC_IN"
635
- if s .attributes ['Type' ].value == "I/O" :
636
- store_pin (pin , name )
637
- else :
638
- continue
639
- siglist = s .getElementsByTagName ('Signal' )
640
- for a in siglist :
641
- sig = a .attributes ['Name' ].value .strip ()
642
- if "ADC" in sig :
643
- store_adc (pin , name , sig )
644
- if all (["DAC" in sig , "_OUT" in sig ]):
645
- store_dac (pin , name , sig )
646
- if "I2C" in sig :
647
- store_i2c (pin , name , sig )
648
- if re .match ('^TIM' , sig ) is not None : #ignore HRTIM
649
- store_pwm (pin , name , sig )
650
- if re .match ('^(LPU|US|U)ART' , sig ) is not None :
651
- store_uart (pin , name , sig )
652
- if "SPI" in sig :
653
- store_spi (pin , name , sig )
654
- if "CAN" in sig :
655
- store_can (pin , name , sig )
656
- if "ETH" in sig :
657
- store_eth (pin , name , sig )
658
- if "QUADSPI" in sig :
659
- store_qspi (pin , name , sig )
660
-
661
- #print (" * * * Sorting lists...")
656
+ parse_pins ()
662
657
sort_my_lists ()
663
-
664
- #print (" * * * Printing lists...")
665
658
print_header ()
666
659
print_all_lists ()
667
660
668
661
nb_pin = (len (io_list ))
669
- print ("nb of I/O pins: %i" % nb_pin )
670
- print (' \n * * * ' + mcu_file + ' OK' )
662
+ print (" * I/O pins found : %i" % nb_pin )
663
+ print ("done \n " )
671
664
clean_all_lists ()
672
665
673
666
out_file .close ()
0 commit comments