Problem when reading accumulator memory

Hi,

I am working on reading the accumulator memory from MDEK1001. I have modified the example from “Example 2c: simple RX with diagnostics” in DW1000 API and it works fine in MDEK1001, and I can show the values of the accumulator data from UART. But there are two problems I found:

(1) In Example 2c, it only read 6 symbols from the accumulator. The buffer length is defined as:

#define ACCUM_DATA_LEN (22(3+3)+1)

I want to read the whole data, i.e., around 1000 symbols from the accumulator. However, I found that if I enlarge the buffer length:

#define ACCUM_DATA_LEN (22(1016)+1)

The code can be built and run, but it gets stuck.

So I tried different sizes, and I found that the code can only work properly when the size is small, such as 20 symbols.

I guess this is because of the interrupts when reading the accumulator? May I know how to solve this?

(2) My second question is about saving the data to a .txt file. Currently, I can display the data on a terminal from UART. But I want to save it to a .txt file. I used

fp = fopen(“Data.txt”,“w”);

and

fprintf(“some data %d \r\n”,accum_data[0]);

But I found that the code was stuck on fopen.

The above are my two questions. I hope someone could help me. Thanks in advance.

Best regards,
Chang

Hi Chang,

The example is extensively commented so I would recommend you to take a look at the comments at the bottom, they should clarify how it works:

[color=#333333][size=small]1. I’ve taken a quick look at the code and I would expect changing the ACCUM_DATA_LEN [/size][size=small]value to 4065 [/size][size=small][font=Arial]should[/font][/size][size=xx-small] [/size][size=small]be fine as the accum_data buffer [/size][size=small]should be the right length.[/size][size=small] What makes you think it’s related to interrupt when reading the accumulator ? Maybe look at the SPI buffer, if it’s too small there may be an issue there. [/size][/color]

[color=#333333][size=small]2. You cannot use fopen on this project. The C code you are writing will be compiled and executed on the microcontroller on the DWM1001, so it makes no sense to use fopen as you would in a classical C project that would run on your computer. [/size][/color]

[color=#333333][size=small]In order to capture the data, I recommend to save the uart output to a log file. [/size][/color]

[color=#333333][size=small]Thank you,[/size][/color]
Let me know how it goes,
Regards
Yves

Dear Yves,

Thank you so much for your reply.

I have read the comments at the bottom of the code. I also expect that changing the ACCUM_DATA_LEN value to 4065 should be fine. However, you can see the result below:

When the ACCUM_DATA_LEN is set to be 81, I get the result shown in the first attached picture (Capture1.jpg).

When the ACCUM_DATA_LEN is set to be 4065, I get nothing. You can see the second attached picture (Capture2.jpg).

I also tried another value. When the ACCUM_DATA_LEN is set to be 121, I get the result but seems that there are something wrong in the end. See the third attached picture as the reference (Capture3.jpg).

For your reference, the part of the code related to this is copied at the end of this post.

Actually I have no idea what the possible reason is to cause this problem. You mentioned the SPI buffer. May I know how to check it?

For the fopen issue, thank you for your explanation. I now have the log file.

Thanks and regards,
Chang

Some code:

if (status_reg & SYS_STATUS_RXFCG)
{

uint16 frame_len = 0;

frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFL_MASK_1023;

if (frame_len <= RX_BUF_LEN)
{
  dwt_readrxdata(rx_buffer, frame_len, 0);
}
dwt_readdiagnostics(&rx_diag);

uint16 fp_int = rx_diag.firstPath / 64;
dwt_readaccdata(accum_data,ACCUM_DATA_LEN, 0);



/* Clear good RX frame event in the DW1000 status register. */
dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG);

tx_count = rx_buffer[ALL_MSG_SN_IDX];
rx_buffer[ALL_MSG_SN_IDX] = 0;
if (memcmp(rx_buffer, rx_resp_msg, ALL_MSG_COMMON_LEN) == 0)
{	
  rx_count++;
  
  printf("Reception # : %d\r\n",rx_count);
  printf("Received from # %d transmission \r\n", tx_count);
  printf("Count of preamble symbols accumulated: %d \r\n",rx_diag.rxPreamCount);
  printf("Index of first path is %d \r\n", rx_diag.firstPath / 64);
  printf("CIR max growth CIR: % d \r\n",rx_diag.maxGrowthCIR);
  printf("LDE max value of noise: %d \r\n", rx_diag.maxNoise);
  printf("Std of noise is %d \r\n",rx_diag.stdNoise);
  printf("First Path AMP2: %d \r\n",rx_diag.firstPathAmp2);
  printf("First Path AMP3: %d \r\n",rx_diag.firstPathAmp3);
  printf("First Path AMP1: %d \r\n",rx_diag.firstPathAmp1);

  for(i=0;i<ACCUM_DATA_LEN;i++){
    printf("%d ",accum_data[i]);
  }
  printf("\r\n\r\n");
}

}
else
{
/* Clear RX error/timeout events in the DW1000 status register. */
dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR);

/* Reset RX to properly reinitialise LDE operation. */
dwt_rxreset();

}

Hi Chang,
Maybe there have size overflow in somewhere…

Hi mhc,

Thanks mhc.

I think so. But I still cannot find how to solve it.

When I set the array size as 1000 or larger, it jumps to HardFault_Handler() when I debug the code. I am looking for the solution from the Internet but get no clue so far.

Best regards,
Chang

Hi Chang,

Do you know which function call cause the HardFault?

How you declare the [color=#333333][size=small]accum_data ? It is local or global variable?[/size][/color]

[color=#333333][size=small]You should declare accum_data as global variable as there are heap size limited in FreeRTOS.[/size][/color]