diff options
author | Paulo Borges <paulo.borges@openbossa.org> | 2013-11-29 20:41:37 -0300 |
---|---|---|
committer | Paulo Borges <paulo.borges@openbossa.org> | 2013-12-22 22:43:05 -0300 |
commit | a05ab49cc4b92fbe62f0ba1eb0c75e8971c0a4dc (patch) | |
tree | c4e2b7f4b5dbcc3f7ed8161ab392249092889902 | |
parent | 2ad20b68c33114055cfd33895b17b9d1f62b3387 (diff) |
nrf51822: Add Makefile.platform and flasher
-rw-r--r-- | platform/nrf51822/Makefile.platform | 91 | ||||
-rw-r--r-- | platform/nrf51822/flasher/erase.jlink | 6 | ||||
-rw-r--r-- | platform/nrf51822/flasher/flash.jlink | 8 | ||||
-rw-r--r-- | platform/nrf51822/flasher/flasher.py | 86 |
4 files changed, 191 insertions, 0 deletions
diff --git a/platform/nrf51822/Makefile.platform b/platform/nrf51822/Makefile.platform new file mode 100644 index 0000000..e3600b6 --- /dev/null +++ b/platform/nrf51822/Makefile.platform @@ -0,0 +1,91 @@ +# Makefile for nRF51822 platform + +# FIXME: Hardcoded path +NRF51_SDK_PATH = /home/borges/workspace/bless/nrf51-sdk +JLINK_PATH = /home/borges/workspace/bless/nrf51-sdk/JLink_Linux_V474 + +ifeq ($(DEVICE_FAMILY),) + DEVICE_FAMILY = NRF51 +endif + +ifeq ($(CPU),) + CPU = cortex-m0 +endif + +ifeq ($(SOC),) + SOC = NRF51822_QFAA_CA +endif + +ifeq ($(SOC_VARIANT),) + SOC_VARIANT = xxaa +endif + +ifeq ($(BOARD),) + BOARD = BOARD_PCA10001 +endif + +ifeq ($(HEAP_SIZE),) + HEAP_SIZE = 0 +endif + +ifeq ($(STACK_SIZE),) + STACK_SIZE = 1024 +endif + +CC = arm-none-eabi-gcc +LD = arm-none-eabi-gcc +OBJCOPY = arm-none-eabi-objcopy +OBJDUMP = arm-none-eabi-objdump +FLASHER = python $(PLATFORM_PATH)/flasher/flasher.py + +SDK_INCLUDE_PATH = $(NRF51_SDK_PATH)/Nordic/nrf51822/Include +SDK_SOURCE_PATH = $(NRF51_SDK_PATH)/Nordic/nrf51822/Source +SDK_TEMPLATE_PATH = $(NRF51_SDK_PATH)/Nordic/nrf51822/Source/templates + +PLATFORM_INCLUDE_PATHS = $(SDK_INCLUDE_PATH) \ + $(SDK_INCLUDE_PATH)/gcc \ + $(SDK_INCLUDE_PATH)/app_common \ + $(SDK_INCLUDE_PATH)/ble/softdevice \ + $(PLATFORM_PATH) + +PLATFORM_CFLAGS = -mcpu=$(CPU) \ + -D$(DEVICE_FAMILY) \ + -D$(BOARD) \ + -D$(SOC) \ + -mfloat-abi=soft \ + --std=gnu99 \ + -mthumb \ + -Werror \ + -Wall \ + -c + +PLATFORM_ASMFLAGS = $(PLATFORM_CFLAGS) \ + -x assembler-with-cpp \ + -D__HEAP_SIZE=$(HEAP_SIZE) \ + -D__STACK_SIZE=$(STACK_SIZE) + +LINKER_SCRIPT = gcc_nrf51_blank_$(SOC_VARIANT).ld +PLATFORM_LDFLAGS = -T$(SDK_TEMPLATE_PATH)/gcc/$(LINKER_SCRIPT) \ + -L$(SDK_TEMPLATE_PATH)/gcc \ + --specs=nano.specs \ + -mabi=aapcs \ + -Xlinker \ + -Map=$(BUILD_PATH)/$(PROJECT_TARGET).map \ + -mthumb \ + -mcpu=$(CPU) + +PLATFORM_SOURCE_PATHS = $(SDK_SOURCE_PATH) \ + $(SDK_SOURCE_PATH)/simple_uart \ + $(SDK_SOURCE_PATH)/nrf_delay \ + $(SDK_TEMPLATE_PATH) \ + $(SDK_TEMPLATE_PATH/gcc) \ + $(PLATFORM_PATH) + +PLATFORM_SOURCE_FILES = system_nrf51.c + +PLATFORM_ASM_PATHS = $(SDK_TEMPLATE_PATH)/gcc + +PLATFORM_ASM_FILES = gcc_startup_nrf51.s + +export JLINK_PATH +export BUILD_PATH diff --git a/platform/nrf51822/flasher/erase.jlink b/platform/nrf51822/flasher/erase.jlink new file mode 100644 index 0000000..1afc5f0 --- /dev/null +++ b/platform/nrf51822/flasher/erase.jlink @@ -0,0 +1,6 @@ +device nrf51822 +w4 4001e504 2 +w4 4001e50c 1 +sleep 100 +r +q diff --git a/platform/nrf51822/flasher/flash.jlink b/platform/nrf51822/flasher/flash.jlink new file mode 100644 index 0000000..5690361 --- /dev/null +++ b/platform/nrf51822/flasher/flash.jlink @@ -0,0 +1,8 @@ +device nrf51822 +speed 1000 +w4 4001e504 1 +loadbin {program} {addr} +sleep 100 +r +g +q diff --git a/platform/nrf51822/flasher/flasher.py b/platform/nrf51822/flasher/flasher.py new file mode 100644 index 0000000..80fffce --- /dev/null +++ b/platform/nrf51822/flasher/flasher.py @@ -0,0 +1,86 @@ +# coding: utf-8 + +# The MIT License (MIT) +# +# Copyright (c) 2013 Paulo B. de Oliveira Filho <pauloborgesfilho@gmail.com> +# Copyright (c) 2013 Claudio Takahasi <claudio.takahasi@gmail.com> +# Copyright (c) 2013 João Paulo Rechi Vita <jprvita@gmail.com> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import subprocess +import argparse +import os.path +import os +import sys + +BUILD_PATH = os.environ["BUILD_PATH"] +FLASHER_PATH = os.path.dirname(os.path.abspath(__file__)) + +############################################################################### + +parser = argparse.ArgumentParser(prog="segger") +subparsers = parser.add_subparsers() + +erase = subparsers.add_parser("erase", help="erase the flash") +erase.set_defaults(command="erase") + +flash = subparsers.add_parser("flash", help="program the flash") +flash.set_defaults(command="flash") +flash.add_argument("program", help="binary file containing the program") + +############################################################################### + +jlinkexe = "LD_LIBRARY_PATH={path}:$LD_LIBRARY_PATH {path}/JLinkExe {script}" + +def exec_jlinkexe(script, path): + try: + print subprocess.check_output(jlinkexe.format( + path=os.environ["JLINK_PATH"], + script=os.path.join(path, script) + ), shell=True) + except subprocess.CalledProcessError, e: + print e.output + return 0 + +def read_script_file(script): + return open(os.path.join(FLASHER_PATH, script), 'r').read() + +def create_tmp_script(name, content): + with open(os.path.join(BUILD_PATH, name), 'w') as f: + f.write(content) + +############################################################################### + +def erase(): + return exec_jlinkexe("erase.jlink", FLASHER_PATH) + +def flash(program): + script_name = "flash.jlink" + content = read_script_file(script_name).format(program=program, addr=0) + create_tmp_script(script_name, content) + return exec_jlinkexe(script_name, BUILD_PATH) + +############################################################################### + +args = parser.parse_args().__dict__ +command = args.pop("command") + +status = globals()[command](**args) +sys.exit(status) |