how to use HFCLK in zephyr with nrf52840

I want to use HFCLK for 52840 in nrf21540dk, I change the prj.conf like this ,but it didn't compile.

CONFIG_NRF_RTC_TIMER=n
CONFIG_CORTEX_M_SYSTICK=y
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=64000000
CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000000

Parents Reply Children
  • Hi,

    Could you elaborate?

    What are you trying to do and how are observing that the 32 MHz doesn't work?

    regards

    Jared

  • I want to receive data from spi and save to sd card, and after a random time the file write error, the Hardware Engineer found the 32M is not working, So I guess the error has something to do with the 32M crystal not working?

  • Hi,

    Can you specify what error the HW engineer found? 

    Also, it would be great if you can specify where in your code the error happens. 

    Have you reproduced this on the nRF21540 DK or are you using a custom board?

    regards

    Jared 

  • Have you reproduced this on the nRF21540 DK or are you using a custom board?

    Yes, I test on the nRF21540 DK.

    Also, it would be great if you can specify where in your code the error happens.

    the error happen when write data to sd card.This is the debug info,the fs_write() return -5,I think it's hardware IO except the problem,So I handed the problem over to the HW engineer.

        int res;
        res = fs_write(&file, (char *)buf, len);
        // res = f_write(&file, buf, len, &bw);
        if(res < 0)
        {
            printk("rb_length = %d, back_length = %d\n", len, res);
            
            send_message_spi(MES_ERR);
            fs_close(&file);
        }
        res = fs_sync(&file);
        return res;

    Can you specify what error the HW engineer found?

    The HW engineer said the  that the oscilloscope can not monitor the 32M crystal,and I found no clk signal detected on X1 oscilator.

  • Hi Jared:

    Tanks for your reply,The HFCLK has two source the HFINT and the HFXO,the HFINT work in normally.If you need a more accurate clock you can use the HFXO, for exanple radio, is right?

    Now there is two threads in my project,one thread receive 32bytes data from spi every 160us and put into a ringbuf, another thread get data from the ringbuf and use fs_write to save data to sd card.Do I need to use the HFXO?

    Now i found the fs_write return error -5 from time to time,what is the reason of this error?

    I'm sure the IO connection is correct, because the program does not return an error at first, but only after running for a while.

Related