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?

Parents
  • 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

  • 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!

Reply Children
No Data
Related