Bluetooth code not working with LF-clock = RC-oscillator.

Getting even the simplest Bluetooth samples to work on our custom boards seem to be difficult. 

The 'Beacon' sample has no dependencies on buttons or LEDs - 

and in *theory SHOULD* work if I set target=nrf52840dk (in VScode's NRFConnect plugin, build-dialogue).

 The *only* difference is that our custom board has *no 32kHz XTAL*, so we instead use internal RC-osc.

Thus, I set these symbols in "prj.conf" (but nothing else from the sample's original config):

<<

CONFIG_CLOCK_CONTROL=y
CONFIG_CLOCK_CONTROL_NRF=y

CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y

CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y

CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=n

>>

However, this ends up in a hardfault - triggered from 'mpsl_init' it seems.

But strangely, this happens *AFTER* this code is taken (at least I can step over it):

<<

err = bt_enable(bt_ready);

>>

err = 0 after line taken.

But, as soon as I let the debugger continue (there is just a 'return 0' afterwards, so only kernel-threads running)

the CPU hangs at 'k_sys_fatal_error_handler()'.

Is this a configuration-related problem? If yes, what other symbols must be set/unset?? Is using internal RC-osc for LCclock NOT recommended at all when using BT/BLE???

Nordic documentation is vague or non-existent when it comes to 32kHz RC-osc usage restrictions.

NOTE;: I have tried to set these symbols as well - but to no avail:

<<

CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC_CALIBRATION=y
CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_LF_ALWAYS_ON=y
CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_PERIOD=8000

>>

Parents
  • Hi,

    The LFRC does not have any external depencies, and should always work, so I do not see it as likely that this is what causes the issue (but if you have not configured the LFCR, execution would stop earlier waiting forever for the non-existing crystal oscillator to start, without triggering an error).

    You write that you use the beacon sample. Have you done any modifications to it? For instance started using peripherals that are used by the kernal or SoftDevice controller?

    Have you enabled and checked the UART log? If so, you should see an indicated of what type of error ocured there.

  • As stated: *no modifications* - except exactly the 5 lines shown in my request. Have tried with and without the 3 extra lines (rgd. calibration) with no luck. Trace from RTT-terminal:

    <<

    00:00:00.002,593] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 54.58864 Build 1214809870
    [00:00:00.003,509] <inf> bt_hci_core: Identity: CE:0B:6F:A3:CD:64 (random)
    [00:00:00.003,540] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x118f, manufacturer 0x0059
    [00:00:00.003,570] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x118f
    Bluetooth initialized
    Beacon started, advertising as CE:0B:6F:A3:CD:64 (random)
    [00:00:00.006,866] <err> mpsl_init: MPSL ASSERT: 112, 1706
    [00:00:00.006,866] <err> os: ***** HARD FAULT *****
    [00:00:00.006,866] <err> os: Fault escalation (see below)
    [00:00:00.006,896] <err> os: ARCH_EXCEPT with reason 3

    [00:00:00.006,896] <err> os: r0/a1: 0x00000003 r1/a2: 0x0000000b r2/a3: 0x0000000a
    [00:00:00.006,927] <err> os: r3/a4: 0x00016331 r12/ip: 0x20005140 r14/lr: 0x000163bb
    [00:00:00.006,927] <err> os: xpsr: 0x41000018
    [00:00:00.006,927] <err> os: Faulting instruction address (r15/pc): 0x0001022c
    [00:00:00.006,958] <err> os: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
    [00:00:00.006,988] <err> os: Fault during interrupt handling

    [00:00:00.007,019] <err> os: Current thread: 0x20001318 (logging)
    [00:00:00.788,482] <err> fatal_error: Resetting system
    *** Booting nRF Connect SDK v3.5.99-ncs1 ***
    Starting Beacon Demo
    [00:00:00.000,488] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision:
    36 f0 e5 0e 87 68 48 fb 02 fd 9f 82 cc 32 e5 7b |6....hH. .....2.{
    91 b1 5c ed |..\.
    [00:00:00.002,563] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:00.002,593] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
    [00:00:00.002,624] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 54.58864 Build 1214809870
    [00:00:00.003,509] <inf> bt_hci_core: Identity: CE:0B:6F:A3:CD:64 (random)
    [00:00:00.003,570] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x118f, manufacturer 0x0059
    [00:00:00.003,601] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x118f
    Bluetooth initialized
    Beacon started, advertising as CE:0B:6F:A3:CD:64 (random)
    [00:00:00.008,758] <err> mpsl_init: MPSL ASSERT: 112, 1706
    [00:00:00.008,789] <err> os: ***** HARD FAULT *****
    [00:00:00.008,789] <err> os: Fault escalation (see below)
    [00:00:00.008,789] <err> os: ARCH_EXCEPT with reason 3

    [00:00:00.008,819] <err> os: r0/a1: 0x00000003 r1/a2: 0x0000000b r2/a3: 0x0000000a
    [00:00:00.008,819] <err> os: r3/a4: 0x00016331 r12/ip: 0x20005140 r14/lr: 0x000163bb
    [00:00:00.008,819] <err> os: xpsr: 0x41000018
    [00:00:00.008,850] <err> os: Faulting instruction address (r15/pc): 0x0001022c
    [00:00:00.008,880] <err> os: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
    [00:00:00.008,880] <err> os: Fault during interrupt handling

    [00:00:00.008,941] <err> os: Current thread: 0x20001318 (logging)
    [00:00:00.790,191] <err> fatal_error: Resetting system
    *** Booting nRF Connect SDK v3.5.99-ncs1 ***
    Starting Beacon Demo
    [00:00:00.000,488] <inf> bt_sdc_hci_driver: SoftDevice Controller build revision:
    36 f0 e5 0e 87 68 48 fb 02 fd 9f 82 cc 32 e5 7b |6....hH. .....2.{
    91 b1 5c ed |..\.
    [00:00:00.002,532] <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:00.002,563] <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
    [00:00:00.002,593] <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 54.58864 Build 1214809870
    [00:00:00.003,509] <inf> bt_hci_core: Identity: CE:0B:6F:A3:CD:64 (random)
    [00:00:00.003,540] <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x118f, manufacturer 0x0059
    [00:00:00.003,570] <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0x118f
    Bluetooth initialized
    Beacon started, advertising as CE:0B:6F:A3:CD:64 (random)
    [00:00:00.014,862] <err> mpsl_init: MPSL ASSERT: 112, 1706
    [00:00:00.014,862] <err> os: ***** HARD FAULT *****
    [00:00:00.014,892] <err> os: Fault escalation (see below)
    [00:00:00.014,892] <err> os: ARCH_EXCEPT with reason 3

    [00:00:00.014,892] <err> os: r0/a1: 0x00000003 r1/a2: 0x00000009 r2/a3: 0x00000008
    [00:00:00.014,923] <err> os: r3/a4: 0x00016331 r12/ip: 0x20005140 r14/lr: 0x000163bb
    [00:00:00.014,923] <err> os: xpsr: 0x41000018
    [00:00:00.014,923] <err> os: Faulting instruction address (r15/pc): 0x0001022c
    [00:00:00.014,984] <err> os: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
    [00:00:00.014,984] <err> os: Fault during interrupt handling

    [00:00:00.015,014] <err> os: Current thread: 0x20001318 (logging)
    [00:00:00.656,860] <err> fatal_error: Resetting system
    *** Booting nRF Connect SDK v3.5.99-ncs1 ***
    Starting Beacon Demo
    [00:00:00.000,488] <inf> bt_sdc_hci_driver: SoftDevice Controller build rev

    >>

    I.e. resets over and over after HARDFAULT :-(

  • To add to this, I have built w. target = NRF7002DK (i.e. MCU=nRF5340) and ran it successfully (verified w. 'BeaconScanner'-app on mobile, detecting EddystoneURL=zephyrproject.org).

    This kit, of course, has a 32kHz XTAL on the nRF5340 MCU - which is the root cause of all problems here ...

  • Hi,

    The issue is not the 32.768 kHz oscillator. The assert you are getting is because the high frequency crystal oscillator has not started. Most likely the crystal or load caps are not mounted or incorrectly mounted, or faulty.

  • Caps and 32MHz-XTAL mounted. I have executed code for I2S-audio successfully (stereo, 16-bit @ 44100Hz), as well as SPI@8MHz and UART@115200baud. Don't get it ... :-/

  • Did you start the HFXO then? If not, the HFINT is used as high frequency source. (The HFXO is generally not started automatically, but the Bluetooth stack and other radio stacks will start it automatically).

    You can attempt to start the HFXO manually to see, using for intsance this code snippet (from the radio test sample). Copy-past it to your application, and call clock_init().

    #include <zephyr/drivers/clock_control.h>
    #include <zephyr/drivers/clock_control/nrf_clock_control.h>
    
    static void clock_init(void)
    {
    	int err;
    	int res;
    	struct onoff_manager *clk_mgr;
    	struct onoff_client clk_cli;
    
    	clk_mgr = z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF);
    	if (!clk_mgr) {
    		printk("Unable to get the Clock manager\n");
    		return;
    	}
    
    	sys_notify_init_spinwait(&clk_cli.notify);
    
    	err = onoff_request(clk_mgr, &clk_cli);
    	if (err < 0) {
    		printk("Clock request failed: %d\n", err);
    		return;
    	}
    
    	do {
    		err = sys_notify_fetch_result(&clk_cli.notify, &res);
    		if (!err && res) {
    			printk("Clock could not be started: %d\n", res);
    			return;
    		}
    	} while (err);
    
    	printk("Clock has started\n");
    }

Reply
  • Did you start the HFXO then? If not, the HFINT is used as high frequency source. (The HFXO is generally not started automatically, but the Bluetooth stack and other radio stacks will start it automatically).

    You can attempt to start the HFXO manually to see, using for intsance this code snippet (from the radio test sample). Copy-past it to your application, and call clock_init().

    #include <zephyr/drivers/clock_control.h>
    #include <zephyr/drivers/clock_control/nrf_clock_control.h>
    
    static void clock_init(void)
    {
    	int err;
    	int res;
    	struct onoff_manager *clk_mgr;
    	struct onoff_client clk_cli;
    
    	clk_mgr = z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF);
    	if (!clk_mgr) {
    		printk("Unable to get the Clock manager\n");
    		return;
    	}
    
    	sys_notify_init_spinwait(&clk_cli.notify);
    
    	err = onoff_request(clk_mgr, &clk_cli);
    	if (err < 0) {
    		printk("Clock request failed: %d\n", err);
    		return;
    	}
    
    	do {
    		err = sys_notify_fetch_result(&clk_cli.notify, &res);
    		if (!err && res) {
    			printk("Clock could not be started: %d\n", res);
    			return;
    		}
    	} while (err);
    
    	printk("Clock has started\n");
    }

Children
No Data
Related