Commit be66a9ec authored by Dave Hylands's avatar Dave Hylands Committed by Damien George

stmhal: Generate modstm constants per build

This causes unnecessary constants to no longer be generated.
Some constants (like UART_BRR) are different between the F4 and F7
parent 4836bcc9
...@@ -13,7 +13,7 @@ include ../py/mkenv.mk ...@@ -13,7 +13,7 @@ include ../py/mkenv.mk
include boards/$(BOARD)/mpconfigboard.mk include boards/$(BOARD)/mpconfigboard.mk
# qstr definitions (must come before including py.mk) # qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h $(BUILD)/modstm_qstr.h
# include py core make definitions # include py core make definitions
include ../py/py.mk include ../py/py.mk
...@@ -325,6 +325,18 @@ $(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/ ...@@ -325,6 +325,18 @@ $(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/
$(BUILD)/pins_$(BOARD).o: $(BUILD)/pins_$(BOARD).c $(BUILD)/pins_$(BOARD).o: $(BUILD)/pins_$(BOARD).c
$(call compile_c) $(call compile_c)
GEN_STMCONST_HDR = $(HEADER_BUILD)/modstm_const.h
GEN_STMCONST_QSTR = $(BUILD)/modstm_qstr.h
CMSIS_MCU_LOWER = $(shell echo $(CMSIS_MCU) | tr '[:upper:]' '[:lower:]')
CMSIS_MCU_HDR = cmsis/devinc/$(CMSIS_MCU_LOWER).h
$(BUILD)/modstm.o: $(GEN_STMCONST_HDR)
# Use a pattern rule here so that make will only call make-stmconst.py once to
# make both modstm_const.h and modstm_qstr.h
$(HEADER_BUILD)/%_const.h $(BUILD)/%_qstr.h: $(CMSIS_MCU_HDR) make-stmconst.py
$(ECHO) "Create stmconst $@"
$(Q)$(PYTHON) make-stmconst.py --qstr $(GEN_STMCONST_QSTR) $(CMSIS_MCU_HDR) > $(GEN_STMCONST_HDR)
$(GEN_CDCINF_HEADER): $(GEN_CDCINF_FILE) $(FILE2H) $(GEN_CDCINF_HEADER): $(GEN_CDCINF_FILE) $(FILE2H)
$(ECHO) "Create $@" $(ECHO) "Create $@"
$(Q)$(PYTHON) $(FILE2H) $< > $@ $(Q)$(PYTHON) $(FILE2H) $< > $@
......
MCU_SERIES = f4 MCU_SERIES = f4
CMSIS_MCU = STM32F405xx
AF_FILE = boards/stm32f405_af.csv AF_FILE = boards/stm32f405_af.csv
LD_FILE = boards/stm32f405.ld LD_FILE = boards/stm32f405.ld
MCU_SERIES = f4 MCU_SERIES = f4
CMSIS_MCU = STM32F401xE
AF_FILE = boards/stm32f401_af.csv AF_FILE = boards/stm32f401_af.csv
LD_FILE = boards/stm32f401.ld LD_FILE = boards/stm32f401.ld
MCU_SERIES = f4 MCU_SERIES = f4
CMSIS_MCU = STM32F405xx
AF_FILE = boards/stm32f405_af.csv AF_FILE = boards/stm32f405_af.csv
LD_FILE = boards/stm32f405.ld LD_FILE = boards/stm32f405.ld
MCU_SERIES = f4 MCU_SERIES = f4
CMSIS_MCU = STM32F405xx
AF_FILE = boards/stm32f405_af.csv AF_FILE = boards/stm32f405_af.csv
LD_FILE = boards/stm32f405.ld LD_FILE = boards/stm32f405.ld
MCU_SERIES = f4 MCU_SERIES = f4
CMSIS_MCU = STM32F405xx
AF_FILE = boards/stm32f405_af.csv AF_FILE = boards/stm32f405_af.csv
LD_FILE = boards/stm32f405.ld LD_FILE = boards/stm32f405.ld
MCU_SERIES = f4 MCU_SERIES = f4
CMSIS_MCU = STM32F405xx
AF_FILE = boards/stm32f405_af.csv AF_FILE = boards/stm32f405_af.csv
LD_FILE = boards/stm32f405.ld LD_FILE = boards/stm32f405.ld
MCU_SERIES = f4 MCU_SERIES = f4
CMSIS_MCU = STM32F405xx
AF_FILE = boards/stm32f405_af.csv AF_FILE = boards/stm32f405_af.csv
LD_FILE = boards/stm32f405.ld LD_FILE = boards/stm32f405.ld
MCU_SERIES = f4 MCU_SERIES = f4
CMSIS_MCU = STM32F407xx
AF_FILE = boards/stm32f405_af.csv AF_FILE = boards/stm32f405_af.csv
LD_FILE = boards/stm32f405.ld LD_FILE = boards/stm32f405.ld
MCU_SERIES = f7 MCU_SERIES = f7
CMSIS_MCU = STM32F746xx
AF_FILE = boards/stm32f746_af.csv AF_FILE = boards/stm32f746_af.csv
LD_FILE = boards/stm32f746.ld LD_FILE = boards/stm32f746.ld
...@@ -7,6 +7,8 @@ expected to change. After generating the file, some manual intervention is ...@@ -7,6 +7,8 @@ expected to change. After generating the file, some manual intervention is
needed to copy the new qstr definitions to qstrdefsport.h. needed to copy the new qstr definitions to qstrdefsport.h.
""" """
from __future__ import print_function
import argparse import argparse
import re import re
...@@ -34,7 +36,7 @@ class Lexer: ...@@ -34,7 +36,7 @@ class Lexer:
('typedef struct', re.compile(r'typedef struct$')), ('typedef struct', re.compile(r'typedef struct$')),
('{', re.compile(r'{$')), ('{', re.compile(r'{$')),
('}', re.compile(r'}$')), ('}', re.compile(r'}$')),
('} TypeDef', re.compile(r'} *(?P<id>[A-Z][A-Za-z0-9_]+)_(?P<global>(Global)?)TypeDef;$')), ('} TypeDef', re.compile(r'} *(?P<id>[A-Z][A-Za-z0-9_]+)_(?P<global>([A-Za-z0-9_]+)?)TypeDef;$')),
('IO reg', re.compile(re_io_reg + r'; +/\*!< ' + re_comment + r', +' + re_addr_offset + r' *\*/')), ('IO reg', re.compile(re_io_reg + r'; +/\*!< ' + re_comment + r', +' + re_addr_offset + r' *\*/')),
('IO reg array', re.compile(re_io_reg + r'\[(?P<array>[2-8])\]; +/\*!< ' + re_comment + r', +' + re_addr_offset + r'-(0x[0-9A-Z]{2,3}) *\*/')), ('IO reg array', re.compile(re_io_reg + r'\[(?P<array>[2-8])\]; +/\*!< ' + re_comment + r', +' + re_addr_offset + r'-(0x[0-9A-Z]{2,3}) *\*/')),
) )
...@@ -157,6 +159,8 @@ const mp_obj_module_t stm_%s_obj = { ...@@ -157,6 +159,8 @@ const mp_obj_module_t stm_%s_obj = {
def main(): def main():
cmd_parser = argparse.ArgumentParser(description='Extract ST constants from a C header file.') cmd_parser = argparse.ArgumentParser(description='Extract ST constants from a C header file.')
cmd_parser.add_argument('file', nargs=1, help='input file') cmd_parser.add_argument('file', nargs=1, help='input file')
cmd_parser.add_argument('-q', '--qstr', dest='qstr_filename', default='build/stmconst_qstr.h',
help='Specified the name of the generated qstr header file')
args = cmd_parser.parse_args() args = cmd_parser.parse_args()
periphs, reg_defs = parse_file(args.file[0]) periphs, reg_defs = parse_file(args.file[0])
...@@ -198,7 +202,8 @@ def main(): ...@@ -198,7 +202,8 @@ def main():
'WWDG', 'WWDG',
'RNG', 'RNG',
): ):
print_regs(reg, reg_defs[reg], needed_qstrs) if reg in reg_defs:
print_regs(reg, reg_defs[reg], needed_qstrs)
#print_regs_as_submodules(reg, reg_defs[reg], modules, needed_qstrs) #print_regs_as_submodules(reg, reg_defs[reg], modules, needed_qstrs)
#print("#define MOD_STM_CONST_MODULES \\") #print("#define MOD_STM_CONST_MODULES \\")
...@@ -207,8 +212,9 @@ def main(): ...@@ -207,8 +212,9 @@ def main():
print("") print("")
for qstr in sorted(needed_qstrs): with open(args.qstr_filename, 'wt') as qstr_file:
print('Q({})'.format(qstr)) for qstr in sorted(needed_qstrs):
print('Q({})'.format(qstr), file=qstr_file)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
...@@ -120,7 +120,7 @@ STATIC const mp_map_elem_t stm_module_globals_table[] = { ...@@ -120,7 +120,7 @@ STATIC const mp_map_elem_t stm_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_mem16), (mp_obj_t)&stm_mem16_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_mem16), (mp_obj_t)&stm_mem16_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_mem32), (mp_obj_t)&stm_mem32_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_mem32), (mp_obj_t)&stm_mem32_obj },
#include "modstmconst.gen.c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