From 7ee80bac8e6fb3f696a40f4ac6bb2cc52fda9fef Mon Sep 17 00:00:00 2001 From: Damien Date: Thu, 24 Oct 2013 00:22:27 +0100 Subject: Add support for SD card (not working). --- stm/sdio.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 stm/sdio.c (limited to 'stm/sdio.c') diff --git a/stm/sdio.c b/stm/sdio.c new file mode 100644 index 000000000..78488df1f --- /dev/null +++ b/stm/sdio.c @@ -0,0 +1,60 @@ +// TODO +// make it work with DMA + +#include +//#include "stm32f4xx_sdio.h" +#include "stm324x7i_eval_sdio_sd.h" +#include "misc.h" +#include "systick.h" + +#define BLOCK_SIZE 512 /* Block Size in Bytes */ + +uint8_t aBuffer_Block_Rx[BLOCK_SIZE]; + +void sdio_init(void) { + SD_Error error = SD_Init(); + printf("Init: %x\n", error); + uint8_t det = SD_Detect(); + printf("Detc: %x\n", det); + + if (!det) { + printf("no card detected\n"); + SD_PowerOFF(); + SD_DeInit(); + return; + } + + // read a block! + error = SD_ReadBlock(aBuffer_Block_Rx, 512, BLOCK_SIZE); + printf("ReadBlock: %d\n", error); + + /* + // Check if the Transfer is finished + error = SD_WaitReadOperation(); + printf("WaitReadOp: %d\n", error); + */ + + uint32_t stc = sys_tick_counter; + while (SD_GetStatus() != SD_TRANSFER_OK) { + if (sys_tick_has_passed(stc, 2000)) { + printf("timeout waiting for read to finish\n"); + break; + } + } + printf("done!!\n"); + + printf("%.16s", aBuffer_Block_Rx); + + /* + snprintf((char*)aBuffer_Block_Rx, BLOCK_SIZE, "Here is some data back for you!\nBLOCK_SIZE=%d\n", BLOCK_SIZE); + error = SD_WriteBlock(aBuffer_Block_Rx, 512, BLOCK_SIZE); + printf("WriteBlock: %d\n", error); + + while (SD_GetStatus() != SD_TRANSFER_OK) { + } + printf("done writing!\n"); + */ + + SD_PowerOFF(); + SD_DeInit(); +} -- cgit v1.2.3