pyVision
A Machine Learning and Signal Processing toolbox

Download .zip Download.tar.gz View on GitHub


MBED Setup Documentation

MBED Setup

###Prerequisites

Mbed test suite and build scripts are Python 2.7 applications and require Python 2.7 runtime environment and setuptools to install dependencies.

  • Install Python 2.7 programming language.
  • Install setuptools
  • Optionally you can install pip which is the PyPA recommended tool for installing Python packages from command line.

Mbed SDK in its repo root directory specifies setup.py file which holds information about all packages which are dependencies for it.

First, clone mbed SDK repo and go to mbed SDK repo’s directory:

From a command line with Git installed, run the following command in a directory where you wish mbed to be stored:

$ git clone https://github.com/mbedmicro/mbed.git

Or

Download mbed sources https://github.com/mbedmicro/mbed

Installing Tools

Second, invoke setup.py so setuptools can install mbed SDK’s dependencies (external Python modules required by mbed SDK):

$ sudo python setup.py install

###Download and Install GCC ARM ToolChain

For example, if you want to change the path to your GNU Tools for ARM Embedded Processors to a path like c:/arm_gcc/bin, you simply need to have a workspace_tools/private_settings.py that contains following line:

> GCC_ARM_PATH = "c:/arm_gcc/bin"

Workspace tools

Workspace tools are set of Python scripts used off-line by Mbed SDK team to:

  • Compile and build mbed SDK,
  • Compile and build libraries included in mbed SDK repo like e.g. ETH (Ethernet), USB, RTOS or CMSIS,
  • Compile, build and run mbed SDK tests,
  • Run test regression locally and in CI server,
  • Get library, target, test configuration (paths, parameters, names etc.).

Configure workspace tools to work with your compilers

we need to tell workspace tools where our compilers are.

  • Go mbed/workspace_tools/ directory and create empty file called private_settings.py.
$ touch private_settings.py
  • Populate this file the Python code below:
from os.path import join
 
# ARMCC
ARM_PATH = "C:/Work/toolchains/ARMCompiler_5.03_117_Windows"
ARM_BIN = join(ARM_PATH, "bin")
ARM_INC = join(ARM_PATH, "include")
ARM_LIB = join(ARM_PATH, "lib")
 
ARM_CPPLIB = join(ARM_LIB, "cpplib")
MY_ARM_CLIB = join(ARM_PATH, "lib", "microlib")
 
# GCC ARM
GCC_ARM_PATH = "C:/Work/toolchains/gcc_arm_4_8/4_8_2013q4/bin"
 
# GCC CodeSourcery
GCC_CS_PATH = "C:/Work/toolchains/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
 
# GCC CodeRed
GCC_CR_PATH = "C:/Work/toolchains/LPCXpresso_6.1.4_194/lpcxpresso/tools/bin"
 
# IAR
IAR_PATH = "C:/Work/toolchains/iar_6_5/arm"
 
SERVER_ADDRESS = "127.0.0.1"
LOCALHOST = "127.0.0.1"
 
# This is moved to separate JSON configuration file used by singletest.py
MUTs = {
}

Replace corresponding variable values with paths to compilers installed in your system:

  • ARM_PATH for armcc compiler.
  • GCC_ARM_PATH for GCC ARM compiler.
  • GCC_CS_PATH for GCC CodeSourcery compiler.
  • GCC_CR_PATH for GCC CodeRed compiler.
  • IAR_PATH for IAR compiler.

Workspace tools will use compiler’s path variable only if you explicit ask for it from command line. You need to replace only paths for your installed compilers.

Note: Settings in private_settings.py will overwrite variables with default values in mbed/workspace_tools/settings.py file.

###Build System

The mbed build system is composed of two scripts:

  • workspace_tools/build.py to build the libraries
  • workspace_tools/make.py to build and run the test projects

Both share a subset of options to specify the target microcontroller and the toolchain:

-m MCU -t TOOLCHAIN

If, for example, you want to build the mbed library for the LPC1768 mbed using the ARM GCC toolchain:

python workspace_tools\build.py -m LPC1768 -t GCC_ARM

If you want to compile source files then issue the command in the root of project directory

python workspace_tools\make.py -m LPC1768 -t GCC_ARM

build.py script

It is the core script to drive compilation, linking and building process for:

  • mbed SDK (with libs like Ethernet, RTOS, USB, USB host).
  • Tests which also can be linked with libraries like RTOS or Ethernet.

Build.py script is a powerful tool to build mbed SDK for all available platforms using all supported by mbed cross-compilers. S

$ python build.py --help
  • The command line parameter -m specifies the MCUs/platformsfor which you want to build the mbed SDK. More than one MCU(s)/platform(s) may be specified with this parameter using comma as delimiter.

    Example for one platform build:

     $ python build.py -m NUCLEO_F334R8 -t GCC_ARM
    

    or for many platforms:

     $ python build.py -m NUCLEO_F303RE,NUCLEO_F334R8 -t GCC_ARM
    
  • Parameter -t defined which toolchain should be used for mbed SDK build. You can build Mbed SDK for multiple toolchains using one command.

  • Below example will compile mbed SDK for Freescale Freedom KL25Z platform using ARM and GCC_ARM compilers:

      $ python build.py -m NUCLEO_F334R8 -t ARM,GCC_ARM
    
  • You can combine this technique to compile multiple targets with multiple compilers.
    $ python build.py -m NUCLEO_F303RE,NUCLEO_F334R8 -t GCC_ARM,ARM
    
  • Building libraries included in mbed SDK’s source code. Parameters -r, -e, -u, -U, -d, -b will add RTOS, Ethernet, USB, USB Host, DSP, U-Blox libraries respectively.

    Example

      $ python build.py -m LPC1768 -t ARM -r -e
    
  • You can be more verbose -v especially if you want to see each compilation / linking command build.py is executing:

      $ python build.py -t GCC_ARM -m LPC1768 -j 8 -v
    

Build Mbed SDK library from sources

Now we look at how to compile the MBED SDK from sources using build.py workspace tools script.

Go to the

mbed/workspace_tools/ directory and type the following command to start the MBED SDK build for LPC1768 platform using ARM compiler.

$ python build.py -m LPC1768 -t GCC_ARM - j 4

For multi-threaded compilation please use option -j X where X is number of cores you want to use to compile mbed SDK.

We can see for a new directory TARGET_LPC1768 was created in build/mbed directory which contains all the build primitives.

build/mbed directory contains all the generic MBED header files which are required for user defined project while build/mbed/TARGET_LPC1768/ contains platform dependent header files required by user defined projects.

build/mbed/TARGET_LPC1768/TOOLCHAIN_GCC_ARM contains mbed SDK library libmbed.a

Workspace tools track changes in source code and build.py script will recompile project with all dependencies in case of changes .

make.py script

make.py is a mbed/workspace_tools/ script used to build user defined projects

The make.py script depends on existing already built mbed SDK and library sources so you need to pre-build mbed SDK and other libraries (such as RTOS library) to link user defined projects with mbed SDK and other mbed library. To pre-build mbed SDK please use build.py script.

make.py shares same subset of options as build.py to specify the target microcontroller and the toolchain:

**Directory Structure for User Defined Project **

—mbed
— workspace—src—project—Makefile
— workspace—src—project—src
— workpace—src—project—Readme.md

###Makefile


DIRNAME=$(shell basename $(realpath ./))
MAKEFILE_PATH=$(realpath ../../../mbed/workspace_tools/make.py)
BUILD_DIR=$(realpath ../../build/)
SOURCE_PATH=$(realpath ./)
BUILD_PATH=$(BUILD_DIR)/$(DIRNAME)
MCU=NUCLEO_F334R8 #board or build profile name
TOOLCHAIN=GCC_ARM # tool chain
FLAGS="-D__STM__ -Wswitch"
all:
        $(MAKEFILE_PATH) --source=$(SOURCE_PATH) --build=$(BUILD_PATH) -m $(MCU) -t $(TOOLCHAIN) $(FLAGS) 

clean:
        rm -r $(BUILD_PATH)

help:
        $(MAKEFILE_PATH) --help

To get started with a new project,simple create a new sub directory in workspace and copy the Makefile ,and execute make to compile the project

$ make 

Modify the FLAGS variable in the Makefile to include command line options for including MBED libraries or other compilation options

###References

  • https://developer.mbed.org/handbook/mbed-tools
  • https://developer.mbed.org/teams/SDK-Development/wiki/Mbed-SDK-build-script-introduction
blog comments powered by Disqus