1)内存到内存
uint8_t srcBuf[8] = {0,1,2,3,4,5,6,7};
uint8_t dstBuf[8];
void DMA_M2M_Test(void)
{
//DMA0测试中,内存到内存不可以,不知道什么情况;
// dma_multi_data_parameter_struct dma_init_parameter;
// rcu_periph_clock_enable(RCU_DMA0);
// dma_deinit(DMA0, DMA_CH1);
// dma_init_parameter.periph_addr = (uint32_t)srcBuf;
// dma_init_parameter.periph_width = DMA_PERIPH_WIDTH_8BIT;
// dma_init_parameter.periph_inc = DMA_PERIPH_INCREASE_ENABLE;
// dma_init_parameter.memory0_addr = (uint32_t)dstBuf;
// dma_init_parameter.memory_width = DMA_MEMORY_WIDTH_8BIT;
// dma_init_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
// dma_init_parameter.circular_mode = DMA_CIRCULAR_MODE_DISABLE;
// dma_init_parameter.direction = DMA_MEMORY_TO_MEMORY;
// dma_init_parameter.number = 8;
// dma_init_parameter.priority = DMA_PRIORITY_ULTRA_HIGH;
//
// dma_multi_data_mode_init(DMA0, DMA_CH1, &dma_init_parameter);
// dma_channel_enable(DMA0, DMA_CH1);
// while(!dma_flag_get(DMA0, DMA_CH1, DMA_INTF_HTFIF));
//
//DMA1测试中,内存到内存可以;
dma_multi_data_parameter_struct dma_init_parameter;
rcu_periph_clock_enable(RCU_DMA1);
dma_deinit(DMA1, DMA_CH1);
dma_init_parameter.periph_addr = (uint32_t)srcBuf;
dma_init_parameter.periph_width = DMA_PERIPH_WIDTH_8BIT;
dma_init_parameter.periph_inc = DMA_PERIPH_INCREASE_ENABLE;
dma_init_parameter.memory0_addr = (uint32_t)dstBuf;
dma_init_parameter.memory_width = DMA_MEMORY_WIDTH_8BIT;
dma_init_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_init_parameter.circular_mode = DMA_CIRCULAR_MODE_DISABLE;
dma_init_parameter.direction = DMA_MEMORY_TO_MEMORY;
dma_init_parameter.number = 8;
dma_init_parameter.priority = DMA_PRIORITY_ULTRA_HIGH;
dma_multi_data_mode_init(DMA1, DMA_CH1, &dma_init_parameter);
dma_channel_enable(DMA1, DMA_CH1);
while(!dma_flag_get(DMA1, DMA_CH1, DMA_INTF_HTFIF));
}
2)内存到串口1
//DMA初始化
/* initialize DMA1 channel7 */
dma_single_data_parameter_struct dma_init_struct;
dma_deinit(DMA1, DMA_CH7);
dma_init_struct.direction = DMA_MEMORY_TO_PERIPH;
dma_init_struct.memory0_addr = (uint32_t)welcome;
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_init_struct.periph_memory_width = DMA_PERIPH_WIDTH_8BIT;
dma_init_struct.number = ARRAYNUM(welcome);
dma_init_struct.periph_addr = USART0_DATA_ADDRESS;
dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH;
dma_single_data_mode_init(DMA1, DMA_CH7, &dma_init_struct);
dma_circulation_disable(DMA1, DMA_CH7);
dma_channel_subperipheral_select(DMA1, DMA_CH7, DMA_SUBPERI4);
/* USART DMA enable for transmission */
usart_dma_transmit_config(USART0, USART_TRANSMIT_DMA_ENABLE);
/* enable DMA1 transfer complete interrupt */
dma_interrupt_enable(DMA1, DMA_CH7, DMA_CHXCTL_FTFIE);
/* enable DMA1 channel7 */
dma_channel_enable(DMA1, DMA_CH7);
void nvic_config(void)
{
nvic_irq_enable(DMA1_Channel7_IRQn, 0, 0);
}
void EXTI10_15_IRQHandler(void)
{
if(RESET != exti_interrupt_flag_get(EXTI_13))
{
exti_interrupt_flag_clear(EXTI_13);
dma_channel_disable(DMA1, DMA_CH7);
dma_transfer_number_config(DMA1, DMA_CH7, ARRAYNUM(welcome));
dma_channel_enable(DMA1, DMA_CH7);
}
}
/*!
\brief this function handles DMA1_Channel7_IRQHandler interrupt
\param[in] none
\param[out] none
\retval none
*/
void DMA1_Channel7_IRQHandler(void)
{
if(dma_interrupt_flag_get(DMA1, DMA_CH7, DMA_INT_FLAG_FTF))
{
gd_eval_led_toggle(LED2);
dma_interrupt_flag_clear(DMA1, DMA_CH7, DMA_INT_FLAG_FTF);
}
}