From 868d767b561e3e83c0592d1dc182b0f5117b8144 Mon Sep 17 00:00:00 2001 From: rbaron Date: Wed, 10 Feb 2021 17:09:13 +0100 Subject: [PATCH] Custom board e73-tbb sort of works. --- code/parasite/boards/e73-tbb.json | 2 +- code/parasite/ldscripts/nrf52832_s132_v6.ld | 40 ++++++++++++++++++ code/parasite/platformio.ini | 12 ++---- resources.md | 45 +++++++++++++++++++++ 4 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 code/parasite/ldscripts/nrf52832_s132_v6.ld diff --git a/code/parasite/boards/e73-tbb.json b/code/parasite/boards/e73-tbb.json index 2921cd1..b87b095 100644 --- a/code/parasite/boards/e73-tbb.json +++ b/code/parasite/boards/e73-tbb.json @@ -1,7 +1,7 @@ { "build": { "arduino":{ - "ldscript": "nrf52_xxaa.ld" + "ldscript": "nrf52832_s132_v6.ld" }, "core": "nRF5", "cpu": "cortex-m4", diff --git a/code/parasite/ldscripts/nrf52832_s132_v6.ld b/code/parasite/ldscripts/nrf52832_s132_v6.ld new file mode 100644 index 0000000..921baab --- /dev/null +++ b/code/parasite/ldscripts/nrf52832_s132_v6.ld @@ -0,0 +1,40 @@ +/* Linker script to configure memory regions. */ +/* Source: https://raw.githubusercontent.com/adafruit/Adafruit_nRF52_Arduino/master/cores/nRF5/linker/nrf52832_s132_v6.ld */ + +SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys) + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0x6D000 - 0x26000 + + /* SRAM required by S132 depend on + * - Attribute Table Size + * - Vendor UUID count + * - Max ATT MTU + * - Concurrent connection peripheral + central + secure links + * - Event Len, HVN queue, Write CMD queue + */ + RAM (rwx) : ORIGIN = 0x20003600, LENGTH = 0x20010000 - 0x20003600 +} + +SECTIONS +{ + . = ALIGN(4); + .svc_data : + { + PROVIDE(__start_svc_data = .); + KEEP(*(.svc_data)) + PROVIDE(__stop_svc_data = .); + } > RAM + + .fs_data : + { + PROVIDE(__start_fs_data = .); + KEEP(*(.fs_data)) + PROVIDE(__stop_fs_data = .); + } > RAM +} INSERT AFTER .data; + +/* TODO(rbaron): This should be failing but it's not. Maybe it's loading it from somewhere else? */ +INCLUDE "nrf52_common.ld" \ No newline at end of file diff --git a/code/parasite/platformio.ini b/code/parasite/platformio.ini index 2aea8eb..d081b63 100644 --- a/code/parasite/platformio.ini +++ b/code/parasite/platformio.ini @@ -8,15 +8,11 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -; [env:adafruit_feather_nrf52832] [env:e73-tbb] platform = nordicnrf52 -board = adafruit_feather_nrf52832 -; board = e73-tbb +; board = adafruit_feather_nrf52832 +; Additionally, I had to force use_adafruit = True in platforms/nordicnrf52/builder/main.py +board = e73-tbb framework = arduino build_flags = -DNRF52 -DS132 -DNRF51_S132 -; upload_port = /dev/cu.usbserial-14330 -; debug_tool = jlink -; protocol = nrfutil -; lib_deps = -; mbed-glimwormbeacons/SEGGER_RTT2 @ 0.0.0+sha.a7800e894aaf \ No newline at end of file +board_build.ldscript = ./ldscripts/nrf52832_s132_v6.ld \ No newline at end of file diff --git a/resources.md b/resources.md index a85a6ac..ed08b1c 100644 --- a/resources.md +++ b/resources.md @@ -51,3 +51,48 @@ Upgrading target on /dev/cu.usbserial-14330 with DFU package /Users/rbaron/dev/p Activating new firmware Device programmed. ``` + +# Linking +In [platformio-core/tools/pioplatform.py](https://github.com/platformio/platformio-core/blob/9c20ab81cb68f1ffb7a8cac22ce95c4c797643ec/platformio/builder/tools/pioplatform.py#L130): +```Python +if "build.ldscript" in board_config: + env.Replace(LDSCRIPT_PATH=board_config.get("build.ldscript")) +``` +In [platformio-core/platformio.py](https://github.com/platformio/platformio-core/blob/9c20ab81cb68f1ffb7a8cac22ce95c4c797643ec/platformio/builder/tools/platformio.py#L65): +```Python +# append into the beginning a main LD script +if env.get("LDSCRIPT_PATH") and not any("-Wl,-T" in f for f in env["LINKFLAGS"]): + env.Prepend(LINKFLAGS=["-T", env.subst("$LDSCRIPT_PATH")]) +``` +The `-T` flag expects a path to a linker script, as per [`ld` docs](https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_chapter/ld_3.html). + +Frameworks, such as the `nordicnrf52`, contain [boards definitions](https://github.com/platformio/platform-nordicnrf52/blob/develop/boards/adafruit_feather_nrf52832.json#L4) that specify the `ldscript`. + +1. For the [adafruit_feather_nrf52832](https://github.com/platformio/platform-nordicnrf52/blob/develop/boards/adafruit_feather_nrf52832.json#L4) board, we have: + +``` +"arduino":{ + "ldscript": "nrf52832_s132_v6.ld" +}, +``` +Which is defined [here](https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/master/cores/nRF5/linker/nrf52832_s132_v6.ld). + +2. For the [nrf52_dk](https://github.com/platformio/platform-nordicnrf52/blob/develop/boards/nrf52_dk.json#L4), we have: +``` +"arduino":{ + "ldscript": "nrf52_xxaa.ld" +}, +``` +Which is the most common linker script, and is part of the nordic official SDK, it seems, available [here](https://github.com/NordicSemiconductor/nrfx/blob/master/mdk/nrf52_xxaa.ld). For reference, check out the linker for the [Adafruit nRF52 Bootloader](https://github.com/adafruit/Adafruit_nRF52_Bootloader/blob/master/linker/nrf52.ld). Here you can see the [memory map](https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/hathach-memory-map) of the nRF52 Feather. + +## Same platform, different framework +Both the Feather nRF52832 and the Generic boards above point to the same platform, the [nordicnrf52](). Inside this platorm, there's a switch for selecting which framework to use, based on the board name, [here](https://github.com/platformio/platform-nordicnrf52/blob/develop/platform.py#L38): +```Python +if self.board_config(board).get("build.bsp.name", + "nrf5") == "adafruit": + self.frameworks["arduino"][ + "package"] = "framework-arduinoadafruitnrf52" +``` + +### Memory layout +The [SoftDevice S132 spec](https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsds_s112%2FSDS%2Fs1xx%2Fmem_usage%2Fmem_resource_map_usage.html&anchor=mem_resource_map_usage) specifies the layout as the soft device begins at addr 0x0 and the application code comes after it, at the address `APP_CODE_BASE`. \ No newline at end of file