This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

UARTE in circular mode

Hi,

I have a question about the UARTE peripheral. is it possible to keep the DMA running and let it write to ram in a circular way? I used DMA on the stm32 before and there we can set it in a circular mode. When the ptr reached the last configured ram address it automatically starts from the front. And while the DMA is running, is there any way to get the current amount in the buffer? Now i have to stop rx before the amount register becomes valid.

  • I actually created a solution using PPI and TIMER in counter mode to get the amount while keeping DMA active:

    NRF_TIMER1->MODE = TIMER_MODE_MODE_LowPowerCounter << TIMER_MODE_MODE_Pos;
    NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos;
    NRF_TIMER1->TASKS_CLEAR = 1;
    NRF_TIMER1->TASKS_START = 1;
    
    NRF_PPI->CH[0].EEP = (SE_UInt32)&pContext->pUart->EVENTS_RXDRDY;
    NRF_PPI->CH[0].TEP = (SE_UInt32)&NRF_TIMER1->TASKS_COUNT;
    
    NRF_PPI->CH[1].EEP = (SE_UInt32)&pContext->pUart->EVENTS_ENDRX;
    NRF_PPI->CH[1].TEP = (SE_UInt32)&NRF_TIMER1->TASKS_CLEAR;
    
    NRF_PPI->CHENSET =  PPI_CHENSET_CH0_Set << PPI_CHENSET_CH0_Pos | PPI_CHENSET_CH1_Set << PPI_CHENSET_CH1_Pos ;
    

    This way I can keep the DMA running and the counter value indicates the current write index of the DMA. Now i can handle the data while keeping the receiver running.

  • If you don't update the RXD.PTR before the next STARTRX task is called it will start writing to the same location. Use shortcut between ENDRX and STARTRX to keep the UARTE always in reception.

    Seems like figured out a way to count the data. Just remember that the data may not be written to RAM when the RXDRDY event triggers:

    For each byte received over the RXD line, an RXDRDY event will be generated. This event is likely to occur before the corresponding data has been transferred to Data RAM.

    You can also read the RXD.AMOUNT register to see how many new bytes have been transferred to the RX buffer in RAM since the last ENDRX event.

  • I know the AMOUNT register can be read after the ENDRX event. But when I keep DMA running it will only update on the overflow moment and result in constandly the same value. Is there maybe another way to keep UARTE rx active and keep track of data without toggling rx on and off to get the AMOUNT?

  • You are correct, sorry for that, the AMOUNT will only be updated at the ENDRX event. I don't know of any other way to count the bytes other than the one you have suggested.

  • Is there maybe a way to get all data with toggling rx off and on? I tried and everytime i miss some bits and get garbage. I reall don't like using a complete timer for a simple dma counter. And I am scared what I will find when i start using other peripherals.

Related