9
9
from xml .dom .minidom import parse , Node
10
10
from argparse import RawTextHelpFormatter
11
11
12
- GENPINMAP_VERSION = "1.0 "
12
+ GENPINMAP_VERSION = "1.1 "
13
13
14
14
ADD_DEVICE_IFDEF = 0
15
15
ADD_QSPI_FEATURE = 0
@@ -189,8 +189,17 @@ def get_gpio_af_numF1(pintofind, iptofind):
189
189
if mygpioaf == 'NOTFOUND' :
190
190
print ('GPIO AF not found in ' + gpiofile + ' for ' + pintofind + ' and the IP ' + iptofind + ' set as AFIO_NONE' )
191
191
mygpioaf = 'AFIO_NONE'
192
- return mygpioaf .replace ('NOTFOUND ' , '' )
193
-
192
+ return mygpioaf .replace ('NOTFOUND ' , '' )\
193
+ .replace ("AFIO_NONE" , "0" )\
194
+ .replace ("AFIO_SPI1_ENABLE" , "1" )\
195
+ .replace ("AFIO_I2C1_ENABLE" , "2" )\
196
+ .replace ("AFIO_USART1_ENABLE" , "3" )\
197
+ .replace ("AFIO_USART3_PARTIAL" , "5" )\
198
+ .replace ("AFIO_TIM1_PARTIAL" , "6" )\
199
+ .replace ("AFIO_TIM3_PARTIAL" , "7" )\
200
+ .replace ("AFIO_TIM2_ENABLE" , "8" )\
201
+ .replace ("AFIO_TIM3_ENABLE" , "9" )\
202
+ .replace ("AFIO_CAN1_2" , "10" )
194
203
195
204
#function to store I/O pin
196
205
def store_pin (pin , name ):
@@ -312,7 +321,7 @@ def print_header():
312
321
//==============================================================================
313
322
// Notes
314
323
//
315
- // - The pins mentionned Px_y_ALTz are alternative possibilities which use other
324
+ // - The pins mentioned Px_y_ALTz are alternative possibilities which use other
316
325
// HW peripheral instances. You can use them the same way as any other "normal"
317
326
// pin (i.e. PwmOut pwm(PA_7_ALT0);). These pins are not displayed on the board
318
327
// pinout image on mbed.org.
@@ -465,9 +474,9 @@ def print_list_header(comment, name, l, switch):
465
474
466
475
s += "MBED_WEAK const PinMap PinMap_%s[] = {\n " % name
467
476
468
- else :
469
- if comment :
470
- s += "\n //*** No %s ***\n " % comment
477
+ # else:
478
+ # if comment:
479
+ # s += "\n//*** No %s ***\n" % comment
471
480
472
481
out_c_file .write (s )
473
482
return len (l )
@@ -482,7 +491,7 @@ def print_adc():
482
491
if p [1 ] in PinLabel .keys ():
483
492
if "STDIO_UART" in PinLabel [p [1 ]]:
484
493
CommentedLine = "//"
485
- if "RCC_OSC" in PinLabel [p [1 ]] or "SWCLK" in PinLabel [ p [ 1 ]] :
494
+ if "RCC_OSC" in PinLabel [p [1 ]]:
486
495
CommentedLine = "//"
487
496
if CommentedLine != "//" :
488
497
if p [0 ] == prev_p :
@@ -525,7 +534,7 @@ def print_dac():
525
534
if p [1 ] in PinLabel .keys ():
526
535
if "STDIO_UART" in PinLabel [p [1 ]]:
527
536
CommentedLine = "//"
528
- if "RCC_OSC" in PinLabel [p [1 ]] or "SWCLK" in PinLabel [ p [ 1 ]] :
537
+ if "RCC_OSC" in PinLabel [p [1 ]]:
529
538
CommentedLine = "//"
530
539
s1 = "%-17s" % (CommentedLine + " {" + p [0 ] + ',' )
531
540
#p[2] : DAC_OUT1 / DAC1_OUT1
@@ -556,7 +565,7 @@ def print_i2c(l):
556
565
if p [1 ] in PinLabel .keys ():
557
566
if "STDIO_UART" in PinLabel [p [1 ]]:
558
567
CommentedLine = "//"
559
- if "RCC_OSC" in PinLabel [p [1 ]] or "SWCLK" in PinLabel [ p [ 1 ]] :
568
+ if "RCC_OSC" in PinLabel [p [1 ]]:
560
569
CommentedLine = "//"
561
570
if CommentedLine != "//" :
562
571
if p [0 ] == prev_p :
@@ -601,7 +610,7 @@ def print_pwm():
601
610
if p [1 ] in PinLabel .keys ():
602
611
if "STDIO_UART" in PinLabel [p [1 ]]:
603
612
CommentedLine = "//"
604
- if "RCC_OSC" in PinLabel [p [1 ]] or "SWCLK" in PinLabel [ p [ 1 ]] :
613
+ if "RCC_OSC" in PinLabel [p [1 ]]:
605
614
CommentedLine = "//"
606
615
if "%s_" % TIM_MST in p [2 ]:
607
616
CommentedLine = "//"
@@ -648,7 +657,7 @@ def print_uart(l):
648
657
if result != 'NOTFOUND' :
649
658
CommentedLine = " "
650
659
if p [1 ] in PinLabel .keys ():
651
- if "RCC_OSC" in PinLabel [p [1 ]] or "SWCLK" in PinLabel [ p [ 1 ]] :
660
+ if "RCC_OSC" in PinLabel [p [1 ]]:
652
661
CommentedLine = "//"
653
662
if CommentedLine != "//" :
654
663
if p [0 ] == prev_p :
@@ -691,7 +700,7 @@ def print_spi(l):
691
700
if p [1 ] in PinLabel .keys ():
692
701
if "STDIO_UART" in PinLabel [p [1 ]]:
693
702
CommentedLine = "//"
694
- if "RCC_OSC" in PinLabel [p [1 ]] or "SWCLK" in PinLabel [ p [ 1 ]] :
703
+ if "RCC_OSC" in PinLabel [p [1 ]]:
695
704
CommentedLine = "//"
696
705
if CommentedLine != "//" :
697
706
if p [0 ] == prev_p :
@@ -727,7 +736,7 @@ def print_can(l):
727
736
if p [1 ] in PinLabel .keys ():
728
737
if "STDIO_UART" in PinLabel [p [1 ]]:
729
738
CommentedLine = "//"
730
- if "RCC_OSC" in PinLabel [p [1 ]] or "SWCLK" in PinLabel [ p [ 1 ]] :
739
+ if "RCC_OSC" in PinLabel [p [1 ]]:
731
740
CommentedLine = "//"
732
741
s1 = "%-17s" % (CommentedLine + " {" + p [0 ] + ',' )
733
742
# p[2] : CAN_RX / CAN1_RX
@@ -762,7 +771,7 @@ def print_qspi(l):
762
771
if p [1 ] in PinLabel .keys ():
763
772
if "STDIO_UART" in PinLabel [p [1 ]]:
764
773
CommentedLine = "//"
765
- if "RCC_OSC" in PinLabel [p [1 ]] or "SWCLK" in PinLabel [ p [ 1 ]] :
774
+ if "RCC_OSC" in PinLabel [p [1 ]]:
766
775
CommentedLine = "//"
767
776
s1 = "%-17s" % (CommentedLine + " {" + p [0 ] + ',' )
768
777
# p[2] : QUADSPI_BK1_IO3 / QUADSPI_CLK / QUADSPI_NCS
@@ -806,9 +815,9 @@ def print_h_file(l, comment):
806
815
alt_index = 0
807
816
s1 = " %s = %s,\n " % (p [2 ].replace ("-" , "_" ), p [0 ])
808
817
out_h_file .write (s1 )
809
- else :
810
- s = ("\n /**** No %s pins ***/\n " % comment )
811
- out_h_file .write (s )
818
+ # else:
819
+ # s = ("\n/**** No %s pins ***/\n" % comment)
820
+ # out_h_file.write(s)
812
821
813
822
814
823
tokenize = re .compile (r'(\d+)|(\D+)' ).findall
@@ -954,10 +963,11 @@ def parse_BoardFile(fileName):
954
963
try :
955
964
PinLabel [EachPin ] = PinData [EachPin ]["GPIO_Label" ]
956
965
957
- if "STLK_RX" in PinLabel [EachPin ]:
958
- PinLabel [EachPin ] = "STDIO_UART_RX"
959
- elif "STLK_TX" in PinLabel [EachPin ]:
960
- PinLabel [EachPin ] = "STDIO_UART_TX"
966
+ if "STLK_RX" in PinLabel [EachPin ] or "STLK_TX" in PinLabel [EachPin ]:
967
+ if "RX" in PinData [EachPin ]["Signal" ]:
968
+ PinLabel [EachPin ] = "STDIO_UART_RX"
969
+ else :
970
+ PinLabel [EachPin ] = "STDIO_UART_TX"
961
971
elif "USART_RX" in PinLabel [EachPin ]:
962
972
PinLabel [EachPin ] = "STDIO_UART_RX"
963
973
elif "USART_TX" in PinLabel [EachPin ]:
@@ -974,10 +984,11 @@ def parse_BoardFile(fileName):
974
984
PinLabel [EachPin ] = "STDIO_UART_RX"
975
985
elif "USART2_TX" in PinLabel [EachPin ]:
976
986
PinLabel [EachPin ] = "STDIO_UART_TX"
977
- elif "STLINK_RX" in PinLabel [EachPin ]:
978
- PinLabel [EachPin ] = "STDIO_UART_RX"
979
- elif "STLINK_TX" in PinLabel [EachPin ]:
980
- PinLabel [EachPin ] = "STDIO_UART_TX"
987
+ elif "STLINK_RX" in PinLabel [EachPin ] or "STLINK_TX" in PinLabel [EachPin ]:
988
+ if "RX" in PinData [EachPin ]["Signal" ]:
989
+ PinLabel [EachPin ] = "STDIO_UART_RX"
990
+ else :
991
+ PinLabel [EachPin ] = "STDIO_UART_TX"
981
992
except :
982
993
pass
983
994
@@ -1126,7 +1137,7 @@ def parse_BoardFile(fileName):
1126
1137
for mcu_file in mcu_list :
1127
1138
if args .mcu :
1128
1139
TargetName = os .path .splitext (mcu_file )[0 ]
1129
- out_path = os .path .join (cur_dir , 'TARGET_ %s' % TargetName )
1140
+ out_path = os .path .join (cur_dir , '%s' % TargetName )
1130
1141
print (" * Output directory: %s" % (out_path ))
1131
1142
print (" * Generating %s and %s with '%s'" % (PeripheralPins_c_filename , PinNames_h_filename , mcu_file ))
1132
1143
input_file_name = os .path .join (cubemxdirMCU , mcu_file )
@@ -1142,7 +1153,36 @@ def parse_BoardFile(fileName):
1142
1153
out_h_file = open (output_hfilename , 'w' )
1143
1154
1144
1155
#open input file
1145
- xml_mcu = parse (input_file_name )
1156
+ try :
1157
+ xml_mcu = parse (input_file_name )
1158
+ except :
1159
+ # Patch waiting for CubeMX correction
1160
+ if "STM32F042K6Tx" in input_file_name :
1161
+ input_file_name = os .path .join (cubemxdirMCU , "STM32F042K(4-6)Tx.xml" )
1162
+ xml_mcu = parse (input_file_name )
1163
+ elif "STM32F429Z" in input_file_name :
1164
+ input_file_name = os .path .join (cubemxdirMCU , "STM32F429ZITx.xml" )
1165
+ xml_mcu = parse (input_file_name )
1166
+ elif "STM32F746Z" in input_file_name :
1167
+ input_file_name = os .path .join (cubemxdirMCU , "STM32F746ZGTx.xml" )
1168
+ xml_mcu = parse (input_file_name )
1169
+ elif "STM32F767Z" in input_file_name :
1170
+ input_file_name = os .path .join (cubemxdirMCU , "STM32F767ZGTx.xml" )
1171
+ xml_mcu = parse (input_file_name )
1172
+
1173
+ elif "STM32L011K4Tx" in input_file_name :
1174
+ input_file_name = os .path .join (cubemxdirMCU , "STM32L011K(3-4)Tx.xml" )
1175
+ xml_mcu = parse (input_file_name )
1176
+ elif "STM32L432KCUx" in input_file_name :
1177
+ input_file_name = os .path .join (cubemxdirMCU , "STM32L432K(B-C)Ux.xml" )
1178
+ xml_mcu = parse (input_file_name )
1179
+ elif "STM32F746N" in input_file_name :
1180
+ input_file_name = os .path .join (cubemxdirMCU , "STM32F746NGHx.xml" )
1181
+ xml_mcu = parse (input_file_name )
1182
+ else :
1183
+ print ("\n ! ! ! Error in CubeMX file. File " + input_file_name + " doesn't exist" )
1184
+ print (" ! ! ! Check in " + cubemxdirMCU )
1185
+ quit ()
1146
1186
gpiofile = find_gpio_file ()
1147
1187
if gpiofile == 'ERROR' :
1148
1188
print ("Could not find GPIO file" )
0 commit comments