From 06530c4297f56c4eb825321666cb01b190ee02b8 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Tue, 16 Nov 2021 11:40:56 +0100 Subject: [PATCH] cpu/stm32: clone cmsis header in build/stm32 --- .../{include/vendor/Makefile => Makefile.cmsis} | 4 ++-- cpu/stm32/Makefile.include | 12 +++++++----- cpu/stm32/dist/irqs/gen_irqs.py | 17 +++++++---------- cpu/stm32/dist/irqs/gen_vectors.py | 13 ++++++------- cpu/stm32/dist/kconfig/README.md | 11 ++++++----- cpu/stm32/dist/kconfig/gen_kconfig.py | 10 +++++----- cpu/stm32/include/vendor/.gitignore | 1 - 7 files changed, 33 insertions(+), 35 deletions(-) rename cpu/stm32/{include/vendor/Makefile => Makefile.cmsis} (91%) delete mode 100644 cpu/stm32/include/vendor/.gitignore diff --git a/cpu/stm32/include/vendor/Makefile b/cpu/stm32/Makefile.cmsis similarity index 91% rename from cpu/stm32/include/vendor/Makefile rename to cpu/stm32/Makefile.cmsis index 6235215272..75a1db5a6d 100644 --- a/cpu/stm32/include/vendor/Makefile +++ b/cpu/stm32/Makefile.cmsis @@ -23,8 +23,8 @@ PKG_LICENSE=Apache-2 # Store the cloned repositories under the stm32 directory to prevent downloads # for each builds. -PKG_SOURCE_DIR = $(RIOTBASE)/cpu/stm32/include/vendor/cmsis/$(CPU_FAM) -PKG_PATCH_DIR = $(CURDIR)/patches/$(CPU_FAM) +PKG_SOURCE_DIR = $(RIOTBASE)/build/stm32/cmsis/$(CPU_FAM) +PKG_PATCH_DIR = $(RIOTCPU)/stm32/include/vendor/patches/$(CPU_FAM) include $(RIOTBASE)/pkg/pkg.mk diff --git a/cpu/stm32/Makefile.include b/cpu/stm32/Makefile.include index c346bd3897..884890ccc1 100644 --- a/cpu/stm32/Makefile.include +++ b/cpu/stm32/Makefile.include @@ -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. 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 +else + STM32CMSIS_INCLUDE_DIR = $(RIOTBASE)/build/stm32/cmsis/$(CPU_FAM)/Include STM32FAM_INCLUDE_FILE = $(STM32CMSIS_INCLUDE_DIR)/stm32$(CPU_FAM)xx.h INCLUDES += -I$(STM32CMSIS_INCLUDE_DIR) endif @@ -83,13 +85,13 @@ endif # 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 # updated. -$(STM32FAM_INCLUDE_FILE): FORCE - $(Q)+$(MAKE) -C $(RIOTCPU)/stm32/include/vendor +$(STM32FAM_INCLUDE_FILE): FORCE $(CLEAN) + $(Q)+$(MAKE) -f $(RIOTBASE)/cpu/stm32/Makefile.cmsis # The vectors source file requires the family headers to be fetched before since # it's generated from the CMSIS content $(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))) # 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 # before since it's generated from all CMSIS content of that family $(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 INCLUDES += -I$(RIOTCPU)/stm32/include/clk diff --git a/cpu/stm32/dist/irqs/gen_irqs.py b/cpu/stm32/dist/irqs/gen_irqs.py index 7a8e45881a..367ac099e4 100755 --- a/cpu/stm32/dist/irqs/gen_irqs.py +++ b/cpu/stm32/dist/irqs/gen_irqs.py @@ -17,10 +17,6 @@ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) RIOTBASE = os.getenv( "RIOTBASE", os.path.abspath(os.path.join(CURRENT_DIR, "../../../.."))) 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( 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""" - headers = os.listdir(STM32_CMSIS_INCLUDE_DIR.format(cpu_fam)) + headers = os.listdir(cmsis_dir) if "Templates" in headers: headers.remove("Templates") 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]) -def irq_numof(cpu_fam, cpu_line): +def irq_numof(cmsis_dir, cpu_line): """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: cmsis_content = cmsis.readlines() @@ -135,13 +131,13 @@ def generate_irqs(context): def main(args): """Main function.""" - cpu_lines = list_cpu_lines(args.cpu_fam) + cpu_lines = list_cpu_lines(args.cmsis_dir, args.cpu_fam) context = { "cpu_fam": args.cpu_fam, "cpu_lines": [ { "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 ] @@ -150,6 +146,7 @@ def main(args): PARSER = argparse.ArgumentParser() +PARSER.add_argument("cmsis_dir", help="CMSIS directory") PARSER.add_argument("cpu_fam", help="STM32 CPU Family") if __name__ == "__main__": diff --git a/cpu/stm32/dist/irqs/gen_vectors.py b/cpu/stm32/dist/irqs/gen_vectors.py index cff84b4c40..4a64f7ea5f 100755 --- a/cpu/stm32/dist/irqs/gen_vectors.py +++ b/cpu/stm32/dist/irqs/gen_vectors.py @@ -18,8 +18,6 @@ RIOTBASE = os.getenv( "RIOTBASE", os.path.abspath(os.path.join(CURRENT_DIR, "../../../.."))) STM32_VECTORS_DIR = os.path.join(RIOTBASE, "cpu/stm32/vectors") 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 = """ /* @@ -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.""" - cpu_fam = cpu_line[5:7] if cpu_line == "STM32F030x4": # STM32F030x4 is provided in the RIOT codebase in a different location cpu_line_cmsis = os.path.join( @@ -59,8 +56,9 @@ def parse_cmsis(cpu_line): cpu_line_cmsis = os.path.join( STM32_VENDOR_DIR, "{}_cm4.h".format(cpu_line.lower())) else: - cpu_line_cmsis = STM32_CMSIS_FILE.format( - cpu_fam.lower(), cpu_line.lower()) + cpu_line_cmsis = os.path.join( + "{}/{}.h".format(cmsis_dir, cpu_line.lower()) + ) with open(cpu_line_cmsis, 'rb') as cmsis: cmsis_content = cmsis.readlines() @@ -137,11 +135,12 @@ def generate_vectors(context): def main(args): """Main function.""" - context = parse_cmsis(args.cpu_line) + context = parse_cmsis(args.cmsis_dir, args.cpu_line) generate_vectors(context) PARSER = argparse.ArgumentParser() +PARSER.add_argument("cmsis_dir", help="CMSIS directory") PARSER.add_argument("cpu_line", help="STM32 CPU line") if __name__ == "__main__": diff --git a/cpu/stm32/dist/kconfig/README.md b/cpu/stm32/dist/kconfig/README.md index b5d9282368..cf4a693a61 100644 --- a/cpu/stm32/dist/kconfig/README.md +++ b/cpu/stm32/dist/kconfig/README.md @@ -13,13 +13,13 @@ the product selector tab, then click the `Export` button to download the Excel sheet (the default filename is `ProductsList.xlsx`). The available CPU lines are extracted from the -`cpu/stm32/include/vendor/cmsis//Include` directory. This means that the +`${RIOTBASE}/build/stm32/cmsis//Include` directory. This means that the headers of a given family are already fetched here. This can be done with the following `make` commands: ``` $ cd $RIOTBASE -$ RIOTBASE=$(pwd) RIOTTOOLS=$(pwd)/dist/tools CPU_FAM= make -C cpu/stm32/include/vendor +$ RIOTBASE=$(pwd) RIOTTOOLS=$(pwd)/dist/tools CPU_FAM= make -f cpu/stm32/Makefile.cmsis ``` `` can be any family in `f0`, `f1`, etc @@ -42,7 +42,7 @@ a given family as follows: ``` $ cd $RIOTBASE -$ ./cpu/stm32/dist/kconfig/gen_kconfig.py --sheets /ProductsList.xlsx +$ ./cpu/stm32/dist/kconfig/gen_kconfig.py ${RIOTBASE}/build/stm32/cmsis//Include --sheets /ProductsList.xlsx ``` The `--sheets` option can take several files. This allows to handle the L4 case @@ -51,7 +51,7 @@ the command should be: ``` $ cd $RIOTBASE -$ ./cpu/stm32/dist/kconfig/gen_kconfig.py l4 --sheets /L4ProductsList.xlsx /L4+ProductsList.xlsx +$ ./cpu/stm32/dist/kconfig/gen_kconfig.py ${RIOTBASE}/build/stm32/cmsis/l4/Include l4 --sheets /L4ProductsList.xlsx /L4+ProductsList.xlsx ``` 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 -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: + cmsis_dir STM32 CMSIS directory cpu_fam STM32 CPU Family optional arguments: diff --git a/cpu/stm32/dist/kconfig/gen_kconfig.py b/cpu/stm32/dist/kconfig/gen_kconfig.py index 8fef1a471b..c735baace6 100755 --- a/cpu/stm32/dist/kconfig/gen_kconfig.py +++ b/cpu/stm32/dist/kconfig/gen_kconfig.py @@ -19,7 +19,6 @@ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) RIOTBASE = os.getenv( "RIOTBASE", os.path.abspath(os.path.join(CURRENT_DIR, "../../../.."))) 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 @@ -43,11 +42,10 @@ def parse_sheet(cpu_fam, sheets): return sorted(models) -def parse_cpu_lines(cpu_fam): +def parse_cpu_lines(cmsis_dir, cpu_fam): """Return the list of available CPU lines.""" - headers_dir = os.path.join(STM32_VENDOR_DIR, cpu_fam, "Include") cpu_lines = [ - header[:-2].upper() for header in os.listdir(headers_dir) + header[:-2].upper() for header in os.listdir(cmsis_dir) if ( header.startswith("stm32") and header != "stm32{}xx.h".format(cpu_fam) @@ -141,7 +139,7 @@ def generate_kconfig(kconfig, context, overwrite, verbose): def main(args): """Main function.""" 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) if args.verbose: print("Generated kconfig files:\n") @@ -150,6 +148,8 @@ def main(args): PARSER = argparse.ArgumentParser() +PARSER.add_argument("cpu_fam", + help="STM32 CMSIS directory") PARSER.add_argument("cpu_fam", help="STM32 CPU Family") PARSER.add_argument("--sheets", "-s", nargs='+', diff --git a/cpu/stm32/include/vendor/.gitignore b/cpu/stm32/include/vendor/.gitignore deleted file mode 100644 index 0fc6729466..0000000000 --- a/cpu/stm32/include/vendor/.gitignore +++ /dev/null @@ -1 +0,0 @@ -cmsis/*