stm32 spi dma 写flash第一字节写不进去

2020-01-01 17:36发布

写flash 刚开始我用spi硬件方式读写是没有问题的,但是当我用spi dma 方式写,然后用硬件方式读,发现有错误!
比如我定义两个数组
u8 rvc[10];   
const u8 send[10] = {0x01,0x02,0x03.0x04,0x05,0x06,0x07,0x08,0x09,0x0a};
用dma写,然后用硬件读,然后打印发现
rvc[0] =0xff
rvc[1] =0x01
rvc[2] =0x02
rvc[3] =0x03
rvc[4] =0x04
rvc[5] =0x05
rvc[6] =0x06
rvc[7] =0x07
rvc[8] =0x08
rvc[9] =0x0a
就是往右移了一位,不知道是为什么,我之前怀凝是DMA字节对齐问题,但是查不出结果,想问一下,有哪位朋友是不是也遇到类似问题了,怎么解决的?
DMA相关写的部分程序:
DMA_DeInit(DMA1_Channel3);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SPI_MASTER_DR_Base;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)0;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = 0xffff;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel3, &DMA_InitStructure);

SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx, ENABLE);
DMA_ITConfig(DMA1_Channel3,DMA_IT_TC,ENABLE);

// NumByteToWrite<256
void Flash_WritePage(uint8_t* pBuffer, u32 WriteAddr, uint16_t NumByteToWrite)
{
            sFLASH_WriteEnable();
            sFLASH_WaitForWriteEnd();
            sFLASH_CS_LOW();
            sFLASH_SendByte(sFLASH_CMD_WRITE);
            sFLASH_SendByte((WriteAddr&0xFF0000)>>16);               
            sFLASH_SendByte((WriteAddr&0xFF00)>>8);
            sFLASH_SendByte(WriteAddr&0xFF);
//    if(NumByteToWrite>256)
//    {
//       NumByteToWrite=256;            
//    }
//    while(NumByteToWrite--)
//    {                                                                                                                                         
//      sFLASH_SendByte(*pBuffer);
//       pBuffer++;
//    }
           DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer;
            DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;   
            DMA_InitStructure.DMA_BufferSize = NumByteToWrite;  
        DMA_Init(DMA1_Channel3, &DMA_InitStructure);
        DMA_Cmd(DMA1_Channel3,ENABLE);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
39条回答
bias
2020-01-05 15:04
515999271 发表于 2014-10-30 15:06
你先试一下吧!

void SPI_Flash_Write_DMA(uint8_t *pBuffer,uint16_t NumByteToWrite)
{
        SPI_Flash_Write_DMA_Config(pBuffer,NumByteToWrite);
        LED4 = 0;
        DMA_Cmd(DMA1_Channel3, ENABLE);
        //while(DMA_GetITStatus(DMA1_IT_TC3) == RESET);
        //while(DMA_GetFlagStatus(DMA1_IT_TC3) == RESET);
        while(!DMA_GetFlagStatus(DMA1_FLAG_TC3));
        LED4 = 1;
        DMA_ClearITPendingBit(DMA1_IT_TC3);
}

都不行,确实就是LED4=0亮了,不灭,还是卡在这里...

一周热门 更多>