cpu/stm32: clone cmsis header in build/stm32

This commit is contained in:
Alexandre Abadie 2021-11-16 11:40:56 +01:00
parent 09e0692a85
commit 06530c4297
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
7 changed files with 33 additions and 35 deletions

View File

@ -23,8 +23,8 @@ PKG_LICENSE=Apache-2
# Store the cloned repositories under the stm32 directory to prevent downloads # Store the cloned repositories under the stm32 directory to prevent downloads
# for each builds. # for each builds.
PKG_SOURCE_DIR = $(RIOTBASE)/cpu/stm32/include/vendor/cmsis/$(CPU_FAM) PKG_SOURCE_DIR = $(RIOTBASE)/build/stm32/cmsis/$(CPU_FAM)
PKG_PATCH_DIR = $(CURDIR)/patches/$(CPU_FAM) PKG_PATCH_DIR = $(RIOTCPU)/stm32/include/vendor/patches/$(CPU_FAM)
include $(RIOTBASE)/pkg/pkg.mk include $(RIOTBASE)/pkg/pkg.mk

View File

@ -74,8 +74,10 @@ $(call target-export-variables,$(VECTORS_O),CPU_LINE)
# which are only used for STM32 system includes and not of interest for RIOT. # which are only used for STM32 system includes and not of interest for RIOT.
CFLAGS += -D__SYSTEM_STM32$(call uppercase,$(CPU_FAM))XX_H CFLAGS += -D__SYSTEM_STM32$(call uppercase,$(CPU_FAM))XX_H
ifeq (,$(filter STM32MP157Cxx,$(CPU_LINE))) ifneq (,$(filter STM32F030x4 STM32MP157Cxx,$(CPU_LINE)))
STM32CMSIS_INCLUDE_DIR = $(RIOTCPU)/stm32/include/vendor/cmsis/$(CPU_FAM)/Include STM32CMSIS_INCLUDE_DIR = $(RIOTCPU)/stm32/include/vendor/cmsis/$(CPU_FAM)/Include
else
STM32CMSIS_INCLUDE_DIR = $(RIOTBASE)/build/stm32/cmsis/$(CPU_FAM)/Include
STM32FAM_INCLUDE_FILE = $(STM32CMSIS_INCLUDE_DIR)/stm32$(CPU_FAM)xx.h STM32FAM_INCLUDE_FILE = $(STM32CMSIS_INCLUDE_DIR)/stm32$(CPU_FAM)xx.h
INCLUDES += -I$(STM32CMSIS_INCLUDE_DIR) INCLUDES += -I$(STM32CMSIS_INCLUDE_DIR)
endif endif
@ -83,13 +85,13 @@ endif
# Fetch all CMSIS headers using the package mechanism. This rule is called all # Fetch all CMSIS headers using the package mechanism. This rule is called all
# the time to ensure it's correctly updated when versions in the packages are # the time to ensure it's correctly updated when versions in the packages are
# updated. # updated.
$(STM32FAM_INCLUDE_FILE): FORCE $(STM32FAM_INCLUDE_FILE): FORCE $(CLEAN)
$(Q)+$(MAKE) -C $(RIOTCPU)/stm32/include/vendor $(Q)+$(MAKE) -f $(RIOTBASE)/cpu/stm32/Makefile.cmsis
# The vectors source file requires the family headers to be fetched before since # The vectors source file requires the family headers to be fetched before since
# it's generated from the CMSIS content # it's generated from the CMSIS content
$(VECTORS_FILE): $(STM32FAM_INCLUDE_FILE) $(VECTORS_FILE): $(STM32FAM_INCLUDE_FILE)
$(Q)$(RIOTBASE)/cpu/stm32/dist/irqs/gen_vectors.py $(CPU_LINE) $(Q)$(RIOTBASE)/cpu/stm32/dist/irqs/gen_vectors.py $(STM32CMSIS_INCLUDE_DIR) $(CPU_LINE)
ifeq (,$(filter STM32MP157Cxx STM32F030x4,$(CPU_LINE))) ifeq (,$(filter STM32MP157Cxx STM32F030x4,$(CPU_LINE)))
# IRQs of STM32F030x4 and STM32MP157Cxx lines are not available in the CMSIS # IRQs of STM32F030x4 and STM32MP157Cxx lines are not available in the CMSIS
@ -103,7 +105,7 @@ endif
# The IRQ header for a given family requires the family headers to be fetched # The IRQ header for a given family requires the family headers to be fetched
# before since it's generated from all CMSIS content of that family # before since it's generated from all CMSIS content of that family
$(STM32IRQS_INCLUDE_FILE): $(STM32FAM_INCLUDE_FILE) $(STM32IRQS_INCLUDE_FILE): $(STM32FAM_INCLUDE_FILE)
$(Q)$(RIOTBASE)/cpu/stm32/dist/irqs/gen_irqs.py $(CPU_FAM) $(Q)$(RIOTBASE)/cpu/stm32/dist/irqs/gen_irqs.py $(STM32CMSIS_INCLUDE_DIR) $(CPU_FAM)
# Include clock configuration directory # Include clock configuration directory
INCLUDES += -I$(RIOTCPU)/stm32/include/clk INCLUDES += -I$(RIOTCPU)/stm32/include/clk

View File

@ -17,10 +17,6 @@ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
RIOTBASE = os.getenv( RIOTBASE = os.getenv(
"RIOTBASE", os.path.abspath(os.path.join(CURRENT_DIR, "../../../.."))) "RIOTBASE", os.path.abspath(os.path.join(CURRENT_DIR, "../../../..")))
STM32_INCLUDE_DIR = os.path.join(RIOTBASE, "cpu/stm32/include") STM32_INCLUDE_DIR = os.path.join(RIOTBASE, "cpu/stm32/include")
STM32_CMSIS_INCLUDE_DIR = os.path.join(
RIOTBASE, STM32_INCLUDE_DIR, "vendor/cmsis/{}/Include/")
STM32_CMSIS_HEADER = os.path.join(
RIOTBASE, STM32_CMSIS_INCLUDE_DIR, "{}.h")
STM32_IRQS_DIR = os.path.join( STM32_IRQS_DIR = os.path.join(
RIOTBASE, STM32_INCLUDE_DIR, "irqs/{}/irqs.h") RIOTBASE, STM32_INCLUDE_DIR, "irqs/{}/irqs.h")
@ -49,9 +45,9 @@ extern "C" {{
""" """
def list_cpu_lines(cpu_fam): def list_cpu_lines(cmsis_dir, cpu_fam):
"""Returns the list CPU lines for a given family""" """Returns the list CPU lines for a given family"""
headers = os.listdir(STM32_CMSIS_INCLUDE_DIR.format(cpu_fam)) headers = os.listdir(cmsis_dir)
if "Templates" in headers: if "Templates" in headers:
headers.remove("Templates") headers.remove("Templates")
if "partition_stm32l5xx.h" in headers: if "partition_stm32l5xx.h" in headers:
@ -61,9 +57,9 @@ def list_cpu_lines(cpu_fam):
return sorted([header.split(".")[0] for header in headers]) return sorted([header.split(".")[0] for header in headers])
def irq_numof(cpu_fam, cpu_line): def irq_numof(cmsis_dir, cpu_line):
"""Parse the CMSIS to get the list IRQs.""" """Parse the CMSIS to get the list IRQs."""
cpu_line_cmsis = STM32_CMSIS_HEADER.format(cpu_fam, cpu_line) cpu_line_cmsis = os.path.join(cmsis_dir, "{}.h".format(cpu_line))
with open(cpu_line_cmsis, 'rb') as cmsis: with open(cpu_line_cmsis, 'rb') as cmsis:
cmsis_content = cmsis.readlines() cmsis_content = cmsis.readlines()
@ -135,13 +131,13 @@ def generate_irqs(context):
def main(args): def main(args):
"""Main function.""" """Main function."""
cpu_lines = list_cpu_lines(args.cpu_fam) cpu_lines = list_cpu_lines(args.cmsis_dir, args.cpu_fam)
context = { context = {
"cpu_fam": args.cpu_fam, "cpu_fam": args.cpu_fam,
"cpu_lines": [ "cpu_lines": [
{ {
"line": cpu_line.upper().replace("X", "x"), "line": cpu_line.upper().replace("X", "x"),
"irq_numof": irq_numof(args.cpu_fam, cpu_line), "irq_numof": irq_numof(args.cmsis_dir, cpu_line),
} }
for cpu_line in cpu_lines for cpu_line in cpu_lines
] ]
@ -150,6 +146,7 @@ def main(args):
PARSER = argparse.ArgumentParser() PARSER = argparse.ArgumentParser()
PARSER.add_argument("cmsis_dir", help="CMSIS directory")
PARSER.add_argument("cpu_fam", help="STM32 CPU Family") PARSER.add_argument("cpu_fam", help="STM32 CPU Family")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -18,8 +18,6 @@ RIOTBASE = os.getenv(
"RIOTBASE", os.path.abspath(os.path.join(CURRENT_DIR, "../../../.."))) "RIOTBASE", os.path.abspath(os.path.join(CURRENT_DIR, "../../../..")))
STM32_VECTORS_DIR = os.path.join(RIOTBASE, "cpu/stm32/vectors") STM32_VECTORS_DIR = os.path.join(RIOTBASE, "cpu/stm32/vectors")
STM32_VENDOR_DIR = os.path.join(RIOTBASE, "cpu/stm32/include/vendor") STM32_VENDOR_DIR = os.path.join(RIOTBASE, "cpu/stm32/include/vendor")
STM32_CMSIS_FILE = os.path.join(
RIOTBASE, STM32_VENDOR_DIR, "cmsis/{}/Include/{}.h")
VECTORS_FORMAT = """ VECTORS_FORMAT = """
/* /*
@ -47,9 +45,8 @@ ISR_VECTOR(1) const isr_t vector_cpu[CPU_IRQ_NUMOF] = {{
""" """
def parse_cmsis(cpu_line): def parse_cmsis(cmsis_dir, cpu_line):
"""Parse the CMSIS to get the list IRQs.""" """Parse the CMSIS to get the list IRQs."""
cpu_fam = cpu_line[5:7]
if cpu_line == "STM32F030x4": if cpu_line == "STM32F030x4":
# STM32F030x4 is provided in the RIOT codebase in a different location # STM32F030x4 is provided in the RIOT codebase in a different location
cpu_line_cmsis = os.path.join( cpu_line_cmsis = os.path.join(
@ -59,8 +56,9 @@ def parse_cmsis(cpu_line):
cpu_line_cmsis = os.path.join( cpu_line_cmsis = os.path.join(
STM32_VENDOR_DIR, "{}_cm4.h".format(cpu_line.lower())) STM32_VENDOR_DIR, "{}_cm4.h".format(cpu_line.lower()))
else: else:
cpu_line_cmsis = STM32_CMSIS_FILE.format( cpu_line_cmsis = os.path.join(
cpu_fam.lower(), cpu_line.lower()) "{}/{}.h".format(cmsis_dir, cpu_line.lower())
)
with open(cpu_line_cmsis, 'rb') as cmsis: with open(cpu_line_cmsis, 'rb') as cmsis:
cmsis_content = cmsis.readlines() cmsis_content = cmsis.readlines()
@ -137,11 +135,12 @@ def generate_vectors(context):
def main(args): def main(args):
"""Main function.""" """Main function."""
context = parse_cmsis(args.cpu_line) context = parse_cmsis(args.cmsis_dir, args.cpu_line)
generate_vectors(context) generate_vectors(context)
PARSER = argparse.ArgumentParser() PARSER = argparse.ArgumentParser()
PARSER.add_argument("cmsis_dir", help="CMSIS directory")
PARSER.add_argument("cpu_line", help="STM32 CPU line") PARSER.add_argument("cpu_line", help="STM32 CPU line")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -13,13 +13,13 @@ the product selector tab, then click the `Export` button to download the Excel
sheet (the default filename is `ProductsList.xlsx`). sheet (the default filename is `ProductsList.xlsx`).
The available CPU lines are extracted from the The available CPU lines are extracted from the
`cpu/stm32/include/vendor/cmsis/<fam>/Include` directory. This means that the `${RIOTBASE}/build/stm32/cmsis/<fam>/Include` directory. This means that the
headers of a given family are already fetched here. This can be done with the headers of a given family are already fetched here. This can be done with the
following `make` commands: following `make` commands:
``` ```
$ cd $RIOTBASE $ cd $RIOTBASE
$ RIOTBASE=$(pwd) RIOTTOOLS=$(pwd)/dist/tools CPU_FAM=<cpu_fam> make -C cpu/stm32/include/vendor $ RIOTBASE=$(pwd) RIOTTOOLS=$(pwd)/dist/tools CPU_FAM=<cpu_fam> make -f cpu/stm32/Makefile.cmsis
``` ```
`<cpu_fam>` can be any family in `f0`, `f1`, etc `<cpu_fam>` can be any family in `f0`, `f1`, etc
@ -42,7 +42,7 @@ a given family as follows:
``` ```
$ cd $RIOTBASE $ cd $RIOTBASE
$ ./cpu/stm32/dist/kconfig/gen_kconfig.py <cpu_fam> --sheets <path-to-sheet>/ProductsList.xlsx $ ./cpu/stm32/dist/kconfig/gen_kconfig.py ${RIOTBASE}/build/stm32/cmsis/<fam>/Include <cpu_fam> --sheets <path-to-sheet>/ProductsList.xlsx
``` ```
The `--sheets` option can take several files. This allows to handle the L4 case The `--sheets` option can take several files. This allows to handle the L4 case
@ -51,7 +51,7 @@ the command should be:
``` ```
$ cd $RIOTBASE $ cd $RIOTBASE
$ ./cpu/stm32/dist/kconfig/gen_kconfig.py l4 --sheets <path-to-sheet>/L4ProductsList.xlsx <path-to-sheet>/L4+ProductsList.xlsx $ ./cpu/stm32/dist/kconfig/gen_kconfig.py ${RIOTBASE}/build/stm32/cmsis/l4/Include l4 --sheets <path-to-sheet>/L4ProductsList.xlsx <path-to-sheet>/L4+ProductsList.xlsx
``` ```
By default, if the `Kconfig.lines` and `Kconfig.models` files of a given family By default, if the `Kconfig.lines` and `Kconfig.models` files of a given family
@ -64,9 +64,10 @@ Print the detailed usage with `--help`:
``` ```
$ ./cpu/stm32/dist/kconfig/gen_kconfig.py --help $ ./cpu/stm32/dist/kconfig/gen_kconfig.py --help
usage: gen_kconfig.py [-h] [--sheets SHEETS [SHEETS ...]] [--overwrite] [--quiet] cpu_fam usage: gen_kconfig.py [-h] [--sheets SHEETS [SHEETS ...]] [--overwrite] [--quiet] cmsis_dir cpu_fam
positional arguments: positional arguments:
cmsis_dir STM32 CMSIS directory
cpu_fam STM32 CPU Family cpu_fam STM32 CPU Family
optional arguments: optional arguments:

View File

@ -19,7 +19,6 @@ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
RIOTBASE = os.getenv( RIOTBASE = os.getenv(
"RIOTBASE", os.path.abspath(os.path.join(CURRENT_DIR, "../../../.."))) "RIOTBASE", os.path.abspath(os.path.join(CURRENT_DIR, "../../../..")))
STM32_KCONFIG_DIR = os.path.join(RIOTBASE, "cpu/stm32/kconfigs") STM32_KCONFIG_DIR = os.path.join(RIOTBASE, "cpu/stm32/kconfigs")
STM32_VENDOR_DIR = os.path.join(RIOTBASE, "cpu/stm32/include/vendor/cmsis")
MODEL_COLUMN = 1 MODEL_COLUMN = 1
@ -43,11 +42,10 @@ def parse_sheet(cpu_fam, sheets):
return sorted(models) return sorted(models)
def parse_cpu_lines(cpu_fam): def parse_cpu_lines(cmsis_dir, cpu_fam):
"""Return the list of available CPU lines.""" """Return the list of available CPU lines."""
headers_dir = os.path.join(STM32_VENDOR_DIR, cpu_fam, "Include")
cpu_lines = [ cpu_lines = [
header[:-2].upper() for header in os.listdir(headers_dir) header[:-2].upper() for header in os.listdir(cmsis_dir)
if ( if (
header.startswith("stm32") and header.startswith("stm32") and
header != "stm32{}xx.h".format(cpu_fam) header != "stm32{}xx.h".format(cpu_fam)
@ -141,7 +139,7 @@ def generate_kconfig(kconfig, context, overwrite, verbose):
def main(args): def main(args):
"""Main function.""" """Main function."""
models = parse_sheet(args.cpu_fam, args.sheets) models = parse_sheet(args.cpu_fam, args.sheets)
lines = parse_cpu_lines(args.cpu_fam) lines = parse_cpu_lines(args.cmsis_dir, args.cpu_fam)
context = get_context(args.cpu_fam, models, lines) context = get_context(args.cpu_fam, models, lines)
if args.verbose: if args.verbose:
print("Generated kconfig files:\n") print("Generated kconfig files:\n")
@ -150,6 +148,8 @@ def main(args):
PARSER = argparse.ArgumentParser() PARSER = argparse.ArgumentParser()
PARSER.add_argument("cpu_fam",
help="STM32 CMSIS directory")
PARSER.add_argument("cpu_fam", PARSER.add_argument("cpu_fam",
help="STM32 CPU Family") help="STM32 CPU Family")
PARSER.add_argument("--sheets", "-s", nargs='+', PARSER.add_argument("--sheets", "-s", nargs='+',

View File

@ -1 +0,0 @@
cmsis/*