1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #17212 from aabadie/pr/cpu/stm32_cmsis_build

cpu/stm32: clone cmsis header in build/stm32
This commit is contained in:
Alexandre Abadie 2021-11-19 15:16:42 +01:00 committed by GitHub
commit 2226dc6e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
# 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

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.
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

View File

@ -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__":

View File

@ -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__":

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`).
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
following `make` commands:
```
$ 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
@ -42,7 +42,7 @@ a given family as follows:
```
$ 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
@ -51,7 +51,7 @@ the command should be:
```
$ 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
@ -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:

View File

@ -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='+',

View File

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