This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How properly configure nrf52840 so it can boot?

According to another question here:

devzone.nordicsemi.com/.../

I'm stuck with waiting for the LFCLK to boot forever.

Normally, keil has a .s startup file that dictates the procedures taken after powering up, or if we are talking about a PIC chip, I can configure all the boot related registers easily in mplabx IDE, but I'm still scratching my head as to where to do the equivalent for an nrf52840.

Is there a config file I can write to? A macro definition I can modify? Or is it in the .s file?

I'm using keil uv5.

I want to use external 32Mhz HFCLK and internal 32.768khz RC LFCLK, where to properly set them up?

Are these 2 the only thing I have to worry about when configuring the chip to start properly?

  • Hello Mitch996

    If you are using a SoftDevice you do not need to configure the high frequency crystal oscillator as the SoftDevice will take care of that. Just make sure you have enabled the clock peripheral in the sdk_config.h file. The LFCLK is typically configured during the ble_stack_init function in the examples, for instance from the hrs example you have the lines

    nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
    
    // Initialize the SoftDevice handler module.
    SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);
    

    Here the clock_lf_cfg contains information about the source, and calibration intervals and crystal accuracy (if present). The SOFTDEVICE_HANDLER_INIT will ensure this information is registered with the SoftDevice. There are several different options available for the LFCLK, see section 17.2 of the nRF52840 product specification

    If you are not using a SoftDevice, you can activate and deactivate the high frequency crystal oscillator, when necessary, by writing a 1 to the TASKS_HFCLKSTART and TASKS_HFCLKSTOP registers, see page 146, section 17.3 table 19 of the product specification.

    Here is a snippet of code from the peripheral\radio\transmitter example

    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART    = 1;
    
    /* Wait for the external oscillator to start up */
    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
    {
        // Do nothing.
    }
    
    /* Start low frequency crystal oscillator for app_timer(used by bsp)*/
    NRF_CLOCK->LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART    = 1;
    
    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
    {
        // Do nothing.
    }
    

    When the device wakes up (from power off or reset) the internal high frequency oscillator will start. This means you do not need to configure anything for the CPU to start. See section 17 of the product specification.

    Best regards

    Jørn Frøysa

  • Hello Jørn Frøysa:

    Thank you for your detailed reply and sorry that I have to bother you again.

    I'm using my customized board, I tried the radio transmitter example, it's working properly, but it doesn't use SD. Now I'm trying to run the ble_app_alert_notification example, the program again stuck at that four line of assembly code waiting for LFCLK to come up for ever.

    You said if a project use SD, then SD will "take care of it", is there anyway I can do it manually?

    I've tried to modify the corresponding sdk_config. h:

    #ifndef CLOCK_CONFIG_LF_SRC
    #define CLOCK_CONFIG_LF_SRC 0 //0 = RC
    

    and I even tried to add these lines in my program:

    NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos); NRF_CLOCK->EVENTS_LFCLKSTARTED = 0; NRF_CLOCK->TASKS_LFCLKSTART = 1;

    But still, it doesn't work.

    What should I do?

  • It is not bother, it's why I'm here! While the SD is enabled the application will have limited access to the clock peripheral, so you won't be able to directly configure the clocks. I would like you to try something for me, using the hrs example from SDK13.0.0, change the sdk_config clock source to RC, like you did. And in the ble_stack_init function, change this snippet

    nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;		
    // Initialize the SoftDevice handler module.
    SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);
    

    To this

    nrf_clock_lf_cfg_t clock_lf_cfg;
    clock_lf_cfg.source = NRF_CLOCK_LF_SRC_RC;
    clock_lf_cfg.rc_ctiv = 16;
    clock_lf_cfg.rc_temp_ctiv = 2;		
    		
    // Initialize the SoftDevice handler module.
    SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);
    

    This works on my end with the pca10056, so it should be a good place to start debugging.

  • I'm sorry I may have misunderstood your previous post. Is your application not using the softdevice at all?

  • All praises be with you! Jørn Frøysa! It worked! Can I add you on skype??? There are a millions things could go wrong yet it's working! And I can see the advertising from 15 feet away!

    Thank you!

Related