From 611c36fe00979fc8ba17d02587592b15465d6676 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 2 May 2018 00:13:52 +0200 Subject: [PATCH 01/12] Added Makefiles for compiling the two projects --- .gitignore | 1 + .travis.yml | 33 ++-- Brewfile | 2 - gcc-arm-embedded.rb | 35 ---- left/Makefile | 54 ++++++ right/Makefile | 73 ++++++++ right/link/MK22FN512xxx12_flash.ld | 276 +++++++++++++++++++++++++++++ scripts/Makedefs.mk | 211 ++++++++++++++++++++++ 8 files changed, 636 insertions(+), 49 deletions(-) delete mode 100644 Brewfile delete mode 100644 gcc-arm-embedded.rb create mode 100644 left/Makefile create mode 100644 right/Makefile create mode 100644 right/link/MK22FN512xxx12_flash.ld create mode 100644 scripts/Makedefs.mk diff --git a/.gitignore b/.gitignore index 7a7b33a..d963037 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ package-lock.json node_modules +build_make diff --git a/.travis.yml b/.travis.yml index f43ba66..d3735ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,25 +1,34 @@ language: generic + cache: directories: - $HOME/Library/Caches/Homebrew/Cask -install: eclipse -noSplash - -application org.eclipse.equinox.p2.director - -repository http://gnuarmeclipse.sourceforge.net/updates - -installIUs ilg.gnuarmeclipse.managedbuild.cross.feature.group + +install: eclipse -noSplash + -application org.eclipse.equinox.p2.director + -repository http://gnuarmeclipse.sourceforge.net/updates + -installIUs ilg.gnuarmeclipse.managedbuild.cross.feature.group -profileProperties org.eclipse.update.install.features=true -script: eclipse -noSplash - -application org.eclipse.cdt.managedbuilder.core.headlessbuild - -import $TRAVIS_BUILD_DIR/left/build - -import $TRAVIS_BUILD_DIR/right/build - -build all + +before_script: + - tar -xf gcc-arm-none-eabi-7-2017-q4-major-*.tar.bz2 + - export PATH=$PATH:$PWD/gcc-arm-none-eabi-7-2017-q4-major/bin + +script: + - eclipse -noSplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -import $TRAVIS_BUILD_DIR/left/build -import $TRAVIS_BUILD_DIR/right/build -build all + - make -j2 -C $TRAVIS_BUILD_DIR/left + - make -j2 -C $TRAVIS_BUILD_DIR/right + matrix: include: - os: linux sudo: required - before_install: + before_install: - curl https://nixos.org/nix/install | sh && . ~/.nix-profile/etc/profile.d/nix.sh - - nix-env -i gcc-arm-embedded-4.8-2014q1-20140314 - nix-env -i eclipse-cpp + - wget "https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2" - os: osx env: PATH="$PATH:/Applications/Eclipse CPP.app/Contents/MacOS" - before_install: brew update && brew bundle -v + before_install: + - brew cask install eclipse-cpp + - wget "https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-mac.tar.bz2" diff --git a/Brewfile b/Brewfile deleted file mode 100644 index dc60eee..0000000 --- a/Brewfile +++ /dev/null @@ -1,2 +0,0 @@ -cask "eclipse-cpp" -cask "./gcc-arm-embedded.rb" diff --git a/gcc-arm-embedded.rb b/gcc-arm-embedded.rb deleted file mode 100644 index 9712513..0000000 --- a/gcc-arm-embedded.rb +++ /dev/null @@ -1,35 +0,0 @@ -cask 'gcc-arm-embedded' do - version '4_8-2014q3' - sha256 '6b30901738b09a8d22fdfff99e991217444b80ac492a6163af5c06a3baaa3487' - - # launchpad.net/gcc-arm-embedded/ was verified as official when first introduced to the cask - url "https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q3-update/+download/gcc-arm-none-eabi-#{version}-20140805-mac.tar.bz2" - name 'GCC ARM Embedded' - homepage 'https://developer.arm.com/open-source/gnu-toolchain/gnu-rm' - - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-addr2line" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-ar" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-as" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-c++" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-c++filt" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-cpp" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-elfedit" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-g++" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-gcc" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-gcc-ar" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-gcc-nm" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-gcc-ranlib" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-gcov" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-gdb" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-gprof" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-ld" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-ld.bfd" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-nm" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-objcopy" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-objdump" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-ranlib" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-readelf" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-size" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-strings" - binary "gcc-arm-none-eabi-#{version}/bin/arm-none-eabi-strip" -end diff --git a/left/Makefile b/left/Makefile new file mode 100644 index 0000000..2e4b524 --- /dev/null +++ b/left/Makefile @@ -0,0 +1,54 @@ +# Copyright (C) 2018 Kristian Lauszus. All rights reserved. +# +# This software may be distributed and modified under the terms of the GNU +# General Public License version 2 (GPL2) as published by the Free Software +# Foundation and appearing in the file GPL2.TXT included in the packaging of +# this file. Please note that GPL2 Section 2[b] requires that all works based +# on this software must also be made publicly available under the terms of +# the GPL2 ("Copyleft"). +# +# Contact information +# ------------------- +# Kristian Lauszus +# Web : http://www.lauszus.com +# e-mail : lauszus@gmail.com + +# Set project name. +PROJECT_NAME = uhk_left + +# Defines the part type that this project uses. +PART = MKL03Z32VFK4 + +# Defines the linker script to use for the application. +LDSCRIPT = ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/gcc/MKL03Z32xxx4_flash.ld + +# Size of the heap and stack. +HEAP_SIZE = 0 +STACK_SIZE = 0x0050 + +# Set the compiler CPU and FPU options. +CPU = -mcpu=cortex-m0plus +FPU = -mfloat-abi=soft + +# Source files. +SOURCE = $(wildcard src/*.c) \ + ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/system_MKL03Z4.c \ + ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/gcc/startup_MKL03Z4.S \ + ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/drivers/fsl_clock.c \ + ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/drivers/fsl_gpio.c \ + ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/drivers/fsl_i2c.c \ + ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/drivers/fsl_lptmr.c \ + ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/drivers/fsl_smc.c \ + ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/drivers/fsl_spi.c \ + ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/drivers/fsl_tpm.c \ + $(wildcard ../shared/*.c) + +# Header files. +IPATH = src \ + ../lib/KSDK_2.0_MKL03Z8xxx4/CMSIS/Include \ + ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4 \ + ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/drivers \ + ../shared + +# Include main Makefile. +include ../scripts/Makedefs.mk diff --git a/right/Makefile b/right/Makefile new file mode 100644 index 0000000..f6ef801 --- /dev/null +++ b/right/Makefile @@ -0,0 +1,73 @@ +# Copyright (C) 2018 Kristian Lauszus. All rights reserved. +# +# This software may be distributed and modified under the terms of the GNU +# General Public License version 2 (GPL2) as published by the Free Software +# Foundation and appearing in the file GPL2.TXT included in the packaging of +# this file. Please note that GPL2 Section 2[b] requires that all works based +# on this software must also be made publicly available under the terms of +# the GPL2 ("Copyleft"). +# +# Contact information +# ------------------- +# Kristian Lauszus +# Web : http://www.lauszus.com +# e-mail : lauszus@gmail.com + +# Set project name. +PROJECT_NAME = uhk_right + +# Defines the part type that this project uses. +PART = MK22FN512VLH12 + +# Defines the linker script to use for the application. +LDSCRIPT = link/MK22FN512xxx12_flash.ld + +# Address of the app vector table. The bootloader will take up the flash before this address. +BL_APP_VECTOR_TABLE_ADDRESS = 0xc000 + +# Size of the heap and stack. +HEAP_SIZE = 0x2000 +STACK_SIZE = 0x0400 + + # Preprocessor directives. +BUILD_FLAGS = -DCPU_$(PART)_cm4 -DBL_APP_VECTOR_TABLE_ADDRESS=$(BL_APP_VECTOR_TABLE_ADDRESS) -DUSB_STACK_BM -DBL_HAS_BOOTLOADER_CONFIG=1 + +# Set the compiler CPU and FPU options. +CPU = -mcpu=cortex-m4 +FPU = -mfpu=fpv4-sp-d16 -mfloat-abi=hard + +# Source files. +SOURCE = $(wildcard src/*.c) \ + $(wildcard src/*/*.c) \ + $(wildcard src/*/*/*.c) \ + ../lib/bootloader/src/bootloader/src/wormhole.c \ + $(wildcard ../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/device/*.c) \ + $(wildcard ../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/osa/*.c) \ + ../lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/system_MK22F51212.c \ + ../lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/gcc/startup_MK22F51212.S \ + ../lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers/fsl_adc16.c \ + ../lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers/fsl_clock.c \ + ../lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers/fsl_ftm.c \ + ../lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers/fsl_gpio.c \ + ../lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers/fsl_i2c.c \ + ../lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers/fsl_pit.c \ + ../lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers/fsl_sim.c \ + ../lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers/fsl_smc.c \ + $(wildcard ../shared/*.c) + +# Header files. +IPATH = src \ + src/ksdk_usb \ + src/buspal \ + src/buspal/bm_usb \ + ../lib/bootloader/src \ + ../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/device \ + ../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/include \ + ../lib/KSDK_2.0_MK22FN512xxx12/middleware/usb_1.0.0/osa \ + ../lib/KSDK_2.0_MK22FN512xxx12/CMSIS/Include \ + ../lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212 \ + ../lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers \ + ../shared + +# Include main Makefile. +include ../scripts/Makedefs.mk diff --git a/right/link/MK22FN512xxx12_flash.ld b/right/link/MK22FN512xxx12_flash.ld new file mode 100644 index 0000000..dd1e065 --- /dev/null +++ b/right/link/MK22FN512xxx12_flash.ld @@ -0,0 +1,276 @@ +/* +** ################################################################### +** Processors: MK22FN512CAP12 +** MK22FN512VDC12 +** MK22FN512VLH12 +** MK22FN512VLL12 +** MK22FN512VMP12 +** +** Compiler: GNU C Compiler +** Reference manual: K22P121M120SF7RM, Rev. 1, March 24, 2014 +** Version: rev. 2.8, 2015-02-19 +** Build: b151217 +** +** Abstract: +** Linker file for the GNU C Compiler +** +** Copyright (c) 2015 Freescale Semiconductor, Inc. +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without modification, +** are permitted provided that the following conditions are met: +** +** o Redistributions of source code must retain the above copyright notice, this list +** of conditions and the following disclaimer. +** +** o Redistributions in binary form must reproduce the above copyright notice, this +** list of conditions and the following disclaimer in the documentation and/or +** other materials provided with the distribution. +** +** o Neither the name of Freescale Semiconductor, Inc. nor the names of its +** contributors may be used to endorse or promote products derived from this +** software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +** +** http: www.freescale.com +** mail: support@freescale.com +** +** ################################################################### +*/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x2000; +STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400; +M_VECTOR_RAM_SIZE = DEFINED(__ram_vector_table__) ? 0x0400 : 0x0; + +/* This should match the value in bootloader_config.h if KBOOT is used */ +BL_APP_VECTOR_TABLE_ADDRESS = DEFINED(__bl_app_vector_table_address__) ? __bl_app_vector_table_address__ : 0; + +/* Specify the memory areas */ +MEMORY +{ + m_interrupts (RX) : ORIGIN = 0x0 + BL_APP_VECTOR_TABLE_ADDRESS, LENGTH = 0x00000400 + m_text (RX) : ORIGIN = 0x00000400 + BL_APP_VECTOR_TABLE_ADDRESS, LENGTH = 512K - 0x400 - BL_APP_VECTOR_TABLE_ADDRESS + m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000 + m_data_2 (RW) : ORIGIN = 0x20000000, LENGTH = 0x0000FF00 + m_noinit (RW) : ORIGIN = 0x2000FF00, LENGTH = 0x000000FF +} + +/* Define output sections */ +SECTIONS +{ + /* The startup code goes first into internal flash */ + .interrupts : + { + __VECTOR_TABLE = .; + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } > m_interrupts + + /* The program code and other data goes into internal flash */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + KEEP (*(.init)) + KEEP (*(.fini)) + . = ALIGN(4); + } > m_text + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > m_text + + .ARM : + { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } > m_text + + .ctors : + { + __CTOR_LIST__ = .; + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + from the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + __CTOR_END__ = .; + } > m_text + + .dtors : + { + __DTOR_LIST__ = .; + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + __DTOR_END__ = .; + } > m_text + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } > m_text + + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } > m_text + + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } > m_text + + __etext = .; /* define a global symbol at end of code */ + __DATA_ROM = .; /* Symbol is used by startup for data initialization */ + + .interrupts_ram : + { + . = ALIGN(4); + __VECTOR_RAM__ = .; + __interrupts_ram_start__ = .; /* Create a global symbol at data start */ + *(.m_interrupts_ram) /* This is a user defined section */ + . += M_VECTOR_RAM_SIZE; + . = ALIGN(4); + __interrupts_ram_end__ = .; /* Define a global symbol at data end */ + } > m_data + + __VECTOR_RAM = DEFINED(__ram_vector_table__) ? __VECTOR_RAM__ : ORIGIN(m_interrupts); + __RAM_VECTOR_TABLE_SIZE_BYTES = DEFINED(__ram_vector_table__) ? (__interrupts_ram_end__ - __interrupts_ram_start__) : 0x0; + + .data : AT(__DATA_ROM) + { + . = ALIGN(4); + __DATA_RAM = .; + __data_start__ = .; /* create a global symbol at data start */ + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + KEEP(*(.jcr*)) + . = ALIGN(4); + __data_end__ = .; /* define a global symbol at data end */ + } > m_data + + __DATA_END = __DATA_ROM + (__data_end__ - __data_start__); + text_end = ORIGIN(m_text) + LENGTH(m_text); + ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data") + + /* Uninitialized data section */ + .bss : ALIGN(4) + { + /* This is used by the startup in order to initialize the .bss section */ + __START_BSS = .; + __bss_start__ = .; + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + } > m_data + + .m_usb_bdt (NOLOAD) : + { + . = ALIGN(512); + *(m_usb_bdt) + } > m_data + + .m_usb_global (NOLOAD) : + { + *(m_usb_global) + __bss_end__ = .; + __END_BSS = .; + } > m_data + + .m_data_2 : + { + . = ALIGN(4); + *(.m_data_2) /* This is an User defined section */ + . = ALIGN(4); + } > m_data_2 + + .heap : + { + . = ALIGN(8); + __end__ = .; + PROVIDE(end = .); + __HeapBase = .; + . += HEAP_SIZE; + __HeapLimit = .; + __heap_limit = .; /* Add for _sbrk */ + } > m_data_2 + + .stack : + { + . = ALIGN(8); + . += STACK_SIZE; + } > m_data_2 + + /* Initializes stack on the end of block */ + __StackTop = ORIGIN(m_data_2) + LENGTH(m_data_2); + __StackLimit = __StackTop - STACK_SIZE; + PROVIDE(__stack = __StackTop); + + .ARM.attributes 0 : { *(.ARM.attributes) } + + ASSERT(__StackLimit >= __HeapLimit, "region m_data_2 overflowed with stack and heap") + + .noinit (NOLOAD): + { + . = ALIGN(4); + _noinit = .; + + *(.noinit .noinit.*) + + . = ALIGN(4) ; + _end_noinit = .; + } > m_noinit + + /* Mandatory to be word aligned, _sbrk assumes this */ + PROVIDE ( end = _end_noinit ); /* was _ebss */ + PROVIDE ( _end = _end_noinit ); + PROVIDE ( __end = _end_noinit ); + PROVIDE ( __end__ = _end_noinit ); +} diff --git a/scripts/Makedefs.mk b/scripts/Makedefs.mk new file mode 100644 index 0000000..98fc69f --- /dev/null +++ b/scripts/Makedefs.mk @@ -0,0 +1,211 @@ +# Copyright (C) 2018 Kristian Lauszus. All rights reserved. +# +# This software may be distributed and modified under the terms of the GNU +# General Public License version 2 (GPL2) as published by the Free Software +# Foundation and appearing in the file GPL2.TXT included in the packaging of +# this file. Please note that GPL2 Section 2[b] requires that all works based +# on this software must also be made publicly available under the terms of +# the GPL2 ("Copyleft"). +# +# Contact information +# ------------------- +# Kristian Lauszus +# Web : http://www.lauszus.com +# e-mail : lauszus@gmail.com + +# Debug using Semihosting. +SEMIHOSTING ?= 0 + +# Build directory. +BUILD_DIR ?= build_make + + # Preprocessor directives. +BUILD_FLAGS += -D__NEWLIB__ -D__USE_CMSIS -D__MCUXPRESSO -DCPU_$(PART) -D__STARTUP_CLEAR_BSS + +# Path to project object file. +PROJECT_OBJ = $(BUILD_DIR)/$(PROJECT_NAME).axf + +# Set the prefix for the tools to use. +PREFIX ?= arm-none-eabi + +# Determine if we are on a Windows machine and set the .exe suffix. +# We can not use the suffix command, as the PREFIX might contain spaces. +UNAME_S := $(shell uname -s) +ifeq ($(OS),Windows_NT) # Native Windows. + SUFFIX := .exe +endif + +# The command for calling the compilers. +CC = $(PREFIX)-gcc$(SUFFIX) +CXX = $(PREFIX)-g++$(SUFFIX) + +# The command for calling the linker. +LD = $(PREFIX)-g++$(SUFFIX) + +# The command for extracting images from the linked executables. +OBJCOPY = $(PREFIX)-objcopy$(SUFFIX) + +# The command for the size tool. +SIZE = $(PREFIX)-size$(SUFFIX) + +# Auto-dependency generation flags. +DEPS = -MMD -MP + +# The flags passed to the assembler. +AFLAGS = -mthumb \ + $(CPU) \ + $(FPU) \ + $(DEPS) \ + $(BUILD_FLAGS) \ + -x assembler-with-cpp + +# The flags passed to the compiler. +CFLAGS = -mthumb \ + $(CPU) \ + $(FPU) \ + $(DEPS) \ + -fno-builtin \ + -ffunction-sections \ + -fdata-sections \ + -fno-common \ + -Wdouble-promotion \ + -Woverflow \ + -Wall \ + -Wshadow \ + $(BUILD_FLAGS) + +# Compiler options for C++ only. +CXXFLAGS = -felide-constructors -fno-exceptions -fno-rtti + +# Set the C/C++ standard to use. +CSTD = -std=gnu11 +CXXSTD = -std=gnu++14 + +# Make all warnings into errors when building using Travis CI. +ifdef TRAVIS + CFLAGS += -Werror +endif + +# Set default value for the bootloader vector table address. +BL_APP_VECTOR_TABLE_ADDRESS ?= 0 + +# The flags passed to the linker. +LDFLAGS = --specs=nano.specs -mthumb $(CPU) $(FPU) -T $(LDSCRIPT) -Wl,-Map=$(PROJECT_OBJ:.axf=.map),--gc-sections,-print-memory-usage,-no-wchar-size-warning,--defsym=__heap_size__=$(HEAP_SIZE),--defsym=__stack_size__=$(STACK_SIZE),--defsym=__bl_app_vector_table_address__=$(BL_APP_VECTOR_TABLE_ADDRESS) + +# Include the following archives. +LDARCHIVES = -Wl,--start-group -lg -lgcc -lm -Wl,--end-group + +# Add flags to the build flags and linker depending on the build settings. +ifeq ($(SEMIHOSTING),1) + # Include Semihost library. + LDARCHIVES += -lcr_newlib_semihost + + # Enable printf floating numbers. + LDFLAGS += -u _printf_float +else + # Include libnosys.a if Semihosting is disabled. + LDARCHIVES += -lnosys +endif + +# Check if the DEBUG environment variable is set. +DEBUG ?= 1 +ifeq ($(DEBUG),1) + CFLAGS += -O3 -g3 -DDEBUG +else + CFLAGS += -O3 -DNDEBUG +endif + +# Add the include file paths to AFLAGS and CFLAGS. +AFLAGS += $(patsubst %,-I%,$(subst :, ,$(IPATH))) +CFLAGS += $(patsubst %,-I%,$(subst :, ,$(IPATH))) + +# Create lists of C, C++ and assembly objects. +C_OBJS := $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(basename $(filter %.c,$(abspath $(SOURCE)))))) +CPP_OBJS := $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(basename $(filter %.cpp,$(abspath $(SOURCE)))))) +S_OBJS := $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(basename $(filter %.S,$(abspath $(SOURCE)))))) + +# Create a list of all objects. +OBJS := $(C_OBJS) $(CPP_OBJS) $(S_OBJS) + +# Define the commands used for compiling the project. +LD_CMD = $(LD) $(LDFLAGS) -o $(@) $(filter %.o %.a, $(^)) $(LDARCHIVES) +CC_CMD = $(CC) $(CFLAGS) $(CSTD) -c $(<) -o $(@) +CXX_CMD = $(CXX) $(CFLAGS) $(CXXFLAGS) $(CXXSTD) -c $(<) -o $(@) +AS_CMD = $(CC) $(AFLAGS) $(CSTD) -c $(<) -o $(@) + +# Everyone need colors in their life! +INTERACTIVE := $(shell [ -t 0 ] && echo 1) +ifeq ($(INTERACTIVE),1) + color_default = \033[0m + color_bold = \033[01m + color_red = \033[31m + color_green = \033[32m + color_yellow = \033[33m + color_blue = \033[34m + color_magenta = \033[35m + color_cyan = \033[36m + color_orange = \033[38;5;172m + color_light_blue = \033[38;5;039m + color_gray = \033[38;5;008m + color_purple = \033[38;5;097m +endif + +.PHONY: all clean + +# The default rule, which causes the project to be built. +all: $(PROJECT_OBJ) + +# The rule to clean out all the build products. +clean: + @rm -rf $(BUILD_DIR) $(wildcard *~) + @echo "$(color_red)Done cleaning!$(color_default)" + +# Rebuild all objects when the Makefile changes. +$(OBJS): Makefile + +# The rule for linking the application. +$(PROJECT_OBJ): $(OBJS) $(LDSCRIPT) + @if [ '$(VERBOSE)' = 1 ]; then \ + echo $(LD_CMD); \ + else \ + echo " $(color_purple)LD$(color_default) $(notdir $(@))"; \ + fi + @echo + @$(LD_CMD) + @echo + @if [ '$(VERBOSE)' = 1 ]; then \ + $(SIZE) -Ax $(@); \ + fi + @$(OBJCOPY) -O binary $(@) $(@:.axf=.bin) + @$(OBJCOPY) -O ihex $(@) $(@:.axf=.hex) + +# The rule for building the object files from each source file. +$(C_OBJS): $(BUILD_DIR)/%.o : %.c + @mkdir -p $(@D) + @if [ '$(VERBOSE)' = 1 ]; then \ + echo $(CC_CMD); \ + else \ + echo " $(color_green)CC$(color_default) $(notdir $(<))"; \ + fi + @$(CC_CMD) + +$(CPP_OBJS): $(BUILD_DIR)/%.o : %.cpp + @mkdir -p $(@D) + @if [ '$(VERBOSE)' = 1 ]; then \ + echo $(CXX_CMD); \ + else \ + echo " $(color_cyan)CXX$(color_default) $(notdir $(<))"; \ + fi + @$(CXX_CMD) + +$(S_OBJS): $(BUILD_DIR)/%.o: %.S + @mkdir -p $(@D) + @if [ '$(VERBOSE)' = 1 ]; then \ + echo $(AS_CMD); \ + else \ + echo " $(color_magenta)AS$(color_default) $(notdir $(<))"; \ + fi + @$(AS_CMD) + +# Include the automatically generated dependency files. +-include $(OBJS:.o=.d) From d9d26814e8620e45d40e23619f8ea7ac52bb94d4 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 2 May 2018 00:35:28 +0200 Subject: [PATCH 02/12] Fix warnings --- right/src/buspal/command.c | 3 --- right/src/buspal/packet/serial_packet.c | 2 +- right/src/led_display.c | 2 +- right/src/main.c | 2 +- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/right/src/buspal/command.c b/right/src/buspal/command.c index 99e9445..e6cf4c1 100644 --- a/right/src/buspal/command.c +++ b/right/src/buspal/command.c @@ -593,9 +593,6 @@ static status_t handle_command_internal(uint8_t *packet, uint32_t packetLength) else { #if FIXED_BUSPAL_BOOTLOADER - size_t offset; - int res; - status = kStatus_Success; /* set default */ res = WaitForStartByte(rxBuf, &offset); if (res==1 && offset==1) diff --git a/right/src/buspal/packet/serial_packet.c b/right/src/buspal/packet/serial_packet.c index cf561b3..21ff990 100644 --- a/right/src/buspal/packet/serial_packet.c +++ b/right/src/buspal/packet/serial_packet.c @@ -110,7 +110,7 @@ status_t serial_packet_read(const peripheral_descriptor_t *self, // Receive the framing data packet. isPacketOk = true; - status_t status = read_data_packet(&framingPacket, g_serialContext.data, packetType); + status = read_data_packet(&framingPacket, g_serialContext.data, packetType); if (status != kStatus_Success) { // No packet available. diff --git a/right/src/led_display.c b/right/src/led_display.c index 7a7e878..76922b4 100644 --- a/right/src/led_display.c +++ b/right/src/led_display.c @@ -109,7 +109,7 @@ void LedDisplay_SetIcon(led_display_icon_t icon, bool isEnabled) void LedDisplay_UpdateIcons(void) { - for (uint8_t i=0; i<=LedDisplayIcon_Last; i++) { + for (led_display_icon_t i=0; i<=LedDisplayIcon_Last; i++) { LedDisplay_SetIcon(i, ledIconStates[i]); } } diff --git a/right/src/main.c b/right/src/main.c index 2897680..12772f2 100644 --- a/right/src/main.c +++ b/right/src/main.c @@ -24,7 +24,7 @@ static void hardwareConfigurationReadFinished(void) EEPROM_LaunchTransfer(EepromOperation_Read, ConfigBufferId_StagingUserConfig, userConfigurationReadFinished); } -void main(void) +int main(void) { InitClock(); InitPeripherals(); From 379d82798296c8d2a37b304a73940e4bbeffab1f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 2 May 2018 00:45:47 +0200 Subject: [PATCH 03/12] Only compile the project using Make --- .travis.yml | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index d3735ee..896f63a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,34 +1,15 @@ -language: generic +language: c -cache: - directories: - - $HOME/Library/Caches/Homebrew/Cask +os: + - linux + - osx -install: eclipse -noSplash - -application org.eclipse.equinox.p2.director - -repository http://gnuarmeclipse.sourceforge.net/updates - -installIUs ilg.gnuarmeclipse.managedbuild.cross.feature.group - -profileProperties org.eclipse.update.install.features=true - -before_script: - - tar -xf gcc-arm-none-eabi-7-2017-q4-major-*.tar.bz2 - - export PATH=$PATH:$PWD/gcc-arm-none-eabi-7-2017-q4-major/bin +install: + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then os_name=mac; else os_name=linux; fi + - wget "https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-$os_name.tar.bz2" + - tar -xf gcc-arm-none-eabi-7-2017-q4-major-*.tar.bz2 + - export PATH=$PATH:$PWD/gcc-arm-none-eabi-7-2017-q4-major/bin script: - - eclipse -noSplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -import $TRAVIS_BUILD_DIR/left/build -import $TRAVIS_BUILD_DIR/right/build -build all - - make -j2 -C $TRAVIS_BUILD_DIR/left - - make -j2 -C $TRAVIS_BUILD_DIR/right - -matrix: - include: - - os: linux - sudo: required - before_install: - - curl https://nixos.org/nix/install | sh && . ~/.nix-profile/etc/profile.d/nix.sh - - nix-env -i eclipse-cpp - - wget "https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2" - - os: osx - env: PATH="$PATH:/Applications/Eclipse CPP.app/Contents/MacOS" - before_install: - - brew cask install eclipse-cpp - - wget "https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-mac.tar.bz2" + - make -j2 -C left + - make -j2 -C right From 47e026006e6b45fd425c973280f6cfbabaa64180 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 2 May 2018 01:05:40 +0200 Subject: [PATCH 04/12] Forgot to fix linker errors for both linker scripts in: https://github.com/UltimateHackingKeyboard/firmware/pull/104/commits/e0528e1714fc3796763b14c73e8b3fb43dbffeef --- right/build/MK22FN512xxx12_flash.original.ld | 29 ++++++++------------ 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/right/build/MK22FN512xxx12_flash.original.ld b/right/build/MK22FN512xxx12_flash.original.ld index 0dbdcee..bf498dd 100644 --- a/right/build/MK22FN512xxx12_flash.original.ld +++ b/right/build/MK22FN512xxx12_flash.original.ld @@ -204,21 +204,27 @@ SECTIONS text_end = ORIGIN(m_text) + LENGTH(m_text); ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data") - USB_RAM_GAP = DEFINED(__usb_ram_size__) ? __usb_ram_size__ : 0x800; /* Uninitialized data section */ - .bss : + .bss : ALIGN(4) { /* This is used by the startup in order to initialize the .bss section */ - . = ALIGN(4); __START_BSS = .; __bss_start__ = .; *(.bss) *(.bss*) - . = ALIGN(512); - USB_RAM_START = .; - . += USB_RAM_GAP; *(COMMON) . = ALIGN(4); + } > m_data + + .m_usb_bdt (NOLOAD) : + { + . = ALIGN(512); + *(m_usb_bdt) + } > m_data + + .m_usb_global (NOLOAD) : + { + *(m_usb_global) __bss_end__ = .; __END_BSS = .; } > m_data @@ -247,17 +253,6 @@ SECTIONS . += STACK_SIZE; } > m_data_2 - m_usb_bdt USB_RAM_START (NOLOAD) : - { - *(m_usb_bdt) - USB_RAM_BDT_END = .; - } - - m_usb_global USB_RAM_BDT_END (NOLOAD) : - { - *(m_usb_global) - } - /* Initializes stack on the end of block */ __StackTop = ORIGIN(m_data_2) + LENGTH(m_data_2); __StackLimit = __StackTop - STACK_SIZE; From a2fae5bbef393f8612ecb6fc758433c3e8ba071e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 2 May 2018 01:08:20 +0200 Subject: [PATCH 05/12] Readded Eclipse build --- .travis.yml | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 896f63a..904846b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,34 @@ language: c -os: - - linux - - osx +cache: + directories: + - $HOME/Library/Caches/Homebrew/Cask -install: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then os_name=mac; else os_name=linux; fi - - wget "https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-$os_name.tar.bz2" +install: eclipse -noSplash + -application org.eclipse.equinox.p2.director + -repository http://gnuarmeclipse.sourceforge.net/updates + -installIUs ilg.gnuarmeclipse.managedbuild.cross.feature.group + -profileProperties org.eclipse.update.install.features=true + +before_script: - tar -xf gcc-arm-none-eabi-7-2017-q4-major-*.tar.bz2 - export PATH=$PATH:$PWD/gcc-arm-none-eabi-7-2017-q4-major/bin script: + - eclipse -noSplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -import $TRAVIS_BUILD_DIR/left/build -import $TRAVIS_BUILD_DIR/right/build -build all - make -j2 -C left - make -j2 -C right + +matrix: + include: + - os: linux + sudo: required + before_install: + - curl https://nixos.org/nix/install | sh && . ~/.nix-profile/etc/profile.d/nix.sh + - nix-env -i eclipse-cpp + - wget "https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2" + - os: osx + env: PATH="$PATH:/Applications/Eclipse CPP.app/Contents/MacOS" + before_install: + - brew cask install eclipse-cpp + - wget "https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-mac.tar.bz2" From 2214f00667fcc416f44746889631e8ed6d1b6564 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 2 May 2018 02:31:39 +0200 Subject: [PATCH 06/12] Added command for flashing the images via the bootloader --- left/Makefile | 3 +++ right/Makefile | 3 +++ scripts/Makedefs.mk | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/left/Makefile b/left/Makefile index 2e4b524..87cabf4 100644 --- a/left/Makefile +++ b/left/Makefile @@ -30,6 +30,9 @@ STACK_SIZE = 0x0050 CPU = -mcpu=cortex-m0plus FPU = -mfloat-abi=soft +# Command for flashing the left half of the keyboard. +FLASH_CMD = node ../lib/agent/packages/usb/update-module-firmware.js leftHalf $(PROJECT_OBJ:.axf=.bin) + # Source files. SOURCE = $(wildcard src/*.c) \ ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/system_MKL03Z4.c \ diff --git a/right/Makefile b/right/Makefile index f6ef801..e0107cf 100644 --- a/right/Makefile +++ b/right/Makefile @@ -36,6 +36,9 @@ BUILD_FLAGS = -DCPU_$(PART)_cm4 -DBL_APP_VECTOR_TABLE_ADDRESS=$(BL_APP_VECTOR_TA CPU = -mcpu=cortex-m4 FPU = -mfpu=fpv4-sp-d16 -mfloat-abi=hard +# Command for flashing the right half of the keyboard. +FLASH_CMD = node ../lib/agent/packages/usb/update-device-firmware.js $(PROJECT_OBJ:.axf=.hex) + # Source files. SOURCE = $(wildcard src/*.c) \ $(wildcard src/*/*.c) \ diff --git a/scripts/Makedefs.mk b/scripts/Makedefs.mk index 98fc69f..f01f6fc 100644 --- a/scripts/Makedefs.mk +++ b/scripts/Makedefs.mk @@ -150,7 +150,7 @@ ifeq ($(INTERACTIVE),1) color_purple = \033[38;5;097m endif -.PHONY: all clean +.PHONY: all clean flash # The default rule, which causes the project to be built. all: $(PROJECT_OBJ) @@ -160,6 +160,9 @@ clean: @rm -rf $(BUILD_DIR) $(wildcard *~) @echo "$(color_red)Done cleaning!$(color_default)" +flash: all + @$(FLASH_CMD) || exit 1 + # Rebuild all objects when the Makefile changes. $(OBJS): Makefile From b8268f55a3c4981e738f9c1f15eea3c5c5847d49 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 2 May 2018 02:35:03 +0200 Subject: [PATCH 07/12] Moved the BL_APP_VECTOR_TABLE_ADDRESS define into Makedefs.mk --- right/Makefile | 12 ++++++------ scripts/Makedefs.mk | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/right/Makefile b/right/Makefile index e0107cf..ec7edf1 100644 --- a/right/Makefile +++ b/right/Makefile @@ -22,16 +22,10 @@ PART = MK22FN512VLH12 # Defines the linker script to use for the application. LDSCRIPT = link/MK22FN512xxx12_flash.ld -# Address of the app vector table. The bootloader will take up the flash before this address. -BL_APP_VECTOR_TABLE_ADDRESS = 0xc000 - # Size of the heap and stack. HEAP_SIZE = 0x2000 STACK_SIZE = 0x0400 - # Preprocessor directives. -BUILD_FLAGS = -DCPU_$(PART)_cm4 -DBL_APP_VECTOR_TABLE_ADDRESS=$(BL_APP_VECTOR_TABLE_ADDRESS) -DUSB_STACK_BM -DBL_HAS_BOOTLOADER_CONFIG=1 - # Set the compiler CPU and FPU options. CPU = -mcpu=cortex-m4 FPU = -mfpu=fpv4-sp-d16 -mfloat-abi=hard @@ -39,6 +33,12 @@ FPU = -mfpu=fpv4-sp-d16 -mfloat-abi=hard # Command for flashing the right half of the keyboard. FLASH_CMD = node ../lib/agent/packages/usb/update-device-firmware.js $(PROJECT_OBJ:.axf=.hex) +# Preprocessor directives. +BUILD_FLAGS = -DCPU_$(PART)_cm4 -DUSB_STACK_BM -DBL_HAS_BOOTLOADER_CONFIG=1 + +# Address of the app vector table. The bootloader will take up the flash before this address. +BL_APP_VECTOR_TABLE_ADDRESS = 0xc000 + # Source files. SOURCE = $(wildcard src/*.c) \ $(wildcard src/*/*.c) \ diff --git a/scripts/Makedefs.mk b/scripts/Makedefs.mk index f01f6fc..6b281ea 100644 --- a/scripts/Makedefs.mk +++ b/scripts/Makedefs.mk @@ -19,8 +19,11 @@ SEMIHOSTING ?= 0 # Build directory. BUILD_DIR ?= build_make - # Preprocessor directives. -BUILD_FLAGS += -D__NEWLIB__ -D__USE_CMSIS -D__MCUXPRESSO -DCPU_$(PART) -D__STARTUP_CLEAR_BSS +# Set default value (no bootloader) for the bootloader vector table address. +BL_APP_VECTOR_TABLE_ADDRESS ?= 0 + +# Preprocessor directives. +BUILD_FLAGS += -D__NEWLIB__ -D__USE_CMSIS -D__MCUXPRESSO -DCPU_$(PART) -D__STARTUP_CLEAR_BSS -DBL_APP_VECTOR_TABLE_ADDRESS=$(BL_APP_VECTOR_TABLE_ADDRESS) # Path to project object file. PROJECT_OBJ = $(BUILD_DIR)/$(PROJECT_NAME).axf @@ -86,9 +89,6 @@ ifdef TRAVIS CFLAGS += -Werror endif -# Set default value for the bootloader vector table address. -BL_APP_VECTOR_TABLE_ADDRESS ?= 0 - # The flags passed to the linker. LDFLAGS = --specs=nano.specs -mthumb $(CPU) $(FPU) -T $(LDSCRIPT) -Wl,-Map=$(PROJECT_OBJ:.axf=.map),--gc-sections,-print-memory-usage,-no-wchar-size-warning,--defsym=__heap_size__=$(HEAP_SIZE),--defsym=__stack_size__=$(STACK_SIZE),--defsym=__bl_app_vector_table_address__=$(BL_APP_VECTOR_TABLE_ADDRESS) From 101abffec41b91c49acdd1bab64fe29b5602fcec Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 2 May 2018 02:53:54 +0200 Subject: [PATCH 08/12] Moved the linker script into the source directory --- right/Makefile | 2 +- right/{ => src}/link/MK22FN512xxx12_flash.ld | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename right/{ => src}/link/MK22FN512xxx12_flash.ld (100%) diff --git a/right/Makefile b/right/Makefile index ec7edf1..c05fdec 100644 --- a/right/Makefile +++ b/right/Makefile @@ -20,7 +20,7 @@ PROJECT_NAME = uhk_right PART = MK22FN512VLH12 # Defines the linker script to use for the application. -LDSCRIPT = link/MK22FN512xxx12_flash.ld +LDSCRIPT = src/link/MK22FN512xxx12_flash.ld # Size of the heap and stack. HEAP_SIZE = 0x2000 diff --git a/right/link/MK22FN512xxx12_flash.ld b/right/src/link/MK22FN512xxx12_flash.ld similarity index 100% rename from right/link/MK22FN512xxx12_flash.ld rename to right/src/link/MK22FN512xxx12_flash.ld From aa4105bdc3919a9afe6f7f2e4e637a2db60af99e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 2 May 2018 03:00:30 +0200 Subject: [PATCH 09/12] Updated license to "GPLv2 or later", so it is compatible with GPLv3 --- left/Makefile | 10 ++++------ right/Makefile | 10 ++++------ scripts/Makedefs.mk | 10 ++++------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/left/Makefile b/left/Makefile index 87cabf4..7941a9c 100644 --- a/left/Makefile +++ b/left/Makefile @@ -1,11 +1,9 @@ # Copyright (C) 2018 Kristian Lauszus. All rights reserved. # -# This software may be distributed and modified under the terms of the GNU -# General Public License version 2 (GPL2) as published by the Free Software -# Foundation and appearing in the file GPL2.TXT included in the packaging of -# this file. Please note that GPL2 Section 2[b] requires that all works based -# on this software must also be made publicly available under the terms of -# the GPL2 ("Copyleft"). +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # # Contact information # ------------------- diff --git a/right/Makefile b/right/Makefile index c05fdec..ab882d3 100644 --- a/right/Makefile +++ b/right/Makefile @@ -1,11 +1,9 @@ # Copyright (C) 2018 Kristian Lauszus. All rights reserved. # -# This software may be distributed and modified under the terms of the GNU -# General Public License version 2 (GPL2) as published by the Free Software -# Foundation and appearing in the file GPL2.TXT included in the packaging of -# this file. Please note that GPL2 Section 2[b] requires that all works based -# on this software must also be made publicly available under the terms of -# the GPL2 ("Copyleft"). +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # # Contact information # ------------------- diff --git a/scripts/Makedefs.mk b/scripts/Makedefs.mk index 6b281ea..3dca4c2 100644 --- a/scripts/Makedefs.mk +++ b/scripts/Makedefs.mk @@ -1,11 +1,9 @@ # Copyright (C) 2018 Kristian Lauszus. All rights reserved. # -# This software may be distributed and modified under the terms of the GNU -# General Public License version 2 (GPL2) as published by the Free Software -# Foundation and appearing in the file GPL2.TXT included in the packaging of -# this file. Please note that GPL2 Section 2[b] requires that all works based -# on this software must also be made publicly available under the terms of -# the GPL2 ("Copyleft"). +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. # # Contact information # ------------------- From 0c4c736552e29074f6c3001fd7ee7407564262e4 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 2 May 2018 09:34:19 +0200 Subject: [PATCH 10/12] Use automatic variables for getting the file name and use the MAKEFILE_LIST variable to rebuild the project when any of the Makefiles change --- scripts/Makedefs.mk | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/Makedefs.mk b/scripts/Makedefs.mk index 3dca4c2..a0f6fc1 100644 --- a/scripts/Makedefs.mk +++ b/scripts/Makedefs.mk @@ -161,21 +161,21 @@ clean: flash: all @$(FLASH_CMD) || exit 1 -# Rebuild all objects when the Makefile changes. -$(OBJS): Makefile +# Rebuild all objects when the Makefiles change. +$(OBJS): $(MAKEFILE_LIST) # The rule for linking the application. $(PROJECT_OBJ): $(OBJS) $(LDSCRIPT) - @if [ '$(VERBOSE)' = 1 ]; then \ - echo $(LD_CMD); \ - else \ - echo " $(color_purple)LD$(color_default) $(notdir $(@))"; \ + @if [ '$(VERBOSE)' = 1 ]; then \ + echo $(LD_CMD); \ + else \ + echo " $(color_purple)LD$(color_default) $(@F)"; \ fi @echo @$(LD_CMD) @echo - @if [ '$(VERBOSE)' = 1 ]; then \ - $(SIZE) -Ax $(@); \ + @if [ '$(VERBOSE)' = 1 ]; then \ + $(SIZE) -Ax $(@); \ fi @$(OBJCOPY) -O binary $(@) $(@:.axf=.bin) @$(OBJCOPY) -O ihex $(@) $(@:.axf=.hex) @@ -183,28 +183,28 @@ $(PROJECT_OBJ): $(OBJS) $(LDSCRIPT) # The rule for building the object files from each source file. $(C_OBJS): $(BUILD_DIR)/%.o : %.c @mkdir -p $(@D) - @if [ '$(VERBOSE)' = 1 ]; then \ - echo $(CC_CMD); \ - else \ - echo " $(color_green)CC$(color_default) $(notdir $(<))"; \ + @if [ '$(VERBOSE)' = 1 ]; then \ + echo $(CC_CMD); \ + else \ + echo " $(color_green)CC$(color_default) $( Date: Wed, 2 May 2018 10:37:27 +0200 Subject: [PATCH 11/12] Added JLink flash scripts --- left/Makefile | 3 +++ right/Makefile | 3 +++ scripts/Makedefs.mk | 21 +++++++++++++++++++-- scripts/flash-left.jlink | 7 +++++++ scripts/flash-right.jlink | 7 +++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 scripts/flash-left.jlink create mode 100644 scripts/flash-right.jlink diff --git a/left/Makefile b/left/Makefile index 7941a9c..1255771 100644 --- a/left/Makefile +++ b/left/Makefile @@ -31,6 +31,9 @@ FPU = -mfloat-abi=soft # Command for flashing the left half of the keyboard. FLASH_CMD = node ../lib/agent/packages/usb/update-module-firmware.js leftHalf $(PROJECT_OBJ:.axf=.bin) +# Path to the JLink script used for the left half. +JLINK_SCRIPT = ../scripts/flash-left.jlink + # Source files. SOURCE = $(wildcard src/*.c) \ ../lib/KSDK_2.0_MKL03Z8xxx4/devices/MKL03Z4/system_MKL03Z4.c \ diff --git a/right/Makefile b/right/Makefile index ab882d3..0ae5f00 100644 --- a/right/Makefile +++ b/right/Makefile @@ -31,6 +31,9 @@ FPU = -mfpu=fpv4-sp-d16 -mfloat-abi=hard # Command for flashing the right half of the keyboard. FLASH_CMD = node ../lib/agent/packages/usb/update-device-firmware.js $(PROJECT_OBJ:.axf=.hex) +# Path to the JLink script used for the right half. +JLINK_SCRIPT = ../scripts/flash-right.jlink + # Preprocessor directives. BUILD_FLAGS = -DCPU_$(PART)_cm4 -DUSB_STACK_BM -DBL_HAS_BOOTLOADER_CONFIG=1 diff --git a/scripts/Makedefs.mk b/scripts/Makedefs.mk index a0f6fc1..c344580 100644 --- a/scripts/Makedefs.mk +++ b/scripts/Makedefs.mk @@ -29,10 +29,24 @@ PROJECT_OBJ = $(BUILD_DIR)/$(PROJECT_NAME).axf # Set the prefix for the tools to use. PREFIX ?= arm-none-eabi +# Set WIN=1 manually for Windows Subsystem for Linux. +WIN ?= 0 + # Determine if we are on a Windows machine and set the .exe suffix. -# We can not use the suffix command, as the PREFIX might contain spaces. UNAME_S := $(shell uname -s) ifeq ($(OS),Windows_NT) # Native Windows. + WIN = 1 +endif + +# Set J-Link executable. +ifeq ($(WIN),1) + JLINK := JLink.exe +else + JLINK := JLinkExe +endif + +# We can not use the suffix command, as the PREFIX might contain spaces. +ifeq ($(WIN),1) SUFFIX := .exe endif @@ -148,7 +162,7 @@ ifeq ($(INTERACTIVE),1) color_purple = \033[38;5;097m endif -.PHONY: all clean flash +.PHONY: all clean flash flash-jlink # The default rule, which causes the project to be built. all: $(PROJECT_OBJ) @@ -161,6 +175,9 @@ clean: flash: all @$(FLASH_CMD) || exit 1 +flash-jlink: all + $(JLINK) -if SWD -CommandFile $(JLINK_SCRIPT) || exit 1 + # Rebuild all objects when the Makefiles change. $(OBJS): $(MAKEFILE_LIST) diff --git a/scripts/flash-left.jlink b/scripts/flash-left.jlink new file mode 100644 index 0000000..a250d9d --- /dev/null +++ b/scripts/flash-left.jlink @@ -0,0 +1,7 @@ +speed 4000 +device MKL03Z32xxx4 +connect +loadfile build_make/uhk_left.hex +RSetType 2 +r +qc diff --git a/scripts/flash-right.jlink b/scripts/flash-right.jlink new file mode 100644 index 0000000..54b3810 --- /dev/null +++ b/scripts/flash-right.jlink @@ -0,0 +1,7 @@ +speed 4000 +device MK22FN512xxx12 +connect +loadfile build_make/uhk_right.hex +RSetType 2 +r +qc From 10802f3f73f2d3ca99907d1e361f567393643de7 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 2 May 2018 10:37:51 +0200 Subject: [PATCH 12/12] Build both the debug and release builds --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 904846b..ccc7eaa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,8 +16,10 @@ before_script: script: - eclipse -noSplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -import $TRAVIS_BUILD_DIR/left/build -import $TRAVIS_BUILD_DIR/right/build -build all - - make -j2 -C left - - make -j2 -C right + - make -C left clean && make -j2 -C left DEBUG=1 + - make -C left clean && make -j2 -C left DEBUG=0 + - make -C right clean && make -j2 -C right DEBUG=1 + - make -C right clean && make -j2 -C right DEBUG=0 matrix: include: