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

>>

  • 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");
    }

  • Tested w. 2 different boards as well. External caps (in '0201' package) from XC1/XC2 to GND are both 12pF. XTAL and caps placed as close as possible (<2mm) from nRF52840 XC-pins. How is it possible that HFXO-clock is not running (or, not running correctly) when I2S and UART works as anticipated???

  • ML7S said:
    How is it possible that HFXO-clock is not running (or, not running correctly) when I2S and UART works as anticipated???

    That is because the high frequency clock can be generated by two different clock sources. When the CPU starts, it runs of the HFINT which is an RC oscillastor. And this is generally used as high frequency clock source unless the HFXO is started (which you do when you need an accurate HF clock). The only difference you will notice when using I2S or UART is that the frequency accuracy is wrose.

  • Tested w. your code exaple above. Ends up looping 'forever' in this DO-WHILE block:

    <<

    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);

    >>

    With 'err'=-11

    and 'res'=106084

    That makes ...???

Related