nRF52840 Boot Time Optimization in NCS

Hi everyone,

I'm experiencing an unexpectedly long boot time on my nRF52840 device using NCS v3.2.0. Could you help me verify if this boot time is normal, or suggest any possible causes?

Setup:

  • Platform: nRF52840
  • SDK: NCS v3.2.0
  • Code Base: peripheral_hids_keyboard (with custom modifications)
  • Board Configuration: Custom board, currently without bootloader

What I did:
To measure boot time, I added timing signal logs at different stages of the boot process. Here are my results:

EARLY
                ~4.8ms
PRE_KERNEL_1
                434ms <-- take long time on here
PRE_KERNEL_2
                76us
POST_KERNEL
                459us
main thread

The code I used for the measurement is as follows:

int prek1_marker(const struct device *dev) {
    gpio_pin_configure(GPIO1_DEV, 2, GPIO_OUTPUT);
    gpio_pin_set(GPIO1_DEV, 2, 1);
    return 0;
}
SYS_INIT(prek1_marker, PRE_KERNEL_1, 0);

int prek2_marker(const struct device *dev) {
    gpio_pin_set(GPIO1_DEV, 2, 0);
    return 0;
}
SYS_INIT(prek2_marker, PRE_KERNEL_2, 0);

int postk_marker(const struct device *dev) {
    gpio_pin_set(GPIO1_DEV, 2, 1);
    return 0;
}
SYS_INIT(postk_marker, POST_KERNEL, 0);

int main(void)
{
    gpio_pin_set(GPIO1_DEV, 2, 0);
    // ...
}

If anyone has experience with boot timing on nRF52840 or suggestions on what could cause the delay at PRE_KERNEL_1, your input would be greatly appreciated. Thank you!

Parents Reply Children
  • Hi,

    I observed the same result after setting CONFIG_SYSTEM_CLOCK_NO_WAIT=y.

  • Thanks for confirming. I now remembered that the initialisation of the cryptocell RNG is quite time consuming. In addition to having CONFIG_SYSTEM_CLOCK_NO_WAIT enabled, please create a DT overlay to change the entropy source from the Cryptocell to the nRF RNG by changing the "zephyr,entropy" assignment in the "chosen" node:

    / {
    	chosen {
    		/*
    		 * In some default configurations within the nRF Connect SDK,
    		 * e.g. on nRF52840 and nRF9160, the chosen zephyr,entropy node
    		 * is &cryptocell. This devicetree overlay ensures that default
    		 * is overridden wherever it is set, as this application uses
    		 * the RNG node for entropy exclusively.
    		 */
    		zephyr,entropy = &rng;
    	};
    };

Related