[英]Reprogramming DMA start address using STM32F103 microcontroller (Cortex-M3)
下面的 IRQ 处理程序会耗尽传入 32 字节数据的 USART3。 第一个 IRQ TC 事件读取前 6 个字节,然后重新编程 DMA 引擎以读取最后 24 个字节。 第二个 TC 重新编组它以再次读取标题。此方法将允许使用 DMA 的可变长度消息。 但是我似乎无法更改 DMA 起始地址。 我希望能够将每条消息存储在一个单独的缓冲区中,但是它只是在收到每条消息时覆盖第一个缓冲区。 我究竟做错了什么? 微控制器是 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);
}
你说:
...重新编程 DMA 引擎以读取最后 24 个字节。
但你的代码说:
DMA_SetCurrDataCounter(DMA1_Channel3,26);
那正确吗? 是 24 还是 26?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.