Skip to content

Commit 7654ff7

Browse files
Able to flash code to nRF52840 DK!
1 parent 46c99d4 commit 7654ff7

File tree

5 files changed

+127
-72
lines changed

5 files changed

+127
-72
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_NRF52840_DK/PinNames.h

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,6 @@ typedef enum {
159159
p45 = P1_13,
160160
p46 = P1_14,
161161
p47 = P1_15,
162-
163-
LED1 = p13,
164-
LED2 = p14,
165-
LED3 = p15,
166-
LED4 = p16,
167-
168-
BUTTON1 = p11,
169-
BUTTON2 = p12,
170-
BUTTON3 = p24,
171-
BUTTON4 = p25,
172162

173163
RX_PIN_NUMBER = p8,
174164
TX_PIN_NUMBER = p6,
@@ -191,69 +181,81 @@ typedef enum {
191181
STDIO_UART_CTS = CTS_PIN_NUMBER,
192182
STDIO_UART_RTS = RTS_PIN_NUMBER,
193183

194-
SPI_PSELMOSI0 = P1_13,
195-
SPI_PSELMISO0 = P1_14,
196-
SPI_PSELSS0 = P1_12,
197-
SPI_PSELSCK0 = P1_15,
184+
ARDUINO_UNO_D0 = P1_1,
185+
ARDUINO_UNO_D1 = P1_2,
186+
ARDUINO_UNO_D2 = P1_3,
187+
ARDUINO_UNO_D3 = P1_4,
188+
ARDUINO_UNO_D4 = P1_5,
189+
ARDUINO_UNO_D5 = P1_6,
190+
ARDUINO_UNO_D6 = P1_7,
191+
ARDUINO_UNO_D7 = P1_8,
192+
193+
ARDUINO_UNO_D8 = P1_10,
194+
ARDUINO_UNO_D9 = P1_11,
195+
ARDUINO_UNO_D10 = P1_12,
196+
ARDUINO_UNO_D11 = P1_13,
197+
ARDUINO_UNO_D12 = P1_14,
198+
ARDUINO_UNO_D13 = P1_15,
198199

199-
SPI_PSELMOSI1 = P1_2,
200-
SPI_PSELMISO1 = P1_3,
201-
SPI_PSELSS1 = P1_1,
202-
SPI_PSELSCK1 = P1_4,
200+
ARDUINO_UNO_D14 = p26,
201+
ARDUINO_UNO_D15 = p27,
203202

204-
SPIS_PSELMOSI = P1_2,
205-
SPIS_PSELMISO = P1_3,
206-
SPIS_PSELSS = P1_1,
207-
SPIS_PSELSCK = P1_4,
203+
ARDUINO_UNO_A0 = p3,
204+
ARDUINO_UNO_A1 = p4,
205+
ARDUINO_UNO_A2 = p28,
206+
ARDUINO_UNO_A3 = p29,
207+
ARDUINO_UNO_A4 = p30,
208+
ARDUINO_UNO_A5 = p31,
209+
210+
// Not connected
211+
NC = (int)0xFFFFFFFF
212+
} PinName;
208213

209-
I2C_SDA0 = p26,
210-
I2C_SCL0 = p27,
214+
// LEDs and buttons
215+
#define LED1 p13
216+
#define LED2 p14
217+
#define LED3 p15
218+
#define LED4 p16
211219

212-
D0 = P1_1,
213-
D1 = P1_2,
214-
D2 = P1_3,
215-
D3 = P1_4,
216-
D4 = P1_5,
217-
D5 = P1_6,
218-
D6 = P1_7,
219-
D7 = P1_8,
220+
#define BUTTON1 p11
221+
#define BUTTON2 p12
222+
#define BUTTON3 p24
223+
#define BUTTON4 p25
220224

221-
D8 = P1_10,
222-
D9 = P1_11,
223-
D10 = P1_12,
224-
D11 = P1_13,
225-
D12 = P1_14,
226-
D13 = P1_15,
225+
// Busses
226+
#define I2C_SDA0 p26
227+
#define I2C_SCL0 p27
227228

228-
D14 = p26,
229-
D15 = p27,
229+
#define SPI_PSELMOSI0 P1_13
230+
#define SPI_PSELMISO0 P1_14
231+
#define SPI_PSELSS0 P1_12
232+
#define SPI_PSELSCK0 P1_15
230233

231-
A0 = p3,
232-
A1 = p4,
233-
A2 = p28,
234-
A3 = p29,
235-
A4 = p30,
236-
A5 = p31,
234+
#define SPI_PSELMOSI1 P1_2
235+
#define SPI_PSELMISO1 P1_3
236+
#define SPI_PSELSS1 P1_1
237+
#define SPI_PSELSCK1 P1_4
237238

238-
/**** QSPI pins ****/
239-
QSPI1_IO0 = P0_20,
240-
QSPI1_IO1 = P0_21,
241-
QSPI1_IO2 = P0_22,
242-
QSPI1_IO3 = P0_23,
243-
QSPI1_SCK = P0_19,
244-
QSPI1_CSN = P0_17,
239+
#define SPIS_PSELMOSI P1_2
240+
#define SPIS_PSELMISO P1_3
241+
#define SPIS_PSELSS P1_1
242+
#define SPIS_PSELSCK P1_4
245243

246-
/**** QSPI FLASH pins ****/
247-
QSPI_FLASH1_IO0 = QSPI1_IO0,
248-
QSPI_FLASH1_IO1 = QSPI1_IO1,
249-
QSPI_FLASH1_IO2 = QSPI1_IO2,
250-
QSPI_FLASH1_IO3 = QSPI1_IO3,
251-
QSPI_FLASH1_SCK = QSPI1_SCK,
252-
QSPI_FLASH1_CSN = QSPI1_CSN,
244+
/**** QSPI pins ****/
245+
#define QSPI1_IO0 P0_20
246+
#define QSPI1_IO1 P0_21
247+
#define QSPI1_IO2 P0_22
248+
#define QSPI1_IO3 P0_23
249+
#define QSPI1_SCK P0_19
250+
#define QSPI1_CSN P0_17
253251

254-
// Not connected
255-
NC = (int)0xFFFFFFFF
256-
} PinName;
252+
/**** QSPI FLASH pins ****/
253+
#define QSPI_FLASH1_IO0 QSPI1_IO0
254+
#define QSPI_FLASH1_IO1 QSPI1_IO1
255+
#define QSPI_FLASH1_IO2 QSPI1_IO2
256+
#define QSPI_FLASH1_IO3 QSPI1_IO3
257+
#define QSPI_FLASH1_SCK QSPI1_SCK
258+
#define QSPI_FLASH1_CSN QSPI1_CSN
257259

258260
typedef enum {
259261
PullNone = 0,

targets/targets.json5

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7472,7 +7472,7 @@ mode is recommended for target MCUs with small amounts of flash and RAM.",
74727472
},
74737473
"NRF52840_DK": {
74747474
"supported_form_factors": [
7475-
"ARDUINO"
7475+
"ARDUINO_UNO"
74767476
],
74777477
"inherits": [
74787478
"MCU_NRF52840"
@@ -7492,6 +7492,9 @@ mode is recommended for target MCUs with small amounts of flash and RAM.",
74927492
"supported_application_profiles": [
74937493
"full", "bare-metal"
74947494
],
7495+
"components_add": [
7496+
"QSPIF"
7497+
],
74957498
"image_url": "https://www.nordicsemi.com/-/media/Images/Products/DevKits/nRF52-Series/nRF52840-DK/nRF52840-DK/nRF52840-DK-prod-page.png?h=750&iar=0&mw=350&w=350&hash=3DB140F6AE70CAE159FD911D8E6E9109"
74967499
},
74977500
"ARDUINO_NANO33BLE": {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Mbed OS upload method configuration file for target NRF52840_DK.
2+
# To change any of these parameters from their default values, set them in your build script between where you
3+
# include app.cmake and where you add mbed os as a subdirectory.
4+
5+
# Notes:
6+
# 1. If you have multiple Mbed devices plugged in to your machine, the MBED upload method only
7+
# works for this device if you set the serial number (e.g. -DMBED_UPLOAD_SERIAL_NUMBER=001050278063).
8+
# This is because for some reason the USB disk mode doesn't make the target name available to the host PC.
9+
# 2. In my testing this device may need a manual reset via the reset button after
10+
# flashing code via the MBED upload method.
11+
# 3. To use this device with PyOCD you need to install the J-Link software package on your system.
12+
# 4. As of Sep 2025, PyOCD can flash but cannot reliably debug. Getting 'cannot read register
13+
# ipsr because core #0 is not halted'.
14+
15+
16+
# General config parameters
17+
# -------------------------------------------------------------
18+
set(UPLOAD_METHOD_DEFAULT MBED)
19+
20+
# Config options for MBED
21+
# -------------------------------------------------------------
22+
set(MBED_UPLOAD_ENABLED TRUE)
23+
24+
# Config options for JLINK
25+
# -------------------------------------------------------------
26+
set(JLINK_UPLOAD_ENABLED TRUE)
27+
set(JLINK_CPU_NAME nRF52840_xxAA)
28+
set(JLINK_UPLOAD_INTERFACE SWD)
29+
set(JLINK_CLOCK_SPEED 4000)
30+
31+
# Config options for PYOCD
32+
# -------------------------------------------------------------
33+
34+
set(PYOCD_UPLOAD_ENABLED TRUE)
35+
set(PYOCD_TARGET_NAME nrf52840)
36+
set(PYOCD_CLOCK_SPEED 4000k)

tools/cmake/upload_methods/UploadMethodJLINK.cmake

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ set(JLINK_NETWORK_ADDRESS "" CACHE STRING "Use a J-Link connected over the netwo
2424
if((NOT "${MBED_UPLOAD_SERIAL_NUMBER}" STREQUAL "") AND (NOT "${JLINK_NETWORK_ADDRESS}" STREQUAL ""))
2525
message(FATAL_ERROR "Cannot use both MBED_UPLOAD_SERIAL_NUMBER and JLINK_NETWORK_ADDRESS at the same time!")
2626
elseif(NOT "${MBED_UPLOAD_SERIAL_NUMBER}" STREQUAL "")
27-
set(JLINK_SELECT_ARG -Select usb=${MBED_UPLOAD_SERIAL_NUMBER} CACHE INTERNAL "" FORCE)
27+
set(JLINK_EXE_SELECT_ARG -USB ${MBED_UPLOAD_SERIAL_NUMBER} CACHE INTERNAL "" FORCE)
28+
set(JLINK_GDB_SELECT_ARG -Select usb=${MBED_UPLOAD_SERIAL_NUMBER})
2829
elseif(NOT "${JLINK_NETWORK_ADDRESS}" STREQUAL "")
29-
set(JLINK_SELECT_ARG -Select ip=${JLINK_NETWORK_ADDRESS} CACHE INTERNAL "" FORCE)
30+
set(JLINK_EXE_SELECT_ARG -IP ${MBED_UPLOAD_SERIAL_NUMBER} CACHE INTERNAL "" FORCE)
31+
set(JLINK_GDB_SELECT_ARG -Select ip=${JLINK_NETWORK_ADDRESS})
3032
else()
3133
# use default behavior
32-
set(JLINK_SELECT_ARG "" CACHE INTERNAL "" FORCE)
34+
set(JLINK_EXE_SELECT_ARG "" CACHE INTERNAL "" FORCE)
35+
set(JLINK_GDB_SELECT_ARG)
3336
endif()
3437

3538
# default to JTAG
@@ -65,7 +68,7 @@ exit
6568
add_custom_target(flash-${TARGET_NAME}
6669
COMMENT "Flashing ${TARGET_NAME} with J-Link..."
6770
COMMAND ${JLINK}
68-
${JLINK_SELECT_ARG}
71+
${JLINK_EXE_SELECT_ARG}
6972
-Device \"${JLINK_CPU_NAME}\"
7073
-Speed ${JLINK_CLOCK_SPEED}
7174
-if ${JLINK_UPLOAD_INTERFACE}
@@ -80,7 +83,7 @@ endfunction(gen_upload_target)
8083
# https://wiki.segger.com/J-Link_GDB_Server:#Command_line_options
8184
set(UPLOAD_GDBSERVER_DEBUG_COMMAND
8285
"${JLINK_GDBSERVER}"
83-
${JLINK_SELECT_ARG}
86+
${JLINK_GDB_SELECT_ARG}
8487
${JLINK_NOGUI_ARG}
8588
-Device \"${JLINK_CPU_NAME}\"
8689
-Speed ${JLINK_CLOCK_SPEED}

tools/python/install_bin_file.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,22 @@ def error(lines, code=-1):
6262
targets = get_detected_targets()
6363
if targets:
6464
for _target in targets:
65+
6566
if _target['name'] is None:
66-
continue
67-
elif _target['name'].upper() == target_name.upper():
68-
if target_uid is None or _target['uid'] == target_uid:
67+
if target_uid is not None and _target['uid'] == target_uid:
68+
# If we have an exact UID match and we don't know the name, then assume that
69+
# the UID is correct.
6970
all_connected.append(_target)
71+
else:
72+
if _target['name'].upper() == target_name.upper():
73+
if target_uid is None or _target['uid'] == target_uid:
74+
# Name matches, UID either matches or was not specified
75+
all_connected.append(_target)
76+
77+
if len(all_connected) == 0 and len(targets) == 1 and targets[0]['name'] is None:
78+
# Special case: if we only have one board connected to the system, then assume it's the one
79+
# we want even if we could not detect its name.
80+
all_connected.append(targets[0])
7081

7182
if len(all_connected) == 0:
7283
error_lines = ["The target board you compiled for is not connected to your system.",

0 commit comments

Comments
 (0)