GPIO driving

Hello,

I'm running both central and peripheral roles for BLE on Zephyr, along with UART and some GPIOs.

  • SDK: 2.6.2

  • The project includes MCUboot, supporting DFU over UART and BLE.

  • Running on a custom board.

Everything works except the status LED.

I suspect an initialization issue, but the strange part is:

  1. If I flash an older, similar project, the LED blinks.

  2. Then, if I flash the problematic project (first MCUboot, then the application), the LED still blinks—albeit with a different pattern, meaning it’s controlled by the new app.

  3. However, if I erase the flash and then flash MCUboot and the app, the LED does not blink at all, everything else works.

My question is not just about what might be wrong with the LED configuration, but also:

  • Why does the LED work in the first scenario?

  • Which part of the flash isn't being overwritten when flashing the new app and MCUboot?

Thank you in advance.
    aliases {
        led0 = &led0;
        mcuboot-button0 = &button0;
        mcuboot-led0 = &led0;
    };

    chosen {
        zephyr,sram = &sram0;
        zephyr,flash = &flash0;
		zephyr,console = &uart0; 
        zephyr,code-partition = &slot0_partition;
    };

    leds {
        compatible = "gpio-leds";
        led0: led_0 {
            gpios = <&gpio0 9 GPIO_ACTIVE_LOW>;
        };
    };

    buttons {
        compatible = "gpio-keys";
        button0: button_0 {
            gpios = <&gpio1 00 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
            label = "Push button switch 3";
        };
    };
};

&gpio0 {
    status = "okay";
};

&gpio1 {
    status = "okay";
};

&gpiote {
    status = "okay";
};
#define LED0_NODE DT_ALIAS(led0)
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

static int led_init(void)
{
    if (!gpio_is_ready_dt(&led))
    {
        return -ENODEV;
    }

    int err = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
    if (err < 0)
    {
        return err;
    }
    gpio_pin_toggle_dt(&led);
    return 0;
}

{
    for (;;)
    {
        err = gpio_pin_toggle_dt(&led);
        if (err < 0)
        {
            LOG_ERR("Main thread loop error");
            return err;
        }
        k_msleep(SLEEP_TIME_MS);
    }
}
Parents
  • Hello,

    Pin P0.9 and P0.10 are assigned to the NFC by default. To use them as regular GPIOS, you can add CONFIG_NFCT_PINS_AS_GPIOS=y to your prj.conf file or edit your board file to enable this config setting by default. This configuration will make the startup code check the NFCPINS register on startup and update it if needed.

    (pin assigments)

    Best regards,

    Vidar

  • Tidar, thank you! This solved the issue.

    Now, I've encountered another problem related to flashing.

    • When I flash the app and bootloader using the VS Code plugin, I can enter MCUboot for serial DFU (UART).

    • However, when I flash the merged.hex file using SEGGER J-Flash Lite, I’m unable to enter MCUboot.

    • If I then reflash just the app with VS Code, it works again.

    I enter MCUboot by toggling the boot and reset pins.

    DFU over BLE always works.

    I suspected the issue is related to the boot pin, but it is the reset pin. When polled down it does nothing

    Could you please advise?

  • 'west flash' which is invoked by the vs code extension when you load the merged.hex will also run 'nrfjprog --pinresetenable' that enables the pinreset functionality by writing to the NV PSELRESET registers. To avoid having to do this, you can enable CONFIG_GPIO_AS_PINRESET in your project config.

Reply Children
No Data
Related