bt_enable changes log behaviour

Hello there,

It seems like calling `bt_enable(NULL)` is changing the behaviour of logging. Adding a 1 ms sleep seems to fix the problem. Do you have any explanation for this?
More info below:

When using this simple main. I am getting the expected logging behaviour.

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <assert.h>

#include "app_version.h"

int main(void)
{
    printk("Zephyr Example Application %s\n", APP_VERSION_STR);
    assert(false);
    
    while (1)
        ;
    
    return 0;
}
This gives the following result on RTT:


*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
Zephyr Example Application 4486442-dirty
ASSERTION FAIL [0] @ WEST_TOPDIR/application/app/src/main.c:20
[00:00:06.051,422] <err> os: r0/a1:  0x00000004  r1/a2:  0x00000014  r2/a3:  0x00000003
[00:00:06.051,452] <err> os: r3/a4:  0x00000000 r12/ip:  0x20007fa8 r14/lr:  0x0001ca15
[00:00:06.051,452] <err> os:  xpsr:  0x61000000
[00:00:06.051,483] <err> os: Faulting instruction address (r15/pc): 0x00033f08
[00:00:06.051,513] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
[00:00:06.051,574] <err> os: Current thread: 0x20002c90 (main)
[00:00:06.277,496] <err> fatal_error: Resetting system

Great, aweseome! This is the expected behaviour.

However if I enable bluetooth I am not seeing any logging anymore:

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <assert.h>

#include "app_version.h"

int main(void)
{
    printk("Zephyr Example Application %s\n", APP_VERSION_STR);
    assert(0 == bt_enable(NULL));
    assert(false);
    
    while (1)
        ;
    
    return 0;
}

Adding a sleep of 1 milisecond after `bt_enable(NULL)` seems to restore the expected behaviour:

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <assert.h>

#include "app_version.h"

int main(void)
{
    printk("Zephyr Example Application %s\n", APP_VERSION_STR);
    assert(0 == bt_enable(NULL));
    k_sleep(K_MSEC(1));
    assert(false);
    
    while (1)
        ;
    
    return 0;
}

*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
Zephyr Example Application 4486442-dirty
[00:00:02.232,635] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision:
                                            e0 7e 2e c1 5e 05 85 23  46 5e 05 85 23  46 [00:00:02.236,083] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
[00:00:02.236,114] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
[00:00:02.236,175] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 224.11902 Build 2231721665
[00:00:02.237,365] <inf> bt_hci_core: Identity: E9:34:29:B6:D5:B7 (random)
[00:00:02.237,426] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x1077, manufacturer 0x0059
[00:00:02.237,457] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x1077[0m
ASSERTION FAIL [0] @ WEST_TOPDIR/application/app/src/main.c:22
[00:00:02.238,555] <err> os: r0/a1:  0x00000004  r1/a2:  0x00000016  r2/a3:  0x00000007
[00:00:02.238,586] <err> os: r3/a4:  0x20001728 r12/ip:  0x20008b28 r14/lr:  0x0001ca1b
[00:00:02.238,616] <err> os:  xpsr:  0x41000000
[00:00:02.238,616] <err> os: Faulting instruction address (r15/pc): 0x0003465c
[00:00:02.238,677] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
[00:00:02.238,708] <err> os: Current thread: 0x20002d88 (main)
[00:00:02.634,643] <err> fatal_error: Resetting system

I am using ncs v2.4.2 on an nRF52840-DK (PCA10056).

Related