diff --git a/.gitignore b/.gitignore index b1bb22d..1458427 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,10 @@ Debug *.user.* *.lss *.d +sdio.cflags +sdio.config +sdio.creator +sdio.cxxflags +sdio.files +sdio.includes + diff --git a/fatfs/shimatta_sdio_driver/shimatta_sdio.c b/fatfs/shimatta_sdio_driver/shimatta_sdio.c index 218011c..9d36f5e 100644 --- a/fatfs/shimatta_sdio_driver/shimatta_sdio.c +++ b/fatfs/shimatta_sdio_driver/shimatta_sdio.c @@ -78,6 +78,62 @@ DSTATUS SDIO_status(){ volatile uint32_t debug; volatile uint32_t debug_timeout; volatile int debug_acmd = 0; + +sdio_write_buffer(uint32_t dlen, uint32_t blklen, uint8_t *buff) +{ + int count; + int byte_count; + int byte_max; + uint32_t fifo; + + SDIO->DLEN = dlen; + + /* Init Transfer */ + SDIO->ICR = SDIO_ICR_CCRCFAILC | SDIO_ICR_DCRCFAILC | SDIO_ICR_CTIMEOUTC | SDIO_ICR_DTIMEOUTC | + SDIO_ICR_TXUNDERRC | SDIO_ICR_RXOVERRC | SDIO_ICR_CMDRENDC | SDIO_ICR_CMDSENTC | SDIO_ICR_DATAENDC | + SDIO_ICR_STBITERRC | SDIO_ICR_DBCKENDC | SDIO_ICR_SDIOITC | SDIO_ICR_CEATAENDC; + SDIO->DCTRL = (blklen<<4) | SDIO_DCTRL_DTEN; + + for (count = 0; count < dlen; count += 4) { + fifo = 0; + + if ((dlen - count) < 4) + byte_max = dlen - count; + else + byte_max = 4; + + for (byte_count = 0; byte_count < byte_max; byte_count++) + { + fifo >>= 8; + fifo |= (((uint32_t)*(buff++)) << 24) & 0xFF000000; + } + + while (SDIO->STA & SDIO_STA_TXFIFOF); + + SDIO->FIFO = fifo; + + } + + while (SDIO->STA & SDIO_STA_TXACT); + +} + +uint8_t data1[512] = {(1<<1), 16, 0xC9, 0x9A, 0x20, 0x84, 0x3E, 0xD7, 0xD9, 0x0B, 0x68, 0x01, + 0xE4, 0x9F, 0x2B, 0xC8, 0x02, 0x77}; +sdio_unlock_card() +{ + + uint32_t resp[10]; + + //SDIO_send_block_length_CMD16(18U); + + SDIO_send_cmd(42, 0, SHORT_ANS); + SDIO_get_response(42, SHORT_ANS, resp); + + sdio_write_buffer(512, 9, data1); + +} + DSTATUS SDIO_initialize(){ int timeout = 0x3000; int i; @@ -148,6 +204,9 @@ DSTATUS SDIO_initialize(){ if (SDIO_send_block_length_CMD16((uint32_t)(1<ICR = SDIO_ICR_CCRCFAILC | SDIO_ICR_DCRCFAILC | SDIO_ICR_CTIMEOUTC | SDIO_ICR_DTIMEOUTC | SDIO_ICR_TXUNDERRC | SDIO_ICR_RXOVERRC | SDIO_ICR_CMDRENDC | SDIO_ICR_CMDSENTC | SDIO_ICR_DATAENDC | SDIO_ICR_STBITERRC | SDIO_ICR_DBCKENDC | SDIO_ICR_SDIOITC | SDIO_ICR_CEATAENDC; - SDIO->DCTRL = (BLOCKSIZE<<4) | SDIO_DCTRL_DTDIR | SDIO_DCTRL_DMAEN | SDIO_DCTRL_DTEN; + SDIO->DCTRL = (BLOCKSIZE<<4) | SDIO_DCTRL_DTDIR | /*SDIO_DCTRL_DMAEN |*/ SDIO_DCTRL_DTEN; debug=0; counter = 0; diff --git a/fatfs/shimatta_sdio_driver/shimatta_sdio_config.h b/fatfs/shimatta_sdio_driver/shimatta_sdio_config.h index 4f81dd0..9597537 100644 --- a/fatfs/shimatta_sdio_driver/shimatta_sdio_config.h +++ b/fatfs/shimatta_sdio_driver/shimatta_sdio_config.h @@ -10,7 +10,7 @@ #define HW_FLOW 0 //0 //1 bit: !=4 //4 bit: 4 -#define BUSWIDTH 4 //4 +#define BUSWIDTH 1 //4 //Initial Transfer CLK (ca. 400kHz) #define INITCLK 130 //120 //Working CLK (Maximum)