diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/PeripheralPins.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/PeripheralPins.c index 335aff45506..01077e8e218 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/PeripheralPins.c +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/PeripheralPins.c @@ -34,6 +34,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ #include "PeripheralPins.h" @@ -67,6 +68,8 @@ const PinMap PinMap_I2C_testing[] = { {P0_23, 0, 0}, {P0_24, 0, 0}, {P0_25, 0, 0}, + {P0_26, 0, 0}, + {P0_27, 0, 0}, {P0_28, 0, 0}, {P0_29, 0, 0}, {P0_30, 0, 0}, @@ -120,6 +123,8 @@ const PinMap PinMap_SPI_testing[] = { {P0_23, 0, 0}, {P0_24, 0, 0}, {P0_25, 0, 0}, + {P0_26, 0, 0}, + {P0_27, 0, 0}, {P0_28, 0, 0}, {P0_29, 0, 0}, {P0_30, 0, 0}, @@ -173,6 +178,8 @@ const PinMap PinMap_UART_testing[] = { {P0_23, 0, 0}, {P0_24, 0, 0}, {P0_25, 0, 0}, + {P0_26, 0, 0}, + {P0_27, 0, 0}, {P0_28, 0, 0}, {P0_29, 0, 0}, {P0_30, 0, 0}, @@ -226,6 +233,8 @@ const PinMap PinMap_PWM_testing[] = { {P0_23, 0, 0}, {P0_24, 0, 0}, {P0_25, 0, 0}, + {P0_26, 0, 0}, + {P0_27, 0, 0}, {P0_28, 0, 0}, {P0_29, 0, 0}, {P0_30, 0, 0}, @@ -279,6 +288,8 @@ const PinMap PinMap_QSPI_testing[] = { {P0_23, 0, 0}, {P0_24, 0, 0}, {P0_25, 0, 0}, + {P0_26, 0, 0}, + {P0_27, 0, 0}, {P0_28, 0, 0}, {P0_29, 0, 0}, {P0_30, 0, 0}, diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_NRF52840_DK/PinNames.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_NRF52840_DK/PinNames.h index 97049436433..289b8a63f07 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_NRF52840_DK/PinNames.h +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_NRF52840_DK/PinNames.h @@ -33,7 +33,8 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ /* MBED TARGET LIST: NRF52840_DK */ @@ -159,16 +160,6 @@ typedef enum { p45 = P1_13, p46 = P1_14, p47 = P1_15, - - LED1 = p13, - LED2 = p14, - LED3 = p15, - LED4 = p16, - - BUTTON1 = p11, - BUTTON2 = p12, - BUTTON3 = p24, - BUTTON4 = p25, RX_PIN_NUMBER = p8, TX_PIN_NUMBER = p6, @@ -191,69 +182,81 @@ typedef enum { STDIO_UART_CTS = CTS_PIN_NUMBER, STDIO_UART_RTS = RTS_PIN_NUMBER, - SPI_PSELMOSI0 = P1_13, - SPI_PSELMISO0 = P1_14, - SPI_PSELSS0 = P1_12, - SPI_PSELSCK0 = P1_15, + ARDUINO_UNO_D0 = P1_1, + ARDUINO_UNO_D1 = P1_2, + ARDUINO_UNO_D2 = P1_3, + ARDUINO_UNO_D3 = P1_4, + ARDUINO_UNO_D4 = P1_5, + ARDUINO_UNO_D5 = P1_6, + ARDUINO_UNO_D6 = P1_7, + ARDUINO_UNO_D7 = P1_8, + + ARDUINO_UNO_D8 = P1_10, + ARDUINO_UNO_D9 = P1_11, + ARDUINO_UNO_D10 = P1_12, + ARDUINO_UNO_D11 = P1_13, + ARDUINO_UNO_D12 = P1_14, + ARDUINO_UNO_D13 = P1_15, + + ARDUINO_UNO_D14 = p26, + ARDUINO_UNO_D15 = p27, - SPI_PSELMOSI1 = P1_2, - SPI_PSELMISO1 = P1_3, - SPI_PSELSS1 = P1_1, - SPI_PSELSCK1 = P1_4, + ARDUINO_UNO_A0 = p3, + ARDUINO_UNO_A1 = p4, + ARDUINO_UNO_A2 = p28, + ARDUINO_UNO_A3 = p29, + ARDUINO_UNO_A4 = p30, + ARDUINO_UNO_A5 = p31, - SPIS_PSELMOSI = P1_2, - SPIS_PSELMISO = P1_3, - SPIS_PSELSS = P1_1, - SPIS_PSELSCK = P1_4, + // Not connected + NC = (int)0xFFFFFFFF +} PinName; - I2C_SDA0 = p26, - I2C_SCL0 = p27, +// LEDs and buttons +#define LED1 p13 +#define LED2 p14 +#define LED3 p15 +#define LED4 p16 - D0 = P1_1, - D1 = P1_2, - D2 = P1_3, - D3 = P1_4, - D4 = P1_5, - D5 = P1_6, - D6 = P1_7, - D7 = P1_8, +#define BUTTON1 p11 +#define BUTTON2 p12 +#define BUTTON3 p24 +#define BUTTON4 p25 - D8 = P1_10, - D9 = P1_11, - D10 = P1_12, - D11 = P1_13, - D12 = P1_14, - D13 = P1_15, +// Busses +#define I2C_SDA0 p26 +#define I2C_SCL0 p27 - D14 = p26, - D15 = p27, +#define SPI_PSELMOSI0 P1_13 +#define SPI_PSELMISO0 P1_14 +#define SPI_PSELSS0 P1_12 +#define SPI_PSELSCK0 P1_15 - A0 = p3, - A1 = p4, - A2 = p28, - A3 = p29, - A4 = p30, - A5 = p31, +#define SPI_PSELMOSI1 P1_2 +#define SPI_PSELMISO1 P1_3 +#define SPI_PSELSS1 P1_1 +#define SPI_PSELSCK1 P1_4 - /**** QSPI pins ****/ - QSPI1_IO0 = P0_20, - QSPI1_IO1 = P0_21, - QSPI1_IO2 = P0_22, - QSPI1_IO3 = P0_23, - QSPI1_SCK = P0_19, - QSPI1_CSN = P0_17, +#define SPIS_PSELMOSI P1_2 +#define SPIS_PSELMISO P1_3 +#define SPIS_PSELSS P1_1 +#define SPIS_PSELSCK P1_4 - /**** QSPI FLASH pins ****/ - QSPI_FLASH1_IO0 = QSPI1_IO0, - QSPI_FLASH1_IO1 = QSPI1_IO1, - QSPI_FLASH1_IO2 = QSPI1_IO2, - QSPI_FLASH1_IO3 = QSPI1_IO3, - QSPI_FLASH1_SCK = QSPI1_SCK, - QSPI_FLASH1_CSN = QSPI1_CSN, +/**** QSPI pins ****/ +#define QSPI1_IO0 P0_20 +#define QSPI1_IO1 P0_21 +#define QSPI1_IO2 P0_22 +#define QSPI1_IO3 P0_23 +#define QSPI1_SCK P0_19 +#define QSPI1_CSN P0_17 - // Not connected - NC = (int)0xFFFFFFFF -} PinName; +/**** QSPI FLASH pins ****/ +#define QSPI_FLASH1_IO0 QSPI1_IO0 +#define QSPI_FLASH1_IO1 QSPI1_IO1 +#define QSPI_FLASH1_IO2 QSPI1_IO2 +#define QSPI_FLASH1_IO3 QSPI1_IO3 +#define QSPI_FLASH1_SCK QSPI1_SCK +#define QSPI_FLASH1_CSN QSPI1_CSN typedef enum { PullNone = 0, diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/TOOLCHAIN_GCC_ARM/NRF52840.ld b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/TOOLCHAIN_GCC_ARM/NRF52840.ld index 30841e58f6b..45a849d2b89 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/TOOLCHAIN_GCC_ARM/NRF52840.ld +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/TOOLCHAIN_GCC_ARM/NRF52840.ld @@ -16,42 +16,17 @@ /* Linker script to configure memory regions. */ -/* Default to no softdevice */ -#if !defined(MBED_APP_START) - #define MBED_APP_START 0x0 -#endif - -#if !defined(MBED_APP_SIZE) - #define MBED_APP_SIZE 0x100000 -#endif - -#if !defined(MBED_RAM_START) - #define MBED_RAM_START 0x20000000 - #define MBED_RAM_SIZE 0x40000 -#endif - #if !defined(MBED_CONF_TARGET_BOOT_STACK_SIZE) #define MBED_CONF_TARGET_BOOT_STACK_SIZE 0x800 #endif - -#define MBED_RAM0_START MBED_RAM_START -#define MBED_RAM0_SIZE 0x100 - -#define MBED_CRASH_REPORT_RAM_START (MBED_RAM0_START + MBED_RAM0_SIZE) #define MBED_CRASH_REPORT_RAM_SIZE 0x100 -#define MBED_RAM1_START (MBED_CRASH_REPORT_RAM_START + MBED_CRASH_REPORT_RAM_SIZE) -#define MBED_RAM1_SIZE (MBED_RAM_SIZE - (MBED_RAM0_SIZE + MBED_CRASH_REPORT_RAM_SIZE)) - MEMORY { - FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE - RAM_NVIC (rwx) : ORIGIN = MBED_RAM0_START, LENGTH = MBED_RAM0_SIZE - RAM_CRASH_DATA (rwx) : ORIGIN = MBED_CRASH_REPORT_RAM_START, LENGTH = MBED_CRASH_REPORT_RAM_SIZE - RAM (rwx) : ORIGIN = MBED_RAM1_START, LENGTH = MBED_RAM1_SIZE + FLASH (rx) : ORIGIN = MBED_CONFIGURED_ROM_BANK_IROM1_START, LENGTH = MBED_CONFIGURED_ROM_BANK_IROM1_SIZE + RAM (rwx) : ORIGIN = MBED_RAM_BANK_IRAM1_START, LENGTH = MBED_RAM_BANK_IRAM1_SIZE } - OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") /* Linker script to place sections and symbol values. Should be used together @@ -84,6 +59,28 @@ ENTRY(Reset_Handler) SECTIONS { + /* RAM vector table */ + .nvictable (NOLOAD) : + { + PROVIDE(__start_nvictable = .); + KEEP(*(.nvictable)) + PROVIDE(__stop_nvictable = .); + } > RAM + + /* Crash data RAM (preserved across resets) */ + .crash_data_ram (NOLOAD): + { + . = ALIGN(8); + __CRASH_DATA_RAM__ = .; + __CRASH_DATA_RAM_START__ = .; /* Create a global symbol at data start */ + . += MBED_CRASH_REPORT_RAM_SIZE; + __CRASH_DATA_RAM_END__ = .; /* Define a global symbol at data end */ + + /* Include any used-defined data in the crash data RAM */ + KEEP(*(.keep.crash_data_ram)) + *(.m_crash_data_ram) + } > RAM + .text : { KEEP(*(.Vectors)) @@ -201,25 +198,6 @@ SECTIONS __edata = .; - .nvictable (NOLOAD) : - { - PROVIDE(__start_nvictable = .); - KEEP(*(.nvictable)) - PROVIDE(__stop_nvictable = .); - } > RAM_NVIC - - .crash_data_ram : - { - . = ALIGN(8); - __CRASH_DATA_RAM__ = .; - __CRASH_DATA_RAM_START__ = .; /* Create a global symbol at data start */ - KEEP(*(.keep.crash_data_ram)) - *(.m_crash_data_ram) /* This is a user defined section */ - . += MBED_CRASH_REPORT_RAM_SIZE; - . = ALIGN(8); - __CRASH_DATA_RAM_END__ = .; /* Define a global symbol at data end */ - } > RAM_CRASH_DATA - .noinit (NOLOAD) : { PROVIDE(__start_noinit = .); diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/cmsis_nvic.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/cmsis_nvic.h index 34314a58493..ae6aacae411 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/cmsis_nvic.h +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/cmsis_nvic.h @@ -3,6 +3,7 @@ ******************************************************************************* * Copyright (c) 2016 ARM Limited. All rights reserved. * All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -35,20 +36,6 @@ #define NVIC_NUM_VECTORS (16 + 48) // CORE + MCU Peripherals #define NVIC_USER_IRQ_OFFSET 16 -// RAM size defines, same as in the linker script -#if !defined(MBED_APP_START) - #define MBED_APP_START 0x0 -#endif - -#if !defined(MBED_APP_SIZE) - #define MBED_APP_SIZE 0x100000 -#endif - -#if !defined(MBED_RAM_START) - #define MBED_RAM_START 0x20000000 - #define MBED_RAM_SIZE 0x40000 -#endif - #include "nrf.h" #include "cmsis.h" diff --git a/targets/targets.json5 b/targets/targets.json5 index 20c795df20f..ca6426bb2ac 100644 --- a/targets/targets.json5 +++ b/targets/targets.json5 @@ -7472,7 +7472,7 @@ mode is recommended for target MCUs with small amounts of flash and RAM.", }, "NRF52840_DK": { "supported_form_factors": [ - "ARDUINO" + "ARDUINO_UNO" ], "inherits": [ "MCU_NRF52840" @@ -7492,6 +7492,9 @@ mode is recommended for target MCUs with small amounts of flash and RAM.", "supported_application_profiles": [ "full", "bare-metal" ], + "components_add": [ + "QSPIF" + ], "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" }, "ARDUINO_NANO33BLE": { diff --git a/targets/upload_method_cfg/NRF52840_DK.cmake b/targets/upload_method_cfg/NRF52840_DK.cmake new file mode 100644 index 00000000000..5e9df0f77f6 --- /dev/null +++ b/targets/upload_method_cfg/NRF52840_DK.cmake @@ -0,0 +1,39 @@ +# Mbed OS upload method configuration file for target NRF52840_DK. +# To change any of these parameters from their default values, set them in your build script between where you +# include app.cmake and where you add mbed os as a subdirectory. + +# Notes: +# 1. If you have multiple Mbed devices plugged in to your machine, the MBED upload method only +# works for this device if you set the serial number (e.g. -DMBED_UPLOAD_SERIAL_NUMBER=001050278063). +# This is because for some reason the USB disk mode doesn't make the target name available to the host PC. +# 2. In my testing this device may need a manual reset via the reset button after +# flashing code via the MBED upload method. +# 3. To use this device with PyOCD you need to install the J-Link software package on your system. +# 4. As of Sep 2025, PyOCD can flash but cannot reliably debug. Getting 'cannot read register +# ipsr because core #0 is not halted'. +# 5. This upload method configuration reflects version 3 of the DK board, which uses an nRF5340 MCU and does +# not have DAPLink firmware available, only J-Link OB. The older version would have had better support for OpenOCD, +# Mbed, and PyOCD upload methods but does not seem to be available any more. + + +# General config parameters +# ------------------------------------------------------------- +set(UPLOAD_METHOD_DEFAULT JLINK) + +# Config options for MBED +# ------------------------------------------------------------- +set(MBED_UPLOAD_ENABLED TRUE) + +# Config options for JLINK +# ------------------------------------------------------------- +set(JLINK_UPLOAD_ENABLED TRUE) +set(JLINK_CPU_NAME nRF52840_xxAA) +set(JLINK_UPLOAD_INTERFACE SWD) +set(JLINK_CLOCK_SPEED 4000) + +# Config options for PYOCD +# ------------------------------------------------------------- + +set(PYOCD_UPLOAD_ENABLED TRUE) +set(PYOCD_TARGET_NAME nrf52840) +set(PYOCD_CLOCK_SPEED 4000k) diff --git a/tools/cmake/upload_methods/UploadMethodJLINK.cmake b/tools/cmake/upload_methods/UploadMethodJLINK.cmake index 0157e3b9ace..0543d282aff 100644 --- a/tools/cmake/upload_methods/UploadMethodJLINK.cmake +++ b/tools/cmake/upload_methods/UploadMethodJLINK.cmake @@ -24,12 +24,15 @@ set(JLINK_NETWORK_ADDRESS "" CACHE STRING "Use a J-Link connected over the netwo if((NOT "${MBED_UPLOAD_SERIAL_NUMBER}" STREQUAL "") AND (NOT "${JLINK_NETWORK_ADDRESS}" STREQUAL "")) message(FATAL_ERROR "Cannot use both MBED_UPLOAD_SERIAL_NUMBER and JLINK_NETWORK_ADDRESS at the same time!") elseif(NOT "${MBED_UPLOAD_SERIAL_NUMBER}" STREQUAL "") - set(JLINK_SELECT_ARG -Select usb=${MBED_UPLOAD_SERIAL_NUMBER} CACHE INTERNAL "" FORCE) + set(JLINK_EXE_SELECT_ARG -USB ${MBED_UPLOAD_SERIAL_NUMBER} CACHE INTERNAL "" FORCE) + set(JLINK_GDB_SELECT_ARG -Select usb=${MBED_UPLOAD_SERIAL_NUMBER}) elseif(NOT "${JLINK_NETWORK_ADDRESS}" STREQUAL "") - set(JLINK_SELECT_ARG -Select ip=${JLINK_NETWORK_ADDRESS} CACHE INTERNAL "" FORCE) + set(JLINK_EXE_SELECT_ARG -IP ${MBED_UPLOAD_SERIAL_NUMBER} CACHE INTERNAL "" FORCE) + set(JLINK_GDB_SELECT_ARG -Select ip=${JLINK_NETWORK_ADDRESS}) else() # use default behavior - set(JLINK_SELECT_ARG "" CACHE INTERNAL "" FORCE) + set(JLINK_EXE_SELECT_ARG "" CACHE INTERNAL "" FORCE) + set(JLINK_GDB_SELECT_ARG) endif() # default to JTAG @@ -65,7 +68,7 @@ exit add_custom_target(flash-${TARGET_NAME} COMMENT "Flashing ${TARGET_NAME} with J-Link..." COMMAND ${JLINK} - ${JLINK_SELECT_ARG} + ${JLINK_EXE_SELECT_ARG} -Device \"${JLINK_CPU_NAME}\" -Speed ${JLINK_CLOCK_SPEED} -if ${JLINK_UPLOAD_INTERFACE} @@ -80,7 +83,7 @@ endfunction(gen_upload_target) # https://wiki.segger.com/J-Link_GDB_Server:#Command_line_options set(UPLOAD_GDBSERVER_DEBUG_COMMAND "${JLINK_GDBSERVER}" - ${JLINK_SELECT_ARG} + ${JLINK_GDB_SELECT_ARG} ${JLINK_NOGUI_ARG} -Device \"${JLINK_CPU_NAME}\" -Speed ${JLINK_CLOCK_SPEED} diff --git a/tools/python/install_bin_file.py b/tools/python/install_bin_file.py index 3fa2900618f..136550bcbfe 100644 --- a/tools/python/install_bin_file.py +++ b/tools/python/install_bin_file.py @@ -62,11 +62,22 @@ def error(lines, code=-1): targets = get_detected_targets() if targets: for _target in targets: + if _target['name'] is None: - continue - elif _target['name'].upper() == target_name.upper(): - if target_uid is None or _target['uid'] == target_uid: + if target_uid is not None and _target['uid'] == target_uid: + # If we have an exact UID match and we don't know the name, then assume that + # the UID is correct. all_connected.append(_target) + else: + if _target['name'].upper() == target_name.upper(): + if target_uid is None or _target['uid'] == target_uid: + # Name matches, UID either matches or was not specified + all_connected.append(_target) + +if len(all_connected) == 0 and len(targets) == 1 and targets[0]['name'] is None and target_uid is None: + # Special case: if we only have one board connected to the system and we aren't filtering by UID, then + # assume it's the one we want even if we could not detect its name. + all_connected.append(targets[0]) if len(all_connected) == 0: error_lines = ["The target board you compiled for is not connected to your system.",