Peripheral uart with variable packet/buffer size

Dear all,

I've got some problems with the uart implementation in the peripheral uart example. I am using nRF52833 DK and SDK 2.0.2.

What I need for evaluation is a device which advertises and has a simple uart interface to comunicate with some python scrips.  

So, peripheral uart example seems to be perfect to start with.  The BLE part (own service etc.) is implemented and works fine.

The idea is to implement a command line shell (LwSHELL) to get/set parameters and send/receive some data. 

 

As not all commands are of the same length and payload can also be variable it is hard to select the "perfect" buffer size. When I get that right the buffer is only released if it is full and the next buffer is loaded:

As you can see the buffer is only put to fifo in the UART_RX_BUF_RELEASED event. 

I've also seen the example in Nordic Dev Academy:

The data is directly processed in the UART_RX_RDY event. This is may be good for setting I/O's, but is also meant to be the solution for larger amount of data or maybe calling

a subfunction which returs a few hundred milliseconds later? Is this callback called in an ISR context? 

For now I modified the example that the data is copied to a second buffer in the UART_RX_RDY event an this buffer will be put to fifo:

But this leads to another question.

What happends if the incoming data does not fit into the buffer anymore? Is it swapped to the new buffer? 

Thanks and best regards.

Oliver

  • Hi Oliver

    I am working on a modified version of the peripheral_uart example with a simplified UART wrapper, to make it easier to interface to the UART, and also to remove the reliance on dynamic memory allocation. 

    Do you think you could give this example a try and see if it works fine for your use case? 

    It was developed and tested in v2.1.2 of the SDK, but I just checked that it builds in v2.0.2 as well. 

    You will find the example here:

    per-uart-app-uart.zip

    Just unzip the included folders anywhere, and add the "peripheral_uart" folder as an existing application. 

    The app_uart driver uses a static FIFO rather than using malloc, and if you use hardware flow control it will automatically de-assert the RTS line when the buffers fill up in order to avoid data loss. 

    By default the sample does not use HWFC though, so you would need to enable this in the device tree if you want to use it (you can modify this in the app.overlay file for instance).  

    Best regards
    Torbjørn

Related