Skip to content

Commit ba5d783

Browse files
authored
Merge pull request #189 from glenne/master
Add USB connect timeout for app reset to UF2 or Serial via GPREGRET
2 parents b37c078 + 755cfa9 commit ba5d783

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

README.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ There are two pins, `DFU` and `FRST` that bootloader will check upon reset/power
5757
- The `GPREGRET` register can also be set to force the bootloader can enter any of above modes (plus a CDC-only mode for Arduino).
5858
`GPREGRET` is set by the application before performing a soft reset.
5959

60+
```c
61+
#include "nrf_nvic.h"
62+
void reset_to_uf2(void) {
63+
NRF_POWER->GPREGRET = 0x57; // 0xA8 OTA, 0x4e Serial
64+
NVIC_SystemReset(); // or sd_nvic_SystemReset();
65+
}
66+
```
67+
6068
On the Nordic PCA10056 DK board, `DFU` is connected to **Button1**, and `FRST` is connected to **Button2**.
6169
So holding down **Button1** while clicking **RESET** will put the board into USB bootloader mode, with UF2 and CDC support.
6270
Holding down **Button2** while clicking **RESET** will put the board into OTA (over-the-air) bootloader mode.
@@ -69,7 +77,7 @@ For other boards, please check the board definition for details.
6977
7078
### Making your own UF2
7179
72-
To create your own UF2 DFU update image, simply use the [Python conversion script](https://github.com/Microsoft/uf2/blob/master/utils/uf2conv.py) on a .bin file or .hex file, specifying the family as **0xADA52840**. If using a .bin file with the conversion script you must specify application address with the -b switch, this address depend on the SoftDevice size/version e.g S140 v6 is 0x26000
80+
To create your own UF2 DFU update image, simply use the [Python conversion script](https://github.com/Microsoft/uf2/blob/master/utils/uf2conv.py) on a .bin file or .hex file, specifying the family as **0xADA52840**. If using a .bin file with the conversion script you must specify application address with the -b switch, this address depend on the SoftDevice size/version e.g S140 v6 is 0x26000
7381
7482
To create a UF2 image from a .bin file:
7583
```
@@ -105,6 +113,15 @@ You must have have a J-Link available to "unbrick" your device.
105113
Prerequisites
106114
107115
- ARM GCC
116+
117+
To install for macos
118+
119+
```bash
120+
brew tap ArmMbed/homebrew-formulae
121+
brew install arm-none-eabi-gcc
122+
brew link --overwrite arm-none-eabi-gcc # if a prior version was present
123+
```
124+
108125
- Nordic's [nRF5x Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools)
109126
- [Python IntelHex](https://pypi.org/project/IntelHex/)
110127

@@ -148,7 +165,7 @@ Makefile:90: *** BOARD not defined. Stop
148165
If you get the following error ...
149166

150167
```
151-
$ make BOARD=feather_nrf52840_express all
168+
$ make BOARD=feather_nrf52840_express all
152169
Compiling file: main.c
153170
/bin/sh: /usr/bin/arm-none-eabi-gcc: No such file or directory
154171
make: *** [_build/main.o] Error 127
@@ -160,6 +177,8 @@ the variable `CROSS_COMPILE` as below:
160177
$ make CROSS_COMPILE=/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi- BOARD=feather_nrf52832 all
161178
```
162179

180+
For other compile errors, check the gcc version with `arm-none-eabi-gcc --version` to insure it is at least 9.x.
181+
163182
#### 2. `ModuleNotFoundError: No module named 'intelhex'`
164183

165184
Install python-intelhex with
@@ -169,9 +188,6 @@ pip install intelhex
169188
```
170189

171190

172-
173-
174-
175191
#### 3. `make: nrfjprog: No such file or directory`
176192

177193
Make sure that `nrfjprog` is available from the command-line. This binary is

src/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ int main(void)
170170

171171
// Serial only mode
172172
bool serial_only_dfu = (NRF_POWER->GPREGRET == DFU_MAGIC_SERIAL_ONLY_RESET);
173+
bool uf2_dfu = (NRF_POWER->GPREGRET == DFU_MAGIC_UF2_RESET);
173174

174175
// start either serial, uf2 or ble
175-
bool dfu_start = _ota_dfu || serial_only_dfu || (NRF_POWER->GPREGRET == DFU_MAGIC_UF2_RESET) ||
176+
bool dfu_start = _ota_dfu || serial_only_dfu || uf2_dfu ||
176177
(((*dbl_reset_mem) == DFU_DBL_RESET_MAGIC) && (NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk));
177178

178179
// Clear GPREGRET if it is our values
@@ -251,7 +252,7 @@ int main(void)
251252
}
252253

253254
// Initiate an update of the firmware.
254-
if (APP_ASKS_FOR_SINGLE_TAP_RESET())
255+
if (APP_ASKS_FOR_SINGLE_TAP_RESET() || uf2_dfu || serial_only_dfu)
255256
{
256257
// If USB is not enumerated in 3s (eg. because we're running on battery), we restart into app.
257258
APP_ERROR_CHECK( bootloader_dfu_start(_ota_dfu, 3000, true) );

0 commit comments

Comments
 (0)