/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / USART RX over DMA

Username:     
Password:     
             

Forum

# 1   2011-04-04 13:52:27 USART RX over DMA

primagen
Member
Registered: 2010-12-07
Posts: 13

USART RX over DMA

Hi,

i need an exampe for RX over DMA.
The one from stm is with fixed buffersize.
But i want to do the input with dynamic lenght.
I dont know how to implement this. The following Code works only with fixed size. Therefore every 4 input i make on terminal is stored in RxBuffer.

#define countof(a)   (sizeof(a) / sizeof(*(a)))
uint8_t RxBuffer[5];
#define RxBufferSize   (countof(RxBuffer) - 1)

void DMA1_Channel6_handler() __attribute__((interrupt));
static void DMA_Config_Usart2RX(void)
{
     DMA1_Channel6->CCR = (DMA_Priority_Low |
              DMA_PeripheralDataSize_Byte |
              DMA_MemoryDataSize_Byte |
              DMA_PeripheralInc_Disable |
              DMA_MemoryInc_Enable |
              DMA_Mode_Normal |
              DMA_DIR_PeripheralSRC |
              DMA_CCR4_TCIE
              );
    DMA1_Channel6->CPAR = (u32)&USART2->DR;
        DMA1_Channel6->CMAR = (u32)RxBuffer;
    DMA1_Channel6->CNDTR = RxBufferSize;
    NVIC_ENABLE_INT(DMA1_Channel6_IRQChannel);
    NVIC_SET_PRIORITY(DMA1_Channel6_IRQChannel, 2);
      DMA1_Channel6->CCR |=DMA_CCR6_EN;
}

void DMA1_Channel6_handler()
{
       DMA1->IFCR = DMA_IFCR_CGIF6;
       DMA_Config_Usart2RX();
}

Offline

 

Board footer