简体   繁体   中英

Reprogramming DMA start address using STM32F103 microcontroller (Cortex-M3)

The below IRQ handler drains the USART3 of incoming 32 byes of data. The first IRQ TC event reads the first 6 bytes, then reprograms the DMA engine to read in the last 24 bytes. The second TC repograms it to read the header again This method will allow for variable length messages using DMA. However I cannot seem to be able the change the DMA start address. I'd like to be able to store each message in a seperate buffer, however it just over writes the first buffer on upon recieving each message. What am I doing wrong? The microcontroller is a STM32F103ze (Cortex-M3).

void DMA1_Channel3_IRQHandler(void)
{
    uint32_t tmpreg = 0;
     /* Test on DMA1 Channel3 Transfer Complete interrupt */
     if(DMA_GetITStatus(DMA1_IT_TC3)) 
     {
          if (rx3_dma_state == RECIEVE_HEADER )
          {
               DMA_Cmd(DMA1_Channel3, DISABLE);/* Disable DMA1_Channel2 transfer*/
               // Now that have received the header. Configure the DMA engine to receive
               // the data portion of the message
               DMA_SetCurrDataCounter(DMA1_Channel3,26);
               DMA_Cmd(DMA1_Channel3, ENABLE);
          } else if ( rx3_dma_state == RECIEVE_MSG )
          {
               //CurrDataCounterEnd3 = DMA_GetCurrDataCounter(DMA1_Channel3);
               DMA_Cmd(DMA1_Channel3, DISABLE);
               /* Get Current Data Counter value after complete transfer */
               USART3_Rx_DMA_Channel_Struct->CMAR = (uint32_t) RxBuffer3LookUp[rx_buffer_index];
               DMA_SetCurrDataCounter(DMA1_Channel3, 6);
               DMA_Cmd(DMA1_Channel3,ENABLE);
               // Set up DMA to write into the next buffer slot (1 of 8)
               ++rx_buffer_index;
               rx_buffer_index %= 8;
          }
          /* Clear DMA1 Channel6 Half Transfer, Transfer Complete and Global interrupt pending bits */
          DMA_ClearITPendingBit(DMA1_IT_GL3);
     }      
     // Update the state to read fake header of 6 bytes
     // or to read the fake data section of the message 26 bytes
     ++rx3_dma_state;
     rx3_dma_state %= 2;
     isr_sem_send(dma_usart3_rx_sem);
}

You say:

...reprograms the DMA engine to read in the last 24 bytes.

but your code says:

DMA_SetCurrDataCounter(DMA1_Channel3,26);

Is that right? Is it 24 or 26?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM