AnsweredAssumed Answered

Buffer sizes for SPI and DMA

Question asked by jdcowpland on Jan 6, 2014
Latest reply on Jan 9, 2014 by jdcowpland
Quick Question: I'm using DMA to transfer some data over SPI, and the first time round, I'm sending data from a buffer of size 3 bytes. I then redefine the DMA to try and send a buffer of size 4 bytes, but it just sends the first 3 bytes. Any idea why? This is my DMA setup, and all I do is call the function with a different sized cmd array each time, and then enable it after the setup.
void DMA_Config(uint8_t cmd[]){
    DMA_InitTypeDef  DMA_InitStructure;
    DMA_Cmd(DMA1_Stream0,DISABLE);
    DMA_Cmd(DMA1_Stream5,DISABLE);
      RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
      DMA_DeInit(DMA1_Stream0);
 
      DMA_InitStructure.DMA_Channel = DMA_Channel_0;
      DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; // Receive
      DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t) spi_rd;
      DMA_InitStructure.DMA_BufferSize = sizeof(spi_rd);
      DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t) (&(SPI3->DR));
      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_High;
      DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
      DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
      DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
      DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
 
      DMA_Init(DMA1_Stream0, &DMA_InitStructure);
 
 
      DMA_DeInit(DMA1_Stream5);
 
      DMA_InitStructure.DMA_Channel = DMA_Channel_0;
      DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; // Transmit
      DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t) cmd;//(uint8_t)Buffer;
      DMA_InitStructure.DMA_BufferSize = (sizeof(cmd)-1);
      DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t) (&(SPI3->DR));
      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_High;
      DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
      DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
      DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
      DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
 
      DMA_Init(DMA1_Stream5, &DMA_InitStructure);
 
 
      /* Enable DMA Stream Transfer Complete interrupt */
      DMA_ITConfig(DMA1_Stream0, DMA_IT_TC, ENABLE);
      DMA_ITConfig(DMA1_Stream5, DMA_IT_TC, ENABLE);
      /* Enable SPI DMA TX Requests */
      SPI_I2S_DMACmd(SPI3, SPI_I2S_DMAReq_Tx, ENABLE);
      /* Enable SPI DMA RX Requests */
      SPI_I2S_DMACmd(SPI3, SPI_I2S_DMAReq_Rx, ENABLE);

Outcomes