How to modify the CLI firmware to read the raw CIR data from DWM3001CDK?

Hi I am trying to enable streaming CIR data through the UART when running Fira application with the CLI firmware written into two DWM3001CDK kits.

I have followed the suggestions in the post: https://forum.qorvo.com/t/how-to-get-the-raw-data-and-transmit-through-usb/21254/8

Currently I can enable this when the RX is running the LISTENR command by modifying the rx_listener_cb function in the listener.c file:

/** @brief ISR level TWR application Rx callback to be called from dwt_isr() as an Rx call-back. */
void rx_listener_cb(const dwt_cb_data_t *rxd)
{
    listener_info_t *pListenerInfo = getListenerInfoPtr();

    if (!pListenerInfo)
    {
        return;
    }

    const int size = sizeof(pListenerInfo->rxPcktBuf.buf) / sizeof(pListenerInfo->rxPcktBuf.buf[0]);
    int head = pListenerInfo->rxPcktBuf.head;
    int tail = pListenerInfo->rxPcktBuf.tail;

    if (CIRC_SPACE(head, tail, size) > 0)
    {
        rx_listener_pckt_t *p = &pListenerInfo->rxPcktBuf.buf[head];

        /* Raw Rx TimeStamp (STS or IPATOV based on STS config). */
        dwt_readrxtimestamp(p->timeStamp, DWT_COMPAT_NONE);
        /* Reading Clock offset for any Rx packets. */
        p->clock_offset = dwt_readclockoffset();
        p->status = rxd->status;

        p->cir_data = (uint32_t *)malloc((CIR_SAMPLE) * sizeof(uint32_t));
        if (p->cir_data == NULL)
        {
            error_handler(1, _ERR_Cannot_Alloc_Memory);  // Handle memory allocation failure
            return;
        }

        /* Read RX diag data. */
        p->all_diag.diag_type = IPATOV;
        dwt_nlos_alldiag(&p->all_diag);
        
        // dwt_nlos_ipdiag_t ip_diag;
        dwt_nlos_ipdiag(&p->ip_diag);
        uint16_t FPI = p->ip_diag.index_fp_u32 / 64;  // first path index stored in 10.6 fixed point format, divide by 64 to get the index

        /* Read CIR Data */
        dwt_readcir(p->cir_data, DWT_ACC_IDX_IP_M, FPI - 5, CIR_SAMPLE, DWT_CIR_READ_LO);
       // ....

Basically calling the driver APIs by myself.

Then I tried to add similar code to the Fira application. I add similar code to fira_session_info_ntf_twr_cb function in the fira_app.c:

static void fira_session_info_ntf_twr_cb(const struct fira_twr_ranging_results *results, void *user_data)
{
    int len = 0;
    struct string_measurement *str_result = (struct string_measurement *)user_data;
    struct fira_twr_measurements *rm;

    
    // /* Read RX diag data. */
    dwt_nlos_ipdiag_t ip_diag;
    dwt_nlos_alldiag_t all_diag;
    all_diag.diag_type = IPATOV;
    dwt_nlos_alldiag(&all_diag);
    dwt_nlos_ipdiag(&ip_diag);
    uint16_t FPI = ip_diag.index_fp_u32 / 64;  // first path index stored in 10.6 fixed point format, divide by 64 to get the index
    /* Print the FPI */
    len += snprintf(&str_result->str[len], str_result->len - len, ", FPI=%u", FPI);

    uint32_t *cir_data = (uint32_t *)malloc((8) * sizeof(uint32_t));
    dwt_readcir(cir_data, DWT_ACC_IDX_IP_M, FPI, 8, DWT_CIR_READ_LO);
    
    /* Print cir_data */
    uint32_t cnt;
    for (cnt = 0; cnt < 8; cnt++)  // Ensure space remains
    {
        uint16_t real_part = (cir_data[cnt] >> 16) & 0xFFFF;
        uint16_t imag_part = cir_data[cnt] & 0xFFFF;
        len += snprintf(&str_result->str[len], str_result->len - len, ", cir_data[%lu]=%04X+j%04X,", cnt, real_part, imag_part);   
    }
    free(cir_data);
   // ....

But all I got about FPI and CIR data are all 0.
I am assuming it is because that this function is only called when a ranging session is ended, and the values in these registers have been reset.

So here is my question, if I wish to enable reading and streaming CIR values in the Fira application, what should I do? Which part of code should I tweak with?

Any help and suggestions would be really appreciated!

Best,
Shanmu

Hello!

I have a very similar issue as you so unfortunately i cant help but i tought maybe you solved it since and you could help me.

I want to log more info, especially the cir and some other datas i might find useful. For this i am also using the same function (the function header: static void fira_range_diagnostics_ntf_cb(const struct fira_ranging_info *info, void *user_data)) I tried to edit it but the cirs and the seg_metrics pointers are always NULL (diagnostics_info->reports->cirs and diagnostics_info->reports->seg_metrics).

I would appreciate any help regarding my issue from you or anyone else! Im sure someone else had the same problem as us and could solve it!

Thanks in advance!

Hi @peter1 ,

I think you should specify the diagnostic field here in common_fira.c:

    r = fira_helper_set_session_diags_frame_reports_fields(fira_context, session_handle, FIRA_RANGING_DIAGNOSTICS_FRAME_REPORT_SEGMENT_METRICS |
                                                                                         FIRA_RANGING_DIAGNOSTICS_FRAME_REPORT_CFO |
                                                                                         FIRA_RANGING_DIAGNOSTICS_FRAME_REPORT_CIRS);

Hi!

I have done that before and i also set the config_state to FIRA_APP_CONFIG_USER in the same file before but it didnt solve the issue.

I suspect there might be a define somewhere i have to edit to solve the problem.

Thank you for the suggestion, i appreciate the help! If you have any other idea what could cause the issue id be greatful if you shared! Again thanks for the idea, but unfortunately it doesnt solve the problem.

Can you try running the UCI build with uwb-qorvo-tools to see if the board is working?

I followed the instruction on ‘UWB-Qorvo-Tools-guide.pdf’ and run the followng:

set_cal -p COM6 rx_diag_config.cir_n_taps 30
set_cal -p COM6 rx_diag_config.cir_fp_tap_offset 0
run_fira_twr -p COM6 --en-diag --diag-fields cir --controlee > "output_rx.log" --ranging-span 20 --slots-per-rr 8

run_fira_twr -p COM11 --en-diag --diag-fields cir  > "output_tx.log" --ranging-span 20 --slots-per-rr 8

Best,

Hi!

I dont really what you mean by to see if the board is working or not. I could do measurements using the board and everything worked fine, my problem is that i cant log these datas only the usual distance, RSSI…

I will give it a try though, but it might take a bit of time since i only used the cli so far. I will get back to you after i tried but if you meant working like being able to measure distance it works just fine.

Thank you, i will try the UCI as soon as i have time for it (probably only tomorrow)!

Hi!

Sorry for the late reply, i was busy with other things and had a smaller issue with the uci which took me a bit to solve. Finally i got to check this and this works for me too!

Thanks a lot for your help!

I am still interested in why the cli one didnt work for me, i would appreciate any suggestion regarding that.

Also i am very new with the uci as you can see and in the short time i spent with this i couldnt figure out how to log the rssi, cir, noise and a lot of other datas at the same time. I can only log them seperately. I would appreciate help with that if you encountered the same issue and know the solution!

Thank you very much again!