Skip to content

Commit

Permalink
#45 Finished off code generator scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert authored and More-Wrong committed Jul 29, 2023
1 parent 52c8c14 commit a7d5f5f
Show file tree
Hide file tree
Showing 2,043 changed files with 60,575 additions and 4,232 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
import sys
import csv
import re

import datetime

peripheralInheritenceInject = {} # peripherals which share a numbering system
peripheralInheritenceIncrement = {} # peripherals which don't

maxOfPeripheral = {}
peripheralPinTypes = {}

#find peripherals which can be treated as smaller peripherals - e.g. USART/UART
with open(sys.argv[1], newline='') as csvfile:
reader = csv.reader(csvfile, delimiter='\t')
Expand All @@ -21,6 +24,8 @@
peripheralInheritenceIncrement[row[0]] = rest


funcNameRegex = '^([^_-]*[^\d_-][^\d]*[^\d_-]*)\d*[_-].*|([^_-]*[^\d_-])'
funcType = '^[^_-]*[^\d_-][^\d]*[^\d_-]*\d*[_-](.*)'

for i in range(2, len(sys.argv)):
functions = set()
Expand All @@ -31,11 +36,20 @@

functionChildren = {}

# find all the types of pin from a given function type, to prepare pin checkers
for func in functions:
strFuncName = re.search(funcNameRegex, func).expand('\\1\\2')
if not strFuncName in peripheralPinTypes:
peripheralPinTypes[strFuncName] = set()
funcTypeM = re.search(funcType, func)
if(funcTypeM):
peripheralPinTypes[strFuncName].add(funcTypeM.expand('\\1'))

# add peripherals which do share numbering systems
extraFuncs = set()
for func in sorted(functions):
functionChildren[func] = set()
strFuncName = re.search('^[^\d]+', func).group(0)
strFuncName = re.search(funcNameRegex, func).expand('\\1\\2')
if(strFuncName in peripheralInheritenceInject):
for alt in peripheralInheritenceInject[strFuncName]:
newFunc = alt+re.search('\d.*', func).group(0)
Expand All @@ -52,21 +66,21 @@

highestByType = {} # the highest label of each peripheral type
for func in functions:
plainName = re.search('^[^\d]+', func).group(0)
match = re.search('\d+', func)
if(match):
number = int(match.group(0))
plainName = re.search(funcNameRegex, func).expand('\\1\\2')
numberM = re.search('\d+', func) # if the peripheral doesn't have a number, we don't care
if(numberM):
number = int(numberM.group(0))
if((not plainName in highestByType) or number > highestByType[plainName]):
highestByType[plainName] = number

# Then add peripherals which don't share numbering
functionInjectNumberMap = {} # preserves the numbering for given original peripherals
extraFuncs = set()
for func in sorted(functions):
strFuncName = re.search('^[^\d]+', func).group(0)
match = re.search('\d+', func)
if(match and (strFuncName in peripheralInheritenceIncrement)):
origNumber = match.group(0)
strFuncName = re.search(funcNameRegex, func).expand('\\1\\2')
numberM = re.search('\d+', func)
if(numberM and (strFuncName in peripheralInheritenceIncrement)):
origNumber = numberM.group(0)
for alt in peripheralInheritenceIncrement[strFuncName]:
if (not alt in functionInjectNumberMap):
functionInjectNumberMap[alt] = {}
Expand All @@ -82,13 +96,25 @@

functions |= extraFuncs

# find all the maximum count of every given function
for func in functions:
strFuncName = re.search(funcNameRegex, func).expand('\\1\\2')
if strFuncName in highestByType:
if((not strFuncName in maxOfPeripheral) or highestByType[strFuncName]>maxOfPeripheral[strFuncName]):
maxOfPeripheral[strFuncName] = highestByType[strFuncName]
else:
if((not strFuncName in maxOfPeripheral) or 1>maxOfPeripheral[strFuncName]):
maxOfPeripheral[strFuncName] = 1


functionPins = {}
functionPinAF = {}

for func in functions:
functionPins[func] = []
functionPinAF[func] = {}

# find what pins can do what functions
for pin in root.iter("{http://mcd.rou.st.com/modules.php?name=mcu}GPIO_Pin"):
pinName = pin.get("Name")
if pinName.find('-')>=0:
Expand All @@ -107,18 +133,53 @@
outputName = re.search('STM32[^_]*', sys.argv[i])
outputName = outputName.group(0)+".h"
with open(outputName, "w") as out:
name = re.search('STM32[^_]*', sys.argv[i])
name = name.group(0)
out.write("/*\n * This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE\n*/\n\n")
out.write("/*\n * This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE\n")
out.write(" * Timestamp: "+datetime.datetime.utcnow().isoformat()+"\n")
out.write(" */\n\n")

out.write("#ifndef LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION\n")
out.write("#define LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION\n\n")
for func in sorted(functions):
usableFuncName = func.replace("-", "_")
for pin in functionPins[func]:
out.write("#define "+func+"_"+pin+"_ "+pin+",GPIO_AF"+str(functionPinAF[func][pin])+"\n");
out.write("#define "+usableFuncName+"_"+pin+"_ "+pin+",GPIO_AF"+str(functionPinAF[func][pin])+"\n");
for pin in functionPins[func]:
out.write("#define _"+func+"_"+pin+"_ 1\n");
out.write("#define _"+usableFuncName+"_"+pin+"_ 1\n");
out.write('\n')
out.write("#endif /* LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION */")

for func in sorted(peripheralPinTypes):
with open("peripheralPinCheck_"+func.lower()+".h", "w") as out:
out.write("/*\n * This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE\n")
out.write(" * Timestamp: "+datetime.datetime.utcnow().isoformat()+"\n")
out.write(" */\n\n")


for type in sorted(peripheralPinTypes[func]):
out.write("#define FIND_VALUE_"+func+"_"+type+"_inner(INDEX,PIN) I2C##_"+func+"_##PIN\n")
out.write("#define FIND_VALUE_"+func+"_"+type+"(INDEX,PIN) FIND_VALUE_"+func+"_"+type+"_inner(INDEX,PIN)\n\n")
for i in range(maxOfPeripheral[func]):
periphName = func+str(i)
out.write("#ifdef USE_"+periphName+"\n")
for type in sorted(peripheralPinTypes[func]):
out.write("#if !FIND_VALUE_"+func+"_"+type+"(_"+periphName+", "+periphName+"_"+type+")\n");
out.write("#error Invalid pin assignment for "+periphName+" "+type+" pin: "+periphName+"_"+type+"\n");
out.write("#endif\n");
out.write("#endif\n\n");


with open("peripheralPinCheck.h", "w") as out:
out.write("/*\n * This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE\n")
out.write(" * Timestamp: "+datetime.datetime.utcnow().isoformat()+"\n")
out.write(" */\n\n")
for func in sorted(peripheralPinTypes):
out.write("#include \"PeripheralChecks/peripheralPinCheck_"+func.lower()+".h\"\n");










Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* llPinCheck.hpp
*
* Created on: 19 Dec 2022
* Author: alicia
*/

#include <llIncludes.hpp>

#ifndef SKIP_PERIPHERAL_PIN_CHECKS

#ifdef STM32
#include "stm32/peripheralPinCheck.h"
#else
#error No supported manufacturer selected
#endif
#endif

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
*/
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
* Timestamp: 2022-12-19T23:52:16.926209
*/

#ifndef LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
#define LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
*/
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
* Timestamp: 2022-12-19T23:52:16.930720
*/

#ifndef LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
#define LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
*/
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
* Timestamp: 2022-12-19T23:52:16.934281
*/

#ifndef LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
#define LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
*/
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
* Timestamp: 2022-12-19T23:52:16.938090
*/

#ifndef LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
#define LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
*/
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
* Timestamp: 2022-12-19T23:52:16.943346
*/

#ifndef LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
#define LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
Expand Down Expand Up @@ -237,14 +238,14 @@
#define _SPI2_SCK_PB13_ 1
#define _SPI2_SCK_PD1_ 1

#define SYS_- functionality on new pin (forecasted in Stingray 64K pinout file)_PD8_ PD8,GPIO_AF4
#define _SYS_- functionality on new pin (forecasted in Stingray 64K pinout file)_PD8_ 1
#define SYS__ functionality on new pin (forecasted in Stingray 64K pinout file)_PD8_ PD8,GPIO_AF4
#define _SYS__ functionality on new pin (forecasted in Stingray 64K pinout file)_PD8_ 1

#define SYS_- new functionality (not forecasted in Stingray 64K pinout file)_PD4_ PD4,GPIO_AF4
#define _SYS_- new functionality (not forecasted in Stingray 64K pinout file)_PD4_ 1
#define SYS__ new functionality (not forecasted in Stingray 64K pinout file)_PD4_ PD4,GPIO_AF4
#define _SYS__ new functionality (not forecasted in Stingray 64K pinout file)_PD4_ 1

#define SYS_- new pin (not existing on Stingray 64K)_PD3_ PD3,GPIO_AF4
#define _SYS_- new pin (not existing on Stingray 64K)_PD3_ 1
#define SYS__ new pin (not existing on Stingray 64K)_PD3_ PD3,GPIO_AF4
#define _SYS__ new pin (not existing on Stingray 64K)_PD3_ 1

#define SYS_CAN_PC15_ PC15,GPIO_AF7
#define _SYS_CAN_PC15_ 1
Expand All @@ -258,8 +259,8 @@
#define SYS_I2C_PC0_ PC0,GPIO_AF7
#define _SYS_I2C_PC0_ 1

#define SYS_IR-Out_PC13_ PC13,GPIO_AF7
#define _SYS_IR-Out_PC13_ 1
#define SYS_IR_Out_PC13_ PC13,GPIO_AF7
#define _SYS_IR_Out_PC13_ 1

#define SYS_SPI_PC1_ PC1,GPIO_AF7
#define _SYS_SPI_PC1_ 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
*/
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
* Timestamp: 2022-12-19T23:52:16.949024
*/

#ifndef LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
#define LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
*/
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
* Timestamp: 2022-12-19T23:52:16.957260
*/

#ifndef LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
#define LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
Expand Down Expand Up @@ -673,17 +674,17 @@
#define _SPI3_SCK_PB3_ 1
#define _SPI3_SCK_PC10_ 1

#define SYS_JTCK-SWCLK_PA14_ PA14,GPIO_AF0
#define _SYS_JTCK-SWCLK_PA14_ 1
#define SYS_JTCK_SWCLK_PA14_ PA14,GPIO_AF0
#define _SYS_JTCK_SWCLK_PA14_ 1

#define SYS_JTDI_PA15_ PA15,GPIO_AF0
#define _SYS_JTDI_PA15_ 1

#define SYS_JTDO-SWO_PB3_ PB3,GPIO_AF0
#define _SYS_JTDO-SWO_PB3_ 1
#define SYS_JTDO_SWO_PB3_ PB3,GPIO_AF0
#define _SYS_JTDO_SWO_PB3_ 1

#define SYS_JTMS-SWDIO_PA13_ PA13,GPIO_AF0
#define _SYS_JTMS-SWDIO_PA13_ 1
#define SYS_JTMS_SWDIO_PA13_ PA13,GPIO_AF0
#define _SYS_JTMS_SWDIO_PA13_ 1

#define SYS_JTRST_PB4_ PB4,GPIO_AF0
#define _SYS_JTRST_PB4_ 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
*/
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
* Timestamp: 2022-12-19T23:52:16.961862
*/

#ifndef LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
#define LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
Expand Down Expand Up @@ -274,17 +275,17 @@
#define _SPI3_SCK_PB3_ 1
#define _SPI3_SCK_PC10_ 1

#define SYS_JTCK-SWCLK_PA14_ PA14,GPIO_AF0
#define _SYS_JTCK-SWCLK_PA14_ 1
#define SYS_JTCK_SWCLK_PA14_ PA14,GPIO_AF0
#define _SYS_JTCK_SWCLK_PA14_ 1

#define SYS_JTDI_PA15_ PA15,GPIO_AF0
#define _SYS_JTDI_PA15_ 1

#define SYS_JTDO-TRACESWO_PB3_ PB3,GPIO_AF0
#define _SYS_JTDO-TRACESWO_PB3_ 1
#define SYS_JTDO_TRACESWO_PB3_ PB3,GPIO_AF0
#define _SYS_JTDO_TRACESWO_PB3_ 1

#define SYS_JTMS-SWDIO_PA13_ PA13,GPIO_AF0
#define _SYS_JTMS-SWDIO_PA13_ 1
#define SYS_JTMS_SWDIO_PA13_ PA13,GPIO_AF0
#define _SYS_JTMS_SWDIO_PA13_ 1

#define SYS_NJTRST_PB4_ PB4,GPIO_AF0
#define _SYS_NJTRST_PB4_ 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
*/
* This file is automatically generated by afTable.py from the xml descriptions provided as part of the STM32Cube IDE
* Timestamp: 2022-12-19T23:52:16.975453
*/

#ifndef LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
#define LOWLEVEL_INCLUDE_DEVICE_ALTERNATE_FUNCTION
Expand Down Expand Up @@ -375,17 +376,17 @@
#define _SPI3_SCK_PB3_ 1
#define _SPI3_SCK_PC10_ 1

#define SYS_JTCK-SWCLK_PA14_ PA14,GPIO_AF0
#define _SYS_JTCK-SWCLK_PA14_ 1
#define SYS_JTCK_SWCLK_PA14_ PA14,GPIO_AF0
#define _SYS_JTCK_SWCLK_PA14_ 1

#define SYS_JTDI_PA15_ PA15,GPIO_AF0
#define _SYS_JTDI_PA15_ 1

#define SYS_JTDO-TRACESWO_PB3_ PB3,GPIO_AF0
#define _SYS_JTDO-TRACESWO_PB3_ 1
#define SYS_JTDO_TRACESWO_PB3_ PB3,GPIO_AF0
#define _SYS_JTDO_TRACESWO_PB3_ 1

#define SYS_JTMS-SWDIO_PA13_ PA13,GPIO_AF0
#define _SYS_JTMS-SWDIO_PA13_ 1
#define SYS_JTMS_SWDIO_PA13_ PA13,GPIO_AF0
#define _SYS_JTMS_SWDIO_PA13_ 1

#define SYS_NJTRST_PB4_ PB4,GPIO_AF0
#define _SYS_NJTRST_PB4_ 1
Expand Down
Loading

0 comments on commit a7d5f5f

Please sign in to comment.