cancel
Showing results for 
Search instead for 
Did you mean: 

DMA Configuration from SRAM to SD Card

cng
Associate II
Posted on May 30, 2012 at 01:55

I am new in developing firmware by using STM32L152VBT6. I need to configure DMA to transfer data from SRAM to SD Card. The data would be {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}. However, I could not write into SD Card and I could not find any problem about it.

DMA_InitTypeDef DMA_TestStructure;

//Enables the DMA1 peripheral clock.

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

SD_Init();

SD_CS_LOW();

DMA_DeInit(DMA1_Channel5);

DMA_TestStructure.DMA_PeripheralBaseAddr = (uint32_t)SD_SPI_DR;

  DMA_TestStructure.DMA_MemoryBaseAddr = (uint32_t)write_data;

  DMA_TestStructure.DMA_DIR = DMA_DIR_PeripheralDST;

  DMA_TestStructure.DMA_BufferSize = 10;

  DMA_TestStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_TestStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

  DMA_TestStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;

  DMA_TestStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;

  DMA_TestStructure.DMA_Mode = DMA_Mode_Normal;

  DMA_TestStructure.DMA_Priority = DMA_Priority_High;

  DMA_TestStructure.DMA_M2M = DMA_M2M_Disable;

DMA_Init(DMA1_Channel5, &DMA_TestStructure);

SPI_I2S_DMACmd(SD_SPI, SPI_I2S_DMAReq_Tx, ENABLE);

SD_SendCmd(SD_CMD_WRITE_SINGLE_BLOCK, write_add, 0xFF);

if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))

  {

    /*!< Send a dummy byte */

    SD_WriteByte(SD_DUMMY_BYTE);

    /*!< Send the data token to signify the start of the data */

    SD_WriteByte(0xFE);

    

DMA_Cmd(DMA1_Channel5, ENABLE);

while (!DMA_GetFlagStatus(DMA1_FLAG_TC5));

SD_ReadByte();

    SD_ReadByte();

    /* Read data response */

    if (SD_GetDataResponse() == SD_DATA_OK)

    {

        rvalue = SD_RESPONSE_NO_ERROR;

    }

}

SD_CS_HIGH();  

SD_WriteByte(SD_DUMMY_BYTE);

DMA_Cmd(DMA1_Channel5, DISABLE);

#dma-spi-stm32-sd
12 REPLIES 12
cng
Associate II
Posted on July 17, 2012 at 05:41

The requirement is not allow customer to see the content in the sd card. If use FsFat mean that the customer can straight away open the file. 

Posted on July 17, 2012 at 16:08

Then you'll want to use SD_ReadBlock, SD_ReadMultiBlocks, SD_WriteBlock and SD_WriteMultiBlocks, to do Sector/Block IO.

If your not up for writing a file system, you could obfuscate the sector content by XOR'ing or encrypting it, at the abstraction layer.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cng
Associate II
Posted on January 28, 2013 at 02:49