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

sd_clock_hfclk_request() ; start of ext. 16MHz Stuck

EDIT:

I'm using nRF51422-QFAA E00 and S310 v1.0.0, SDK - nRF51 5.2.0.

I'm starting HFCLK from externall crystal for ADC conversion. Since I have no SD enabled everything is OK, but within SD and using function sd_clock_hfclk_request() problem appears. It simmply stuck in the loop where sd_clock_hfclk_is_running(&tmp) is checked -> still returning 0. Enabling SD I have same as in examples and if I try the other SD funcs (like sd_temp_get()) they works ok. Example project with BLE and ANT works ok - I can see broadcast.

I tried to recompile project with S210 v 3.0.0 with same behaviour. I can't see in PAN doc any problem about that for my revision.

Here is my code for hfclk start for SD and non SD use:

void V_hw_HFClock_Enabled(void)
{
	u32 p_is_running;
	
	// XTALFREQ is set by UICR (16MHz default)	
	/* Start 16 MHz crystal oscillator */
	#ifdef NO_SD
		NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
		NRF_CLOCK->TASKS_HFCLKSTART = 1;
		/* Wait for the external oscillator to start up */
		while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {} 
		NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
	#else
		(void)sd_clock_hfclk_request();
		do { 
			sd_clock_hfclk_is_running(&p_is_running); 
		}while(p_is_running==0);	
	#endif
}


void V_hw_SD_Setup(void)
{
	u32 err_code;

	err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, softdevice_assert_callback);		// ABS06-32.768kHz-9-T +-20ppm
	if(err_code != NRF_SUCCESS) V_error_handler(E_SD_EN);
  err_code = sd_nvic_SetPriority(SD_EVT_IRQn, NRF_APP_PRIORITY_LOW); 
  if(err_code != NRF_SUCCESS) V_error_handler(E_SD_SP);
  err_code = sd_nvic_EnableIRQ(SD_EVT_IRQn);      
  if(err_code != NRF_SUCCESS) V_error_handler(E_SD_EI);	
}

main loop:
V_hw_SoC_Init();
	
	sd_temp_get(&p);
	tmp2 = sd_clock_hfclk_request();
	if(tmp2 != NRF_SUCCESS) NRF_GPIO->OUTSET = (1UL << LED);
	do { 
			tmp2 = sd_clock_hfclk_is_running(&tmp); 
			if(tmp2 != NRF_SUCCESS) NRF_GPIO->OUTSET = (1UL << LED);
		}while(tmp==0);	
	NRF_GPIO->OUTSET = (1UL << LED);

LED is still OFF, so no error and can't get out of loop (unitl WDG after 2sec made a reset).

I don't know why it works when I'm not using SD and start HF CLK with registers and why not with enabled SD and HF start by SD funcs. I have attached HF CLK XTAL 16MHz (NX2520SA) startup if someone can compare for startup time.

scope_0.png scope_1.png scope_2.png

  • FormerMember
    0 FormerMember

    Instead of using sd_softdevice_enable(..), try to use SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false);. As you can see in the SOFTDEVICE_HANDLER_INIT-function-macro definition, SOFTDEVICE_HANDLER_INIT (..) will among others call sd_softdevice_enable(..).

    The following S310 code is what I have been testing:

    #define LED_NO_RUN                           LED_0
    #define LED_ERROR                            LED_1
    #define LED_FINISHED                         LED_2 
    
    
    void V_hw_SD_Setup(void)
    {
    uint32_t  err_code;
    
    // Initialize the SoftDevice handler module.
    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false);   
    }
    
    //main loop:
    int main(void)
    {
    uint32_t tmp2;
    uint32_t tmp;
    int32_t   p;
    
    nrf_gpio_cfg_output(LED_NO_RUN);
    nrf_gpio_cfg_output(LED_ERROR);
    nrf_gpio_cfg_output(LED_FINISHED);
    
    V_hw_SD_Setup();
    
    sd_temp_get(&p);
    tmp2 = sd_clock_hfclk_request();
    if(tmp2 != NRF_SUCCESS) 
    {   
        nrf_gpio_pin_set(LED_NO_RUN);
    }
    
    do { 
            tmp2 = sd_clock_hfclk_is_running(&tmp); 
            if(tmp2 != NRF_SUCCESS)  
            {
                nrf_gpio_pin_set(LED_ERROR);
            }
        }while(tmp==0); 
    
    nrf_gpio_pin_set(LED_FINISHED);
    }
    
  • Hmm, this "workaround" works for me. Thanks.

Related