Clone of official tools

Committer:
Anders Blomdell
Date:
Thu Feb 04 17:17:13 2021 +0100
Revision:
47:21ae3e5a7128
Parent:
43:2a7da56ebd24
Add a few normpath calls

Who changed what in which revision?

UserRevisionLine numberNew contents of line
theotherjimmy 43:2a7da56ebd24 1 """
theotherjimmy 43:2a7da56ebd24 2 * mbed Microcontroller Library
theotherjimmy 43:2a7da56ebd24 3 * Copyright (c) 2006-2018 ARM Limited
theotherjimmy 43:2a7da56ebd24 4 *
theotherjimmy 43:2a7da56ebd24 5 * Licensed under the Apache License, Version 2.0 (the "License");
theotherjimmy 43:2a7da56ebd24 6 * you may not use this file except in compliance with the License.
theotherjimmy 43:2a7da56ebd24 7 * You may obtain a copy of the License at
theotherjimmy 43:2a7da56ebd24 8 *
theotherjimmy 43:2a7da56ebd24 9 * http://www.apache.org/licenses/LICENSE-2.0
theotherjimmy 43:2a7da56ebd24 10 *
theotherjimmy 43:2a7da56ebd24 11 * Unless required by applicable law or agreed to in writing, software
theotherjimmy 43:2a7da56ebd24 12 * distributed under the License is distributed on an "AS IS" BASIS,
theotherjimmy 43:2a7da56ebd24 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
theotherjimmy 43:2a7da56ebd24 14 * See the License for the specific language governing permissions and
theotherjimmy 43:2a7da56ebd24 15 * limitations under the License.
theotherjimmy 43:2a7da56ebd24 16 """
theotherjimmy 43:2a7da56ebd24 17
theotherjimmy 43:2a7da56ebd24 18 import argparse
theotherjimmy 43:2a7da56ebd24 19 import datetime
theotherjimmy 43:2a7da56ebd24 20 import fnmatch
theotherjimmy 43:2a7da56ebd24 21 import json
theotherjimmy 43:2a7da56ebd24 22 import os
theotherjimmy 43:2a7da56ebd24 23 import re
theotherjimmy 43:2a7da56ebd24 24 import sys
theotherjimmy 43:2a7da56ebd24 25 import textwrap
theotherjimmy 43:2a7da56ebd24 26 from xml.dom.minidom import parse, Node
theotherjimmy 43:2a7da56ebd24 27 from argparse import RawTextHelpFormatter
theotherjimmy 43:2a7da56ebd24 28
theotherjimmy 43:2a7da56ebd24 29 GENPINMAP_VERSION = "1.3"
theotherjimmy 43:2a7da56ebd24 30
theotherjimmy 43:2a7da56ebd24 31 ADD_DEVICE_IFDEF = 0
theotherjimmy 43:2a7da56ebd24 32 ADD_QSPI_FEATURE = 1
theotherjimmy 43:2a7da56ebd24 33
theotherjimmy 43:2a7da56ebd24 34 mcu_file=""
theotherjimmy 43:2a7da56ebd24 35 mcu_list = [] #'name'
theotherjimmy 43:2a7da56ebd24 36 io_list = [] #'PIN','name'
theotherjimmy 43:2a7da56ebd24 37 adclist = [] #'PIN','name','ADCSignal'
theotherjimmy 43:2a7da56ebd24 38 daclist = [] #'PIN','name','DACSignal'
theotherjimmy 43:2a7da56ebd24 39 i2cscl_list = [] #'PIN','name','I2CSCLSignal'
theotherjimmy 43:2a7da56ebd24 40 i2csda_list = [] #'PIN','name','I2CSDASignal'
theotherjimmy 43:2a7da56ebd24 41 pwm_list = [] #'PIN','name','PWM'
theotherjimmy 43:2a7da56ebd24 42 uarttx_list = [] #'PIN','name','UARTtx'
theotherjimmy 43:2a7da56ebd24 43 uartrx_list = [] #'PIN','name','UARTrx'
theotherjimmy 43:2a7da56ebd24 44 uartcts_list = [] #'PIN','name','UARTcts'
theotherjimmy 43:2a7da56ebd24 45 uartrts_list = [] #'PIN','name','UARTrts'
theotherjimmy 43:2a7da56ebd24 46 spimosi_list = [] #'PIN','name','SPIMOSI'
theotherjimmy 43:2a7da56ebd24 47 spimiso_list = [] #'PIN','name','SPIMISO'
theotherjimmy 43:2a7da56ebd24 48 spissel_list = [] #'PIN','name','SPISSEL'
theotherjimmy 43:2a7da56ebd24 49 spisclk_list = [] #'PIN','name','SPISCLK'
theotherjimmy 43:2a7da56ebd24 50 cantd_list = [] #'PIN','name','CANTD'
theotherjimmy 43:2a7da56ebd24 51 canrd_list = [] #'PIN','name','CANRD'
theotherjimmy 43:2a7da56ebd24 52 eth_list = [] #'PIN','name','ETH'
theotherjimmy 43:2a7da56ebd24 53 quadspidata_list = [] #'PIN','name','QUADSPIDATA'
theotherjimmy 43:2a7da56ebd24 54 quadspisclk_list = [] #'PIN','name','QUADSPISCLK'
theotherjimmy 43:2a7da56ebd24 55 quadspissel_list = [] #'PIN','name','QUADSPISSEL'
theotherjimmy 43:2a7da56ebd24 56 usb_list = [] #'PIN','name','USB'
theotherjimmy 43:2a7da56ebd24 57 osc_list = [] #'PIN','name','OSC'
theotherjimmy 43:2a7da56ebd24 58 sys_list = [] #'PIN','name','SYS'
theotherjimmy 43:2a7da56ebd24 59
theotherjimmy 43:2a7da56ebd24 60 TIM_MST_LIST = { # Timer used for us ticker is hardcoded in this script
theotherjimmy 43:2a7da56ebd24 61 "NUCLEO_F030R8":"TIM1",
theotherjimmy 43:2a7da56ebd24 62 "NUCLEO_F072RB":"TIM2",
theotherjimmy 43:2a7da56ebd24 63 "NUCLEO_F091RC":"TIM2",
theotherjimmy 43:2a7da56ebd24 64 "NUCLEO_F070RB":"TIM1",
theotherjimmy 43:2a7da56ebd24 65 "NUCLEO_F042K6":"TIM2",
theotherjimmy 43:2a7da56ebd24 66 "NUCLEO_F031K6":"TIM2",
theotherjimmy 43:2a7da56ebd24 67 "NUCLEO_F103RB":"TIM4",
theotherjimmy 43:2a7da56ebd24 68 "NUCLEO_F207ZG":"TIM5",
theotherjimmy 43:2a7da56ebd24 69 "NUCLEO_F302R8":"TIM2",
theotherjimmy 43:2a7da56ebd24 70 "NUCLEO_F334R8":"TIM2",
theotherjimmy 43:2a7da56ebd24 71 "NUCLEO_F303RE":"TIM2",
theotherjimmy 43:2a7da56ebd24 72 "NUCLEO_F303K8":"TIM2",
theotherjimmy 43:2a7da56ebd24 73 "NUCLEO_F303ZE":"TIM2",
theotherjimmy 43:2a7da56ebd24 74 "NUCLEO_F401RE":"TIM5",
theotherjimmy 43:2a7da56ebd24 75 "NUCLEO_F411RE":"TIM5",
theotherjimmy 43:2a7da56ebd24 76 "NUCLEO_F446RE":"TIM5",
theotherjimmy 43:2a7da56ebd24 77 "NUCLEO_F410RB":"TIM5",
theotherjimmy 43:2a7da56ebd24 78 "NUCLEO_F429ZI":"TIM5",
theotherjimmy 43:2a7da56ebd24 79 "NUCLEO_F446ZE":"TIM5",
theotherjimmy 43:2a7da56ebd24 80 "NUCLEO_F412ZG":"TIM5",
theotherjimmy 43:2a7da56ebd24 81 "NUCLEO_F413ZH":"TIM5",
theotherjimmy 43:2a7da56ebd24 82 "NUCLEO_F746ZG":"TIM5",
theotherjimmy 43:2a7da56ebd24 83 "NUCLEO_F767ZI":"TIM5",
theotherjimmy 43:2a7da56ebd24 84 "NUCLEO_F722ZE":"TIM5",
theotherjimmy 43:2a7da56ebd24 85 "NUCLEO_H743ZI":"TIM5",
theotherjimmy 43:2a7da56ebd24 86 "NUCLEO_L053R8":"TIM21",
theotherjimmy 43:2a7da56ebd24 87 "NUCLEO_L073RZ":"TIM21",
theotherjimmy 43:2a7da56ebd24 88 "NUCLEO_L031K6":"TIM21",
theotherjimmy 43:2a7da56ebd24 89 "NUCLEO_L011K4":"TIM21",
theotherjimmy 43:2a7da56ebd24 90 "NUCLEO_L152RE":"TIM5",
theotherjimmy 43:2a7da56ebd24 91 "NUCLEO_L476RG":"TIM5",
theotherjimmy 43:2a7da56ebd24 92 "NUCLEO_L432KC":"TIM2",
theotherjimmy 43:2a7da56ebd24 93 "NUCLEO_L496ZG":"TIM5",
theotherjimmy 43:2a7da56ebd24 94 "NUCLEO_L496ZG_P":"TIM5",
theotherjimmy 43:2a7da56ebd24 95 "NUCLEO_L433RC_P":"TIM2",
theotherjimmy 43:2a7da56ebd24 96
theotherjimmy 43:2a7da56ebd24 97 "DISCO_F051R8":"TIM1",
theotherjimmy 43:2a7da56ebd24 98 "DISCO_F100RB":"TIM4",
theotherjimmy 43:2a7da56ebd24 99 "DISCO_F303VC":"TIM2",
theotherjimmy 43:2a7da56ebd24 100 "DISCO_F334C8":"TIM2",
theotherjimmy 43:2a7da56ebd24 101 "DISCO_F401VC":"TIM5",
theotherjimmy 43:2a7da56ebd24 102 "DISCO_F407VG":"TIM5",
theotherjimmy 43:2a7da56ebd24 103 "DISCO_F413ZH":"TIM5",
theotherjimmy 43:2a7da56ebd24 104 "DISCO_F429ZI":"TIM5",
theotherjimmy 43:2a7da56ebd24 105 "DISCO_F469NI":"TIM5",
theotherjimmy 43:2a7da56ebd24 106 "DISCO_F769NI":"TIM5",
theotherjimmy 43:2a7da56ebd24 107 "DISCO_F746NG":"TIM5",
theotherjimmy 43:2a7da56ebd24 108 "DISCO_L053C8":"TIM21",
theotherjimmy 43:2a7da56ebd24 109 "DISCO_L072CZ_LRWAN1":"TIM21",
theotherjimmy 43:2a7da56ebd24 110 "DISCO_L475VG_IOT01A":"TIM5",
theotherjimmy 43:2a7da56ebd24 111 "DISCO_L476VG":"TIM5",
theotherjimmy 43:2a7da56ebd24 112 "DISCO_L496AG":"TIM5"
theotherjimmy 43:2a7da56ebd24 113 }
theotherjimmy 43:2a7da56ebd24 114
theotherjimmy 43:2a7da56ebd24 115
theotherjimmy 43:2a7da56ebd24 116 def find_gpio_file():
theotherjimmy 43:2a7da56ebd24 117 res = 'ERROR'
theotherjimmy 43:2a7da56ebd24 118 itemlist = xml_mcu.getElementsByTagName('IP')
theotherjimmy 43:2a7da56ebd24 119 for s in itemlist:
theotherjimmy 43:2a7da56ebd24 120 a = s.attributes['Name'].value
theotherjimmy 43:2a7da56ebd24 121 if "GPIO" in a:
theotherjimmy 43:2a7da56ebd24 122 res = s.attributes['Version'].value
theotherjimmy 43:2a7da56ebd24 123 return res
theotherjimmy 43:2a7da56ebd24 124
theotherjimmy 43:2a7da56ebd24 125 def get_gpio_af_num(pintofind, iptofind):
theotherjimmy 43:2a7da56ebd24 126 if 'STM32F10' in mcu_file:
theotherjimmy 43:2a7da56ebd24 127 return get_gpio_af_numF1(pintofind, iptofind)
theotherjimmy 43:2a7da56ebd24 128 #DBG print ('pin to find ' + pintofind)
theotherjimmy 43:2a7da56ebd24 129 i=0
theotherjimmy 43:2a7da56ebd24 130 mygpioaf = 'NOTFOUND'
theotherjimmy 43:2a7da56ebd24 131 for n in xml_gpio.documentElement.childNodes:
theotherjimmy 43:2a7da56ebd24 132 i += 1
theotherjimmy 43:2a7da56ebd24 133 j = 0
theotherjimmy 43:2a7da56ebd24 134 if n.nodeType == Node.ELEMENT_NODE:
theotherjimmy 43:2a7da56ebd24 135 for firstlevel in n.attributes.items():
theotherjimmy 43:2a7da56ebd24 136 # if 'PB7' in firstlevel:
theotherjimmy 43:2a7da56ebd24 137 if pintofind == firstlevel[1]:
theotherjimmy 43:2a7da56ebd24 138 #DBG print (i , firstlevel)
theotherjimmy 43:2a7da56ebd24 139 #n = pin node found
theotherjimmy 43:2a7da56ebd24 140 for m in n.childNodes:
theotherjimmy 43:2a7da56ebd24 141 j += 1
theotherjimmy 43:2a7da56ebd24 142 k = 0
theotherjimmy 43:2a7da56ebd24 143 if m.nodeType == Node.ELEMENT_NODE:
theotherjimmy 43:2a7da56ebd24 144 for secondlevel in m.attributes.items():
theotherjimmy 43:2a7da56ebd24 145 k += 1
theotherjimmy 43:2a7da56ebd24 146 # if 'I2C1_SDA' in secondlevel:
theotherjimmy 43:2a7da56ebd24 147 if iptofind in secondlevel:
theotherjimmy 43:2a7da56ebd24 148 #DBG print (i, j, m.attributes.items())
theotherjimmy 43:2a7da56ebd24 149 # m = IP node found
theotherjimmy 43:2a7da56ebd24 150 for p in m.childNodes:
theotherjimmy 43:2a7da56ebd24 151 if p.nodeType == Node.ELEMENT_NODE:
theotherjimmy 43:2a7da56ebd24 152 #p node of 'Specific parameter'
theotherjimmy 43:2a7da56ebd24 153 #DBG print (i,j,k,p.attributes.items())
theotherjimmy 43:2a7da56ebd24 154 for myc in p.childNodes:
theotherjimmy 43:2a7da56ebd24 155 #DBG print (myc)
theotherjimmy 43:2a7da56ebd24 156 if myc.nodeType == Node.ELEMENT_NODE:
theotherjimmy 43:2a7da56ebd24 157 #myc = node of ALTERNATE
theotherjimmy 43:2a7da56ebd24 158 for mygpioaflist in myc.childNodes:
theotherjimmy 43:2a7da56ebd24 159 mygpioaf += ' ' + mygpioaflist.data
theotherjimmy 43:2a7da56ebd24 160 #print (mygpioaf)
theotherjimmy 43:2a7da56ebd24 161 if mygpioaf == 'NOTFOUND':
theotherjimmy 43:2a7da56ebd24 162 print ('GPIO AF not found in ' + gpiofile + ' for ' + pintofind + ' and the IP ' + iptofind)
theotherjimmy 43:2a7da56ebd24 163 #quit()
theotherjimmy 43:2a7da56ebd24 164 return mygpioaf.replace('NOTFOUND ', '')
theotherjimmy 43:2a7da56ebd24 165
theotherjimmy 43:2a7da56ebd24 166 def get_gpio_af_numF1(pintofind, iptofind):
theotherjimmy 43:2a7da56ebd24 167 #print ('pin to find ' + pintofind + ' ip to find ' + iptofind)
theotherjimmy 43:2a7da56ebd24 168 i=0
theotherjimmy 43:2a7da56ebd24 169 mygpioaf = 'NOTFOUND'
theotherjimmy 43:2a7da56ebd24 170 for n in xml_gpio.documentElement.childNodes:
theotherjimmy 43:2a7da56ebd24 171 i += 1
theotherjimmy 43:2a7da56ebd24 172 j = 0
theotherjimmy 43:2a7da56ebd24 173 if n.nodeType == Node.ELEMENT_NODE:
theotherjimmy 43:2a7da56ebd24 174 for firstlevel in n.attributes.items():
theotherjimmy 43:2a7da56ebd24 175 #print ('firstlevel ' , firstlevel)
theotherjimmy 43:2a7da56ebd24 176 # if 'PB7' in firstlevel:
theotherjimmy 43:2a7da56ebd24 177 if pintofind == firstlevel[1]:
theotherjimmy 43:2a7da56ebd24 178 #print ('firstlevel ' , i , firstlevel)
theotherjimmy 43:2a7da56ebd24 179 #n = pin node found
theotherjimmy 43:2a7da56ebd24 180 for m in n.childNodes:
theotherjimmy 43:2a7da56ebd24 181 j += 1
theotherjimmy 43:2a7da56ebd24 182 k = 0
theotherjimmy 43:2a7da56ebd24 183 if m.nodeType == Node.ELEMENT_NODE:
theotherjimmy 43:2a7da56ebd24 184 for secondlevel in m.attributes.items():
theotherjimmy 43:2a7da56ebd24 185 #print ('secondlevel ' , i, j, k , secondlevel)
theotherjimmy 43:2a7da56ebd24 186 k += 1
theotherjimmy 43:2a7da56ebd24 187 # if 'I2C1_SDA' in secondlevel:
theotherjimmy 43:2a7da56ebd24 188 if iptofind in secondlevel:
theotherjimmy 43:2a7da56ebd24 189 # m = IP node found
theotherjimmy 43:2a7da56ebd24 190 #print (i, j, m.attributes.items())
theotherjimmy 43:2a7da56ebd24 191 for p in m.childNodes:
theotherjimmy 43:2a7da56ebd24 192 #p node 'RemapBlock'
theotherjimmy 43:2a7da56ebd24 193 if p.nodeType == Node.ELEMENT_NODE and p.hasChildNodes() == False:
theotherjimmy 43:2a7da56ebd24 194 mygpioaf += ' AFIO_NONE'
theotherjimmy 43:2a7da56ebd24 195 else:
theotherjimmy 43:2a7da56ebd24 196 for s in p.childNodes:
theotherjimmy 43:2a7da56ebd24 197 if s.nodeType == Node.ELEMENT_NODE:
theotherjimmy 43:2a7da56ebd24 198 #s node 'Specific parameter'
theotherjimmy 43:2a7da56ebd24 199 #DBG print (i,j,k,p.attributes.items())
theotherjimmy 43:2a7da56ebd24 200 for myc in s.childNodes:
theotherjimmy 43:2a7da56ebd24 201 #DBG print (myc)
theotherjimmy 43:2a7da56ebd24 202 if myc.nodeType == Node.ELEMENT_NODE:
theotherjimmy 43:2a7da56ebd24 203 #myc = AF value
theotherjimmy 43:2a7da56ebd24 204 for mygpioaflist in myc.childNodes:
theotherjimmy 43:2a7da56ebd24 205 mygpioaf += ' ' + mygpioaflist.data.replace("__HAL_", "").replace("_REMAP", "")
theotherjimmy 43:2a7da56ebd24 206 #print mygpioaf
theotherjimmy 43:2a7da56ebd24 207 if mygpioaf == 'NOTFOUND':
theotherjimmy 43:2a7da56ebd24 208 print ('GPIO AF not found in ' + gpiofile + ' for ' + pintofind + ' and the IP ' + iptofind + ' set as AFIO_NONE')
theotherjimmy 43:2a7da56ebd24 209 mygpioaf = 'AFIO_NONE'
theotherjimmy 43:2a7da56ebd24 210 return mygpioaf.replace('NOTFOUND ', '')\
theotherjimmy 43:2a7da56ebd24 211 .replace("AFIO_NONE", "0")\
theotherjimmy 43:2a7da56ebd24 212 .replace("AFIO_SPI1_ENABLE", "1")\
theotherjimmy 43:2a7da56ebd24 213 .replace("AFIO_I2C1_ENABLE", "2")\
theotherjimmy 43:2a7da56ebd24 214 .replace("AFIO_USART1_ENABLE", "3")\
theotherjimmy 43:2a7da56ebd24 215 .replace("AFIO_USART3_PARTIAL", "5")\
theotherjimmy 43:2a7da56ebd24 216 .replace("AFIO_TIM1_PARTIAL", "6")\
theotherjimmy 43:2a7da56ebd24 217 .replace("AFIO_TIM3_PARTIAL", "7")\
theotherjimmy 43:2a7da56ebd24 218 .replace("AFIO_TIM2_ENABLE", "8")\
theotherjimmy 43:2a7da56ebd24 219 .replace("AFIO_TIM3_ENABLE", "9")\
theotherjimmy 43:2a7da56ebd24 220 .replace("AFIO_CAN1_2", "10")
theotherjimmy 43:2a7da56ebd24 221
theotherjimmy 43:2a7da56ebd24 222 #function to store I/O pin
theotherjimmy 43:2a7da56ebd24 223 def store_pin (pin, name):
theotherjimmy 43:2a7da56ebd24 224 p = [pin, name]
theotherjimmy 43:2a7da56ebd24 225 io_list.append(p)
theotherjimmy 43:2a7da56ebd24 226
theotherjimmy 43:2a7da56ebd24 227 #function to store ADC list
theotherjimmy 43:2a7da56ebd24 228 def store_adc (pin, name, signal):
theotherjimmy 43:2a7da56ebd24 229 adclist.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 230
theotherjimmy 43:2a7da56ebd24 231 #function to store DAC list
theotherjimmy 43:2a7da56ebd24 232 def store_dac (pin, name, signal):
theotherjimmy 43:2a7da56ebd24 233 daclist.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 234
theotherjimmy 43:2a7da56ebd24 235 #function to store I2C list
theotherjimmy 43:2a7da56ebd24 236 def store_i2c (pin, name, signal):
theotherjimmy 43:2a7da56ebd24 237 #is it SDA or SCL ?
theotherjimmy 43:2a7da56ebd24 238 if "_SCL" in signal:
theotherjimmy 43:2a7da56ebd24 239 i2cscl_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 240 if "_SDA" in signal:
theotherjimmy 43:2a7da56ebd24 241 i2csda_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 242
theotherjimmy 43:2a7da56ebd24 243 #function to store timers
theotherjimmy 43:2a7da56ebd24 244 def store_pwm(pin, name, signal):
theotherjimmy 43:2a7da56ebd24 245 if "_CH" in signal:
theotherjimmy 43:2a7da56ebd24 246 pwm_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 247
theotherjimmy 43:2a7da56ebd24 248 #function to store Uart pins
theotherjimmy 43:2a7da56ebd24 249 def store_uart(pin, name, signal):
theotherjimmy 43:2a7da56ebd24 250 if "_TX" in signal:
theotherjimmy 43:2a7da56ebd24 251 uarttx_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 252 if "_RX" in signal:
theotherjimmy 43:2a7da56ebd24 253 uartrx_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 254 if "_CTS" in signal:
theotherjimmy 43:2a7da56ebd24 255 uartcts_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 256 if "_RTS" in signal:
theotherjimmy 43:2a7da56ebd24 257 uartrts_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 258
theotherjimmy 43:2a7da56ebd24 259 #function to store SPI pins
theotherjimmy 43:2a7da56ebd24 260 def store_spi(pin, name, signal):
theotherjimmy 43:2a7da56ebd24 261 if "_MISO" in signal:
theotherjimmy 43:2a7da56ebd24 262 spimiso_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 263 if "_MOSI" in signal:
theotherjimmy 43:2a7da56ebd24 264 spimosi_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 265 if "_SCK" in signal:
theotherjimmy 43:2a7da56ebd24 266 spisclk_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 267 if "_NSS" in signal:
theotherjimmy 43:2a7da56ebd24 268 spissel_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 269
theotherjimmy 43:2a7da56ebd24 270 #function to store CAN pins
theotherjimmy 43:2a7da56ebd24 271 def store_can(pin, name, signal):
theotherjimmy 43:2a7da56ebd24 272 if "_RX" in signal:
theotherjimmy 43:2a7da56ebd24 273 canrd_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 274 if "_TX" in signal:
theotherjimmy 43:2a7da56ebd24 275 cantd_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 276
theotherjimmy 43:2a7da56ebd24 277 #function to store ETH list
theotherjimmy 43:2a7da56ebd24 278 def store_eth (pin, name, signal):
theotherjimmy 43:2a7da56ebd24 279 eth_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 280
theotherjimmy 43:2a7da56ebd24 281 #function to store QSPI pins
theotherjimmy 43:2a7da56ebd24 282 def store_qspi (pin, name, signal):
theotherjimmy 43:2a7da56ebd24 283 if "_BK" in signal:
theotherjimmy 43:2a7da56ebd24 284 quadspidata_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 285 if "_CLK" in signal:
theotherjimmy 43:2a7da56ebd24 286 quadspisclk_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 287 if "_NCS" in signal:
theotherjimmy 43:2a7da56ebd24 288 quadspissel_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 289
theotherjimmy 43:2a7da56ebd24 290 #function to store USB pins
theotherjimmy 43:2a7da56ebd24 291 def store_usb (pin, name, signal):
theotherjimmy 43:2a7da56ebd24 292 usb_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 293
theotherjimmy 43:2a7da56ebd24 294 #function to store OSC pins
theotherjimmy 43:2a7da56ebd24 295 def store_osc (pin, name, signal):
theotherjimmy 43:2a7da56ebd24 296 osc_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 297
theotherjimmy 43:2a7da56ebd24 298 #function to store SYS pins
theotherjimmy 43:2a7da56ebd24 299 def store_sys (pin, name, signal):
theotherjimmy 43:2a7da56ebd24 300 sys_list.append([pin,name,signal])
theotherjimmy 43:2a7da56ebd24 301
theotherjimmy 43:2a7da56ebd24 302 def print_header():
theotherjimmy 43:2a7da56ebd24 303 s = ("""/* mbed Microcontroller Library
theotherjimmy 43:2a7da56ebd24 304 *******************************************************************************
theotherjimmy 43:2a7da56ebd24 305 * Copyright (c) %i, STMicroelectronics
theotherjimmy 43:2a7da56ebd24 306 * All rights reserved.
theotherjimmy 43:2a7da56ebd24 307 *
theotherjimmy 43:2a7da56ebd24 308 * Redistribution and use in source and binary forms, with or without
theotherjimmy 43:2a7da56ebd24 309 * modification, are permitted provided that the following conditions are met:
theotherjimmy 43:2a7da56ebd24 310 *
theotherjimmy 43:2a7da56ebd24 311 * 1. Redistributions of source code must retain the above copyright notice,
theotherjimmy 43:2a7da56ebd24 312 * this list of conditions and the following disclaimer.
theotherjimmy 43:2a7da56ebd24 313 * 2. Redistributions in binary form must reproduce the above copyright notice,
theotherjimmy 43:2a7da56ebd24 314 * this list of conditions and the following disclaimer in the documentation
theotherjimmy 43:2a7da56ebd24 315 * and/or other materials provided with the distribution.
theotherjimmy 43:2a7da56ebd24 316 * 3. Neither the name of STMicroelectronics nor the names of its contributors
theotherjimmy 43:2a7da56ebd24 317 * may be used to endorse or promote products derived from this software
theotherjimmy 43:2a7da56ebd24 318 * without specific prior written permission.
theotherjimmy 43:2a7da56ebd24 319 *
theotherjimmy 43:2a7da56ebd24 320 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
theotherjimmy 43:2a7da56ebd24 321 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
theotherjimmy 43:2a7da56ebd24 322 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
theotherjimmy 43:2a7da56ebd24 323 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
theotherjimmy 43:2a7da56ebd24 324 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
theotherjimmy 43:2a7da56ebd24 325 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
theotherjimmy 43:2a7da56ebd24 326 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
theotherjimmy 43:2a7da56ebd24 327 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
theotherjimmy 43:2a7da56ebd24 328 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
theotherjimmy 43:2a7da56ebd24 329 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
theotherjimmy 43:2a7da56ebd24 330 *******************************************************************************
theotherjimmy 43:2a7da56ebd24 331 *
theotherjimmy 43:2a7da56ebd24 332 * Automatically generated from %s
theotherjimmy 43:2a7da56ebd24 333 */
theotherjimmy 43:2a7da56ebd24 334
theotherjimmy 43:2a7da56ebd24 335 #include "PeripheralPins.h"
theotherjimmy 43:2a7da56ebd24 336 #include "mbed_toolchain.h"
theotherjimmy 43:2a7da56ebd24 337
theotherjimmy 43:2a7da56ebd24 338 //==============================================================================
theotherjimmy 43:2a7da56ebd24 339 // Notes
theotherjimmy 43:2a7da56ebd24 340 //
theotherjimmy 43:2a7da56ebd24 341 // - The pins mentioned Px_y_ALTz are alternative possibilities which use other
theotherjimmy 43:2a7da56ebd24 342 // HW peripheral instances. You can use them the same way as any other "normal"
theotherjimmy 43:2a7da56ebd24 343 // pin (i.e. PwmOut pwm(PA_7_ALT0);). These pins are not displayed on the board
theotherjimmy 43:2a7da56ebd24 344 // pinout image on mbed.org.
theotherjimmy 43:2a7da56ebd24 345 //
theotherjimmy 43:2a7da56ebd24 346 // - The pins which are connected to other components present on the board have
theotherjimmy 43:2a7da56ebd24 347 // the comment "Connected to xxx". The pin function may not work properly in this
theotherjimmy 43:2a7da56ebd24 348 // case. These pins may not be displayed on the board pinout image on mbed.org.
theotherjimmy 43:2a7da56ebd24 349 // Please read the board reference manual and schematic for more information.
theotherjimmy 43:2a7da56ebd24 350 //
theotherjimmy 43:2a7da56ebd24 351 // - Warning: pins connected to the default STDIO_UART_TX and STDIO_UART_RX pins are commented
theotherjimmy 43:2a7da56ebd24 352 // See https://os.mbed.com/teams/ST/wiki/STDIO for more information.
theotherjimmy 43:2a7da56ebd24 353 //
theotherjimmy 43:2a7da56ebd24 354 //==============================================================================
theotherjimmy 43:2a7da56ebd24 355
theotherjimmy 43:2a7da56ebd24 356 """ % (datetime.datetime.now().year, os.path.basename(input_file_name)))
theotherjimmy 43:2a7da56ebd24 357 out_c_file.write( s )
theotherjimmy 43:2a7da56ebd24 358
theotherjimmy 43:2a7da56ebd24 359 s = ("""/* mbed Microcontroller Library
theotherjimmy 43:2a7da56ebd24 360 *******************************************************************************
theotherjimmy 43:2a7da56ebd24 361 * Copyright (c) %i, STMicroelectronics
theotherjimmy 43:2a7da56ebd24 362 * All rights reserved.
theotherjimmy 43:2a7da56ebd24 363 *
theotherjimmy 43:2a7da56ebd24 364 * Redistribution and use in source and binary forms, with or without
theotherjimmy 43:2a7da56ebd24 365 * modification, are permitted provided that the following conditions are met:
theotherjimmy 43:2a7da56ebd24 366 *
theotherjimmy 43:2a7da56ebd24 367 * 1. Redistributions of source code must retain the above copyright notice,
theotherjimmy 43:2a7da56ebd24 368 * this list of conditions and the following disclaimer.
theotherjimmy 43:2a7da56ebd24 369 * 2. Redistributions in binary form must reproduce the above copyright notice,
theotherjimmy 43:2a7da56ebd24 370 * this list of conditions and the following disclaimer in the documentation
theotherjimmy 43:2a7da56ebd24 371 * and/or other materials provided with the distribution.
theotherjimmy 43:2a7da56ebd24 372 * 3. Neither the name of STMicroelectronics nor the names of its contributors
theotherjimmy 43:2a7da56ebd24 373 * may be used to endorse or promote products derived from this software
theotherjimmy 43:2a7da56ebd24 374 * without specific prior written permission.
theotherjimmy 43:2a7da56ebd24 375 *
theotherjimmy 43:2a7da56ebd24 376 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
theotherjimmy 43:2a7da56ebd24 377 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
theotherjimmy 43:2a7da56ebd24 378 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
theotherjimmy 43:2a7da56ebd24 379 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
theotherjimmy 43:2a7da56ebd24 380 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
theotherjimmy 43:2a7da56ebd24 381 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
theotherjimmy 43:2a7da56ebd24 382 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
theotherjimmy 43:2a7da56ebd24 383 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
theotherjimmy 43:2a7da56ebd24 384 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
theotherjimmy 43:2a7da56ebd24 385 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
theotherjimmy 43:2a7da56ebd24 386 *******************************************************************************
theotherjimmy 43:2a7da56ebd24 387 *
theotherjimmy 43:2a7da56ebd24 388 * Automatically generated from %s
theotherjimmy 43:2a7da56ebd24 389 */
theotherjimmy 43:2a7da56ebd24 390
theotherjimmy 43:2a7da56ebd24 391 #ifndef MBED_PINNAMES_H
theotherjimmy 43:2a7da56ebd24 392 #define MBED_PINNAMES_H
theotherjimmy 43:2a7da56ebd24 393
theotherjimmy 43:2a7da56ebd24 394 #include "cmsis.h"
theotherjimmy 43:2a7da56ebd24 395 #include "PinNamesTypes.h"
theotherjimmy 43:2a7da56ebd24 396
theotherjimmy 43:2a7da56ebd24 397 #ifdef __cplusplus
theotherjimmy 43:2a7da56ebd24 398 extern "C" {
theotherjimmy 43:2a7da56ebd24 399 #endif
theotherjimmy 43:2a7da56ebd24 400
theotherjimmy 43:2a7da56ebd24 401 typedef enum {
theotherjimmy 43:2a7da56ebd24 402 ALT0 = 0x100,
theotherjimmy 43:2a7da56ebd24 403 ALT1 = 0x200,
theotherjimmy 43:2a7da56ebd24 404 ALT2 = 0x300,
theotherjimmy 43:2a7da56ebd24 405 ALT3 = 0x400
theotherjimmy 43:2a7da56ebd24 406 } ALTx;
theotherjimmy 43:2a7da56ebd24 407
theotherjimmy 43:2a7da56ebd24 408 typedef enum {
theotherjimmy 43:2a7da56ebd24 409
theotherjimmy 43:2a7da56ebd24 410 """ % (datetime.datetime.now().year, os.path.basename(input_file_name)))
theotherjimmy 43:2a7da56ebd24 411 out_h_file.write( s )
theotherjimmy 43:2a7da56ebd24 412
theotherjimmy 43:2a7da56ebd24 413
theotherjimmy 43:2a7da56ebd24 414 def print_footer():
theotherjimmy 43:2a7da56ebd24 415 s = ("""
theotherjimmy 43:2a7da56ebd24 416 // Not connected
theotherjimmy 43:2a7da56ebd24 417 NC = (int)0xFFFFFFFF
theotherjimmy 43:2a7da56ebd24 418 } PinName;
theotherjimmy 43:2a7da56ebd24 419
theotherjimmy 43:2a7da56ebd24 420 #ifdef __cplusplus
theotherjimmy 43:2a7da56ebd24 421 }
theotherjimmy 43:2a7da56ebd24 422 #endif
theotherjimmy 43:2a7da56ebd24 423
theotherjimmy 43:2a7da56ebd24 424 #endif
theotherjimmy 43:2a7da56ebd24 425 """)
theotherjimmy 43:2a7da56ebd24 426 out_h_file.write(s)
theotherjimmy 43:2a7da56ebd24 427
theotherjimmy 43:2a7da56ebd24 428
theotherjimmy 43:2a7da56ebd24 429 def print_all_lists():
theotherjimmy 43:2a7da56ebd24 430 if print_list_header("ADC", "ADC", adclist, "ANALOGIN"):
theotherjimmy 43:2a7da56ebd24 431 print_adc()
theotherjimmy 43:2a7da56ebd24 432 if print_list_header("DAC", "DAC", daclist, "ANALOGOUT"):
theotherjimmy 43:2a7da56ebd24 433 print_dac()
theotherjimmy 43:2a7da56ebd24 434 if print_list_header("I2C", "I2C_SDA", i2csda_list, "I2C"):
theotherjimmy 43:2a7da56ebd24 435 print_i2c(i2csda_list)
theotherjimmy 43:2a7da56ebd24 436 if print_list_header("", "I2C_SCL", i2cscl_list, "I2C"):
theotherjimmy 43:2a7da56ebd24 437 print_i2c(i2cscl_list)
theotherjimmy 43:2a7da56ebd24 438 if print_list_header("PWM", "PWM", pwm_list, "PWMOUT"):
theotherjimmy 43:2a7da56ebd24 439 print_pwm()
theotherjimmy 43:2a7da56ebd24 440 if print_list_header("SERIAL", "UART_TX", uarttx_list, "SERIAL"):
theotherjimmy 43:2a7da56ebd24 441 print_uart(uarttx_list)
theotherjimmy 43:2a7da56ebd24 442 if print_list_header("", "UART_RX", uartrx_list, "SERIAL"):
theotherjimmy 43:2a7da56ebd24 443 print_uart(uartrx_list)
theotherjimmy 43:2a7da56ebd24 444 if print_list_header("", "UART_RTS", uartrts_list, "SERIAL"):
theotherjimmy 43:2a7da56ebd24 445 print_uart(uartrts_list)
theotherjimmy 43:2a7da56ebd24 446 if print_list_header("", "UART_CTS", uartcts_list, "SERIAL"):
theotherjimmy 43:2a7da56ebd24 447 print_uart(uartcts_list)
theotherjimmy 43:2a7da56ebd24 448 if print_list_header("SPI", "SPI_MOSI", spimosi_list, "SPI"):
theotherjimmy 43:2a7da56ebd24 449 print_spi(spimosi_list)
theotherjimmy 43:2a7da56ebd24 450 if print_list_header("", "SPI_MISO", spimiso_list, "SPI"):
theotherjimmy 43:2a7da56ebd24 451 print_spi(spimiso_list)
theotherjimmy 43:2a7da56ebd24 452 if print_list_header("", "SPI_SCLK", spisclk_list, "SPI"):
theotherjimmy 43:2a7da56ebd24 453 print_spi(spisclk_list)
theotherjimmy 43:2a7da56ebd24 454 if print_list_header("", "SPI_SSEL", spissel_list, "SPI"):
theotherjimmy 43:2a7da56ebd24 455 print_spi(spissel_list)
theotherjimmy 43:2a7da56ebd24 456 if print_list_header("CAN", "CAN_RD", canrd_list, "CAN"):
theotherjimmy 43:2a7da56ebd24 457 print_can(canrd_list)
theotherjimmy 43:2a7da56ebd24 458 if print_list_header("", "CAN_TD", cantd_list, "CAN"):
theotherjimmy 43:2a7da56ebd24 459 print_can(cantd_list)
theotherjimmy 43:2a7da56ebd24 460 if ADD_QSPI_FEATURE:
theotherjimmy 43:2a7da56ebd24 461 if print_list_header("QUADSPI", "QSPI_DATA", quadspidata_list, "QSPI"):
theotherjimmy 43:2a7da56ebd24 462 print_qspi(quadspidata_list)
theotherjimmy 43:2a7da56ebd24 463 if print_list_header("", "QSPI_SCLK", quadspisclk_list, "QSPI"):
theotherjimmy 43:2a7da56ebd24 464 print_qspi(quadspisclk_list)
theotherjimmy 43:2a7da56ebd24 465 if print_list_header("", "QSPI_SSEL", quadspissel_list, "QSPI"):
theotherjimmy 43:2a7da56ebd24 466 print_qspi(quadspissel_list)
theotherjimmy 43:2a7da56ebd24 467 print_h_file(usb_list, "USB")
theotherjimmy 43:2a7da56ebd24 468 print_h_file(eth_list, "ETHERNET")
theotherjimmy 43:2a7da56ebd24 469 print_h_file(osc_list, "OSCILLATOR")
theotherjimmy 43:2a7da56ebd24 470 print_h_file(sys_list, "DEBUG")
theotherjimmy 43:2a7da56ebd24 471
theotherjimmy 43:2a7da56ebd24 472 def print_list_header(comment, name, l, switch):
theotherjimmy 43:2a7da56ebd24 473 s = ""
theotherjimmy 43:2a7da56ebd24 474 if len(l)>0:
theotherjimmy 43:2a7da56ebd24 475 if comment:
theotherjimmy 43:2a7da56ebd24 476 s += "\n//*** %s ***\n" % comment
theotherjimmy 43:2a7da56ebd24 477
theotherjimmy 43:2a7da56ebd24 478 s += "\n"
theotherjimmy 43:2a7da56ebd24 479
theotherjimmy 43:2a7da56ebd24 480 if name == "PWM":
theotherjimmy 43:2a7da56ebd24 481 if TargetName in TIM_MST_LIST.keys():
theotherjimmy 43:2a7da56ebd24 482 s += "// %s cannot be used because already used by the us_ticker\n" % TIM_MST_LIST[TargetName]
theotherjimmy 43:2a7da56ebd24 483 else:
theotherjimmy 43:2a7da56ebd24 484 s += "// TIM<x> cannot be used because already used by the us_ticker\n"
theotherjimmy 43:2a7da56ebd24 485 s += "// You have to comment all PWM using TIM_MST defined in hal_tick.h file\n"
theotherjimmy 43:2a7da56ebd24 486 s += "// or update python script (check TIM_MST_LIST) and re-run it\n"
theotherjimmy 43:2a7da56ebd24 487
theotherjimmy 43:2a7da56ebd24 488 if ADD_DEVICE_IFDEF:
theotherjimmy 43:2a7da56ebd24 489 s += "#ifdef DEVICE_%s\n" % switch
theotherjimmy 43:2a7da56ebd24 490
theotherjimmy 43:2a7da56ebd24 491 s += "MBED_WEAK const PinMap PinMap_%s[] = {\n" % name
theotherjimmy 43:2a7da56ebd24 492
theotherjimmy 43:2a7da56ebd24 493 # else:
theotherjimmy 43:2a7da56ebd24 494 # if comment:
theotherjimmy 43:2a7da56ebd24 495 # s += "\n//*** No %s ***\n" % comment
theotherjimmy 43:2a7da56ebd24 496
theotherjimmy 43:2a7da56ebd24 497 out_c_file.write(s)
theotherjimmy 43:2a7da56ebd24 498 return len(l)
theotherjimmy 43:2a7da56ebd24 499
theotherjimmy 43:2a7da56ebd24 500 def print_adc():
theotherjimmy 43:2a7da56ebd24 501 s_pin_data = 'STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, '
theotherjimmy 43:2a7da56ebd24 502 prev_p = ''
theotherjimmy 43:2a7da56ebd24 503 alt_index = 0
theotherjimmy 43:2a7da56ebd24 504 for p in adclist:
theotherjimmy 43:2a7da56ebd24 505 if "IN" in p[2]:
theotherjimmy 43:2a7da56ebd24 506 CommentedLine = " "
theotherjimmy 43:2a7da56ebd24 507 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 508 if "STDIO_UART" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 509 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 510 if "RCC_OSC" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 511 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 512 if CommentedLine != "//":
theotherjimmy 43:2a7da56ebd24 513 if p[0] == prev_p:
theotherjimmy 43:2a7da56ebd24 514 prev_p = p[0]
theotherjimmy 43:2a7da56ebd24 515 p[0] += '_ALT%d' % alt_index
theotherjimmy 43:2a7da56ebd24 516 alt_index += 1
theotherjimmy 43:2a7da56ebd24 517 else:
theotherjimmy 43:2a7da56ebd24 518 prev_p = p[0]
theotherjimmy 43:2a7da56ebd24 519 alt_index = 0
theotherjimmy 43:2a7da56ebd24 520 s1 = "%-17s" % (CommentedLine + " {" + p[0] + ',')
theotherjimmy 43:2a7da56ebd24 521 a = p[2].split('_')
theotherjimmy 43:2a7da56ebd24 522 inst = a[0].replace("ADC", "")
theotherjimmy 43:2a7da56ebd24 523 if len(inst) == 0:
theotherjimmy 43:2a7da56ebd24 524 inst = '1' #single ADC for this product
theotherjimmy 43:2a7da56ebd24 525 s1 += "%-7s" % ('ADC_' + inst + ',')
theotherjimmy 43:2a7da56ebd24 526 chan = re.sub('IN[N|P]?', '', a[1])
theotherjimmy 43:2a7da56ebd24 527 s1 += s_pin_data + chan
theotherjimmy 43:2a7da56ebd24 528 s1 += ', 0)}, // ' + p[2]
theotherjimmy 43:2a7da56ebd24 529 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 530 s1 += ' // Connected to ' + PinLabel[p[1]]
theotherjimmy 43:2a7da56ebd24 531 s1 += '\n'
theotherjimmy 43:2a7da56ebd24 532 out_c_file.write(s1)
theotherjimmy 43:2a7da56ebd24 533 out_c_file.write( """ {NC, NC, 0}
theotherjimmy 43:2a7da56ebd24 534 };
theotherjimmy 43:2a7da56ebd24 535
theotherjimmy 43:2a7da56ebd24 536 // !!! SECTION TO BE CHECKED WITH DEVICE REFERENCE MANUAL
theotherjimmy 43:2a7da56ebd24 537 MBED_WEAK const PinMap PinMap_ADC_Internal[] = {
theotherjimmy 43:2a7da56ebd24 538 {ADC_TEMP, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)},
theotherjimmy 43:2a7da56ebd24 539 {ADC_VREF, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 17, 0)},
theotherjimmy 43:2a7da56ebd24 540 {ADC_VBAT, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 18, 0)},
theotherjimmy 43:2a7da56ebd24 541 {NC, NC, 0}
theotherjimmy 43:2a7da56ebd24 542 };
theotherjimmy 43:2a7da56ebd24 543 """)
theotherjimmy 43:2a7da56ebd24 544 if ADD_DEVICE_IFDEF:
theotherjimmy 43:2a7da56ebd24 545 out_c_file.write( "#endif\n" )
theotherjimmy 43:2a7da56ebd24 546
theotherjimmy 43:2a7da56ebd24 547 def print_dac():
theotherjimmy 43:2a7da56ebd24 548 for p in daclist:
theotherjimmy 43:2a7da56ebd24 549 CommentedLine = " "
theotherjimmy 43:2a7da56ebd24 550 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 551 if "STDIO_UART" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 552 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 553 if "RCC_OSC" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 554 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 555 s1 = "%-17s" % (CommentedLine + " {" + p[0] + ',')
theotherjimmy 43:2a7da56ebd24 556 #p[2] : DAC_OUT1 / DAC1_OUT1
theotherjimmy 43:2a7da56ebd24 557 a = p[2].split('_')
theotherjimmy 43:2a7da56ebd24 558 inst = a[0].replace("DAC", "")
theotherjimmy 43:2a7da56ebd24 559 b = a[1].replace("OUT", "")
theotherjimmy 43:2a7da56ebd24 560 if len(inst) == 0:
theotherjimmy 43:2a7da56ebd24 561 inst = '1' # single DAC for this product
theotherjimmy 43:2a7da56ebd24 562 s1 += "%-7s" % ('DAC_' + inst + ',')
theotherjimmy 43:2a7da56ebd24 563 s1 += 'STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, ' + b + ', 0)}, // ' + p[2]
theotherjimmy 43:2a7da56ebd24 564 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 565 s1 += ' // Connected to ' + PinLabel[p[1]]
theotherjimmy 43:2a7da56ebd24 566 s1 += '\n'
theotherjimmy 43:2a7da56ebd24 567 out_c_file.write(s1)
theotherjimmy 43:2a7da56ebd24 568 out_c_file.write( """ {NC, NC, 0}
theotherjimmy 43:2a7da56ebd24 569 };
theotherjimmy 43:2a7da56ebd24 570 """)
theotherjimmy 43:2a7da56ebd24 571 if ADD_DEVICE_IFDEF:
theotherjimmy 43:2a7da56ebd24 572 out_c_file.write( "#endif\n" )
theotherjimmy 43:2a7da56ebd24 573
theotherjimmy 43:2a7da56ebd24 574 def print_i2c(l):
theotherjimmy 43:2a7da56ebd24 575 prev_p = ''
theotherjimmy 43:2a7da56ebd24 576 alt_index = 0
theotherjimmy 43:2a7da56ebd24 577 for p in l:
theotherjimmy 43:2a7da56ebd24 578 result = get_gpio_af_num(p[1], p[2])
theotherjimmy 43:2a7da56ebd24 579 if result != 'NOTFOUND':
theotherjimmy 43:2a7da56ebd24 580 CommentedLine = " "
theotherjimmy 43:2a7da56ebd24 581 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 582 if "STDIO_UART" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 583 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 584 if "RCC_OSC" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 585 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 586 if CommentedLine != "//":
theotherjimmy 43:2a7da56ebd24 587 if p[0] == prev_p:
theotherjimmy 43:2a7da56ebd24 588 prev_p = p[0]
theotherjimmy 43:2a7da56ebd24 589 p[0] += '_ALT%d' % alt_index
theotherjimmy 43:2a7da56ebd24 590 alt_index += 1
theotherjimmy 43:2a7da56ebd24 591 else:
theotherjimmy 43:2a7da56ebd24 592 prev_p = p[0]
theotherjimmy 43:2a7da56ebd24 593 alt_index = 0
theotherjimmy 43:2a7da56ebd24 594 s1 = "%-17s" % (CommentedLine + " {" + p[0] + ',')
theotherjimmy 43:2a7da56ebd24 595 # p[2] : I2C1_SDA / FMPI2C1_SDA
theotherjimmy 43:2a7da56ebd24 596 if "FMP" in p[2]:
theotherjimmy 43:2a7da56ebd24 597 inst = p[2].split('_')[0].replace("FMPI2C", "")
theotherjimmy 43:2a7da56ebd24 598 s1 += "%-10s" % ('FMPI2C_' + inst + ',')
theotherjimmy 43:2a7da56ebd24 599 else:
theotherjimmy 43:2a7da56ebd24 600 inst = p[2].split('_')[0].replace("I2C", "")
theotherjimmy 43:2a7da56ebd24 601 s1 += "%-7s" % ('I2C_' + inst + ',')
theotherjimmy 43:2a7da56ebd24 602 s1 += 'STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, '
theotherjimmy 43:2a7da56ebd24 603 r = result.split(' ')
theotherjimmy 43:2a7da56ebd24 604 for af in r:
theotherjimmy 43:2a7da56ebd24 605 s2 = s1 + af + ')},'
theotherjimmy 43:2a7da56ebd24 606 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 607 s2 += ' // Connected to ' + PinLabel[p[1]]
theotherjimmy 43:2a7da56ebd24 608 s2 += '\n'
theotherjimmy 43:2a7da56ebd24 609 out_c_file.write(s2)
theotherjimmy 43:2a7da56ebd24 610 out_c_file.write( """ {NC, NC, 0}
theotherjimmy 43:2a7da56ebd24 611 };
theotherjimmy 43:2a7da56ebd24 612 """)
theotherjimmy 43:2a7da56ebd24 613 if ADD_DEVICE_IFDEF:
theotherjimmy 43:2a7da56ebd24 614 out_c_file.write( "#endif\n" )
theotherjimmy 43:2a7da56ebd24 615
theotherjimmy 43:2a7da56ebd24 616 def print_pwm():
theotherjimmy 43:2a7da56ebd24 617 prev_p = ''
theotherjimmy 43:2a7da56ebd24 618 alt_index = 0
theotherjimmy 43:2a7da56ebd24 619 TIM_MST = "NOT_KNOWN"
theotherjimmy 43:2a7da56ebd24 620 if TargetName in TIM_MST_LIST.keys():
theotherjimmy 43:2a7da56ebd24 621 TIM_MST = TIM_MST_LIST[TargetName]
theotherjimmy 43:2a7da56ebd24 622 for p in pwm_list:
theotherjimmy 43:2a7da56ebd24 623 result = get_gpio_af_num(p[1], p[2])
theotherjimmy 43:2a7da56ebd24 624 if result != 'NOTFOUND':
theotherjimmy 43:2a7da56ebd24 625 CommentedLine = " "
theotherjimmy 43:2a7da56ebd24 626 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 627 if "STDIO_UART" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 628 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 629 if "RCC_OSC" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 630 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 631 if "%s_" % TIM_MST in p[2]:
theotherjimmy 43:2a7da56ebd24 632 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 633 if CommentedLine != "//":
theotherjimmy 43:2a7da56ebd24 634 if p[0] == prev_p:
theotherjimmy 43:2a7da56ebd24 635 prev_p = p[0]
theotherjimmy 43:2a7da56ebd24 636 p[0] += '_ALT%d' % alt_index
theotherjimmy 43:2a7da56ebd24 637 alt_index += 1
theotherjimmy 43:2a7da56ebd24 638 else:
theotherjimmy 43:2a7da56ebd24 639 prev_p = p[0]
theotherjimmy 43:2a7da56ebd24 640 alt_index = 0
theotherjimmy 43:2a7da56ebd24 641 s1 = "%-17s" % (CommentedLine + " {" + p[0] + ',')
theotherjimmy 43:2a7da56ebd24 642 # p[2] : TIM2_CH1 / TIM15_CH1N
theotherjimmy 43:2a7da56ebd24 643 a = p[2].split('_')
theotherjimmy 43:2a7da56ebd24 644 inst = a[0].replace("TIM", "PWM_")
theotherjimmy 43:2a7da56ebd24 645 # if len(inst) == 3:
theotherjimmy 43:2a7da56ebd24 646 # inst += '1'
theotherjimmy 43:2a7da56ebd24 647 s1 += "%-8s" % (inst + ',')
theotherjimmy 43:2a7da56ebd24 648 chan = a[1].replace("CH", "")
theotherjimmy 43:2a7da56ebd24 649 if chan.endswith('N'):
theotherjimmy 43:2a7da56ebd24 650 neg = ', 1'
theotherjimmy 43:2a7da56ebd24 651 chan = chan.strip('N')
theotherjimmy 43:2a7da56ebd24 652 else:
theotherjimmy 43:2a7da56ebd24 653 neg = ', 0'
theotherjimmy 43:2a7da56ebd24 654 s1 += 'STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, '
theotherjimmy 43:2a7da56ebd24 655 r = result.split(' ')
theotherjimmy 43:2a7da56ebd24 656 for af in r:
theotherjimmy 43:2a7da56ebd24 657 s2 = s1 + af + ', ' + chan + neg + ')}, // ' + p[2]
theotherjimmy 43:2a7da56ebd24 658 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 659 s2 += ' // Connected to ' + PinLabel[p[1]]
theotherjimmy 43:2a7da56ebd24 660 s2 += '\n'
theotherjimmy 43:2a7da56ebd24 661 out_c_file.write(s2)
theotherjimmy 43:2a7da56ebd24 662 out_c_file.write( """ {NC, NC, 0}
theotherjimmy 43:2a7da56ebd24 663 };
theotherjimmy 43:2a7da56ebd24 664 """)
theotherjimmy 43:2a7da56ebd24 665 if ADD_DEVICE_IFDEF:
theotherjimmy 43:2a7da56ebd24 666 out_c_file.write( "#endif\n" )
theotherjimmy 43:2a7da56ebd24 667
theotherjimmy 43:2a7da56ebd24 668 def print_uart(l):
theotherjimmy 43:2a7da56ebd24 669 prev_p = ''
theotherjimmy 43:2a7da56ebd24 670 alt_index = 0
theotherjimmy 43:2a7da56ebd24 671 for p in l:
theotherjimmy 43:2a7da56ebd24 672 result = get_gpio_af_num(p[1], p[2])
theotherjimmy 43:2a7da56ebd24 673 if result != 'NOTFOUND':
theotherjimmy 43:2a7da56ebd24 674 CommentedLine = " "
theotherjimmy 43:2a7da56ebd24 675 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 676 if "RCC_OSC" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 677 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 678 if CommentedLine != "//":
theotherjimmy 43:2a7da56ebd24 679 if p[0] == prev_p:
theotherjimmy 43:2a7da56ebd24 680 prev_p = p[0]
theotherjimmy 43:2a7da56ebd24 681 p[0] += '_ALT%d' % alt_index
theotherjimmy 43:2a7da56ebd24 682 alt_index += 1
theotherjimmy 43:2a7da56ebd24 683 else:
theotherjimmy 43:2a7da56ebd24 684 prev_p = p[0]
theotherjimmy 43:2a7da56ebd24 685 alt_index = 0
theotherjimmy 43:2a7da56ebd24 686 s1 = "%-17s" % (CommentedLine + " {" + p[0] + ',')
theotherjimmy 43:2a7da56ebd24 687 # p[2] : USART2_RX
theotherjimmy 43:2a7da56ebd24 688 b=p[2].split('_')[0]
theotherjimmy 43:2a7da56ebd24 689 b = b.replace("UART", "UART_")
theotherjimmy 43:2a7da56ebd24 690 b = b.replace("USART", "UART_")
theotherjimmy 43:2a7da56ebd24 691 s1 += "%-9s" % (b[:len(b)-1] + b[len(b)-1:] + ',')
theotherjimmy 43:2a7da56ebd24 692 if 'STM32F10' in mcu_file and l == uartrx_list:
theotherjimmy 43:2a7da56ebd24 693 s1 += 'STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLUP, '
theotherjimmy 43:2a7da56ebd24 694 else:
theotherjimmy 43:2a7da56ebd24 695 s1 += 'STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, '
theotherjimmy 43:2a7da56ebd24 696 r = result.split(' ')
theotherjimmy 43:2a7da56ebd24 697 for af in r:
theotherjimmy 43:2a7da56ebd24 698 s2 = s1 + af + ')},'
theotherjimmy 43:2a7da56ebd24 699 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 700 s2 += ' // Connected to ' + PinLabel[p[1]]
theotherjimmy 43:2a7da56ebd24 701 s2 += '\n'
theotherjimmy 43:2a7da56ebd24 702 out_c_file.write(s2)
theotherjimmy 43:2a7da56ebd24 703 out_c_file.write( """ {NC, NC, 0}
theotherjimmy 43:2a7da56ebd24 704 };
theotherjimmy 43:2a7da56ebd24 705 """)
theotherjimmy 43:2a7da56ebd24 706 if ADD_DEVICE_IFDEF:
theotherjimmy 43:2a7da56ebd24 707 out_c_file.write( "#endif\n" )
theotherjimmy 43:2a7da56ebd24 708
theotherjimmy 43:2a7da56ebd24 709 def print_spi(l):
theotherjimmy 43:2a7da56ebd24 710 prev_p = ''
theotherjimmy 43:2a7da56ebd24 711 alt_index = 0
theotherjimmy 43:2a7da56ebd24 712 for p in l:
theotherjimmy 43:2a7da56ebd24 713 result = get_gpio_af_num(p[1], p[2])
theotherjimmy 43:2a7da56ebd24 714 if result != 'NOTFOUND':
theotherjimmy 43:2a7da56ebd24 715 CommentedLine = " "
theotherjimmy 43:2a7da56ebd24 716 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 717 if "STDIO_UART" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 718 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 719 if "RCC_OSC" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 720 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 721 if CommentedLine != "//":
theotherjimmy 43:2a7da56ebd24 722 if p[0] == prev_p:
theotherjimmy 43:2a7da56ebd24 723 prev_p = p[0]
theotherjimmy 43:2a7da56ebd24 724 p[0] += '_ALT%d' % alt_index
theotherjimmy 43:2a7da56ebd24 725 alt_index += 1
theotherjimmy 43:2a7da56ebd24 726 else:
theotherjimmy 43:2a7da56ebd24 727 prev_p = p[0]
theotherjimmy 43:2a7da56ebd24 728 alt_index = 0
theotherjimmy 43:2a7da56ebd24 729 s1 = "%-17s" % (CommentedLine + " {" + p[0] + ',')
theotherjimmy 43:2a7da56ebd24 730 # p[2] : SPI1_MISO
theotherjimmy 43:2a7da56ebd24 731 instance=p[2].split('_')[0].replace("SPI", "")
theotherjimmy 43:2a7da56ebd24 732 s1 += "%-7s" % ('SPI_' + instance + ',')
theotherjimmy 43:2a7da56ebd24 733 s1 += 'STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, '
theotherjimmy 43:2a7da56ebd24 734 r = result.split(' ')
theotherjimmy 43:2a7da56ebd24 735 for af in r:
theotherjimmy 43:2a7da56ebd24 736 s2 = s1 + af + ')},'
theotherjimmy 43:2a7da56ebd24 737 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 738 s2 += ' // Connected to ' + PinLabel[p[1]]
theotherjimmy 43:2a7da56ebd24 739 s2 += '\n'
theotherjimmy 43:2a7da56ebd24 740 out_c_file.write(s2)
theotherjimmy 43:2a7da56ebd24 741 out_c_file.write( """ {NC, NC, 0}
theotherjimmy 43:2a7da56ebd24 742 };
theotherjimmy 43:2a7da56ebd24 743 """)
theotherjimmy 43:2a7da56ebd24 744 if ADD_DEVICE_IFDEF:
theotherjimmy 43:2a7da56ebd24 745 out_c_file.write( "#endif\n" )
theotherjimmy 43:2a7da56ebd24 746
theotherjimmy 43:2a7da56ebd24 747 def print_can(l):
theotherjimmy 43:2a7da56ebd24 748 for p in l:
theotherjimmy 43:2a7da56ebd24 749 result = get_gpio_af_num(p[1], p[2])
theotherjimmy 43:2a7da56ebd24 750 if result != 'NOTFOUND':
theotherjimmy 43:2a7da56ebd24 751 CommentedLine = " "
theotherjimmy 43:2a7da56ebd24 752 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 753 if "STDIO_UART" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 754 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 755 if "RCC_OSC" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 756 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 757 s1 = "%-17s" % (CommentedLine + " {" + p[0] + ',')
theotherjimmy 43:2a7da56ebd24 758 # p[2] : CAN_RX / CAN1_RX
theotherjimmy 43:2a7da56ebd24 759 p[2] = p[2].replace("FD", "")
theotherjimmy 43:2a7da56ebd24 760 instance = p[2].split('_')[0].replace("CAN", "")
theotherjimmy 43:2a7da56ebd24 761 if len(instance) == 0:
theotherjimmy 43:2a7da56ebd24 762 instance = '1'
theotherjimmy 43:2a7da56ebd24 763 s1 += "%-7s" % ('CAN_' + instance + ',')
theotherjimmy 43:2a7da56ebd24 764 if 'STM32F10' in mcu_file and l == canrd_list:
theotherjimmy 43:2a7da56ebd24 765 s1 += 'STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, '
theotherjimmy 43:2a7da56ebd24 766 else:
theotherjimmy 43:2a7da56ebd24 767 s1 += 'STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, '
theotherjimmy 43:2a7da56ebd24 768 r = result.split(' ')
theotherjimmy 43:2a7da56ebd24 769 for af in r:
theotherjimmy 43:2a7da56ebd24 770 s2 = s1 + af + ')},'
theotherjimmy 43:2a7da56ebd24 771 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 772 s2 += ' // Connected to ' + PinLabel[p[1]]
theotherjimmy 43:2a7da56ebd24 773 s2 += '\n'
theotherjimmy 43:2a7da56ebd24 774 out_c_file.write(s2)
theotherjimmy 43:2a7da56ebd24 775 out_c_file.write( """ {NC, NC, 0}
theotherjimmy 43:2a7da56ebd24 776 };
theotherjimmy 43:2a7da56ebd24 777 """)
theotherjimmy 43:2a7da56ebd24 778 if ADD_DEVICE_IFDEF:
theotherjimmy 43:2a7da56ebd24 779 out_c_file.write( "#endif\n" )
theotherjimmy 43:2a7da56ebd24 780
theotherjimmy 43:2a7da56ebd24 781 def print_qspi(l):
theotherjimmy 43:2a7da56ebd24 782 for p in l:
theotherjimmy 43:2a7da56ebd24 783 result = get_gpio_af_num(p[1], p[2])
theotherjimmy 43:2a7da56ebd24 784 if result != 'NOTFOUND':
theotherjimmy 43:2a7da56ebd24 785 CommentedLine = " "
theotherjimmy 43:2a7da56ebd24 786 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 787 if "STDIO_UART" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 788 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 789 if "RCC_OSC" in PinLabel[p[1]]:
theotherjimmy 43:2a7da56ebd24 790 CommentedLine = "//"
theotherjimmy 43:2a7da56ebd24 791 s1 = "%-16s" % (CommentedLine + " {" + p[0] + ',')
theotherjimmy 43:2a7da56ebd24 792 # p[2] : QUADSPI_BK1_IO3 / QUADSPI_CLK / QUADSPI_NCS
theotherjimmy 43:2a7da56ebd24 793 s1 += "%-8s" % ('QSPI_1,')
theotherjimmy 43:2a7da56ebd24 794 result = result.replace("GPIO_AF10_OTG_FS", "GPIO_AF10_QSPI")
theotherjimmy 43:2a7da56ebd24 795 s1 += 'STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, ' + result +')},'
theotherjimmy 43:2a7da56ebd24 796 s1 += ' // ' + p[2]
theotherjimmy 43:2a7da56ebd24 797 if p[1] in PinLabel.keys():
theotherjimmy 43:2a7da56ebd24 798 s1 += ' // Connected to ' + PinLabel[p[1]]
theotherjimmy 43:2a7da56ebd24 799 s1 += '\n'
theotherjimmy 43:2a7da56ebd24 800 out_c_file.write(s1)
theotherjimmy 43:2a7da56ebd24 801 out_c_file.write( """ {NC, NC, 0}
theotherjimmy 43:2a7da56ebd24 802 };
theotherjimmy 43:2a7da56ebd24 803 """)
theotherjimmy 43:2a7da56ebd24 804 if ADD_DEVICE_IFDEF:
theotherjimmy 43:2a7da56ebd24 805 out_c_file.write( "#endif\n" )
theotherjimmy 43:2a7da56ebd24 806
theotherjimmy 43:2a7da56ebd24 807 def print_h_file(l, comment):
theotherjimmy 43:2a7da56ebd24 808 if len(l) > 0:
theotherjimmy 43:2a7da56ebd24 809 s = ("\n/**** %s pins ****/\n" % comment)
theotherjimmy 43:2a7da56ebd24 810 out_h_file.write(s)
theotherjimmy 43:2a7da56ebd24 811
theotherjimmy 43:2a7da56ebd24 812 prev_s = ''
theotherjimmy 43:2a7da56ebd24 813 alt_index = 0
theotherjimmy 43:2a7da56ebd24 814 for p in l:
theotherjimmy 43:2a7da56ebd24 815 if p[2] == prev_s:
theotherjimmy 43:2a7da56ebd24 816 prev_s = p[2]
theotherjimmy 43:2a7da56ebd24 817 p[2] += '_ALT%d' % alt_index
theotherjimmy 43:2a7da56ebd24 818 alt_index += 1
theotherjimmy 43:2a7da56ebd24 819 else:
theotherjimmy 43:2a7da56ebd24 820 prev_s = p[2]
theotherjimmy 43:2a7da56ebd24 821 alt_index = 0
theotherjimmy 43:2a7da56ebd24 822 s1 = " %s = %s,\n" % (p[2].replace("-", "_"), p[0])
theotherjimmy 43:2a7da56ebd24 823 out_h_file.write(s1)
theotherjimmy 43:2a7da56ebd24 824 # else:
theotherjimmy 43:2a7da56ebd24 825 # s = ("\n/**** No %s pins ***/\n" % comment)
theotherjimmy 43:2a7da56ebd24 826 # out_h_file.write(s)
theotherjimmy 43:2a7da56ebd24 827
theotherjimmy 43:2a7da56ebd24 828
theotherjimmy 43:2a7da56ebd24 829 tokenize = re.compile(r'(\d+)|(\D+)').findall
theotherjimmy 43:2a7da56ebd24 830
theotherjimmy 43:2a7da56ebd24 831 def natural_sortkey(list_2_elem):
theotherjimmy 43:2a7da56ebd24 832 return tuple(int(num) if num else alpha for num, alpha in tokenize(list_2_elem[0]))
theotherjimmy 43:2a7da56ebd24 833
theotherjimmy 43:2a7da56ebd24 834 def natural_sortkey2(list_2_elem):
theotherjimmy 43:2a7da56ebd24 835 return tuple(int(num) if num else alpha for num, alpha in tokenize(list_2_elem[2]))
theotherjimmy 43:2a7da56ebd24 836
theotherjimmy 43:2a7da56ebd24 837 def natural_sortkey_uart(list_2_elem):
theotherjimmy 43:2a7da56ebd24 838 return tuple(int(num) if num else alpha for num, alpha in tokenize(list_2_elem[2].replace("USART", "UART").replace("LPUART", "ZUART")))
theotherjimmy 43:2a7da56ebd24 839
theotherjimmy 43:2a7da56ebd24 840 def natural_sortkey_i2c(list_2_elem):
theotherjimmy 43:2a7da56ebd24 841 return tuple(int(num) if num else alpha for num, alpha in tokenize(list_2_elem[2].replace("FMPI2C", "ZFMPI2C")))
theotherjimmy 43:2a7da56ebd24 842
theotherjimmy 43:2a7da56ebd24 843 def sort_my_lists():
theotherjimmy 43:2a7da56ebd24 844 adclist.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 845 daclist.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 846 i2cscl_list.sort(key=natural_sortkey_i2c) # first sort on name column
theotherjimmy 43:2a7da56ebd24 847 i2csda_list.sort(key=natural_sortkey_i2c) # first sort on name column
theotherjimmy 43:2a7da56ebd24 848 i2cscl_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 849 i2csda_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 850 pwm_list.sort(key=natural_sortkey2) # first sort on name column
theotherjimmy 43:2a7da56ebd24 851 pwm_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 852 uarttx_list.sort(key=natural_sortkey_uart) # first sort on name column
theotherjimmy 43:2a7da56ebd24 853 uartrx_list.sort(key=natural_sortkey_uart) # first sort on name column
theotherjimmy 43:2a7da56ebd24 854 uartcts_list.sort(key=natural_sortkey_uart) # first sort on name column
theotherjimmy 43:2a7da56ebd24 855 uartrts_list.sort(key=natural_sortkey_uart) # first sort on name column
theotherjimmy 43:2a7da56ebd24 856 uarttx_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 857 uartrx_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 858 uartcts_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 859 uartrts_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 860 spimosi_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 861 spimiso_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 862 spissel_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 863 spisclk_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 864 cantd_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 865 canrd_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 866 eth_list.sort(key=natural_sortkey2)
theotherjimmy 43:2a7da56ebd24 867 quadspidata_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 868 quadspisclk_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 869 quadspissel_list.sort(key=natural_sortkey)
theotherjimmy 43:2a7da56ebd24 870 usb_list.sort(key=natural_sortkey2)
theotherjimmy 43:2a7da56ebd24 871 osc_list.sort(key=natural_sortkey2)
theotherjimmy 43:2a7da56ebd24 872 sys_list.sort(key=natural_sortkey2)
theotherjimmy 43:2a7da56ebd24 873
theotherjimmy 43:2a7da56ebd24 874 def clean_all_lists():
theotherjimmy 43:2a7da56ebd24 875 del io_list[:]
theotherjimmy 43:2a7da56ebd24 876 del adclist[:]
theotherjimmy 43:2a7da56ebd24 877 del daclist[:]
theotherjimmy 43:2a7da56ebd24 878 del i2cscl_list[:]
theotherjimmy 43:2a7da56ebd24 879 del i2csda_list[:]
theotherjimmy 43:2a7da56ebd24 880 del pwm_list[:]
theotherjimmy 43:2a7da56ebd24 881 del uarttx_list[:]
theotherjimmy 43:2a7da56ebd24 882 del uartrx_list[:]
theotherjimmy 43:2a7da56ebd24 883 del uartcts_list[:]
theotherjimmy 43:2a7da56ebd24 884 del uartrts_list[:]
theotherjimmy 43:2a7da56ebd24 885 del spimosi_list[:]
theotherjimmy 43:2a7da56ebd24 886 del spimiso_list[:]
theotherjimmy 43:2a7da56ebd24 887 del spissel_list[:]
theotherjimmy 43:2a7da56ebd24 888 del spisclk_list[:]
theotherjimmy 43:2a7da56ebd24 889 del cantd_list[:]
theotherjimmy 43:2a7da56ebd24 890 del canrd_list[:]
theotherjimmy 43:2a7da56ebd24 891 del eth_list[:]
theotherjimmy 43:2a7da56ebd24 892 del quadspidata_list[:]
theotherjimmy 43:2a7da56ebd24 893 del quadspisclk_list[:]
theotherjimmy 43:2a7da56ebd24 894 del quadspissel_list[:]
theotherjimmy 43:2a7da56ebd24 895 del usb_list[:]
theotherjimmy 43:2a7da56ebd24 896 del osc_list[:]
theotherjimmy 43:2a7da56ebd24 897 del sys_list[:]
theotherjimmy 43:2a7da56ebd24 898
theotherjimmy 43:2a7da56ebd24 899 def parse_pins():
theotherjimmy 43:2a7da56ebd24 900 # print (" * Getting pins per Ips...")
theotherjimmy 43:2a7da56ebd24 901 pinregex=r'^(P[A-Z][0-9][0-5]?)'
theotherjimmy 43:2a7da56ebd24 902 itemlist = xml_mcu.getElementsByTagName('Pin')
theotherjimmy 43:2a7da56ebd24 903 for s in itemlist:
theotherjimmy 43:2a7da56ebd24 904 m = re.match(pinregex, s.attributes['Name'].value)
theotherjimmy 43:2a7da56ebd24 905 if m:
theotherjimmy 43:2a7da56ebd24 906 pin = m.group(0)[:2] + '_' + m.group(0)[2:] # pin formatted P<port>_<number>: PF_O
theotherjimmy 43:2a7da56ebd24 907 name = s.attributes['Name'].value.strip() # full name: "PF0 / OSC_IN"
theotherjimmy 43:2a7da56ebd24 908 if s.attributes['Type'].value == "I/O":
theotherjimmy 43:2a7da56ebd24 909 store_pin(pin, name)
theotherjimmy 43:2a7da56ebd24 910 else:
theotherjimmy 43:2a7da56ebd24 911 continue
theotherjimmy 43:2a7da56ebd24 912 siglist = s.getElementsByTagName('Signal')
theotherjimmy 43:2a7da56ebd24 913 for a in siglist:
theotherjimmy 43:2a7da56ebd24 914 sig = a.attributes['Name'].value.strip()
theotherjimmy 43:2a7da56ebd24 915 if "ADC" in sig:
theotherjimmy 43:2a7da56ebd24 916 store_adc(pin, name, sig)
theotherjimmy 43:2a7da56ebd24 917 if all(["DAC" in sig, "_OUT" in sig]):
theotherjimmy 43:2a7da56ebd24 918 store_dac(pin, name, sig)
theotherjimmy 43:2a7da56ebd24 919 if "I2C" in sig:
theotherjimmy 43:2a7da56ebd24 920 store_i2c(pin, name, sig)
theotherjimmy 43:2a7da56ebd24 921 if re.match('^TIM', sig) is not None: #ignore HRTIM
theotherjimmy 43:2a7da56ebd24 922 store_pwm(pin, name, sig)
theotherjimmy 43:2a7da56ebd24 923 if re.match('^(LPU|US|U)ART', sig) is not None:
theotherjimmy 43:2a7da56ebd24 924 store_uart(pin, name, sig)
theotherjimmy 43:2a7da56ebd24 925 if "SPI" in sig:
theotherjimmy 43:2a7da56ebd24 926 store_spi(pin, name, sig)
theotherjimmy 43:2a7da56ebd24 927 if "CAN" in sig:
theotherjimmy 43:2a7da56ebd24 928 store_can(pin, name, sig)
theotherjimmy 43:2a7da56ebd24 929 if "ETH" in sig:
theotherjimmy 43:2a7da56ebd24 930 store_eth(pin, name, sig)
theotherjimmy 43:2a7da56ebd24 931 if "QUADSPI" in sig:
theotherjimmy 43:2a7da56ebd24 932 store_qspi(pin, name, sig)
theotherjimmy 43:2a7da56ebd24 933 if "USB" in sig:
theotherjimmy 43:2a7da56ebd24 934 store_usb(pin, name, sig)
theotherjimmy 43:2a7da56ebd24 935 if "RCC_OSC" in sig:
theotherjimmy 43:2a7da56ebd24 936 store_osc(pin, name, sig)
theotherjimmy 43:2a7da56ebd24 937 if "SYS_" in sig:
theotherjimmy 43:2a7da56ebd24 938 store_sys(pin, name, sig)
theotherjimmy 43:2a7da56ebd24 939
theotherjimmy 43:2a7da56ebd24 940 PinData = {}
theotherjimmy 43:2a7da56ebd24 941 PinLabel = {}
theotherjimmy 43:2a7da56ebd24 942
theotherjimmy 43:2a7da56ebd24 943 def parse_BoardFile(fileName):
theotherjimmy 43:2a7da56ebd24 944 print(" * Board file: '%s'" % (fileName))
theotherjimmy 43:2a7da56ebd24 945 board_file = open(board_file_name, "r")
theotherjimmy 43:2a7da56ebd24 946 # IOC_PIN_pattern = re.compile(r'(P[A-I][\d]*).*\.([\w]*)=(.*)')
theotherjimmy 43:2a7da56ebd24 947 IOC_PIN_pattern = re.compile(r'(.*)\.([\w]*)=(.*)')
theotherjimmy 43:2a7da56ebd24 948 for line in board_file.readlines():
theotherjimmy 43:2a7da56ebd24 949 IOC_PIN = re.match(IOC_PIN_pattern, line)
theotherjimmy 43:2a7da56ebd24 950 if IOC_PIN:
theotherjimmy 43:2a7da56ebd24 951 if IOC_PIN.groups()[0] in PinData.keys():
theotherjimmy 43:2a7da56ebd24 952 PinData[IOC_PIN.groups()[0]][IOC_PIN.groups()[1]] = IOC_PIN.groups()[2]
theotherjimmy 43:2a7da56ebd24 953 else:
theotherjimmy 43:2a7da56ebd24 954 PinData[IOC_PIN.groups()[0]] = {}
theotherjimmy 43:2a7da56ebd24 955 PinData[IOC_PIN.groups()[0]][IOC_PIN.groups()[1]] = IOC_PIN.groups()[2]
theotherjimmy 43:2a7da56ebd24 956 # IOC_MCU = re.match(r'Mcu\.UserName=(.*)', line)
theotherjimmy 43:2a7da56ebd24 957 IOC_MCU = re.match(r'Mcu\.Name=(.*)', line)
theotherjimmy 43:2a7da56ebd24 958 if IOC_MCU:
theotherjimmy 43:2a7da56ebd24 959 mcu_list.append("%s.xml" % IOC_MCU.groups()[0])
theotherjimmy 43:2a7da56ebd24 960
theotherjimmy 43:2a7da56ebd24 961 board_file.close()
theotherjimmy 43:2a7da56ebd24 962
theotherjimmy 43:2a7da56ebd24 963 for EachPin in PinData:
theotherjimmy 43:2a7da56ebd24 964 try:
theotherjimmy 43:2a7da56ebd24 965 PinLabel[EachPin] = PinData[EachPin]["Signal"]
theotherjimmy 43:2a7da56ebd24 966 except:
theotherjimmy 43:2a7da56ebd24 967 pass
theotherjimmy 43:2a7da56ebd24 968
theotherjimmy 43:2a7da56ebd24 969 try:
theotherjimmy 43:2a7da56ebd24 970 PinLabel[EachPin] = PinData[EachPin]["GPIO_Label"]
theotherjimmy 43:2a7da56ebd24 971
theotherjimmy 43:2a7da56ebd24 972 if "STLK_RX" in PinLabel[EachPin] or "STLK_TX" in PinLabel[EachPin]:
theotherjimmy 43:2a7da56ebd24 973 # Patch waiting for CubeMX correction
theotherjimmy 43:2a7da56ebd24 974 if "RX" in PinData[EachPin]["Signal"]:
theotherjimmy 43:2a7da56ebd24 975 PinLabel[EachPin] = "STDIO_UART_RX"
theotherjimmy 43:2a7da56ebd24 976 else:
theotherjimmy 43:2a7da56ebd24 977 PinLabel[EachPin] = "STDIO_UART_TX"
theotherjimmy 43:2a7da56ebd24 978 elif "USART_RX" in PinLabel[EachPin]:
theotherjimmy 43:2a7da56ebd24 979 PinLabel[EachPin] = "STDIO_UART_RX"
theotherjimmy 43:2a7da56ebd24 980 elif "USART_TX" in PinLabel[EachPin]:
theotherjimmy 43:2a7da56ebd24 981 PinLabel[EachPin] = "STDIO_UART_TX"
theotherjimmy 43:2a7da56ebd24 982 elif "VCP_RX" in PinLabel[EachPin]:
theotherjimmy 43:2a7da56ebd24 983 PinLabel[EachPin] = "STDIO_UART_RX"
theotherjimmy 43:2a7da56ebd24 984 elif "VCP_TX" in PinLabel[EachPin]:
theotherjimmy 43:2a7da56ebd24 985 PinLabel[EachPin] = "STDIO_UART_TX"
theotherjimmy 43:2a7da56ebd24 986 elif "ST_LINK_UART1_RX" in PinLabel[EachPin]:
theotherjimmy 43:2a7da56ebd24 987 PinLabel[EachPin] = "STDIO_UART_RX"
theotherjimmy 43:2a7da56ebd24 988 elif "ST_LINK_UART1_TX" in PinLabel[EachPin]:
theotherjimmy 43:2a7da56ebd24 989 PinLabel[EachPin] = "STDIO_UART_TX"
theotherjimmy 43:2a7da56ebd24 990 elif "USART2_RX" in PinLabel[EachPin]:
theotherjimmy 43:2a7da56ebd24 991 PinLabel[EachPin] = "STDIO_UART_RX"
theotherjimmy 43:2a7da56ebd24 992 elif "USART2_TX" in PinLabel[EachPin]:
theotherjimmy 43:2a7da56ebd24 993 PinLabel[EachPin] = "STDIO_UART_TX"
theotherjimmy 43:2a7da56ebd24 994 elif "STLINK_RX" in PinLabel[EachPin] or "STLINK_TX" in PinLabel[EachPin]:
theotherjimmy 43:2a7da56ebd24 995 # Patch waiting for CubeMX correction
theotherjimmy 43:2a7da56ebd24 996 if "RX" in PinData[EachPin]["Signal"]:
theotherjimmy 43:2a7da56ebd24 997 PinLabel[EachPin] = "STDIO_UART_RX"
theotherjimmy 43:2a7da56ebd24 998 else:
theotherjimmy 43:2a7da56ebd24 999 PinLabel[EachPin] = "STDIO_UART_TX"
theotherjimmy 43:2a7da56ebd24 1000 except:
theotherjimmy 43:2a7da56ebd24 1001 pass
theotherjimmy 43:2a7da56ebd24 1002
theotherjimmy 43:2a7da56ebd24 1003 # main
theotherjimmy 43:2a7da56ebd24 1004 print ("\nScript version %s" % GENPINMAP_VERSION)
theotherjimmy 43:2a7da56ebd24 1005 cur_dir = os.getcwd()
theotherjimmy 43:2a7da56ebd24 1006 PeripheralPins_c_filename = 'PeripheralPins.c'
theotherjimmy 43:2a7da56ebd24 1007 PinNames_h_filename = 'PinNames.h'
theotherjimmy 43:2a7da56ebd24 1008 config_filename = 'cube_path.json'
theotherjimmy 43:2a7da56ebd24 1009
theotherjimmy 43:2a7da56ebd24 1010 try:
theotherjimmy 43:2a7da56ebd24 1011 config_file = open(config_filename, "r")
theotherjimmy 43:2a7da56ebd24 1012 except IOError:
theotherjimmy 43:2a7da56ebd24 1013 print("Please set your configuration in '%s' file" % config_filename)
theotherjimmy 43:2a7da56ebd24 1014 config_file = open(config_filename, "w")
theotherjimmy 43:2a7da56ebd24 1015 if sys.platform.startswith('win32'):
theotherjimmy 43:2a7da56ebd24 1016 print("Platform is Windows")
theotherjimmy 43:2a7da56ebd24 1017 cubemxdir = 'C:\\Program Files (x86)\\STMicroelectronics\\STM32Cube\\STM32CubeMX'
theotherjimmy 43:2a7da56ebd24 1018 elif sys.platform.startswith('linux'):
theotherjimmy 43:2a7da56ebd24 1019 print("Platform is Linux")
theotherjimmy 43:2a7da56ebd24 1020 cubemxdir = os.getenv("HOME")+'/STM32CubeMX'
theotherjimmy 43:2a7da56ebd24 1021 elif sys.platform.startswith('darwin'):
theotherjimmy 43:2a7da56ebd24 1022 print("Platform is Mac OSX")
theotherjimmy 43:2a7da56ebd24 1023 cubemxdir = '/Applications/STMicroelectronics/STM32CubeMX.app/Contents/Resources'
theotherjimmy 43:2a7da56ebd24 1024 else:
theotherjimmy 43:2a7da56ebd24 1025 print("Platform unknown")
theotherjimmy 43:2a7da56ebd24 1026 cubemxdir = '<Set CubeMX install directory>'
theotherjimmy 43:2a7da56ebd24 1027 config_file.write(json.dumps({"CUBEMX_DIRECTORY":cubemxdir}))
theotherjimmy 43:2a7da56ebd24 1028 config_file.close()
theotherjimmy 43:2a7da56ebd24 1029 exit(1)
theotherjimmy 43:2a7da56ebd24 1030
theotherjimmy 43:2a7da56ebd24 1031 config = json.load(config_file)
theotherjimmy 43:2a7da56ebd24 1032 config_file.close()
theotherjimmy 43:2a7da56ebd24 1033 cubemxdir = config["CUBEMX_DIRECTORY"]
theotherjimmy 43:2a7da56ebd24 1034
theotherjimmy 43:2a7da56ebd24 1035 parser = argparse.ArgumentParser(
theotherjimmy 43:2a7da56ebd24 1036 description=textwrap.dedent('''\
theotherjimmy 43:2a7da56ebd24 1037 Script will generate %s thanks to the xml files description available in
theotherjimmy 43:2a7da56ebd24 1038 STM32CubeMX directory defined in '%s':
theotherjimmy 43:2a7da56ebd24 1039 \t%s''' % (PeripheralPins_c_filename, config_filename, cubemxdir)),
theotherjimmy 43:2a7da56ebd24 1040 epilog=textwrap.dedent('''\
theotherjimmy 43:2a7da56ebd24 1041 Once generated, you have to check and comment pins that can not be used (specific HW, internal ADC channels, remove PWM using us ticker timer, ...)
theotherjimmy 43:2a7da56ebd24 1042 '''),
theotherjimmy 43:2a7da56ebd24 1043 formatter_class=RawTextHelpFormatter)
theotherjimmy 43:2a7da56ebd24 1044 group = parser.add_mutually_exclusive_group()
theotherjimmy 43:2a7da56ebd24 1045
theotherjimmy 43:2a7da56ebd24 1046 group.add_argument("-l", "--list", help="list available mcu xml files description in STM32CubeMX", action="store_true")
theotherjimmy 43:2a7da56ebd24 1047
theotherjimmy 43:2a7da56ebd24 1048 group.add_argument("-b", "--boards", help="list available boards description in STM32CubeMX", action="store_true")
theotherjimmy 43:2a7da56ebd24 1049
theotherjimmy 43:2a7da56ebd24 1050 group.add_argument("-m", "--mcu", metavar='xml', help=textwrap.dedent('''\
theotherjimmy 43:2a7da56ebd24 1051 specify the mcu xml file description in STM32CubeMX to use (use double quotes).
theotherjimmy 43:2a7da56ebd24 1052 Parameter can be a filter like L496 if you want to parse all L496 chips (-m STM32 to parse all).
theotherjimmy 43:2a7da56ebd24 1053 '''))
theotherjimmy 43:2a7da56ebd24 1054
theotherjimmy 43:2a7da56ebd24 1055 group.add_argument("-t", "--target", metavar='HW', help=textwrap.dedent('''\
theotherjimmy 43:2a7da56ebd24 1056 specify the board file description in STM32CubeMX to use (use double quotes).
theotherjimmy 43:2a7da56ebd24 1057 Parameter can be a filter like L496 (only the first file found will be parsed).
theotherjimmy 43:2a7da56ebd24 1058 '''))
theotherjimmy 43:2a7da56ebd24 1059
theotherjimmy 43:2a7da56ebd24 1060 args = parser.parse_args()
theotherjimmy 43:2a7da56ebd24 1061
theotherjimmy 43:2a7da56ebd24 1062 if not(os.path.isdir(cubemxdir)):
theotherjimmy 43:2a7da56ebd24 1063 print ("\n ! ! ! Cube Mx seems not to be installed or not at the requested location")
theotherjimmy 43:2a7da56ebd24 1064 print ("\n ! ! ! please check the value you set for 'CUBEMX_DIRECTORY' in '%s' file" % config_filename)
theotherjimmy 43:2a7da56ebd24 1065 quit()
theotherjimmy 43:2a7da56ebd24 1066
theotherjimmy 43:2a7da56ebd24 1067 cubemxdirMCU = os.path.join(cubemxdir, 'db', 'mcu')
theotherjimmy 43:2a7da56ebd24 1068 cubemxdirIP = os.path.join(cubemxdir, 'db', 'mcu', 'IP')
theotherjimmy 43:2a7da56ebd24 1069 cubemxdirBOARDS = os.path.join(cubemxdir, 'db', 'plugins', 'boardmanager', 'boards')
theotherjimmy 43:2a7da56ebd24 1070
theotherjimmy 43:2a7da56ebd24 1071 version_file = os.path.join(cubemxdir, 'db', 'package.xml')
theotherjimmy 43:2a7da56ebd24 1072 try:
theotherjimmy 43:2a7da56ebd24 1073 xml_file = parse(version_file)
theotherjimmy 43:2a7da56ebd24 1074 PackDescription_item = xml_file.getElementsByTagName('PackDescription')
theotherjimmy 43:2a7da56ebd24 1075 for item in PackDescription_item:
theotherjimmy 43:2a7da56ebd24 1076 CUBEMX_DB_VERSION = item.attributes['Release'].value
theotherjimmy 43:2a7da56ebd24 1077 except:
theotherjimmy 43:2a7da56ebd24 1078 CUBEMX_DB_VERSION = "NOT_FOUND"
theotherjimmy 43:2a7da56ebd24 1079 print ("CubeMX DB version %s\n" % CUBEMX_DB_VERSION)
theotherjimmy 43:2a7da56ebd24 1080
theotherjimmy 43:2a7da56ebd24 1081 if args.list:
theotherjimmy 43:2a7da56ebd24 1082 FileCount = 0
theotherjimmy 43:2a7da56ebd24 1083 for f in fnmatch.filter(os.listdir(cubemxdirMCU), 'STM32*.xml'):
theotherjimmy 43:2a7da56ebd24 1084 print(f)
theotherjimmy 43:2a7da56ebd24 1085 FileCount += 1
theotherjimmy 43:2a7da56ebd24 1086 print
theotherjimmy 43:2a7da56ebd24 1087 print("%i available xml files description" % FileCount)
theotherjimmy 43:2a7da56ebd24 1088 quit()
theotherjimmy 43:2a7da56ebd24 1089
theotherjimmy 43:2a7da56ebd24 1090 if args.boards:
theotherjimmy 43:2a7da56ebd24 1091 NucleoFileCount = 0
theotherjimmy 43:2a7da56ebd24 1092 DiscoFileCount = 0
theotherjimmy 43:2a7da56ebd24 1093 for f in fnmatch.filter(os.listdir(cubemxdirBOARDS), '*AllConfig.ioc'):
theotherjimmy 43:2a7da56ebd24 1094 print(f)
theotherjimmy 43:2a7da56ebd24 1095 if "Nucleo" in f:
theotherjimmy 43:2a7da56ebd24 1096 NucleoFileCount += 1
theotherjimmy 43:2a7da56ebd24 1097 elif "Discovery" in f:
theotherjimmy 43:2a7da56ebd24 1098 DiscoFileCount += 1
theotherjimmy 43:2a7da56ebd24 1099 print
theotherjimmy 43:2a7da56ebd24 1100 print("%2i available Nucleo files description" % NucleoFileCount)
theotherjimmy 43:2a7da56ebd24 1101 print("%2i available Disco files description" % DiscoFileCount)
theotherjimmy 43:2a7da56ebd24 1102 quit()
theotherjimmy 43:2a7da56ebd24 1103
theotherjimmy 43:2a7da56ebd24 1104 if args.mcu:
theotherjimmy 43:2a7da56ebd24 1105 #check input file exists
theotherjimmy 43:2a7da56ebd24 1106 if os.path.isfile(os.path.join(cubemxdirMCU, args.mcu)):
theotherjimmy 43:2a7da56ebd24 1107 mcu_list.append(args.mcu)
theotherjimmy 43:2a7da56ebd24 1108 else:
theotherjimmy 43:2a7da56ebd24 1109 mcu_list = fnmatch.filter(os.listdir(cubemxdirMCU), '*%s*' % args.mcu)
theotherjimmy 43:2a7da56ebd24 1110 if len(mcu_list) == 0:
theotherjimmy 43:2a7da56ebd24 1111 print (" ! ! ! " + args.mcu + " file not found")
theotherjimmy 43:2a7da56ebd24 1112 print (" ! ! ! Check in " + cubemxdirMCU + " the correct name of this file")
theotherjimmy 43:2a7da56ebd24 1113 print (" ! ! ! You may use double quotes for this file if it contains special characters")
theotherjimmy 43:2a7da56ebd24 1114 quit()
theotherjimmy 43:2a7da56ebd24 1115
theotherjimmy 43:2a7da56ebd24 1116 if args.target:
theotherjimmy 43:2a7da56ebd24 1117 board_file_name = os.path.join(cubemxdirBOARDS, args.target)
theotherjimmy 43:2a7da56ebd24 1118 if not(os.path.isfile(board_file_name)):
theotherjimmy 43:2a7da56ebd24 1119 board_list = fnmatch.filter(os.listdir(cubemxdirBOARDS), '*%s*AllConfig.ioc' % args.target)
theotherjimmy 43:2a7da56ebd24 1120 if len(board_list) == 0:
theotherjimmy 43:2a7da56ebd24 1121 print (" ! ! ! No file contains " + args.target)
theotherjimmy 43:2a7da56ebd24 1122 print (" ! ! ! Check in " + cubemxdirBOARDS + " the correct filter to apply")
theotherjimmy 43:2a7da56ebd24 1123 quit()
theotherjimmy 43:2a7da56ebd24 1124 elif len(board_list) > 1:
theotherjimmy 43:2a7da56ebd24 1125 print (" ! ! ! Multiple files contains " + args.target)
theotherjimmy 43:2a7da56ebd24 1126 for board_elem in board_list: print (board_elem)
theotherjimmy 43:2a7da56ebd24 1127 print (" ! ! ! Only the first one will be parsed\n")
theotherjimmy 43:2a7da56ebd24 1128 board_file_name = os.path.join(cubemxdirBOARDS,board_list[0])
theotherjimmy 43:2a7da56ebd24 1129 if not (os.path.isfile(board_file_name)):
theotherjimmy 43:2a7da56ebd24 1130 print (" ! ! ! " + args.target + " file not found")
theotherjimmy 43:2a7da56ebd24 1131 print (" ! ! ! Check in " + cubemxdirBOARDS + " the correct name of this file")
theotherjimmy 43:2a7da56ebd24 1132 print (" ! ! ! You may use double quotes for this file if it contains special characters")
theotherjimmy 43:2a7da56ebd24 1133 quit()
theotherjimmy 43:2a7da56ebd24 1134 parse_BoardFile(board_file_name)
theotherjimmy 43:2a7da56ebd24 1135 TargetName = ""
theotherjimmy 43:2a7da56ebd24 1136 if "Nucleo" in board_file_name:
theotherjimmy 43:2a7da56ebd24 1137 TargetName += "NUCLEO_"
theotherjimmy 43:2a7da56ebd24 1138 elif "Discovery" in board_file_name:
theotherjimmy 43:2a7da56ebd24 1139 TargetName += "DISCO_"
theotherjimmy 43:2a7da56ebd24 1140 elif "Evaluation" in board_file_name:
theotherjimmy 43:2a7da56ebd24 1141 TargetName += "EVAL_"
theotherjimmy 43:2a7da56ebd24 1142 m = re.search(r'STM32([\w][\dR]{3}[\w]{0,2})[\w]*_Board', board_file_name)
theotherjimmy 43:2a7da56ebd24 1143 if m:
theotherjimmy 43:2a7da56ebd24 1144 TargetName += "%s" % m.group(1)
theotherjimmy 43:2a7da56ebd24 1145 # specific case
theotherjimmy 43:2a7da56ebd24 1146 if "-P" in args.target:
theotherjimmy 43:2a7da56ebd24 1147 TargetName += "_P"
theotherjimmy 43:2a7da56ebd24 1148 if TargetName == "DISCO_L072":
theotherjimmy 43:2a7da56ebd24 1149 TargetName += "CZ_LRWAN1"
theotherjimmy 43:2a7da56ebd24 1150 if TargetName == "DISCO_L475V":
theotherjimmy 43:2a7da56ebd24 1151 TargetName += "G_IOT01A"
theotherjimmy 43:2a7da56ebd24 1152 else:
theotherjimmy 43:2a7da56ebd24 1153 quit()
theotherjimmy 43:2a7da56ebd24 1154
theotherjimmy 43:2a7da56ebd24 1155 for mcu_file in mcu_list:
theotherjimmy 43:2a7da56ebd24 1156 if args.mcu:
theotherjimmy 43:2a7da56ebd24 1157 TargetName = os.path.splitext(mcu_file)[0]
theotherjimmy 43:2a7da56ebd24 1158 out_path = os.path.join(cur_dir, '%s' % TargetName)
theotherjimmy 43:2a7da56ebd24 1159 print(" * Output directory: %s" % (out_path))
theotherjimmy 43:2a7da56ebd24 1160 print(" * Generating %s and %s with '%s'" % (PeripheralPins_c_filename, PinNames_h_filename, mcu_file))
theotherjimmy 43:2a7da56ebd24 1161 input_file_name = os.path.join(cubemxdirMCU, mcu_file)
theotherjimmy 43:2a7da56ebd24 1162 output_cfilename = os.path.join(out_path, PeripheralPins_c_filename)
theotherjimmy 43:2a7da56ebd24 1163 output_hfilename = os.path.join(out_path, PinNames_h_filename)
theotherjimmy 43:2a7da56ebd24 1164 if not(os.path.isdir(out_path)):
theotherjimmy 43:2a7da56ebd24 1165 os.makedirs(out_path)
theotherjimmy 43:2a7da56ebd24 1166
theotherjimmy 43:2a7da56ebd24 1167 if (os.path.isfile(output_cfilename)):
theotherjimmy 43:2a7da56ebd24 1168 # print (" * Requested %s file already exists and will be overwritten" % PeripheralPins_c_filename)
theotherjimmy 43:2a7da56ebd24 1169 os.remove(output_cfilename)
theotherjimmy 43:2a7da56ebd24 1170 out_c_file = open(output_cfilename, 'w')
theotherjimmy 43:2a7da56ebd24 1171 out_h_file = open(output_hfilename, 'w')
theotherjimmy 43:2a7da56ebd24 1172
theotherjimmy 43:2a7da56ebd24 1173 #open input file
theotherjimmy 43:2a7da56ebd24 1174 try:
theotherjimmy 43:2a7da56ebd24 1175 xml_mcu = parse(input_file_name)
theotherjimmy 43:2a7da56ebd24 1176 except:
theotherjimmy 43:2a7da56ebd24 1177 # Patch waiting for CubeMX correction
theotherjimmy 43:2a7da56ebd24 1178 if "STM32F042K6Tx" in input_file_name:
theotherjimmy 43:2a7da56ebd24 1179 input_file_name = os.path.join(cubemxdirMCU, "STM32F042K(4-6)Tx.xml")
theotherjimmy 43:2a7da56ebd24 1180 xml_mcu = parse(input_file_name)
theotherjimmy 43:2a7da56ebd24 1181 elif "STM32F429Z" in input_file_name:
theotherjimmy 43:2a7da56ebd24 1182 input_file_name = os.path.join(cubemxdirMCU, "STM32F429ZITx.xml")
theotherjimmy 43:2a7da56ebd24 1183 xml_mcu = parse(input_file_name)
theotherjimmy 43:2a7da56ebd24 1184 elif "STM32F746Z" in input_file_name:
theotherjimmy 43:2a7da56ebd24 1185 input_file_name = os.path.join(cubemxdirMCU, "STM32F746ZGTx.xml")
theotherjimmy 43:2a7da56ebd24 1186 xml_mcu = parse(input_file_name)
theotherjimmy 43:2a7da56ebd24 1187 elif "STM32F767Z" in input_file_name:
theotherjimmy 43:2a7da56ebd24 1188 input_file_name = os.path.join(cubemxdirMCU, "STM32F767ZGTx.xml")
theotherjimmy 43:2a7da56ebd24 1189 xml_mcu = parse(input_file_name)
theotherjimmy 43:2a7da56ebd24 1190
theotherjimmy 43:2a7da56ebd24 1191 elif "STM32L011K4Tx" in input_file_name:
theotherjimmy 43:2a7da56ebd24 1192 input_file_name = os.path.join(cubemxdirMCU, "STM32L011K(3-4)Tx.xml")
theotherjimmy 43:2a7da56ebd24 1193 xml_mcu = parse(input_file_name)
theotherjimmy 43:2a7da56ebd24 1194 elif "STM32L432KCUx" in input_file_name:
theotherjimmy 43:2a7da56ebd24 1195 input_file_name = os.path.join(cubemxdirMCU, "STM32L432K(B-C)Ux.xml")
theotherjimmy 43:2a7da56ebd24 1196 xml_mcu = parse(input_file_name)
theotherjimmy 43:2a7da56ebd24 1197 elif "STM32F746N" in input_file_name:
theotherjimmy 43:2a7da56ebd24 1198 input_file_name = os.path.join(cubemxdirMCU, "STM32F746NGHx.xml")
theotherjimmy 43:2a7da56ebd24 1199 xml_mcu = parse(input_file_name)
theotherjimmy 43:2a7da56ebd24 1200 else:
theotherjimmy 43:2a7da56ebd24 1201 print ("\n ! ! ! Error in CubeMX file. File " + input_file_name + " doesn't exist")
theotherjimmy 43:2a7da56ebd24 1202 print (" ! ! ! Check in " + cubemxdirMCU)
theotherjimmy 43:2a7da56ebd24 1203 quit()
theotherjimmy 43:2a7da56ebd24 1204 gpiofile = find_gpio_file()
theotherjimmy 43:2a7da56ebd24 1205 if gpiofile == 'ERROR':
theotherjimmy 43:2a7da56ebd24 1206 print("Could not find GPIO file")
theotherjimmy 43:2a7da56ebd24 1207 quit()
theotherjimmy 43:2a7da56ebd24 1208 xml_gpio = parse(os.path.join(cubemxdirIP, 'GPIO-' + gpiofile + '_Modes.xml'))
theotherjimmy 43:2a7da56ebd24 1209 print (" * GPIO file: " + os.path.join(cubemxdirIP, 'GPIO-' + gpiofile + '_Modes.xml'))
theotherjimmy 43:2a7da56ebd24 1210
theotherjimmy 43:2a7da56ebd24 1211 parse_pins()
theotherjimmy 43:2a7da56ebd24 1212 sort_my_lists()
theotherjimmy 43:2a7da56ebd24 1213 print_header()
theotherjimmy 43:2a7da56ebd24 1214 print_all_lists()
theotherjimmy 43:2a7da56ebd24 1215 print_footer()
theotherjimmy 43:2a7da56ebd24 1216
theotherjimmy 43:2a7da56ebd24 1217 nb_pin = (len(io_list))
theotherjimmy 43:2a7da56ebd24 1218 nb_connected_pin = len(PinLabel)
theotherjimmy 43:2a7da56ebd24 1219 print (" * I/O pins found: %i connected: %i\n" % (nb_pin, nb_connected_pin))
theotherjimmy 43:2a7da56ebd24 1220 clean_all_lists()
theotherjimmy 43:2a7da56ebd24 1221
theotherjimmy 43:2a7da56ebd24 1222 out_c_file.close()
theotherjimmy 43:2a7da56ebd24 1223 out_h_file.close()