DMA_SxNDTR 启用流后将自身设置为最大值 (65535)
DMA_SxNDTR sets itself to max value (65535) after stream enabled
我正在尝试使用 DMA 和 USART1 来接收 stm32f205xx 系列中的数据。在初始化序列之后,我读取了 NDTR 寄存器,它的值为 4,正是我放在那里的值。但是在流启用后 NDTR 的值是 65535.
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
DMA2_Stream2->CR &= ~DMA_SxCR_EN;
while(DMA2_Stream2->CR & DMA_SxCR_EN);
DMA2_Stream2->PAR = (uint32_t)&(USART1->DR);
DMA2_Stream2->M0AR = (uint32_t)&test_array[0];
DMA2_Stream2->NDTR = 4;
uint32_t temp = DMA2_Stream2->NDTR; // HERE 4
DMA2_Stream2->CR |= (4<<25); //ch4 for stream 2
DMA2_Stream2->CR |= (3<<16); //very high priority
DMA2_Stream2->CR |= (1<<10); //increment memory
DMA2_Stream2->CR |= (1<<5); //flow control
DMA2_Stream2->CR |= (1<<4); //transmit complete interrupt enable
DMA2_Stream2->CR |= (1<<2)|(1<<1); //all interrupts available
DMA2_Stream2->FCR |= (1<<7); //all interrupts available
NVIC_EnableIRQ(DMA2_Stream2_IRQn);
uart1_init();
DMA2_Stream2->CR |= DMA_SxCR_EN;
temp = DMA2_Stream2->NDTR; //HERE 65535
这是错误的
DMA2_Stream2->CR |= (1<<5); //流量控制
阅读参考手册流量控制
这是将 DMA 配置寄存器设置为外设流量控制而不是 "normal" 流量控制的症状。
- 在"normal"流量控制中,是
DMA_SxNDTR
设置了要传输的数据块个数,每传输一个item就减1。 DMA_SxNDTR 达到 0 时传输完成。
- 当使用"peripheral"流控时,外设通过其他方式向DMA控制器发送传输结束信号。
来自STM32F767参考手册RM0410第8.2节(对于不同的MCU,但具有相似的外围硬件)
– DMA flow controller: the number of data items to be transferred is software programmable
from 1 to 65535
– Peripheral flow controller: the number of data items to be transferred is unknown
and controlled by the source or the destination peripheral that signals the end of
the transfer by hardware
另请参见同一手册中的 8.3.16 节流量控制器
我正在尝试使用 DMA 和 USART1 来接收 stm32f205xx 系列中的数据。在初始化序列之后,我读取了 NDTR 寄存器,它的值为 4,正是我放在那里的值。但是在流启用后 NDTR 的值是 65535.
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
DMA2_Stream2->CR &= ~DMA_SxCR_EN;
while(DMA2_Stream2->CR & DMA_SxCR_EN);
DMA2_Stream2->PAR = (uint32_t)&(USART1->DR);
DMA2_Stream2->M0AR = (uint32_t)&test_array[0];
DMA2_Stream2->NDTR = 4;
uint32_t temp = DMA2_Stream2->NDTR; // HERE 4
DMA2_Stream2->CR |= (4<<25); //ch4 for stream 2
DMA2_Stream2->CR |= (3<<16); //very high priority
DMA2_Stream2->CR |= (1<<10); //increment memory
DMA2_Stream2->CR |= (1<<5); //flow control
DMA2_Stream2->CR |= (1<<4); //transmit complete interrupt enable
DMA2_Stream2->CR |= (1<<2)|(1<<1); //all interrupts available
DMA2_Stream2->FCR |= (1<<7); //all interrupts available
NVIC_EnableIRQ(DMA2_Stream2_IRQn);
uart1_init();
DMA2_Stream2->CR |= DMA_SxCR_EN;
temp = DMA2_Stream2->NDTR; //HERE 65535
这是错误的 DMA2_Stream2->CR |= (1<<5); //流量控制 阅读参考手册流量控制
这是将 DMA 配置寄存器设置为外设流量控制而不是 "normal" 流量控制的症状。
- 在"normal"流量控制中,是
DMA_SxNDTR
设置了要传输的数据块个数,每传输一个item就减1。 DMA_SxNDTR 达到 0 时传输完成。 - 当使用"peripheral"流控时,外设通过其他方式向DMA控制器发送传输结束信号。
来自STM32F767参考手册RM0410第8.2节(对于不同的MCU,但具有相似的外围硬件)
– DMA flow controller: the number of data items to be transferred is software programmable from 1 to 65535
– Peripheral flow controller: the number of data items to be transferred is unknown and controlled by the source or the destination peripheral that signals the end of the transfer by hardware
另请参见同一手册中的 8.3.16 节流量控制器