nRF52840 UART send more than 256 bytes

I'm sending some data from nRF52840 to another device through wired UART. When data is less than 256-byte long, it works fine. But when it's larger than 256 bytes, I get ERROR 4 [NRF_ERROR_NO_MEM]. I have already changed UART_TX_BUF_SIZE to 1024 in APP_UART_FIFO_INIT. Is there anything else I should change? Thanks

Parents
  • Hello, 

    It should be sufficient to only increase the FIFO TX buffer. Are you able to debug the app to see exactly where the NRF_ERROR_NO_MEM is returned? Is it from the app_fifo_put() call in app_uart_put()? 

    Thanks,

    Vidar

  • Hello,

    The printout from RTT viewer just shows NRF_ERROR_NO_MEM at the line of app_uart_put(). How do I get deep into app_uart_put()?

    Thanks

  • Hello,

    When you initiate a debug session in your IDE, you can set a breakpoint at the app_uart_put() call and then single-step into the function. However, after examining the app_uart_put() implementation, I found that only the app_fifo_put() function can return NRF_ERROR_NO_MEM. This means the FIFO must be filling up faster than it's being emptied.

    I suggest you try to increase the TX buf size further to see if it helps. You may also consider using the UART driver or the Libuarte - advanced UARTE driver to allow you to work with larger DMA buffers (app_uart only allows sending of 1-byte at a time).

  • I have already increased TX buf size to 1024, hence I have this question. 

    The issue is guaranteed to happen when the data size is 257 bytes, but fine when the data size is 255 bytes. I assume the difference of 2 bytes won't have such huge impact?

Reply
  • I have already increased TX buf size to 1024, hence I have this question. 

    The issue is guaranteed to happen when the data size is 257 bytes, but fine when the data size is 255 bytes. I assume the difference of 2 bytes won't have such huge impact?

Children
  • What I meant to suggest was that you increase the TX buffer size even further, e.g., from 1024 to 2048 bytes. This is to help narrow down the problem.

    The issue is guaranteed to happen when the data size is 257 bytes, but fine when the data size is 255 bytes. I assume the difference of 2 bytes won't have such huge impact?

    Are you sending just one packet of 257 bytes when the error occurs? Can you post the relevant code here?

  • Just tried changing 1024 to 2048, it's still the same error. 

    Do you have access to private case 314336? I posted the complete code there to ask for another question. 

  • Yes, I can access the ticket. Are you logging the UART output from the device when the error arises? I see that you are sending UART data from multiple places in your code and it would be helpful to know how much data has been sent before the error occurs. The issue is likely that data is being added to the FIFO buffer faster than it's being transmitted over UART. 

    Also, where did you increase the packet length to 257 bytes?

  • This happens at line 753. This is the only place calling uart_send function at that time. 

    Data is set from line 719 to 722. Total array length is 270, I just play with uint16_t data_length = 16. When data_length is set to 16, the total data to send is 257 and it reports error. If I change data_length to 14, total data length is 255 and it works. 

  • How much data has been sent up to that point, and how often is this function being called? Your 1024-byte FIFO obviously shouldn't return NRF_ERROR_NO_MEM if you're only sending a single 257-byte packet.