2021-05-25 02:17:24 +00:00
|
|
|
import sys
|
2021-04-20 01:37:49 +00:00
|
|
|
import yaml
|
|
|
|
import re
|
|
|
|
import os
|
2021-05-19 08:37:52 +00:00
|
|
|
import re
|
2021-04-20 01:37:49 +00:00
|
|
|
|
2021-06-12 16:28:21 +00:00
|
|
|
try:
|
|
|
|
from yaml import CSafeLoader as SafeLoader
|
|
|
|
except ImportError:
|
|
|
|
from yaml import SafeLoader
|
|
|
|
|
|
|
|
|
2021-04-20 01:37:49 +00:00
|
|
|
abspath = os.path.abspath(__file__)
|
|
|
|
dname = os.path.dirname(abspath)
|
|
|
|
os.chdir(dname)
|
|
|
|
|
2021-05-25 02:17:24 +00:00
|
|
|
data_path = '../stm32-data/data'
|
2021-04-20 01:37:49 +00:00
|
|
|
|
2021-05-25 02:17:24 +00:00
|
|
|
try:
|
|
|
|
_, chip_name, output_file = sys.argv
|
|
|
|
except:
|
2021-06-16 13:12:07 +00:00
|
|
|
raise Exception("Usage: gen.py STM32F429ZI_CM0 path/to/generated.rs")
|
|
|
|
|
|
|
|
c = chip_name.split('_', 1)
|
|
|
|
|
|
|
|
chip_name = c[0].upper()
|
|
|
|
core_name = None
|
|
|
|
|
|
|
|
if len(c) > 1:
|
|
|
|
core_name = c[1].lower()
|
2021-05-09 23:20:04 +00:00
|
|
|
|
2021-05-25 02:17:24 +00:00
|
|
|
# ======= load chip
|
|
|
|
with open(f'{data_path}/chips/{chip_name}.yaml', 'r') as f:
|
2021-06-12 16:28:21 +00:00
|
|
|
chip = yaml.load(f, Loader=SafeLoader)
|
2021-05-09 23:20:04 +00:00
|
|
|
|
2021-05-25 02:17:24 +00:00
|
|
|
# ======= Generate!
|
|
|
|
with open(output_file, 'w') as f:
|
|
|
|
singletons = [] # USART1, PA5, EXTI8
|
|
|
|
exti_interrupts = [] # EXTI IRQs, EXTI0, EXTI4_15 etc.
|
|
|
|
pins = set() # set of all present pins. PA4, PA5...
|
|
|
|
|
|
|
|
# ========= peripherals
|
|
|
|
|
|
|
|
singletons.extend((f'EXTI{x}' for x in range(16)))
|
|
|
|
num_dmas = 0
|
|
|
|
|
2021-06-16 13:12:07 +00:00
|
|
|
core = chip['cores'][0]
|
|
|
|
if core_name != None:
|
|
|
|
for c in chip['cores']:
|
|
|
|
if core_name == c['name']:
|
|
|
|
core = c
|
|
|
|
|
|
|
|
for (name, peri) in core['peripherals'].items():
|
2021-05-25 02:17:24 +00:00
|
|
|
if 'block' not in peri:
|
|
|
|
continue
|
|
|
|
|
|
|
|
block = peri['block']
|
|
|
|
block_mod, block_name_unparsed = block.rsplit('/')
|
|
|
|
block_mod, block_version = block_mod.rsplit('_')
|
|
|
|
block_name = ''
|
|
|
|
for b in block_name_unparsed.split('_'):
|
|
|
|
block_name += b.capitalize()
|
|
|
|
|
|
|
|
custom_singletons = False
|
|
|
|
|
|
|
|
if block_mod == 'gpio':
|
|
|
|
custom_singletons = True
|
|
|
|
port = name[4:]
|
|
|
|
port_num = ord(port) - ord('A')
|
|
|
|
|
|
|
|
for pin_num in range(16):
|
|
|
|
pin = f'P{port}{pin_num}'
|
|
|
|
pins.add(pin)
|
|
|
|
singletons.append(pin)
|
|
|
|
|
|
|
|
if block_mod == 'dma':
|
|
|
|
custom_singletons = True
|
|
|
|
for ch_num in range(8):
|
|
|
|
channel = f'{name}_CH{ch_num}'
|
|
|
|
singletons.append(channel)
|
|
|
|
|
|
|
|
if not custom_singletons:
|
|
|
|
singletons.append(name)
|
|
|
|
|
|
|
|
f.write(f"embassy_extras::peripherals!({','.join(singletons)});")
|