endTransmission() and requestFrom() both spin on unbounded while(!EVENT) loops waiting on the TWIM peripheral. Several of these loops - notably the EVENTS_STOPPED wait - have no EVENTS_ERROR escape at all, so if the hardware never raises the expected event (e.g. probing an I2C address on a bus with nothing attached and no pull-ups), the call never returns and the whole single-threaded firmware hangs forever. Reported in #771 with the same root cause already identified in the issue thread. Also affects boards that probe for an optional/absent I2C device at boot before anything else initializes - e.g. MeshCore's Xiao_nrf52 target, which runs an RTC autodiscovery scan in radio_init() and hangs on every cold boot when no RTC is wired up (no serial, no BLE - see meshcore-dev/MeshCore#2068). Adds a bounded I2C_TWIM_TIMEOUT_MS (default 100ms, overridable) to every wait loop in both functions. A timeout that occurs before the hardware transaction actually completed is surfaced as a proper error return (endTransmission: 4 "other error"; requestFrom: 0 bytes read) rather than silently falling through to a success path - a timeout on the address/data phase must not be reported as if a device ACKed. Tested on a Seeed XIAO nRF52840 + Wio-SX1262 board that reliably hung at boot (via MeshCore's RTC autodiscovery probe) after every power cycle. With this patch the same probe now completes (with a timeout) in well under a second per address instead of hanging indefinitely, and the board boots and runs normally.
Arduino Core for Adafruit Bluefruit nRF52 Boards
This repository contains the Arduino BSP for Adafruit Bluefruit nRF52 series:
- Adafruit CLUE nRF52840
- Adafruit Circuit Playground Bluefruit
- Adafruit Feather nRF52832
- Adafruit Feather nRF52840 Express
- Adafruit Feather nRF52840 Sense
- Adafruit ItsyBitsy nRF52840 Express
- Adafruit LED Glasses Driver nRF52840
- Adafruit Metro nRF52840 Express
- Raytac MDBT50Q-RX Dongle
Following boards are also included but are not officially supported:
BSP Installation
There are two methods that you can use to install this BSP. We highly recommend the first option unless you wish to participate in active development of this codebase via Github.
Recommended: Adafruit nRF52 BSP via the Arduino Board Manager
- Download and install the Arduino IDE (At least v1.6.12)
- Start the Arduino IDE
- Go into Preferences
- Add https://adafruit.github.io/arduino-board-index/package_adafruit_index.json as an 'Additional Board Manager URL'
- Restart the Arduino IDE
- Open the Boards Manager from the Tools -> Board menu and install 'Adafruit nRF52 by Adafruit'
- Once the BSP is installed, select 'Adafruit Feather nRF52840 Express' from the Tools -> Board menu, which will update your system config to use the right compiler and settings for the nRF52.
Optional (Core Development): Adafruit nRF52 BSP via git
- Install BSP via Board Manager as above to install compiler & tools.
- Delete the core folder
nrf52installed by Board Manager in Adruino15, depending on your OS. It could be
- macOS :
~/Library/Arduino15/packages/adafruit/hardware/nrf52 - Linux :
~/.arduino15/packages/adafruit/hardware/nrf52 - Windows:
%APPDATA%\Local\Arduino15\packages\adafruit\hardware\nrf52
cd <SKETCHBOOK>, where<SKETCHBOOK>is your Arduino Sketch folder:
- macOS :
~/Documents/Arduino - Linux :
~/Arduino - Windows:
~/Documents/Arduino
- Create a folder named
hardware/adafruit, if it does not exist, and change directories to it - Clone this repo & its submodules:
git clone https://github.com/adafruit/Adafruit_nRF52_Arduino.git
cd Adafruit_nRF52_Arduino
git submodule update --init
- Restart the Arduino IDE
- Once the BSP is installed, select 'Adafruit Feather nRF52840 Express' from the Tools -> Board menu, which will update your system config to use the right compiler and settings for the nRF52.
Adafruit's nrfutil tools
adafruit-nrfutil (derived from Nordic pc-nrfutil) is needed to upload sketch via serial port.
- For Windows and macOS, pre-built executable binaries are included in the BSP at
tools/adafruit-nrfutil/. It should work out of the box. - Linux user need to run follow command to install it from PyPi
$ pip3 install adafruit-nrfutil --user
Drivers
- SiLabs CP2104 driver is required for USB to Serial when using with Feather nRF52832
Bootloader
Bootloader can be updated via UF2 file or DFU if already existed. Or flash on new blank chip using following guide
Update Bootloader with UF2 ( nRF52840 only and require 0.4.0+ )
This only works with nRF52840 and require existing bootloader version is at least 0.4.0:
- Quickly doulbe tap reset button to put your board in to bootloader mode. A mass storage device i.e
FTHR840BOOTwill appear - Download latest UF2 for your board i.e
update-{BOARD}-{version}_nosd.uf2from Adafruit_nRF52_Bootloader release page - Drap and drop the UF2 file into
FTHR840BOOTdrive to perform update then wait until the board reset.x
Update Bootloader with DFU
To upgrade to the latest Bootloader + Softdevice using the serial port within Arduino IDE.
- Select
Tools > Board > Adafruit Feather nRF52840 Express - Select
Tools > Programmer > Bootloader DFU for Bluefruit nRF52 - Select
Tools > Burn Bootloader - WAIT until the process complete ~30 seconds
Note: close the Serial Monitor before you click "Burn Bootloader". Afterwards, you shouldn't close the Arduino IDE, unplug the Feather, launch Serial Monitor etc ... to abort the process. There is a high chance it will brick your device! Do this with care and caution.
Burning new Bootloader
To burn the bootloader from within the Arduino IDE, you will need the following tools installed on your system and available in the system path:
Check to make sure you can run nrfjprog from your terminal/command prompt
macOS Note At present, you will need to create a symlink in /usr/local/bin to the
nrfjprog tool wherever you have added it. You can run the following command, for example:
$ ln -s $HOME/prog/nordic/nrfjprog/nrfjprog /usr/local/bin/nrfjprog
Once the tools above have been installed and added to your system path, from the Arduino IDE:
- Select
Tools > Board > Adafruit Feather nRF52840 Express - Select
Tools > Programmer > J-Link for Feather52 - Select
Tools > Burn Bootloaderwith the board and J-Link connected
If you wish to modify bootloader to your own need, check out its repo here Adafruit_nRF52_Bootloader
Manually Burning the Bootloader via nrfjprog
The bootloader hex file can be found at bin/bootloader run the command as follows:
$ nrfjprog -e -f nrf52
$ nrfjprog --program feather_nrf52832_bootloader.hex -f nrf52
$ nrfjprog --reset -f nrf52
Credits
This core is based on Arduino-nRF5 by Sandeep Mistry, which in turn is based on the Arduino SAMD Core.
The following libraries are used: