Skip to content

Commit c1e6624

Browse files
authored
Merge pull request #1470 from gpshead/mdk_usb_dongle
Add Makerdiary nRF52840 MDK USB dongle support.
2 parents ea5acb7 + 91452ec commit c1e6624

File tree

8 files changed

+251
-2
lines changed

8 files changed

+251
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ git:
2121
# that SDK is shortest and add it there. In the case of major re-organizations,
2222
# just try to make the builds "about equal in run time"
2323
env:
24-
- TRAVIS_TESTS="unix docs translations website" TRAVIS_BOARDS="circuitplayground_express mini_sam_m4 grandcentral_m4_express pca10056 pca10059 feather_nrf52840_express makerdiary_nrf52840_mdk particle_boron particle_argon particle_xenon sparkfun_nrf52840_mini" TRAVIS_SDK=arm:nrf
24+
- TRAVIS_TESTS="unix docs translations website" TRAVIS_BOARDS="circuitplayground_express mini_sam_m4 grandcentral_m4_express pca10056 pca10059 feather_nrf52840_express makerdiary_nrf52840_mdk makerdiary_nrf52840_mdk_usb_dongle particle_boron particle_argon particle_xenon sparkfun_nrf52840_mini" TRAVIS_SDK=arm:nrf
2525
- TRAVIS_BOARDS="metro_m0_express metro_m4_express pirkey_m0 trellis_m4_express trinket_m0" TRAVIS_SDK=arm
2626
- TRAVIS_BOARDS="feather_radiofruit_zigbee gemma_m0 hallowing_m0_express itsybitsy_m0_express itsybitsy_m4_express meowmeow" TRAVIS_SDK=arm
2727
- TRAVIS_BOARDS="feather_m0_express_crickit feather_m0_rfm69 feather_m0_rfm9x feather_m4_express arduino_zero arduino_mkr1300 arduino_mkrzero" TRAVIS_SDK=arm

ports/nrf/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ the following links:
3535

3636
* Adafruit Feather nRF52840: `boards/feather_nrf52840_express/README.md`: 1MB Flash, 256KB SRAM
3737
* Nordic PCA10056 (uses nRF52840): `boards/pca10056/README.md`
38-
* MakerDiary NRF52840 MDK: `boards/makerdiary_nrf52840_mdk/README.md`
38+
* MakerDiary nRF52840 MDK: `boards/makerdiary_nrf52840_mdk/README.md`
39+
* MakerDiary nRF52840 MDK USB Dongle: `boards/makerdiary_nrf52840_mdk_usb_dongle/README.md`
3940

4041
For all other board targets, see the generic notes below.
4142

@@ -76,6 +77,7 @@ Target Board (BOARD) | Bluetooth Stack (SD) | Bluetooth Support | Fl
7677
pca10056 | s140 | Peripheral and Scanner | [Segger](#segger-targets)
7778
feather_nrf52840_express | s140 | Peripheral and Scanner | UF2 bootloader
7879
makerdiary_nrf52840_mdk | s140 | Peripheral and Scanner | pyocd or ARM mbed DAPLink
80+
makerdiary_nrf52840_mdk_usb_dongle | s140 | Peripheral and Scanner | DFU bootloader & nrfutil
7981

8082
## Segger Targets
8183

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# MakerDiary NRF52840 MDK USB Dongle
2+
3+
Refer to [The makerdiary Github repo](https://github.com/makerdiary/nrf52840-mdk-usb-dongle)
4+
or [The nrf52840-mdk-usb-dongle wiki](https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/)
5+
for more details about the device.
6+
7+
This is pretty much just the nRF52840 with a useful number of pins exposed for
8+
your pleasure along with one RGB LED and an onboard antenna in a USB stick form
9+
factor with room for headers on the sides.
10+
11+
Note that all three LEDs on this device are wired through sinks, not sources,
12+
so flip your boolean expectations when dealing with `DigitalInOut` or `PWMOut`
13+
on this device --
14+
`led.value = True` or `led.duty_cycle = 0xffff` turns the LED off!
15+
16+
The onboard button is hard wired to the Reset pin so you cannot use it yourself.
17+
18+
## Installing CircuitPython submodules
19+
20+
Before you can build, you will need to run the following commands once, which
21+
will install the submodules that are part of the CircuitPython ecosystem, and
22+
build the `mpy-cross` tool:
23+
24+
```
25+
$ cd circuitpython
26+
$ git submodule update --init
27+
$ make -C mpy-cross
28+
```
29+
30+
## Note about bootloaders
31+
32+
While most Adafruit devices come with (or can easily be flashed with) an
33+
Adafruit-provided bootloader (supporting niceties like UF2 flashing), this
34+
board comes with one that supports DFU via nrfutil. If you ever need to
35+
restore the DFU bootloader via a SWD debugger, use
36+
[the nRF52 open bootloader hex file](https://github.com/makerdiary/nrf52840-mdk-usb-dongle/tree/master/firmware/open_bootloader).
37+
38+
## Building and Flashing CircuitPython
39+
40+
```
41+
$ cd ports/nrf
42+
```
43+
44+
### Build CircuitPython for the MDK USB Dongle
45+
46+
```
47+
make BOARD=makerdiary_nrf52840_mdk_usb_dongle SD=s140 V=1 -j4 hex
48+
```
49+
50+
This should produce a `build-makerdiary_nrf52840_mdk_usb_dongle-s140/firmware.hex` file.
51+
52+
### Install nrfutil
53+
54+
You'll need to have [nrfutil](https://pypi.org/project/nrfutil/) installed as
55+
appropriate for your system.
56+
As of 2019-01, _nrfutil still requires Python 2.7_... ugh!
57+
58+
### Flash the nRF52 Radio Soft Device
59+
60+
Build a DFU package from the softdevice hex file and flash it:
61+
62+
```sh
63+
nrfutil pkg generate --hw-version 52 --sd-req 0x00 --sd-id 0xAE --softdevice bluetooth/s140_nrf52_6.1.0/s140_nrf52_6.1.0_softdevice.hex dfu_sd140-6.1.0.zip
64+
nrfutil dfu usb-serial -pkg dfu_sd140-6.1.0.zip -p /dev/tty.usbmodemABRACADBRA # likely /dev/ttyACM0 on Linux
65+
```
66+
67+
Note that the `--sd=id 0xAE` comes from the Nordic nRF52 manual for SoftDevice
68+
6.1.0. When the SoftDevice is changed, read the Nordic manual to find the
69+
correct value and use it on all of the `nrfutil pkg generate` commands.
70+
71+
`/dev/tty.usbmodem*` is a macOS name. On Linux it'll likely be `/dev/ttyACM*`. On Windows probably a COM port.
72+
73+
### Flash CircuitPython
74+
75+
Build a DFU package from the hex application file and flash it:
76+
77+
```
78+
nrfutil pkg generate --sd-req 0xAE --application build-makerdiary_nrf52840_mdk_usb_dongle-s140/firmware.hex --hw-version 52 --application-version 1 dfu_circuitpython.zip
79+
nrfutil dfu usb-serial -pkg dfu_circuitpython.zip -p /dev/tty.usbmodemABRACADBRA
80+
```
81+
82+
I'm not sure if `--application-version 1` is actually meaningful or required.
83+
84+
After this, your device should be up and running CircuitPython. When it
85+
resets, you'll see the CIRCUITPY USB filesystem and a new console usb modem
86+
serial port show up.
87+
88+
```
89+
Adafruit CircuitPython 4.0.0-alpha.5-139-g10ceb6716 on 2019-01-14; MakerDiary nRF52840 MDK USB Dongle with nRF52840
90+
>>>
91+
```
92+
93+
### TODO items
94+
95+
* Update the Makefile to do the above DFU .zip building and nrfutil flashing.
96+
* Create a UF2 bootloader for this. It is already a USB stick form factor, it deserves to behave like one.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "boards/board.h"
28+
29+
void board_init(void) {
30+
}
31+
32+
bool board_requests_safe_mode(void) {
33+
return false;
34+
}
35+
36+
void reset_board(void) {
37+
38+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Glenn Ruben Bakke
7+
* Copyright (c) 2018 Dan Halbert for Adafruit Industries
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#include "nrfx/hal/nrf_gpio.h"
29+
30+
#define MAKERDIARY_NRF52840_MDK_DONGLE
31+
32+
#define MICROPY_HW_BOARD_NAME "MakerDiary nRF52840 MDK USB Dongle"
33+
#define MICROPY_HW_MCU_NAME "nRF52840"
34+
#define MICROPY_PY_SYS_PLATFORM "MakerDiary52840MDKDongle"
35+
36+
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
37+
38+
// If you change this, then make sure to update the linker scripts as well to
39+
// make sure you don't overwrite code
40+
#define PORT_HEAP_SIZE (128 * 1024)
41+
// TODO #define CIRCUITPY_INTERNAL_NVM_SIZE 8192
42+
43+
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
44+
45+
#define BOARD_HAS_CRYSTAL 1 // according to the schematic we do
46+
47+
// See https://github.com/adafruit/circuitpython/issues/1300, circuitpython
48+
// doesn't yet support NFC so just force those pins to be GPIO.
49+
#define CONFIG_NFCT_PINS_AS_GPIOS
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
USB_VID = 0x239A
2+
USB_PID = 0x802A
3+
USB_PRODUCT = "nRF52840-MDK-Dongle"
4+
USB_MANUFACTURER = "makerdiary"
5+
6+
MCU_SERIES = m4
7+
MCU_VARIANT = nrf52
8+
MCU_SUB_VARIANT = nrf52840
9+
MCU_CHIP = nrf52840
10+
SD ?= s140
11+
SOFTDEV_VERSION ?= 6.1.0
12+
13+
BOOT_SETTING_ADDR = 0xFF000
14+
BOOT_FILE = boards/$(BOARD)/bootloader/$(SOFTDEV_VERSION)/$(BOARD)_bootloader_$(SOFTDEV_VERSION)_s140
15+
16+
ifeq ($(SD),)
17+
LD_FILE = boards/nrf52840_1M_256k.ld
18+
else
19+
LD_FILE = boards/adafruit_$(MCU_SUB_VARIANT)_$(SD_LOWER)_v$(firstword $(subst ., ,$(SOFTDEV_VERSION))).ld
20+
endif
21+
22+
NRF_DEFINES += -DNRF52840_XXAA -DNRF52840
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "shared-bindings/board/__init__.h"
2+
3+
#include "board_busses.h"
4+
5+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
6+
{ MP_ROM_QSTR(MP_QSTR_AIN0), MP_ROM_PTR(&pin_P0_02) },
7+
{ MP_ROM_QSTR(MP_QSTR_AIN1), MP_ROM_PTR(&pin_P0_03) },
8+
{ MP_ROM_QSTR(MP_QSTR_AIN2), MP_ROM_PTR(&pin_P0_04) },
9+
{ MP_ROM_QSTR(MP_QSTR_AIN3), MP_ROM_PTR(&pin_P0_05) },
10+
11+
{ MP_ROM_QSTR(MP_QSTR_AREF), MP_ROM_PTR(&pin_P0_04) }, // User must connect manually.
12+
{ MP_ROM_QSTR(MP_QSTR_VDIV), MP_ROM_PTR(&pin_P0_05) }, // User must connect manually.
13+
14+
// Not defining the NFC names until CircuitPython supports NFC.
15+
// { MP_ROM_QSTR(MP_QSTR_NFC1), MP_ROM_PTR(&pin_P0_09) },
16+
// { MP_ROM_QSTR(MP_QSTR_NFC2), MP_ROM_PTR(&pin_P0_10) },
17+
18+
{ MP_ROM_QSTR(MP_QSTR_P2), MP_ROM_PTR(&pin_P0_02) },
19+
{ MP_ROM_QSTR(MP_QSTR_P3), MP_ROM_PTR(&pin_P0_03) },
20+
{ MP_ROM_QSTR(MP_QSTR_P4), MP_ROM_PTR(&pin_P0_04) },
21+
{ MP_ROM_QSTR(MP_QSTR_P5), MP_ROM_PTR(&pin_P0_05) },
22+
{ MP_ROM_QSTR(MP_QSTR_P6), MP_ROM_PTR(&pin_P0_06) },
23+
{ MP_ROM_QSTR(MP_QSTR_P7), MP_ROM_PTR(&pin_P0_07) },
24+
{ MP_ROM_QSTR(MP_QSTR_P8), MP_ROM_PTR(&pin_P0_08) },
25+
{ MP_ROM_QSTR(MP_QSTR_P9), MP_ROM_PTR(&pin_P0_09) },
26+
{ MP_ROM_QSTR(MP_QSTR_P10), MP_ROM_PTR(&pin_P0_10) },
27+
{ MP_ROM_QSTR(MP_QSTR_P18), MP_ROM_PTR(&pin_P0_18) }, // !Reset button.
28+
{ MP_ROM_QSTR(MP_QSTR_P19), MP_ROM_PTR(&pin_P0_19) },
29+
{ MP_ROM_QSTR(MP_QSTR_P22), MP_ROM_PTR(&pin_P0_22) }, // green led, low is on.
30+
{ MP_ROM_QSTR(MP_QSTR_P23), MP_ROM_PTR(&pin_P0_23) }, // red led, low is on.
31+
{ MP_ROM_QSTR(MP_QSTR_P24), MP_ROM_PTR(&pin_P0_24) }, // blue led, low is on.
32+
33+
{ MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_P0_23) }, // Low is on.
34+
{ MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_P0_22) }, // Low is on.
35+
{ MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_P0_24) }, // Low is on.
36+
37+
// BUT this is the RESET pin so we can't really use it.
38+
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_P0_18) }, // Low is pressed.
39+
};
40+
41+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

tools/build_board_info.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
# nRF52840 dev kits that may not have UF2 bootloaders,
3939
"makerdiary_nrf52840_mdk": HEX,
40+
"makerdiary_nrf52840_mdk_usb_dongle": HEX,
4041
"pca10056": BIN_UF2,
4142
"pca10059": BIN_UF2
4243
}

0 commit comments

Comments
 (0)