Skip to content

Commit 959ecf9

Browse files
committed
STM32 : genpinmap script version 1.1
1 parent 5a76718 commit 959ecf9

File tree

1 file changed

+68
-28
lines changed

1 file changed

+68
-28
lines changed

targets/TARGET_STM/tools/genpinmap_mbed.py

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from xml.dom.minidom import parse, Node
1010
from argparse import RawTextHelpFormatter
1111

12-
GENPINMAP_VERSION = "1.0"
12+
GENPINMAP_VERSION = "1.1"
1313

1414
ADD_DEVICE_IFDEF = 0
1515
ADD_QSPI_FEATURE = 0
@@ -189,8 +189,17 @@ def get_gpio_af_numF1(pintofind, iptofind):
189189
if mygpioaf == 'NOTFOUND':
190190
print ('GPIO AF not found in ' + gpiofile + ' for ' + pintofind + ' and the IP ' + iptofind + ' set as AFIO_NONE')
191191
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")
194203

195204
#function to store I/O pin
196205
def store_pin (pin, name):
@@ -312,7 +321,7 @@ def print_header():
312321
//==============================================================================
313322
// Notes
314323
//
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
316325
// HW peripheral instances. You can use them the same way as any other "normal"
317326
// pin (i.e. PwmOut pwm(PA_7_ALT0);). These pins are not displayed on the board
318327
// pinout image on mbed.org.
@@ -465,9 +474,9 @@ def print_list_header(comment, name, l, switch):
465474

466475
s += "MBED_WEAK const PinMap PinMap_%s[] = {\n" % name
467476

468-
else:
469-
if comment:
470-
s += "\n//*** No %s ***\n" % comment
477+
# else:
478+
# if comment:
479+
# s += "\n//*** No %s ***\n" % comment
471480

472481
out_c_file.write(s)
473482
return len(l)
@@ -482,7 +491,7 @@ def print_adc():
482491
if p[1] in PinLabel.keys():
483492
if "STDIO_UART" in PinLabel[p[1]]:
484493
CommentedLine = "//"
485-
if "RCC_OSC" in PinLabel[p[1]] or "SWCLK" in PinLabel[p[1]]:
494+
if "RCC_OSC" in PinLabel[p[1]]:
486495
CommentedLine = "//"
487496
if CommentedLine != "//":
488497
if p[0] == prev_p:
@@ -525,7 +534,7 @@ def print_dac():
525534
if p[1] in PinLabel.keys():
526535
if "STDIO_UART" in PinLabel[p[1]]:
527536
CommentedLine = "//"
528-
if "RCC_OSC" in PinLabel[p[1]] or "SWCLK" in PinLabel[p[1]]:
537+
if "RCC_OSC" in PinLabel[p[1]]:
529538
CommentedLine = "//"
530539
s1 = "%-17s" % (CommentedLine + " {" + p[0] + ',')
531540
#p[2] : DAC_OUT1 / DAC1_OUT1
@@ -556,7 +565,7 @@ def print_i2c(l):
556565
if p[1] in PinLabel.keys():
557566
if "STDIO_UART" in PinLabel[p[1]]:
558567
CommentedLine = "//"
559-
if "RCC_OSC" in PinLabel[p[1]] or "SWCLK" in PinLabel[p[1]]:
568+
if "RCC_OSC" in PinLabel[p[1]]:
560569
CommentedLine = "//"
561570
if CommentedLine != "//":
562571
if p[0] == prev_p:
@@ -601,7 +610,7 @@ def print_pwm():
601610
if p[1] in PinLabel.keys():
602611
if "STDIO_UART" in PinLabel[p[1]]:
603612
CommentedLine = "//"
604-
if "RCC_OSC" in PinLabel[p[1]] or "SWCLK" in PinLabel[p[1]]:
613+
if "RCC_OSC" in PinLabel[p[1]]:
605614
CommentedLine = "//"
606615
if "%s_" % TIM_MST in p[2]:
607616
CommentedLine = "//"
@@ -648,7 +657,7 @@ def print_uart(l):
648657
if result != 'NOTFOUND':
649658
CommentedLine = " "
650659
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]]:
652661
CommentedLine = "//"
653662
if CommentedLine != "//":
654663
if p[0] == prev_p:
@@ -691,7 +700,7 @@ def print_spi(l):
691700
if p[1] in PinLabel.keys():
692701
if "STDIO_UART" in PinLabel[p[1]]:
693702
CommentedLine = "//"
694-
if "RCC_OSC" in PinLabel[p[1]] or "SWCLK" in PinLabel[p[1]]:
703+
if "RCC_OSC" in PinLabel[p[1]]:
695704
CommentedLine = "//"
696705
if CommentedLine != "//":
697706
if p[0] == prev_p:
@@ -727,7 +736,7 @@ def print_can(l):
727736
if p[1] in PinLabel.keys():
728737
if "STDIO_UART" in PinLabel[p[1]]:
729738
CommentedLine = "//"
730-
if "RCC_OSC" in PinLabel[p[1]] or "SWCLK" in PinLabel[p[1]]:
739+
if "RCC_OSC" in PinLabel[p[1]]:
731740
CommentedLine = "//"
732741
s1 = "%-17s" % (CommentedLine + " {" + p[0] + ',')
733742
# p[2] : CAN_RX / CAN1_RX
@@ -762,7 +771,7 @@ def print_qspi(l):
762771
if p[1] in PinLabel.keys():
763772
if "STDIO_UART" in PinLabel[p[1]]:
764773
CommentedLine = "//"
765-
if "RCC_OSC" in PinLabel[p[1]] or "SWCLK" in PinLabel[p[1]]:
774+
if "RCC_OSC" in PinLabel[p[1]]:
766775
CommentedLine = "//"
767776
s1 = "%-17s" % (CommentedLine + " {" + p[0] + ',')
768777
# p[2] : QUADSPI_BK1_IO3 / QUADSPI_CLK / QUADSPI_NCS
@@ -806,9 +815,9 @@ def print_h_file(l, comment):
806815
alt_index = 0
807816
s1 = " %s = %s,\n" % (p[2].replace("-", "_"), p[0])
808817
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)
812821

813822

814823
tokenize = re.compile(r'(\d+)|(\D+)').findall
@@ -954,10 +963,11 @@ def parse_BoardFile(fileName):
954963
try:
955964
PinLabel[EachPin] = PinData[EachPin]["GPIO_Label"]
956965

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"
961971
elif "USART_RX" in PinLabel[EachPin]:
962972
PinLabel[EachPin] = "STDIO_UART_RX"
963973
elif "USART_TX" in PinLabel[EachPin]:
@@ -974,10 +984,11 @@ def parse_BoardFile(fileName):
974984
PinLabel[EachPin] = "STDIO_UART_RX"
975985
elif "USART2_TX" in PinLabel[EachPin]:
976986
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"
981992
except:
982993
pass
983994

@@ -1126,7 +1137,7 @@ def parse_BoardFile(fileName):
11261137
for mcu_file in mcu_list:
11271138
if args.mcu:
11281139
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)
11301141
print(" * Output directory: %s" % (out_path))
11311142
print(" * Generating %s and %s with '%s'" % (PeripheralPins_c_filename, PinNames_h_filename, mcu_file))
11321143
input_file_name = os.path.join(cubemxdirMCU, mcu_file)
@@ -1142,7 +1153,36 @@ def parse_BoardFile(fileName):
11421153
out_h_file = open(output_hfilename, 'w')
11431154

11441155
#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()
11461186
gpiofile = find_gpio_file()
11471187
if gpiofile == 'ERROR':
11481188
print("Could not find GPIO file")

0 commit comments

Comments
 (0)