2012-03-07 02:12 AM
Hi,
I develop a project on the STM32F4 discovery board and I want use a MicroSD card. I work with Atollic TrueStudio for STM32. So I search a driver to use my MicroSD card with SPI. I have an API to FATFs and an API to configure the SPI module but I haven't the driver to use MicroSD card. My goal is to achieve a datalogger. Thanks for your help.2012-03-08 01:56 AM
eLua for STM32F4 includes spi mode sd driver.. that supposedly works
on our testing however it did not work, we are not investigating it any more as we need the real SD card support not spi modeAntti2012-03-08 06:31 AM
ok SD card things work, but need to disable GCC optimization to get it working
just an updateAntti2012-03-08 07:50 AM
To work with uSD by SPI no extra driver required.
Make your board SPI ports & pins initialization, and add to the FATFS diskio: for transmission:#define
xmit_spi(dat) SD_SPI->DR =(dat);
while
((SD_SPI->SR & SPI_I2S_FLAG_TXE) == RESET);\
while
(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_BSY) == SET);
for reception:#define
rcvr_spi_m(dst) SD_SPI->DR=0xFF;
while
((SD_SPI->SR & SPI_I2S_FLAG_RXNE) == RESET);\*(dst)=SD_SPI->DR;
while
(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_BSY) == SET)
and
static
BYTE
rcvr_spi (
void
)
{
SD_SPI->
DR
= 0xFF;
while
(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) ==
RESET
);
while
(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_BSY) ==
SET
);
return
SD_SPI->
DR
;}
Of course, add some code to the FATAFS diskio FCLK_FAST(), FCLK_SLOW() etc.
And DO not forget to skip CRC Error in xmit_datablock (), as STM ERRATA says. A lot of people have overlooked this.After that all works fine.
PS. Speaking ''as STM ERRATA says'' i mean not the exatly case for SDIO IF but recommendations how to avoid the problem.2012-03-09 05:52 AM
Thanks for this response !
but
I still can
not
run
my sd card
:( I found the driver elua (elua_mmc.c) but my sd card work on SDC mode and no MMC. I also test the project by Martin Thomas (http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/arm_memcards/index.html#stm32_memcard
) but it doesn't work on my card !! I think I can create my own driver :( because I find difficult to understand the library and Ican not
make it work
!!2012-03-10 04:16 AM
we are soon porting the SD mode driver for eLua, keep tuned I post the link to our project soon.
We got the SD mode stuff working after disabling compiler optimization so its only a matter of adjusting some files to get it done for lua2012-03-10 05:26 AM
I really can't understand what kind of driver you are speaking and looking for.
SPI is the simpliest communication protocol, especially without DMA.what do you need to drive SD by SPI:
HW
1) properly connect signal lines MOSI,MISO,SCLK (and SS or any GPIO for SD CS) 2) Set pullup resistors (at least to MOSI and MISO lines), optionally decoupling capacitor between power lines close to cardSW
1) initialize SPI with a standard peripheral driver 2) enable SPIThen, select SD.
To write data to : 1) SD_SPI -> DR = data; wait for the end of transmission: 2) while (SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET); when all bytes send wait for BSY flag: 3) while (SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_BSY) == SET); 4)deselect SD.If you don't use the highest speed, you can skip waiting for BSY flag and even TXE. But better keep them at place.
To read data from SD:
Send dummy byte: 1) SD_SPI -> DR = 0xff; wait for the end of transmission: 2) while (SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_RXNE) == RESET); get the data: data = SD_SPI -> DR;if needed, check BSY flag.
That's all.
Due to SD is a block device, I showed some macros for FATFS to read from/write to SD in my previous post.
But what does your valuable driver do?2012-03-10 06:23 AM
and I do not understand to whom you reply... :(
eLua includes built in support for SD over SPI, there is no code for SD hardware. so there is some porting needed.. or maybe you did not reply to me at all.we have 0% interest in SD over SPI at all.. (its TOO SIMPLE :)Antti2012-03-10 06:37 AM
Mainly I'm speaking to topic starter.
He said that his projet uses FATFS, where proper low-level SD card initialization occurs. (though it is nothing more than several lines of code) and SPI uSD. In this case you should provide some hardware-depended procedures to FATFS, like SPI low clock setting procedure (400KHz or less) for SD initialization.2012-03-21 11:15 AM