High Current 400ms+ Startup Delay BLE Beacon Using RC Oscillator

Setup:  

- VS Code - NRF Connect v 2.1.0 

- Hardware: NRF52840-DK  @ 1.8V

- Application: BLE Beacon (https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/bluetooth/beacon)  

KConfig/prj.conf:  

CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=n
CONFIG_BT_DEVICE_NAME="MyName"
CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=n
CONFIG_BOARD_ENABLE_DCDC=y
I have disabled the LFXTAL and enabled the RC Oscillator as the clock source to reduce startup time, however from cold boot I am seeing a ~430ms period of inactivity that is running @ 4mA. 
power consumption
If I change my clock settings back to use the XTAL then another 400ms (expected) period is added for a total of 800ms of no BLE activity:  
current consumption with xtal
Yes I have powered cycled after programming. Yes I have performed a Pristine build. 
When I load up the same BLE Beacon firmware from NRF5 SDK with the same clock settings, I DO NOT see this 400+ms delay. This looks to be specific to NCS/Zephyr. 
Screenshot of NRF5 SDK sample code with RC oscillator as soft device clock:
nrf5 sdk no delay
I saw this post:  nRF52840 startup delay   
However this setting: CONFIG_ENTROPY_CC3XX=n  causes a build error. 
Any idea why the default NCS/Zephyr implementation for the BLE Beacon has this 400+ms delay before any BLE beacons are sent and why its at ~4mA?
Is there some additional KConfig setting I need to change?
  • I tseems like cc3xx initialization is causing this delay but I need to understand more on the default settings in nRF5SDK and NCS. It looks like CC3xx is enabled by default in newer SDK and seems like it was not the case in older SDK. But before I say anything concrete, let me do some internal investigation.

  • It seems like in NCS when using BLE cc3xx is enabled by default in the config and we have seen in other case that this is the root cause for the startup delay. So we need to focus on disabling this if you can use internal RNG instead of cc3xx. What errors are you getting when you try to disable CC3XX?

  • Well if all I change, based on the other ticket, is 

    CONFIG_ENTROPY_CC3XX=n
    I get the following build error (again I have not changed any source, and the only KConfig settings are shared above):  
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map 
    : && ccache /opt/nordic/ncs/toolchains/v2.1.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc   zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf  -fuse-ld=bfd  -Wl,-T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=/Users/[me]/workspace/[redacted]/beacon/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a  zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a  zephyr/lib/libc/minimal/liblib__libc__minimal.a  zephyr/lib/posix/liblib__posix.a  zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a  zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a  zephyr/subsys/bluetooth/common/libsubsys__bluetooth__common.a  zephyr/subsys/bluetooth/host/libsubsys__bluetooth__host.a  zephyr/subsys/net/libsubsys__net.a  zephyr/subsys/random/libsubsys__random.a  zephyr/drivers/clock_control/libdrivers__clock_control.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/entropy/libdrivers__entropy.a  zephyr/drivers/timer/libdrivers__timer.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  modules/nrf/lib/multithreading_lock/lib..__nrf__lib__multithreading_lock.a  modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a  modules/nrf/subsys/bluetooth/controller/lib..__nrf__subsys__bluetooth__controller.a  modules/nrf/subsys/mpsl/init/lib..__nrf__subsys__mpsl__init.a  modules/nrf/drivers/mpsl/clock_control/lib..__nrf__drivers__mpsl__clock_control.a  modules/nrf/drivers/hw_cc310/lib..__nrf__drivers__hw_cc310.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  modules/segger/libmodules__segger.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -L"/opt/nordic/ncs/toolchains/v2.1.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/thumb/v7e-m/nofp"  -L/Users/[me]/workspace/[redacted]/beacon/build/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  -no-pie  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -mfp16-format=ieee  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  /opt/nordic/ncs/v2.1.0/nrfxlib/mpsl/lib/cortex-m4/soft-float/libmpsl.a  /opt/nordic/ncs/v2.1.0/nrfxlib/crypto/nrf_cc310_platform/lib/cortex-m4/soft-float/no-interrupts/libnrf_cc310_platform_0.9.15.a  /opt/nordic/ncs/v2.1.0/nrfxlib/softdevice_controller/lib/cortex-m4/soft-float/libsoftdevice_controller_peripheral.a && cd /Users/[me]/workspace/[redacted]/beacon/build/zephyr && /opt/nordic/ncs/toolchains/v2.1.0/Cellar/cmake/3.20.5/bin/cmake -E echo
    /opt/nordic/ncs/toolchains/v2.1.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.bfd: zephyr/subsys/random/libsubsys__random.a(rand32_xoshiro128.c.obj): in function `xoshiro128_initialize':
    /opt/nordic/ncs/v2.1.0/zephyr/subsys/random/rand32_xoshiro128.c:51: undefined reference to `__device_dts_ord_119'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/v2.1.0/bin/cmake --build /Users/[me]/workspace/[redacted]/beacon/build
    So I'm thinking that there must be additional KConfig settings needed to properly disable CC33xx and use the internal RNG instead. Have any guidance on what these settings should be?
  • I am able to reproduce this, I will try to find out what other dependency there is that we need to disable/Enable along with HW_CC3XX and come back to you soon.

  • Please add this in your proj.conf to disable CC3XX backend and use nrf rng backend instead

    CONFIG_HW_CC3XX=n
    CONFIG_ENTROPY_CC3XX=n
    CONFIG_ENTROPY_NRF5_RNG=y
    CONFIG_CC3XX_BACKEND=n

    and add this to your ovelay file

    	chosen {
    		zephyr,entropy = &rng;
    		};

Related