SWD Flash via J-Link on Feather nRF52840 Sense Erases Bootloader (Zephyr v3.0.0), No RTT Logs

Hello Nordic Team,

I am experiencing an issue when attempting to flash a Zephyr RTOS application (v3.0.0) to the Adafruit Feather nRF52840 Sense board using a J-Link debugger over the SWD pins on the board’s backside.

Current Setup:

  • Board: Adafruit Feather nRF52840 Sense

  • Debugger: Segger J-Link, connected to SWD pins

  • Development Environment: VS Code with Zephyr SDK v3.0.0

This is main.c file.

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/sys/printk.h>
#include <zephyr/sys/util.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main);

void main(void)
{
    // Get the device binding for UART0
    const struct device *uart_dev = DEVICE_DT_GET(DT_NODELABEL(uart0));
    
    if (!device_is_ready(uart_dev)) {
        LOG_INF("Error: UART device not ready.\n");
        return;
    }

    LOG_INF("Message sent via UART.\n");

    while (1) {
        LOG_INF("Message sending via UART.\n");
        printk("Message sent via UART.\n");
        k_msleep(1000);
    }
}

This is prj.conf

# Enable Pinctrl
CONFIG_PINCTRL=y

# Enable UART
CONFIG_SERIAL=y

# Enable console and logging over UART
CONFIG_UART_CONSOLE=y
CONFIG_CONSOLE=y
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3

# Enable minimal Zephyr C library
CONFIG_NEWLIB_LIBC=y

Problem:

  • Flashing via the Arduino IDE (UF2 bootloader over USB) works as expected.

  • When flashing my Zephyr application over SWD, the on-board UF2 bootloader is erased. After the SWD flash, none of the board’s peripherals (sensors, LEDs, buttons, micro-USB port, etc.) respond until I manually restore the bootloader.

  • I am unable to see any debug output logs via RTT. I also wired up a physical UART for serial printing, but nothing appears on the COM port after SWD programming.

Questions:

  1. Is there a recommended SWD flash sequence or Zephyr project configuration—particularly for Adafruit’s nRF52840 Sense—that will preserve the UF2 bootloader partition?

  2. Are there any Nordic-provided tools, scripts, or linker-script modifications to deploy a Zephyr v3.0.0 build from VS Code without overwriting the bootloader?

  3. If SWD-based deployment cannot preserve the UF2 bootloader, can you suggest an alternative programming interface or streamlined workflow for Zephyr development on this board?

I look forward to your recommendations.

Regards,
Anmol

Parents
  • Hi Anmol,

    Is there a recommended SWD flash sequence or Zephyr project configuration—particularly for Adafruit’s nRF52840 Sense—that will preserve the UF2 bootloader partition?

    SWD and the nRF52840 are fundamentally the same regardless of board, so no special considerations are needed. If you want to keep a bootloader or anythign else out side of the image you are flashing, you need to program without an erase all. From VS Code, that means not pressing the icon to the right of the Flash action. And if programming using nrfutil device, use:

    nrfutil device program --options chip_erase_mode=ERASE_RANGES_TOUCHED_BY_FIRMWARE --firmware merged.hex
    (replace merged.hex with the path to your hex file).

    That said, the problem here may not be directly related to flashing. The first thing that comes to mind, is that I wonder what boad you build the project for, and if the project is built to accomodate teh UF2 bootloader (so that you don't have anythign starting at address 0)? If tha tis the case, you eithe rneed the UF2 bootlaoder in place, or you change the configuration to place the application (or anothe rbootloade) at addess 0. Can you check this first?

    Are there any Nordic-provided tools, scripts, or linker-script modifications to deploy a Zephyr v3.0.0 build from VS Code without overwriting the bootloader?

    You can create board files that handle this, or add a static partitioning that places the application at a specific address. This is typically handled in the board fiels, and is for instance done for instance for nRF52840 Dongle (the latter has the old nRF5 SDK USB bootloader). See this thread.

    If SWD-based deployment cannot preserve the UF2 bootloader, can you suggest an alternative programming interface or streamlined workflow for Zephyr development on this board?

    SWD should not be a problem, but the project you build must accomodate the existing bootlodaer if you want to keep it (it cannot overlap, and need to start where the existing bootloader expect the application to start). Moreover, I have no knowledge of the UF2 bootloader, but it may be that it needs some metadata so that you eithe need to generate that and also flash that, or that it will be easier to update via the bootloader to get that handled by the bootloader (again this is just speculations).

    PS: But if you intend to use SWD, perhaps there is no point in keeping the UF2 bootloader?

Reply
  • Hi Anmol,

    Is there a recommended SWD flash sequence or Zephyr project configuration—particularly for Adafruit’s nRF52840 Sense—that will preserve the UF2 bootloader partition?

    SWD and the nRF52840 are fundamentally the same regardless of board, so no special considerations are needed. If you want to keep a bootloader or anythign else out side of the image you are flashing, you need to program without an erase all. From VS Code, that means not pressing the icon to the right of the Flash action. And if programming using nrfutil device, use:

    nrfutil device program --options chip_erase_mode=ERASE_RANGES_TOUCHED_BY_FIRMWARE --firmware merged.hex
    (replace merged.hex with the path to your hex file).

    That said, the problem here may not be directly related to flashing. The first thing that comes to mind, is that I wonder what boad you build the project for, and if the project is built to accomodate teh UF2 bootloader (so that you don't have anythign starting at address 0)? If tha tis the case, you eithe rneed the UF2 bootlaoder in place, or you change the configuration to place the application (or anothe rbootloade) at addess 0. Can you check this first?

    Are there any Nordic-provided tools, scripts, or linker-script modifications to deploy a Zephyr v3.0.0 build from VS Code without overwriting the bootloader?

    You can create board files that handle this, or add a static partitioning that places the application at a specific address. This is typically handled in the board fiels, and is for instance done for instance for nRF52840 Dongle (the latter has the old nRF5 SDK USB bootloader). See this thread.

    If SWD-based deployment cannot preserve the UF2 bootloader, can you suggest an alternative programming interface or streamlined workflow for Zephyr development on this board?

    SWD should not be a problem, but the project you build must accomodate the existing bootlodaer if you want to keep it (it cannot overlap, and need to start where the existing bootloader expect the application to start). Moreover, I have no knowledge of the UF2 bootloader, but it may be that it needs some metadata so that you eithe need to generate that and also flash that, or that it will be easier to update via the bootloader to get that handled by the bootloader (again this is just speculations).

    PS: But if you intend to use SWD, perhaps there is no point in keeping the UF2 bootloader?

Children
No Data
Related