GD32H7系列 DMA传输多个num到SPI外设就会出错,CHEN寄存器不再清零。
dma_single_data_parameter_struct dma_init_struct;
__attribute__((aligned(32))) uint32_t spi3_send_array[BUFFER_SIZE] = {};
void DMA_Init(void)
{
uint16_t i;
SCB_CleanDCache_by_Addr((uint32_t *)spi3_send_array, BUFFER_SIZE * 2);
nvic_irq_enable(EXTI0_IRQn, 1U, 0U); //add DMA_INT EXTI0_IRQn ENET0_IRQn
// dma_single_data_parameter_struct dma_init_struct;
rcu_periph_clock_enable(RCU_DMA0);
rcu_periph_clock_enable(RCU_DMAMUX);
dma_deinit(DMA0, DMA_CH0);
dma_single_data_para_struct_init(&dma_init_struct);
dma_init_struct.request = DMA_REQUEST_SPI3_TX;
dma_init_struct.direction = DMA_MEMORY_TO_PERIPH;
dma_init_struct.memory0_addr = (uint32_t)spi3_send_array;
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_init_struct.periph_memory_width = DMA_PERIPH_WIDTH_32BIT;
dma_init_struct.number = BUFFER_SIZE;
dma_init_struct.periph_addr = SPI3_DATA_ADDRESS;
dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH;
dma_single_data_mode_init(DMA0, DMA_CH0, &dma_init_struct);
dma_circulation_disable(DMA0, DMA_CH0);
// dma_interrupt_enable(DMA0, DMA_CH0, DMA_CHXCTL_FTFIE);
dma_interrupt_disable(DMA0, DMA_CH0, DMA_INTF_FEEIF);
dma_channel_enable(DMA0, DMA_CH0);
}
void 发送处理(void)
{
SCB_CleanInvalidateDCache();
dma_flag_clear(DMA0, DMA_CH0, DMA_INTF_FTFIF);
dma_init_struct.memory0_addr = (uint32_t)spi3_send_array;
dma_init_struct.number = BUFFER_SIZE;
dma_single_data_mode_init(DMA0, DMA_CH0, &dma_init_struct);
dma_channel_enable(DMA0, DMA_CH0);
spi_dma_enable(SPI3, SPI_DMA_TRANSMIT);
spi_master_transfer_start(SPI3, SPI_TRANS_START);
while(!dma_flag_get(DMA0, DMA_CH0, DMA_INTF_FTFIF)); //等待传输完成,FTFIF被置一
dma_flag_clear(DMA0, DMA_CH0, DMA_INTF_FTFIF);
spi_dma_disable(SPI3, SPI_DMA_TRANSMIT);
SCB_CleanInvalidateDCache();
DMA_trans_enable = 0;
exti_interrupt_flag_clear(EXTI_0);
}