BSPACM
20150113
Board Support Package for ARM Cortex-M Microcontrollers
|
The fundamental architecture of BSPACM is based on the following assumptions:
struct
data layouts for core and peripheral registers, standard "intrinsics" such as __disable_irq()
and __WFI()
, global variables like SystemCoreClock
and functions like SystemCoreClockUpdate()
. Most vendors readily supply the necessary headers, along with the documentation required to use them.-ffunction-sections
and -fdata-sections
), and eliminating unreferenced sections from the executable (gcc -Wl
,-gc-sections).make
build tool.CMSIS provides core header files for each Cortex-M architecture, as well as a standard for vendor-specific peripheral interfaces. It also defines the names for exception handlers and core support functions, and provides example implementations of startup and system initialization code for each architecture.
Where vendor-supplied CMSIS support is adequate the vendor files are used. In other situations CMSIS standard implementations direct from ARM are used.
BSPACM provides its own linker scripts and startup assembly files that derive from the ARM examples. These scripts are shared by all applications; customization is performed through BSPACM support for weak symbols and preprocessor flags. BSPACM changes to support this generality includes:
DEVICE_LDSCRIPT_PATH
in make
.SysTick_Handler
and UART0_IRQHandler
, not SysTickIntHandler
or UARTIntHandler
).__STARTUP_USE_UNIQUE_DEFAULT_HANDLER
when the startup files are assembled.CMSIS specifies a number of standard variables and functions that are to be provided by the vendor. Among these are:
SystemCoreClock
is a uint32_t
global which represents the processor speed in Hertz.SystemInit()
is a function that is called within the startup code to initialize the clocks (and SystemCoreClock
) prior to invoking constructors and calling main()
.SystemCoreClockUpdate()
is a function that reads the clock peripheral configuration and updates the value of SystemCoreClock
.BSPACM is written with the expectation that these and similar standard functions and data objects exist and may be used.
At this time Texas Instruments does not support CMSIS, so a minimum generic system_TM4C.c
is provided in the TM4C device series area.
Although Silicon Labs (Energy Micro) does provide a CMSIS startup file, its SystemInit()
fails to initialize SystemCoreClock
. At this time, BSPACM has not chosen to fix this error locally.
BSPACM targets systems designed around ARM Cortex-M series microprocessors. The intent is that all architecture variations within Cortex-M will be supported: at the time of writing that includes Cortex-M0+, Cortex-M3, and Cortex-M4 devices.
To share implementation and concepts among the widest possible range of target platforms, the following taxonomy is used:
A BSPACM application is built for a specific board, by providing the BOARD
make
variable when compiling it. All further information not explicitly provided by the application is derived from the board identification.
The structure of the BSPACM workspace reflects the taxonomy in Target System Model. You can browse the current directory structure through the BSPACM github project page.
board
directory contains subdirectories for each supported board. The manufacturer's preferred name for the board, in lower case, should be used as the subdirectory name.device
directory contains a series of subdirectories: each series contains subdirectories for each of its lines, which in turn contain subdirectories for each of its devices. Again the manufacturer's preferred name, in lower case, is used for each directory.include
directory contains a hierarchy of C header files that will be located using angle-bracket include directives in C sources. The top level contains only a subdirectory bspacm
, ensuring that each included file is associated with the BSPACM namespace and does not conflict with vendor or third-party libraries.src
directory contains a hierarchy of C implementation files. Source directories are further refined to reflect the include files for which they provide implementation.toolchain
directory contains material specific to the compiler/linker toolchain, using the CMSIS standard toolchain identifiers GCC
(GNU Tools for ARM Embedded Processors) and the unsupported toolchains ARM
, G++
, and IAR
. Each toolchain directory will contain material such as linker scripts and CMSIS-standard assembly language startup sources for each Cortex-M architecture.The include
and src
directories are reproduced as necessary within the board and device hierarchies so that specific implementations are associated with the most general level to which they apply.
Other directories such as examples
, doc
, and maintainer
are either self-explanatory or not relevant to most users.
All header files in BSPACM are placed so that they are included with the angle-bracket version of C's #include
preprocessor directive with the leading bspacm
enforcing placement in a namespace.
bspacm/utility
hierarchy provides common interface to non-peripheral capabilities, such as <bspacm/utility/led.h>.bspacm/periph
hierarchy provides common interface to peripherals such as UARTs, SPI, I2C, timers, real-time clocks, etc.bspacm/newlib
hierarchy provides access to BSPACM's Interfacing with newlib (libc) support infrastructure.Other directories and files may be added over time.
The bspacm/internal
hierarchy provides header files that should not be made visible in public API for various reasons. Internal header files named something.inc
are template files that are included into headers or implementation files, possibly multiple times, to specialize code or data structures for specific purposes, such as defining a standard IRQHandler function or filling out a device description table.
Multiple include/bspacm
hierarchies may combine to produce the environment used for a particular application. The application may add its own hierarchy first, but the core make
infrastructure will also search the board, device, device line, and device series (in that order) before falling back to the generic hierarchy. Device-specific template (.inc) and header files are found within the extended set of hierarchies.
Implementation files are placed into subdirectories of src
corresponding to the header file that they implement.
As with include files, there are specific source directories available at the board, device, device line, and device series layers as well as the application. Unlike include files, there is no ordered searching within these directories: the full path to each implementation file that contributes to an application are added to the list of source files by one of the Makefile components. See Makefile Architecture.
The board
hiearchy contains subdirectories for each supported board, identified by the manufacturer's preferred name, in lower case. This identifier is also used as the value of the BOARD
variable in the Makefile architecture.
Within each board directory should be the following files:
Set the board identifier in the BOARD
make variable. Then include the appropriate Makefile.device
from the device hierarchy, with an absolute path generally beginning with $(BSPACM_ROOT)
.
Any other board- or device-specific make variables may also be set. Generally these should begin with the prefix BOARD_
. For example, BOARD_STYLE
is used in EFM32 boards to distinguish DK (development kit) from STK (starter kit).
README
Contain salient information about the board: a link to manufacturer's home page, basic characteristics like flash/RAM sizes, pin assignments for LEDs, buttons, and console UART, and whatever else might be useful. Don't repeat information that can easily be found elsewhere; don't make the reader go hunting for the most basic information.
This file may have a suffix such as .md (Markdown),
.rst (reStructuredText), or
.txt (plain text) identifying the text markup style used within the file.
A header file included by <bspacm/config.h> that provides declarations related for common peripherals such as the default UART device. It may be copied to the application source directory and modified to meet specific application needs.
The contents of this file should be synchronized with the corresponding src/periph_config.c
file.
An implementation file that provides definitions for common peripherals such as the default UART device. The PERIPH_CONFIG_SRC
variable used by Makefile Architecture defaults to the version supplied here, but it may be overridden to provide an application-specific implementation.
A template file included by device-specific header and implementation files to describe the LEDs that are available on the board.
The device hierarchy contains (recursively) information on each device series, line, and specific device supported in the baseline BSPACM infrastructure. At the top level is the device series, identified by the manufacturer's preferred name.
Each layer in the hierarchy has include
and src
subdirectories that provide interface and implementation specific to that layer. In addition, the following files are found at various levels in this hierarchy:
This file is necessarily found at the device layer of the hierarchy (e.g., device/efm32/efm32gg/efm32gg990f256/Makefile.device
).
Set the device identifier in the DEVICE
make variable. Provide definitions for TARGET_MFLAGS
, TARGET_CPPFLAGS
, ARM_PROCESSOR
, and other variables that cannot be defined at the line or series levels.
End by including the appropriate Makefile.line
from the device hierarchy, with an absolute path generally beginning with $(BSPACM_ROOT)
.
This file is necessarily found at the line layer of the hierarchy (e.g., device/efm32/efm32gg/Makefile.line
).
Set the device line identifier in the DEVICE_LINE
make variable. Provide definitions for TARGET_MFLAGS
, TARGET_CPPFLAGS
, ARM_PROCESSOR
, and other variables that cannot be defined at the series level.
Then include the appropriate Makefile.series
from the device hierarchy, with an absolute path generally beginning with $(BSPACM_ROOT)
.
This file is necessarily found at the series layer of the hierarchy (e.g., device/efm32/Makefile.series
).
Set the device line identifier in the DEVICE_LINE
make variable. Provide defaults for TARGET_MFLAGS
, TARGET_CPPFLAGS
, ARM_PROCESSOR
, and other variables that have not already been defined.
Define BOARD_LIBVENDOR_A
to the archive file for vendor libraries such as TivaWare or emlib. Provide the necessary make
rules to build that archive.
Append to BOARD_LIBBSPACM_SRC
any device-specific implementation files.
Define a command DO_FLASH_IMAGE
which takes a single argument that is the name of an ARM binary and programs it into the board.
A file for the GCC toolchain describing the memory regions, i.e. size of flash and ram available on the device. The file will be included into the generic linker script for the processor.
Generally this is found at the device (deepest) level. If it is not placed there, the DEVICE_LDSCRIPT_PATH
make
variable must be defined to instruct the linker where it can be found.
A file describing the entries in the interrupt vector table for the device, in a form suitable for inclusion into linker scripts and/or startup sources. The file wraps the standard names, in order, with a macro that is expanded in context to create a CMSIS standard *_IRQHandler
definition or reference.
Generally this is found at the line level.
A directory containing template files included by device-specific header and implementation files to declare or define specific peripherals. The files should have a base name corresponding to the peripheral; e.g. usart.inc
or leuart.inc
.
BSPACM uses GNU make features to simplify the build process at the cost of increased maintainer complexity.
Each application has its own Makefile
which initializes the SRC
variable to the list of application-specific sources, then includes $(BSPACM_ROOT)/make/Makefile.common
. That file then includes board and device specific files, constructs compiler and linker arguments, and provides the rules necessary to build the libraries, object files, and application itself.
BSPACM's make
infrastructure preprocesses source files to determine dependencies, and automatically rebuilds all files that are affected by source code changes.
Object files specific to an application, including the startup and system modules from CMSIS, are compiled and stored in the current directory alongside the Makefile. Object files and libraries that should be independent of the application are stored in the BSPACM board directory.
Standard targets include:
app.axf
builds the application into ELF format install
downloads the application to the board, after building it clean
removes all application-specific build files. This should be done when rebuilding an application for a new board, as the object files may have invalid references. realclean
removes all board-specific build files. This may be necessary when changing code-generation and link-related toolchain flags.All make
variables should be documented within make/Makefile.common
and the reader is directed there for full details. Only the most commonly specified variables are described here. See the various example applications to learn more.
SRC
This variable contains the list of source code files, exclusive of vendor and BSPACM libraries, that contribute to an application. C (.c), C++ (
.cc), and assembly-with-c-preprocessor (
.S) sources are recognized, and
make
build rules dynamically created to build the object files and place them in the current directory.
BOARD
This variable must be set to identify the target for the application. The value is the board identifier as specified by the corresponding subdirectory of $(BSPACM_ROOT)/boards
Copyright 2014-2015, Peter A. Bigot