nrf5340dk cycles do not update

Hi,
I got strange error which I can't to fix.

From time to time, I get the same readings from every function which counts the CPU cycles.
They all base on DWT_CTRL.
Board is clocked with 64Mhz, OS is clocked with NRF_RTC_TIMER.

When I execute multiple times a function like this `k_cycle_get_32`, I get the same reading until the thread locks itself again.
I receive SPI data every 250us, so there should be no problems with this, if the CPU is clocked with a few MHz.

My thread looks like this:

void ads129x_th(void)
{
    /* setup ecg */
    ads129x_setup();

    for (;;)
    {
        /*
         * Wait for semaphore from ISR; if acquired, do related work, then
         * go to next loop iteration (the semaphore might have been given
         * again); else, make the CPU idle.
         */
        if (k_sem_take(&ads129x_new_data, K_FOREVER) == 0)
        {
    /* track status of buffers */
    static size_t bytes_written = 0;

    /* add timestamp */
    uint32_t end_time = k_cycle_get_32();
    return conv_u24_to_raw(k_cyc_to_us_ceil32(end_time), tx_data.buffer, 0);

    /* do processing */
    /* NOTE: Work directly on a ring buffer memory */
    int ret = spi_read(ads129x_config.ads129x_spi, &ads129x_config.ads129x_spi_cfg, &ads129x_rx);
    if (!ret)
    {
        /* add missing leads */
        ads129x_load_augmented_leads(tx_data.packet.leads._buffer);

        ads129x_dump_data(tx_data.packet.leads._buffer);
        /* send data to the consumers */
        k_pipe_put(&ads129x_pipe, &tx_data.buffer, ADS129x_DATA_BUFFER_SIZE, &bytes_written, sizeof(pipe_packet_u), K_NO_WAIT);
    }
        }
    }
}

I tried:

⇾ using base k_cycle_get_32
→ using timing functions
→ using Cortex M systick with different clock speed

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


All of them are broken.

Could somebody help me :D
Parents Reply Children
No Data
Related