@@ -296,226 +296,185 @@ def print_list_header(comment, name, l, switch):
296296 return len (l )
297297
298298def print_adc ():
299- i = 0
300- if len (adclist )> 0 :
301- # Check GPIO version (alternate or not)
302- s_pin_data = 'STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, '
303- while i < len (adclist ):
304- p = adclist [i ]
305- if "IN" in p [2 ]:
306- s1 = "%-12s" % (" {" + p [0 ] + ',' )
307- a = p [2 ].split ('_' )
308- inst = a [0 ].replace ("ADC" , "" )
309- if len (inst ) == 0 :
310- inst = '1' #single ADC for this product
311- s1 += "%-7s" % ('ADC' + inst + ',' )
312- chan = re .sub ('IN[N|P]?' , '' , a [1 ])
313- s1 += s_pin_data + chan
314- s1 += ', 0)}, // ' + p [2 ] + '\n '
315- out_file .write (s1 )
316- i += 1
317-
318- out_file .write ( """ {NC, NP, 0}
299+ # Check GPIO version (alternate or not)
300+ s_pin_data = 'STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, '
301+ for p in adclist :
302+ if "IN" in p [2 ]:
303+ s1 = "%-12s" % (" {" + p [0 ] + ',' )
304+ a = p [2 ].split ('_' )
305+ inst = a [0 ].replace ("ADC" , "" )
306+ if len (inst ) == 0 :
307+ inst = '1' #single ADC for this product
308+ s1 += "%-7s" % ('ADC' + inst + ',' )
309+ chan = re .sub ('IN[N|P]?' , '' , a [1 ])
310+ s1 += s_pin_data + chan
311+ s1 += ', 0)}, // ' + p [2 ] + '\n '
312+ out_file .write (s1 )
313+ out_file .write ( """ {NC, NP, 0}
319314};
320315#endif
321316""" )
322317
323318def print_dac ():
324- i = 0
325- if len (daclist )> 0 :
326- while i < len (daclist ):
327- p = daclist [i ]
328- b = p [2 ]
329- s1 = "%-12s" % (" {" + p [0 ] + ',' )
330- #2nd element is the DAC signal
331- if b [3 ] == '_' : # 1 DAC in this chip
332- s1 += 'DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b [7 ] + ', 0)}, // ' + b + '\n '
333- else :
334- s1 += 'DAC' + b [3 ] + ', STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b [8 ] + ', 0)}, // ' + b + '\n '
335- out_file .write (s1 )
336- i += 1
337- out_file .write ( """ {NC, NP, 0}
319+ for p in daclist :
320+ b = p [2 ]
321+ s1 = "%-12s" % (" {" + p [0 ] + ',' )
322+ #2nd element is the DAC signal
323+ if b [3 ] == '_' : # 1 DAC in this chip
324+ s1 += 'DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b [7 ] + ', 0)}, // ' + b + '\n '
325+ else :
326+ s1 += 'DAC' + b [3 ] + ', STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b [8 ] + ', 0)}, // ' + b + '\n '
327+ out_file .write (s1 )
328+ out_file .write ( """ {NC, NP, 0}
338329};
339330#endif
340331""" )
341332
342333def print_i2c (xml , l ):
343- i = 0
344- if len (l )> 0 :
345- while i < len (l ):
346- p = l [i ]
347- result = get_gpio_af_num (xml , p [1 ], p [2 ])
348- if result != 'NOTFOUND' :
349- s1 = "%-12s" % (" {" + p [0 ] + ',' )
350- #2nd element is the I2C XXX signal
351- b = p [2 ].split ('_' )[0 ]
352- s1 += b [:len (b )- 1 ] + b [len (b )- 1 ] + ', STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, '
353- r = result .split (' ' )
354- for af in r :
355- s2 = s1 + af + ')},\n '
356- out_file .write (s2 )
357- i += 1
358- out_file .write ( """ {NC, NP, 0}
334+ for p in l :
335+ result = get_gpio_af_num (xml , p [1 ], p [2 ])
336+ if result != 'NOTFOUND' :
337+ s1 = "%-12s" % (" {" + p [0 ] + ',' )
338+ #2nd element is the I2C XXX signal
339+ b = p [2 ].split ('_' )[0 ]
340+ s1 += b [:len (b )- 1 ] + b [len (b )- 1 ] + ', STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, '
341+ r = result .split (' ' )
342+ for af in r :
343+ s2 = s1 + af + ')},\n '
344+ out_file .write (s2 )
345+ out_file .write ( """ {NC, NP, 0}
359346};
360347#endif
361348""" )
362349
363350def print_pwm (xml ):
364- i = 0
365- if len (pwm_list )> 0 :
366- while i < len (pwm_list ):
367- p = pwm_list [i ]
368- result = get_gpio_af_num (xml , p [1 ], p [2 ])
369- if result != 'NOTFOUND' :
370- s1 = "%-12s" % (" {" + p [0 ] + ',' )
371- #2nd element is the PWM signal
372- a = p [2 ].split ('_' )
373- inst = a [0 ]
374- if len (inst ) == 3 :
375- inst += '1'
376- s1 += "%-8s" % (inst + ',' )
377- chan = a [1 ].replace ("CH" , "" )
378- if chan .endswith ('N' ):
379- neg = ', 1'
380- chan = chan .strip ('N' )
381- else :
382- neg = ', 0'
383- s1 += 'STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, '
384- r = result .split (' ' )
385- for af in r :
386- s2 = s1 + af + ', ' + chan + neg + ')}, // ' + p [2 ] + '\n '
387- out_file .write (s2 )
388- i += 1
389- out_file .write ( """ {NC, NP, 0}
351+ for p in pwm_list :
352+ result = get_gpio_af_num (xml , p [1 ], p [2 ])
353+ if result != 'NOTFOUND' :
354+ s1 = "%-12s" % (" {" + p [0 ] + ',' )
355+ #2nd element is the PWM signal
356+ a = p [2 ].split ('_' )
357+ inst = a [0 ]
358+ if len (inst ) == 3 :
359+ inst += '1'
360+ s1 += "%-8s" % (inst + ',' )
361+ chan = a [1 ].replace ("CH" , "" )
362+ if chan .endswith ('N' ):
363+ neg = ', 1'
364+ chan = chan .strip ('N' )
365+ else :
366+ neg = ', 0'
367+ s1 += 'STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, '
368+ r = result .split (' ' )
369+ for af in r :
370+ s2 = s1 + af + ', ' + chan + neg + ')}, // ' + p [2 ] + '\n '
371+ out_file .write (s2 )
372+ out_file .write ( """ {NC, NP, 0}
390373};
391374#endif
392375""" )
393376
394377def print_uart (xml , l ):
395- i = 0
396- if len (l )> 0 :
397- while i < len (l ):
398- p = l [i ]
399- result = get_gpio_af_num (xml , p [1 ], p [2 ])
400- if result != 'NOTFOUND' :
401- s1 = "%-12s" % (" {" + p [0 ] + ',' )
402- #2nd element is the UART_XX signal
403- b = p [2 ].split ('_' )[0 ]
404- s1 += "%-9s" % (b [:len (b )- 1 ] + b [len (b )- 1 :] + ',' )
405- if 'STM32F10' in mcu_file and l == uartrx_list :
406- s1 += 'STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, '
407- else :
408- s1 += 'STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, '
409- r = result .split (' ' )
410- for af in r :
411- s2 = s1 + af + ')},\n '
412- out_file .write (s2 )
413- i += 1
414-
378+ for p in l :
379+ result = get_gpio_af_num (xml , p [1 ], p [2 ])
380+ if result != 'NOTFOUND' :
381+ s1 = "%-12s" % (" {" + p [0 ] + ',' )
382+ #2nd element is the UART_XX signal
383+ b = p [2 ].split ('_' )[0 ]
384+ s1 += "%-9s" % (b [:len (b )- 1 ] + b [len (b )- 1 :] + ',' )
385+ if 'STM32F10' in mcu_file and l == uartrx_list :
386+ s1 += 'STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, '
387+ else :
388+ s1 += 'STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, '
389+ r = result .split (' ' )
390+ for af in r :
391+ s2 = s1 + af + ')},\n '
392+ out_file .write (s2 )
415393 out_file .write ( """ {NC, NP, 0}
416394};
417395#endif
418396""" )
419397
420398def print_spi (xml , l ):
421- i = 0
422- if len (l )> 0 :
423- while i < len (l ):
424- p = l [i ]
425- result = get_gpio_af_num (xml , p [1 ], p [2 ])
426- if result != 'NOTFOUND' :
427- s1 = "%-12s" % (" {" + p [0 ] + ',' )
428- #2nd element is the SPI_XXXX signal
429- instance = p [2 ].split ('_' )[0 ].replace ("SPI" , "" )
430- s1 += 'SPI' + instance + ', STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, '
431- r = result .split (' ' )
432- for af in r :
433- s2 = s1 + af + ')},\n '
434- out_file .write (s2 )
435- i += 1
436-
437- out_file .write ( """ {NC, NP, 0}
399+ for p in l :
400+ result = get_gpio_af_num (xml , p [1 ], p [2 ])
401+ if result != 'NOTFOUND' :
402+ s1 = "%-12s" % (" {" + p [0 ] + ',' )
403+ #2nd element is the SPI_XXXX signal
404+ instance = p [2 ].split ('_' )[0 ].replace ("SPI" , "" )
405+ s1 += 'SPI' + instance + ', STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, '
406+ r = result .split (' ' )
407+ for af in r :
408+ s2 = s1 + af + ')},\n '
409+ out_file .write (s2 )
410+ out_file .write ( """ {NC, NP, 0}
438411};
439412#endif
440413""" )
441414
442415def print_can (xml , l ):
443- i = 0
444- if len (l )> 0 :
445- while i < len (l ):
446- p = l [i ]
447- b = p [2 ]
448- result = get_gpio_af_num (xml , p [1 ], p [2 ])
449- if result != 'NOTFOUND' :
450- s1 = "%-12s" % (" {" + p [0 ] + ',' )
451- #2nd element is the CAN_XX signal
452- instance = p [2 ].split ('_' )[0 ].replace ("CAN" , "" )
453- if len (instance ) == 0 :
454- instance = '1'
455- if 'STM32F10' in mcu_file and l == canrd_list :
456- s1 += 'CAN' + instance + ', STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, '
457- else :
458- s1 += 'CAN' + instance + ', STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, '
459- r = result .split (' ' )
460- for af in r :
461- s2 = s1 + af + ')},\n '
462- out_file .write (s2 )
463- i += 1
464- out_file .write ( """ {NC, NP, 0}
416+ for p in l :
417+ b = p [2 ]
418+ result = get_gpio_af_num (xml , p [1 ], p [2 ])
419+ if result != 'NOTFOUND' :
420+ s1 = "%-12s" % (" {" + p [0 ] + ',' )
421+ #2nd element is the CAN_XX signal
422+ instance = p [2 ].split ('_' )[0 ].replace ("CAN" , "" )
423+ if len (instance ) == 0 :
424+ instance = '1'
425+ if 'STM32F10' in mcu_file and l == canrd_list :
426+ s1 += 'CAN' + instance + ', STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, '
427+ else :
428+ s1 += 'CAN' + instance + ', STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, '
429+ r = result .split (' ' )
430+ for af in r :
431+ s2 = s1 + af + ')},\n '
432+ out_file .write (s2 )
433+ out_file .write ( """ {NC, NP, 0}
465434};
466435#endif
467436""" )
468437
469438def print_eth (xml , l ):
470- i = 0
471- if len (l )> 0 :
472- prev_s = ''
473- while i < len (l ):
474- p = l [i ]
475- result = get_gpio_af_num (xml , p [1 ], p [2 ])
476- if result != 'NOTFOUND' :
477- s1 = "%-12s" % (" {" + p [0 ] + ',' )
478- #2nd element is the ETH_XXXX signal
479- s1 += 'ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result + ')},'
480- #check duplicated lines, only signal differs
481- if (prev_s == s1 ):
482- s1 = '|' + p [2 ]
483- else :
484- if len (prev_s )> 0 :
485- out_file .write ('\n ' )
486- prev_s = s1
487- s1 += ' // ' + p [2 ]
488- out_file .write (s1 )
489- i += 1
490-
491- out_file .write ( """\n {NC, NP, 0}
439+ prev_s = ''
440+ for p in l :
441+ result = get_gpio_af_num (xml , p [1 ], p [2 ])
442+ if result != 'NOTFOUND' :
443+ s1 = "%-12s" % (" {" + p [0 ] + ',' )
444+ #2nd element is the ETH_XXXX signal
445+ s1 += 'ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result + ')},'
446+ #check duplicated lines, only signal differs
447+ if (prev_s == s1 ):
448+ s1 = '|' + p [2 ]
449+ else :
450+ if len (prev_s )> 0 :
451+ out_file .write ('\n ' )
452+ prev_s = s1
453+ s1 += ' // ' + p [2 ]
454+ out_file .write (s1 )
455+ out_file .write ( """\n {NC, NP, 0}
492456};
493457#endif
494458""" )
495459
496460def print_qspi (xml , l ):
497- i = 0
498- if len (l )> 0 :
499- prev_s = ''
500- while i < len (l ):
501- p = l [i ]
502- result = get_gpio_af_num (xml , p [1 ], p [2 ])
503- if result != 'NOTFOUND' :
504- s1 = "%-12s" % (" {" + p [0 ] + ',' )
505- #2nd element is the QUADSPI_XXXX signal
506- s1 += 'QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result + ')},'
507- #check duplicated lines, only signal differs
508- if (prev_s == s1 ):
509- s1 = '|' + p [2 ]
510- else :
511- if len (prev_s )> 0 :
512- out_file .write ('\n ' )
513- prev_s = s1
514- s1 += ' // ' + p [2 ]
515- out_file .write (s1 )
516- i += 1
517-
518- out_file .write ( """\n {NC, NP, 0}
461+ prev_s = ''
462+ for p in l :
463+ result = get_gpio_af_num (xml , p [1 ], p [2 ])
464+ if result != 'NOTFOUND' :
465+ s1 = "%-12s" % (" {" + p [0 ] + ',' )
466+ #2nd element is the QUADSPI_XXXX signal
467+ s1 += 'QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result + ')},'
468+ #check duplicated lines, only signal differs
469+ if (prev_s == s1 ):
470+ s1 = '|' + p [2 ]
471+ else :
472+ if len (prev_s )> 0 :
473+ out_file .write ('\n ' )
474+ prev_s = s1
475+ s1 += ' // ' + p [2 ]
476+ out_file .write (s1 )
477+ out_file .write ( """\n {NC, NP, 0}
519478};
520479#endif
521480""" )
0 commit comments