User Tools

Site Tools


s340:arduino_ide_integration_for_the_nrf52840_feather_express_with_s340

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
s340:arduino_ide_integration_for_the_nrf52840_feather_express_with_s340 [2020/03/29 20:07]
orrmany [Introduction]
s340:arduino_ide_integration_for_the_nrf52840_feather_express_with_s340 [2020/05/05 20:11]
orrmany
Line 3: Line 3:
 This lazy-guide is a HOWTO about how I made my modified, ANT+ capable Adafruit Feather nRF52840 Express being integrated into the Arduino desktop IDE. This lazy-guide is a HOWTO about how I made my modified, ANT+ capable Adafruit Feather nRF52840 Express being integrated into the Arduino desktop IDE.
  
-===== Introduction ===== +**//This page has been republished ​to my WordPress blog for analytics purposesRead it there: https://blogarak.wordpress.com/2020/03/29/arduino-ide-integration-for-the-nrf52840-feather-express-with-s340/ //**
-On the page [[:​s340_softdevice_adafruit_nrf52840_feather_express|S340 SoftDevice & Adafruit nRF52840 Express Feather]] I have described how to make the nRF52840 Express Feather ANT radio-protocol capable. ​  +
-The trick was to add the S340 Softdevice to the bootloader. The original Arduino IDE support from Adafruit for this board based on the same bootloader.  +
- +
-The support of any board in Arduino IDE is based on a special Board Support Package (BSP). A BSP is a software package, such BSP package in Arduino jargon is also called as an "​Arduino Core" package. The nRF52840 Feather is supported by the "​[[https://​learn.adafruit.com/​introducing-the-adafruit-nrf52840-feather/​arduino-bsp-setup|Adafruit nRF52 by Adafruit]]"​ Core. This BSP is built on top of the [[https://​github.com/​adafruit/​Adafruit_nRF52_Bootloader|Adafruit Bootloader]],​ which we just modified to include the S340 SoftDevice (SD) instead/​beyond of the S140 BLE-only softdevice (see section [[#​Prerequisites]]).  +
- +
-Whenever we want to upload an Arduino sketch, then the Arduino IDE invokes the appropriate board-specific compiler and linker via the BSP, then "​uploads"​ it to the board via the appropriate upload-mechanism specified by the BSP.  +
- +
-In case of the nRF52840 Feather, this means bundling the freshly compiled sketch with the softdevice corresponding to the board, then uploading it to the board  +
-  ​either via USB-UART (using adafruit-nrfutil) +
-  ​or via some other methods (not covered here). +
- +
-For integrating S340 SD support into the Adafruit Core we have to achieve that  +
-  - the Core bundles the S340 SD with the sketch instead of the original S140 SD  +
-  - and that the memory-layout settings are adapted to the different softdevice +
-===== Credits ===== +
-This work is based on [[https://github.com/​rtgree01|rtgree01]]'​s PlatformIO adaptation. See also the [[http://​orrmany.hu/​wiki/​doku.php?​id=arduino:​s340_softdevice_adafruit_nrf52840_feather_express#​credits|Credits]] section with the page [[arduino:​s340_softdevice_adafruit_nrf52840_feather_express|S340 SoftDevice & Adafruit nRF52840 Express Feather]] +
-===== Prerequisites ===== +
-This HOWTO assumes that +
-  - You are familiar with [[https://​www.arduino.cc/​en/​Guide/​Introduction|Arduino]],​ with [[https://​www.arduino.cc/​en/​Guide/​HomePage|Arduino based SW development]] and with the [[https://​www.arduino.cc/​en/​main/​software|Arduino desktop IDE]], which latter you have downloaded and installed already. +
-  - You have an [[https://​www.adafruit.com/​product/​4062|Adafruit Feather nRF52840 Express]] which [[arduino:​s340_softdevice_adafruit_nrf52840_feather_express|you have made ANT protocol capable]] +
- +
-===== Integration step-by-step ===== +
-Adafruit ​has described [[https://​learn.adafruit.com/​introducing-the-adafruit-nrf52840-feather/​arduino-bsp-setup|how to install their BSP]] either via the Arduino IDE board manager, or directly from GitHub. The latter method is said to be intended if //"you wish to do any development against the core codebase [..] you can also optionally install the Adafruit nRF52 BSP manually using '​git'"//​. We will do exactly like that --- except that we are going to install the alternative,​ S340 SD equipped bootloader that we have [[:​s340_softdevice_adafruit_nrf52840_feather_express|recently made]]! :) +
- +
-In order to make this lazy self-contained,​ I have copied the text of the [[https://​learn.adafruit.com/​introducing-the-adafruit-nrf52840-feather/​arduino-bsp-setup|Adafruit Arduino Support Setup]] here, the verbatim copied text is denoted with a gray quotation-bar  +
-==== First step: install regular BSP as described by Adafruit ==== +
-=== 1. Install the nRF52 Core by Adafruit via the board manager ===  +
->    * Download and install the Arduino IDE (At least v1.8) +
->    *  Start the Arduino IDE +
->    *  Go into Preferences +
->    *  Add https:​www.adafruit.com/​package_adafruit_index.json as an '​Additional Board Manager URL' (see image below) {{ :​s340:​microcontrollers_screen_shot_2017-03-19_at_22.16.49.png?​direct&​200 |}}  +
->  *  Restart the Arduino IDE +
->  *  Open the Boards Manager option from the Tools -> Board menu and install '​Adafruit nRF52 by Adafruit'​ (see image below){{ :​s340:​microcontrollers_nrf52bsp.png?​direct&​200 |}} It will take up to a few minutes to finish installing the cross-compiling toolchain and tools associated with this BSP. The delay during the installation stage shown in the image below is normal, please be patient and let the installation terminate normally:{{ :​s340:​microcontrollers_screen_shot_2017-04-19_at_20.23.20.png?​direct&​200 |}}  +
->  *  Once the BSP is installed, select '​Adafruit Bluefruit nRF52840 Feather Express'​ from the Tools -> Board menu, which will update your system config to use the right compiler and settings for the nRF52:{{ :​s340:​microcontrollers_screenshot_2019-01-01_at_12.59.47.png?​direct&​200 |}} +
- +
-=== 2. LINUX ONLY: adafruit-nrfutil Tool Installation ​ === +
- +
-> ''​adafruit-nrfutil''​ is a modified version of Nordic'​s nrfutil, which is used to flash boards using the built in serial bootloader. It is originally written for python2, but have been migrated ​to python3 and renamed to adafruit-nrfutil since BSP version 0.8.5.  +
-+
-> **This step is only required on Linux, pre-built binaries of adafruit-nrfutil ​for Windows and MacOS are already included in the BSPThat should work out of the box for most setups.** +
-+
-> Install python3 if it is not installed in your system already +
-> <code bash> +
-    $ sudo apt-get install python3 +
-</​code>​ +
-> Then run the following command to install the tool from PyPi +
-> <code bash> +
-    $ pip3 install --user adafruit-nrfutil +
-</​code>​ +
-> Add pip3 installation dir to your PATH if it is not added already. Make sure adafruit-nrfutil can be executed in terminal by running +
-> <code bash> +
-    $ adafruit-nrfutil version +
-    adafruit-nrfutil version 0.5.3.post12 +
-</​code>​ +
- +
-==== Second major stepreplace the bootloader with the modified bootloader ==== +
-The initial part of these steps are identical to that of the manual installment of the Adafruit bootloader from GitHub. However, instead of installing the Adafruit one from GitHub we rather install the one modified by us when we have added the [[arduino:​s340_softdevice_adafruit_nrf52840_feather_express|S340 SoftDevice for ANT radio-protocol support]]. +
- +
->   1. Install BSP via Board Manager as above to install compiler & tools. +
->   2. Delete the core folder ''​nrf52''​ installed by Board Manager in Adruino15, depending on your OS. It could be: +
->> ​ **macOS**: ''​~/​Library/​Arduino15/​packages/​adafruit/​hardware/​nrf52''<​br/>​ +
->> ​ **Linux**: ''​~/​.arduino15/​packages/​adafruit/​hardware/​nrf52''<​br/>​ +
->> ​ **Windows**:​ ''​%APPDATA%\Local\Arduino15\packages\adafruit\hardware\nrf52''​ +
->   ​3. ​ Go to the sketchbook folder on your command line, which should be one of the following:​ +
->> ​   **macOS**: ~/​Documents/​Arduino +
->> ​   **Linux**: ~/Arduino +
->> ​   **Windows**:​ ~/​Documents/​Arduino +
->  4. Create a folder named hardware/​Adafruit,​ if it does not exist, and change directories into it. +
->  5. Clone the Adafruit_nRF52_Arduino repo in the folder described in step 2: +
->> ​ <​code>​git clone git@github.com:​adafruit/​Adafruit_nRF52_Arduino.git +
-cd Adafruit_nRF52_Arduino +
-git submodule update --init --recursive +
-</​code>​ +
-Instead of cloning the the original Adafruit bootloader, if you are lazy you can clone my modified one:  +
-<code bash> +
-git clone -b adding-S340-to-nrf52840-Feather --single-branch ​https://github.com/​orrmany/​Adafruit_nRF52_Arduino.git +
-cd Adafruit_nRF52_Arduino +
-git submodule update --init --recursive +
-</​code>​ +
-If you **//do use my repo//**, the do **not** forget that you will still need to download the [[https://​www.thisisant.com/developer/components/nrf52832#​tab_protocol_stacks_tab|S340 softdevice from thisisant.com]] and install it into the proper place, as redistribution of the said SoftDevice by individuals is not permited. You //must// sign the ANT license and respect its conditions. The way you can get the S340 is described at the [[https://​www.nordicsemi.com/​Software-and-tools/​Software/​S340-ANT|Nordic Semiconductor page]]. +
-About the "​installation to the proper place" check out substep #2 of Section C of the page [[arduino:​s340_softdevice_adafruit_nrf52840_feather_express#​c_modify_the_adafruit_bootloader|describing the bootloader modification]] +
->  6. This should result in a final folder name like ''​.../​Documents/​Arduino/​hardware/​Adafruit/​Adafruit_nRF52_Arduino''​. +
-7. Quit the Arduino IDE +
- +
-==== Third major step: add S340 to the BSP ==== +
-  ​//(Already done in my modified repo on Github.)// Go inside the freshly cloned repo, i.e., into ''​.../​Documents/​Arduino/​hardware/​Adafruit/​Adafruit_nRF52_Arduino''​. Modify ''​boards.txt''​ as follows. Duplicate the subsection called ''​Bluefruit Feather nRF52840 Express s340''​ within the file and in the second copy rename every instance of the string "​s140"​ with "​s340":<​code diff> +
-diff --git a/​boards.txt b/​boards.txt +
-index f6a6d4b1..1d190722 100644 +
---- a/​boards.txt +
-+++ b/​boards.txt +
-@@ -112,6 +112,60 @@ feather52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2 +
- ​feather52840.menu.debug.l3=Level 3 (Segger SystemView) +
- ​feather52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3 +
- +
-+# ---------------------------------- +
-+# Bluefruit Feather nRF52840 Express s340 +
-+# ---------------------------------- +
-+feather52840_s340.name=Adafruit Bluefruit Feather nRF52840 Express w.ANT +
-+
-+# VID/​PID ​for bootloader with/​without UF2, Arduino + Circuitpython App +
-+feather52840_s340.vid.0=0x239A +
-+feather52840_s340.pid.0=0x8029 +
-+feather52840_s340.vid.1=0x239A +
-+feather52840_s340.pid.1=0x0029 +
-+feather52840_s340.vid.2=0x239A +
-+feather52840_s340.pid.2=0x002A +
-+feather52840_s340.vid.3=0x239A +
-+feather52840_s340.pid.3=0x802A +
-+
-+# Upload +
-+feather52840_s340.bootloader.tool=bootburn +
-+feather52840_s340.upload.tool=nrfutil +
-+feather52840_s340.upload.protocol=nrfutil +
-+feather52840_s340.upload.use_1200bps_touch=true +
-+feather52840_s340.upload.wait_for_upload_port=true +
-+feather52840_s340.upload.maximum_size=815104 +
-+feather52840_s340.upload.maximum_data_size=237568 +
-+#TODO: fix sizes above +
-+
-+# Build +
-+feather52840_s340.build.mcu=cortex-m4 +
-+feather52840_s340.build.f_cpu=64000000 +
-+feather52840_s340.build.board=NRF52840_FEATHER +
-+feather52840_s340.build.core=nRF5 +
-+feather52840_s340.build.variant=feather_nrf52840_express +
-+feather52840_s340.build.usb_manufacturer="​Adafruit LLC" +
-+feather52840_s340.build.usb_product="​Feather nRF52840 Express"​ +
-+feather52840_s340.build.extra_flags=-DNRF52840_XXAA {build.flags.usb} +
-+feather52840_s340.build.ldscript=nrf52840_s340_v6.ld +
-+feather52840_s340.build.vid=0x239A +
-+feather52840_s340.build.pid=0x8029 +
-+
-+# SofDevice Menu +
-+feather52840_s340.menu.softdevice.s340v6=0.3.0 SoftDevice s340 6.1.1 +
-+feather52840_s340.menu.softdevice.s340v6.build.sd_name=s340 +
-+feather52840_s340.menu.softdevice.s340v6.build.sd_version=6.1.1 +
-+feather52840_s340.menu.softdevice.s340v6.build.sd_fwid=0x00B9 +
-+
-+# Debug Menu +
-+feather52840_s340.menu.debug.l0=Level 0 (Release) +
-+feather52840_s340.menu.debug.l0.build.debug_flags=-DCFG_DEBUG=0 +
-+feather52840_s340.menu.debug.l1=Level 1 (Error Message) +
-+feather52840_s340.menu.debug.l1.build.debug_flags=-DCFG_DEBUG=1 +
-+feather52840_s340.menu.debug.l2=Level 2 (Full Debug) +
-+feather52840_s340.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2 +
-+feather52840_s340.menu.debug.l3=Level 3 (Segger SystemView) +
-+feather52840_s340.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3 +
-+
- +
- # ---------------------------------- +
- # Bluefruit ItsyBitsy nRF52840 Express +
-</​code>​ +
-  - //(Already done in my modified repo on Github.)// Go to ''​cores/​nRF5/​linker''​. Copy the file ''/​nrf52840_s340_v6.ld''​ into ''/​nrf52840_s140_v6.ld''​. Edit line #8:  +
-    ​Change content of line #8 from '' ​ FLASH (rx)     : ORIGIN = 0x26000, LENGTH = 0xED000 ​0x26000''​ +
-    ​Change content of line #8 to '' ​ FLASH (rx)     : ORIGIN = 0x31000, LENGTH = 0xF4000 ​0x31000''<​code diff> +
-diff --git a/​cores/​nRF5/​linker/​nrf52840_s340_v6.ld b/​cores/​nRF5/​linker/​nrf52840_s340_v6.ld +
-new file mode 100644 +
-index 00000000..2657d122 +
---- /dev/null +
-+++ b/​cores/​nRF5/​linker/​nrf52840_s340_v6.ld +
-@@ -0,0 +1,38 @@ +
-+/* Linker script to configure memory regions. */ +
-+
-+SEARCH_DIR(.) +
-+GROUP(-lgcc -lc -lnosys) +
-+
-+MEMORY +
-+{ +
-+  FLASH (rx)     : ORIGIN = 0x31000, LENGTH = 0xF4000 - 0x31000 +
-+
-+  /* SRAM required by S132 depend on +
-+   * - Attribute Table Size (Number of Services and Characteristics) +
-+   * - Vendor UUID count +
-+   * - Max ATT MTU +
-+   * - Concurrent connection peripheral + central + secure links +
-+   * - Event Len, HVN queue, Write CMD queue +
-+   */ +
-+  RAM (rwx) :  ORIGIN = 0x20006000, LENGTH = 0x20040000 - 0x20006000 +
-+} +
-+
-+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; +
-+
-+INCLUDE "​nrf52_common.ld"​ +
-</​code>​ +
-  - //(Already done in my modified repo on Github.)// Go to ''​cores/​nRF5/​nordic/​softdevice/''​ and create subdirectory ''​s340_nrf52_6.1.1_API''​.  +
-  - Copy the ''​include ''​ subdirectory ofthe S340 SoftDevice under this ''​s340_nrf52_6.1.1_API''​ subdirectory:<​code txt>​.../​s340_nrf52_6.1.1_API +
- ​└── include +
-     ​├── ant_error.h +
-     ​├── ant_interface.h +
-     ​├── ant_parameters.h +
-     ​├── ble.h +
-     ​├── ble_err.h +
-     ​├── ble_gap.h +
-     ​├── ble_gatt.h +
-     ​├── ble_gattc.h +
-     ​├── ble_gatts.h +
-     ​├── ble_hci.h +
-     ​├── ble_l2cap.h +
-     ​├── ble_ranges.h +
-     ​├── ble_types.h +
-     ​├── nrf52 +
-     ​│   └── nrf_mbr.h +
-     ​├── nrf_error.h +
-     ​├── nrf_error_sdm.h +
-     ​├── nrf_error_soc.h +
-     ​├── nrf_nvic.h +
-     ​├── nrf_sd_def.h +
-     ​├── nrf_sdm.h +
-     ​├── nrf_soc.h +
-     ​└── nrf_svc.h +
-</​code>​ +
-  - Go to ''​bootloader/​feather_nrf52840_express''​. You will find ''​feather_nrf52840_express_bootloader-0.3.0_s**1**40_6.1.1.zip''​ and  ''​feather_nrf52840_express_bootloader-0.3.0_s**1**40_6.1.1.hex''​ here. Now copy the corresponding files or s340 as ''​feather_nrf52840_express_bootloader-0.3.0_s**3**40_6.1.1.hex''​ and ''​feather_nrf52840_express_bootloader-0.3.0_s**3**40_6.1.1.zip''​ from where you have built the modified bootloader with S340 (see page [[arduino:​s340_softdevice_adafruit_nrf52840_feather_express|S340 SoftDevice & Adafruit nRF52840 Express Feather]] about how to build it). That is, the directory ''​bootloader/feather_nrf52840_express''​ should look like this<​code txt> +
-.../feather_nrf52840_express +
-       ​├── feather_nrf52840_express_bootloader-0.3.0_s140_6.1.1.zip +
-       ​├── feather_nrf52840_express_bootloader-0.3.0_s140_6.1.1.hex +
-       ​├── feather_nrf52840_express_bootloader-0.3.0_s340_6.1.1.hex +
-       ​└── feather_nrf52840_express_bootloader-0.3.0_s340_6.1.1.zip +
-</code> +
-  - //(Already done in my modified repo on Github.)// Go to ''​libraries/​Bluefruit52Lib/​src/''​ and modify ''​bluefruit.cpp''​ as follows: <code diff>​diff --git a/​libraries/​Bluefruit52Lib/​src/​bluefruit.cpp b/​libraries/​Bluefruit52Lib/​src/​bluefruit.cpp +
-index d17f66e4..1fe53626 100644 +
---- a/​libraries/​Bluefruit52Lib/​src/​bluefruit.cpp +
-+++ b/​libraries/​Bluefruit52Lib/​src/​bluefruit.cpp +
-@@ -318,7 +318,11 @@ bool AdafruitBluefruit::​begin(uint8_t prph_count, uint8_t central_count) +
-   #​error Clock Source is not configured, define USE_LFXO or USE_LFRC according to your board in variant.h +
- #​endif +
- +
-+#ifdef ANT_LICENSE_KEY +
-+  VERIFY_STATUS( sd_softdevice_enable(&​clock_cfg,​ nrf_error_cb,​ ANT_LICENSE_KEY),​ false ); +
-+#else +
-   ​VERIFY_STATUS( sd_softdevice_enable(&​clock_cfg,​ nrf_error_cb),​ false ); +
-+#endif +
- +
- #​ifdef USE_TINYUSB +
-   ​usb_softdevice_post_enable();​ +
-+
-</​code>​ +
-    ​* **Do not forget** that you shall obtain the [[https://​www.thisisant.com/​developer/​ant-plus/​ant-plus-basics/​network-keys|ANT License Key]] from ThisIsAnt.com and ''#​define''​ said ANT_LICENSE_KEY in your sketch! +
-  - Start the Arduino IDE +
- +
-Now you can build and upload sketches from the Arduino IDE by using ''​Adafruit Bluefruit Feather nRF52840 Express w.ANT''​ as board type +
-===== Caveats ===== +
-  * Please note, that the above changes just mean that you have replaced the bootloader and the softdevice with  an ANT+ capable one. //​Developing ANT+ application needs additional software, which you need to develop yourself, or obtain and adapt from thisisant.org,​ for example// +
-  * All the regular Arduino sketches and all the Bluefruit52 SW is supposed to run as-is with the modified bootloader +
-  * **NOTE** that CircuitPython compatibility will be lost with this modification. The CircuitPython interpreter is distributed as UF2 binary firmware-update and that is bundled with the S140 BLE softdevice. Trying to "​update"​ an S340 equipped nRF52804 Feather with the CircuitPython interpreter formware will most likely "​brick"​ your Feather and you will need a Segger J-Link firmware-updater to "​unbrick"​ your Feather+
  
s340/arduino_ide_integration_for_the_nrf52840_feather_express_with_s340.txt · Last modified: 2020/05/05 20:11 by orrmany