GithubHelp home page GithubHelp logo

adamheinrich / cm-makefile Goto Github PK

View Code? Open in Web Editor NEW
46.0 3.0 6.0 103 KB

Makefile template for Cortex-M projects using the GCC ARM Embedded toolchain.

License: GNU Lesser General Public License v3.0

Makefile 100.00%

cm-makefile's Introduction

CM-Makefile: Makefile template for Cortex-M projects

Makefile template for ARM Cortex-M projects using the Arm GNU Toolchain. The template is meant to be included in project-specific Makefile.

See repository cm-makefile-examples for usage examples.

Dependencies

To successfully compile and debug the project, you need:

  • Linux desktop (OS X should work as well)
  • GCC ARM Embedded toolchain
  • MCU vendor's HAL (start-up code, register definitions, ...)

Optional software:

Installation instructions are described in a separate file.

Usage

First, create Makefile. The Makefile should link to source files outside the project's source directory (such as libraries provided by the manufacturer) and include *.mk files from the CM-Makefile project. For example:

BIN = hello                     # Name of the output binary
SDK_DIR = ../mcu-vendor         # Target-specific library

INC = -I$(SDK_DIR)/inc
SRC_ASM = $(SDK_DIR)/src/startup.S
SCR_C = $(SDK_DIR)/src/system.c
SRC_LD = $(SDK_DIR)/target.ld

OPENOCD = openocd -f board/my_board.cfg

include cm-makefile/config.mk
include cm-makefile/openocd.mk  # For flash, debug and gdb targets
include cm-makefile/rules.mk

See the cm-makefile-examples repository for real-world examples.

Then simply run make to compile the project and make flash to upload it to the target.

The process will create .elf, .hex and .bin binaries in the build directory together with other files useful for debugging:

  • .disasm: Disassembly output
  • .sym: Name list (useful to check memory layout)
  • .map: Linker map (useful to check linked object files, discarded sections, etc.)

To use a specific toolchain (other than the default arm-none-eabi), simply set the CROSS_COMPILE variable:

make CROSS_COMPILE=/usr/local/gcc-arm-none-eabi-4_9-2015q3/bin/arm-none-eabi-

Flashing and debugging

To flash the program into the target device, run make flash. To reset the CPU, run make reset.

Three different flasher implementations are provided:

  • OpenOCD (openocd.mk)
  • Black Magic Probe
  • J-Link (jlink.mk)

To debug the project, run make gdb (which starts OpenOCD's GDB server) followed by make debug in a different terminal (which starts GDB in TUI mode).

It is also possible to use the Eclipse standalone debugger using make cdtdebug. The debugger has to be available as cdtdebug. If it isn't, simply change the CDTDEBUG variable.

J-Link and OpenOCD probes support make rtt which starts a RTT server. The RTT output can be captured using JLinkRTTClient or nc localhost 19021.

If needed, it is possible to provide a custom gdb executable by setting the GDB variable:

make GDB=/opt/arm-none-eabi-gdb-11.1/bin/arm-none-eabi-gdb debug

Configuration

The configuration is quite straightforward. Most of variables used in config.mk and rules.mk can be modified by the project-specific Makefile. For example:

  • SRC_DIR: The main directory where source files are located (. by default)
  • BUILD_DIR: The directory where object files and binaries are stored (./build by default)
  • INC: Include path for header files (-I*.h) or linker scripts (-L*.ld)
  • SRC_ASM: Assembly source files (*.S, *.s) outside the main SRC_DIR directory (e.g. target-specific startup code)
  • SRC_C: C source files (*.c) outside the main SRC_DIR directory
  • SRC_LD: Linker script (*.ld)
  • DEF: Custom macros (-DMACRO equals to #define MACRO)
  • ARCHFLAGS: CPU architecture (see below)
  • FPFLAGS: FLoating point configuration (see below)
  • WARNFLAGS: GCC warning options. You can define your own set of options or disable the unwanted ones by appending -Wno-* flags
  • DBGFLAGS: GCC debugging options (-ggdb by defualt)
  • OPTFLAGS: GCC optimization options (-O3 by defualt)
  • PREPFLAGS: GCC preprocessor options (-MD -MP by defualt)
  • STDFLAGS: GCC C dialect options (-std=gnu99 by default)
  • CXXSTDFLAGS: GCC C++ dialect options (-std=gnu++11 by default)

Configuraiton specific to different debug probes

For openocd.mk:

  • OPENOCD: OpenOCD command (with script selection) to set up debug session. You can use one of the built-in scripts or create your own.

For blackmagic.mk:

  • BLACKMAGIC_PORT: Serial port to be used for the Black Magic Probe

For jlink.mk:

  • JLINK_DEVICE: Target device (Cortex-M0 by default)
  • JLINK_SPEED: Programming speed in Hz (1000 by default)

Configuration for a different target

CM-Makefile can be easily used with a different CPU core than the default Cortex-M0. It's only necessary to configure the ARCHFLAGS and FPFLAGS variables (FPFLAGS defaults to -mfloat-abi=soft):

CPU ARCHFLAGS FPFLAGS
Cortex-M0 (default) -mcpu=cortex-m0 -mfloat-abi=soft
Cortex-M0+ -mcpu=cortex-m0plus -mfloat-abi=soft
Cortex-3 -mcpu=cortex-m3 -mfloat-abi=soft
Cortex-M4 (Soft FP) -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16
Cortex-M4 (Hard FP) -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16

License

CM-Makefile is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

See COPYING and COPYING.LESSER for details.

cm-makefile's People

Contributors

adamheinrich avatar alpo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cm-makefile's Issues

Best way to pass in -L linker option

Hi there,

it looks like you're only expecting the user to specify a single linker script. Is there a nicer way than the following to pass in the linker library directories using -L ?

BIN = app
# snip for brevity
include cm-makefile/config.mk
include cm-makefile/rules.mk

LDFLAGS += -L./linker

Linking math and c++

I am trying to link against CMSIS math library to use an fft but without success.
Furthermore I need to compile and link an extra c++ library for nrf24 modules but it seems your makefile doesn't support c++.
I was trying various options
From Atollic TrueSTUDIO I see
-Wl,--start-group -lc -lm -lcstd++ -lsupc++ -Wl,--end-group
I tried to add this to the LDFLAGS in config.mk but without success.
Can you provide some hints what to do?
Do I need nano.specs for m4?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.