demo中是spi 读gd25Q Norflash数据,运行正常,改用dma 方式无法工作。我的代码如下:
void spiflash_dma_config(uint8_t *data)
{
rcu_periph_clock_enable(RCU_DMA1);
dma_single_data_parameter_struct spi_dma_init_struct;
dma_deinit(DMA1,DMA_CH6);
spi_dma_init_struct.direction = DMA_PERIPH_TO_MEMORY;
spi_dma_init_struct.number = 8;
spi_dma_init_struct.periph_addr = (uint32_t)&SPI_DATA(SPI5);
spi_dma_init_struct.periph_memory_width = DMA_PERIPH_WIDTH_8BIT;
spi_dma_init_struct.priority = DMA_PRIORITY_LOW;
spi_dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
spi_dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
spi_dma_init_struct.circular_mode = DMA_CIRCULAR_MODE_DISABLE;
spi_dma_init_struct.memory0_addr = (uint32_t)data;
dma_single_data_mode_init(DMA1,DMA_CH6,&spi_dma_init_struct);
dma_channel_subperipheral_select(DMA1,DMA_CH6,DMA_SUBPERI1);//接收通道配置
dma_circulation_disable(DMA1, DMA_CH6);
dma_channel_disable(DMA1,DMA_CH6);
spi_dma_disable(SPI5,SPI_DMA_RECEIVE);
}
void spi_flash_dma_read(uint32_t read_addr)
{
SPI_FLASH_CS_LOW();
spi_flash_send_byte(READ);
spi_flash_send_byte((read_addr & 0xFF0000) >> 16);
spi_flash_send_byte((read_addr& 0xFF00) >> 8);
spi_flash_send_byte(read_addr & 0xFF);
dma_channel_enable(DMA1,DMA_CH6);
spi_dma_enable(SPI5, SPI_DMA_RECEIVE);
while(dma_flag_get(DMA1,DMA_CH6,DMA_FLAG_FTF)!= SET){}
dma_flag_clear(DMA1,DMA_CH6,DMA_FLAG_FTF);
dma_channel_disable(DMA1,DMA_CH6);
SPI_FLASH_CS_HIGH();
}
main()
{。。。。初始化省略
spi_flash_init(); //这是demo的
spiflash_dma_config(my_buf);
spi_flash_dma_read(0x0c0000);
}
发现一直在 while(dma_flag_get(DMA1,DMA_CH6,DMA_FLAG_FTF)!= SET){}中,求指导,谢谢!
|