How to modify the low-speed crystal oscillator type and power supply mode in the code?

NCS2.7.0

board:nrf54L15

We need a hardware to equip the nrf54l15 hardware, such as using internal or external low-speed crystal, power supply method is DCDC or LDO, etc.

Just like the old SDK, you can modify these in the code, but ncs can change it in the configuration file.

eg:

1. burn param to uicr

2. read uicr param 

3. code set param(xtal rc or dcdc ldo)

 
 change dcdc or ldo
old SDK
sd_power_dcdc_mode_set NRF_POWER_DCDC_ENABLE
change xtal or rc
old SDK
I can modify clock_lf_cfg to decide whether to use internal or external crystal.
sd_softdevice_enable clock_lf_cfg,app_error_fault_handler);
I found that ncs uses clock control, but I don't know how to change it. Please give me some suggestions.
I tried restarting the clock this way but I don't know if it's possible.
Parents
  • Hi,

    To use LFRC instead of LFXO use this in your Kconfig (for instance in prj.conf or in a board configuratin file if you have that for your custom board):

    CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
    CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=n
    CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC_CALIBRATION=y
    CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y

    (The DK borad files will use crystal by default, by setting CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y)

    To use DCDC, include BOARD_ENABLE_DCDC=y in the configuration when using nRF Connect SDK 2.7.0 or earlier. Also use the following for nRF54L (and other boards in main or SDK 2.8.0 or later):

    &vregmain {
    	status = "okay";
    	regulator-initial-mode = <NRF5X_REG_MODE_DCDC>;
    };

    (If using LDO use NRF5X_REG_MODE_LDO instead of  NRF5X_REG_MODE_DCDC).

  • One firmware for multiple hardware
    For example, a hardware with an external low-speed crystal oscillator and dcdc
    a hardware with an external low-speed crystal oscillator and ldo
    a hardware without an external low-speed crystal oscillator and dcdc
    a hardware without an external low-speed crystal oscillator and ldo

  • Hi,

       Thanks for your response.

        We know whether the board has LFXO and dcdc, so we can burn the parameters into UICR first when burning and then use uicr param set param.

    Is it possible to reconfigure parameters during initialization?

    If this is really not possible, I can also use your answer to convince my boss to make multiple firmwares for adaptation.

    Thanks

  • Hi,

    I see. If you can check in UICR, then you can make a decision based on UICR content. This is not directly supported, but you can modify power_and_clock_configuration() in zephyr/soc/nordic/nrf54l/soc.c (this is part of the SDK and is expected to change going forward).

    When it comes to clcok control this is also a decition made by Kconfig during build and in code it id used by the Zephyr clock control driver in zephyr/drivers/clock_control/clock_control_nrf.c and when initializing MPSL in nrf/subsys/mpsl/init/mpsl_init.c. I see no direct techincal reason why you cannot modify this to do it dynamically, but it will require some changes to the SDK that you will have to handle and maintain over time.

    I would argue that using separate board fiels and/or overlay files for separate HW variants is cleanest, and that is how this is intended to be handled.

  • Hi,

    Sorry for the late reply, because we are celebrating the National Day.


    I tested the method you provided yesterday, and the power supply method is OK.

     The crystal oscillator still needs your help. I will continue to test it today.

    Because this is my first time using ncs to do a project, I don’t know much about these, so I still need your help. Thanks

    Here are my steps.The purpose is to try to use RC in XTAL mode, but it can't work.

    ncs2.7.0

    board: nrf54l15

    1. prj.conf

    2. Change mpsl_init.c

       2.1 mpsl_lib_init_internal

       

      2.2 mpsl_calibration_work_handler

    2.3 mpsl_low_prio_init

    3. change nrf_clock_control.h

  • Hi,

    I am not sure what you are attempting to show by the code snippet screenshots?

    As discussed earlier, switching clock source compile time is supported, and that is handled by Kconfigs. There are other relevant configs, but the most important it to set CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y to use the RC and CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y to use the xtal. This should wrok out of the box on any device wihtout needing to do any code changes. Does it not for you?

    Or are you starting to work on a way to modify the LF clock source run-time? If so, that is not supporte dand would requier changes (I also suspect it may get a bit dirty as this was never designed to be run-time configurable). If this is what you are doing and are having problems, then please share your changes in form of a diff or similar and explain the thinking behind it and how it behaves, so that I can try to understand on my end and perhaps provide some clues.

Reply
  • Hi,

    I am not sure what you are attempting to show by the code snippet screenshots?

    As discussed earlier, switching clock source compile time is supported, and that is handled by Kconfigs. There are other relevant configs, but the most important it to set CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y to use the RC and CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y to use the xtal. This should wrok out of the box on any device wihtout needing to do any code changes. Does it not for you?

    Or are you starting to work on a way to modify the LF clock source run-time? If so, that is not supporte dand would requier changes (I also suspect it may get a bit dirty as this was never designed to be run-time configurable). If this is what you are doing and are having problems, then please share your changes in form of a diff or similar and explain the thinking behind it and how it behaves, so that I can try to understand on my end and perhaps provide some clues.

Children
Related