2012-05-29 04:55 PM
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-sd2012-05-29 07:31 PM
Does 10 bytes represent a valid block size on the SD card?
2012-05-29 09:58 PM
I had tried for SD_BLOCK_SIZE which is equal 200 but it still cannot work.
2012-06-15 05:18 AM
i think, I've read this somewhere
''Only the DMA2 controller can perform memory-to-memory transfers''confirm it and please inform2012-06-15 07:00 AM
i think, I've read this somewhere ''Only the DMA2 controller can perform memory-to-memory transfers''confirm it and please inform
Read where, care to cite? Which chip? I'm not aware this is an issue, you might have issues with DMA2 writing to APB1 peripherals. SD Card in this context is not a ''memory'', as it attaches via a peripheral bus (SPI/SDIO) and not within the memory map of the STM32Fxxx parts. The STM32F4xx parts don't support DMA into the 64KB CCM region.2012-06-16 09:39 AM
Here's a cite for the STM32F4, page 168
''Note: 1 When memory-to-memory mode is used, the Circular and Direct modes are not allowed.2 Only the DMA2 controller is able to perform memory-to-memory transfers.''
2012-07-16 12:34 AM
but it is not memory-memory transfer. I had check the reference manual that sd card is using spi2 and the spi2 receive is using dma1.
2012-07-16 05:08 AM
but it is not memory-memory transfer. I had check the reference manual that sd card is using spi2 and the spi2 receive is using dma1.
''SD Card in this context is not a ''memory'', as it attaches via a peripheral bus (SPI/SDIO) and not within the memory map of the STM32Fxxx parts.'' They are also complex block driven devices, suggest you dig through some of the STM32 examples for F1, F2, F4 and USB that demonstrate SD Card usages. There are other examples on the forum where an SD Card is used with FsFat.2012-07-16 05:30 PM
I would not like to use the FsFat because of the requirement. Have any solutions or example?
2012-07-16 06:28 PM
I would not like to use the FsFat because of the requirement. Have any solutions or example?
What requirement(s)? Like I said you should probably review, and understand, the sample code in several of the STM32Fx firmware library releases. Here's one specifically for the STM32L152, but there are others. STM32L1xx_StdPeriph_Lib_V1.1.1\Utilities\STM32_EVAL\STM32L152D_EVAL\stm32l152d_eval_sdio_sd.c The stuff is broken into layers, the basic level you probably want to access the card on is the 512 byte/block level. From there you might be able to find a practical/workable method of doing what you want. If the method you want is not practical you might have to come up with a method that is.