Compare commits

..

No commits in common. "e616e22dd7bc768a659febcc72638b3b8d8fcda5" and "a2256acd94609163588c81aa66c445e0b2167501" have entirely different histories.

3 changed files with 32 additions and 29 deletions

View File

@ -373,12 +373,9 @@ static void sdio_init_hw()
static int sdio_send_read_block_cmd17(uint32_t addr)
{
uint32_t response;
int retry;
int ret;
sdio_send_cmd(17, addr, SHORT_ANS);
ret = sdio_get_response(17, SHORT_ANS, &response);
return ret;
return sdio_get_response(17, SHORT_ANS, &response);
}
static int sdio_send_all_send_cid_cmd2()
@ -608,7 +605,6 @@ DRESULT sdio_disk_read(BYTE *buff, DWORD sector, UINT count){
uint32_t sdio_status;
uint32_t fifo;
uint32_t counter;
union sdio_status_conv status;
addr = (card_info.type == SD_V2_HC ? (sector) : (sector*512));
for (; count > 0; count--) {
@ -623,13 +619,7 @@ DRESULT sdio_disk_read(BYTE *buff, DWORD sector, UINT count){
// DMASTREAM->CR = DMAP2M | DMA_SxCR_PL_1 | DMA_SxCR_PL_1;
// DMASTREAM->CR |= DMA_SxCR_EN;
do {
sdio_check_status_register_cmd13(card_info.rca, &status.value);
} while (status.statusstruct.CURRENT_STATE != CURRENT_STATE_TRAN);
SDIO->DLEN = (1 << BLOCKSIZE);
SDIO->DTIMER = DTIMEOUT;
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 |
@ -714,6 +704,16 @@ DRESULT sdio_disk_write(const BYTE *buff, DWORD sector, UINT count)
addr = (card_info.type == SD_V2_HC ? (sector) : (sector * 512));
while (count) {
do {
sdio_check_status_register_cmd13(card_info.rca, &status.value);
} while (status.statusstruct.CURRENT_STATE == CURRENT_STATE_PRG ||
status.statusstruct.CURRENT_STATE == CURRENT_STATE_RCV);
if (status.statusstruct.CURRENT_STATE == CURRENT_STATE_STBY) {
if (sdio_send_select_card_cmd7(card_info.rca))
return RES_ERROR;
}
do {
sdio_check_status_register_cmd13(card_info.rca, &status.value);
} while (status.statusstruct.READY_FOR_DATA != 1);

View File

@ -14,9 +14,9 @@
//Initial Transfer CLK (ca. 400kHz)
#define INITCLK 130 //120
//Working CLK (Maximum)
#define WORKCLK 8 //0
#define WORKCLK 50 //0
//Data Timeout in CLK Cycles
#define DTIMEOUT 0x8000 //150
#define DTIMEOUT 0x3000 //150
//DMA Stream used for TX and RX DMA2 Stream 3 or 6 possible
// Currently not used due to possible misalignment of the data buffer.
//#define DMASTREAM DMA2_Stream6

33
main.c
View File

@ -22,15 +22,11 @@ volatile uint32_t sdio_wait;
int initreq = 0xFF;
//const char *write_string = "This is a write test. Okay... Writing seems to work. Let's close the file\n";
char buff[8192*6];
int main()
{
int i;
int main() {
char buff[1024];
char *name;
FILINFO fno;
char *write_string = "This is a write test. Okay... Writing seems to work. Let's close the file\n";
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
__DSB();
@ -45,17 +41,24 @@ int main()
initreq = f_mount(&SDfs, "0:/", 1);
while(initreq);
for (i = 0; i < 8192*6; i++)
buff[i] = 'A';
initreq = f_opendir(&root, "/");
if (initreq == FR_OK) {
if (!f_readdir(&root, &fno))
{
name = fno.fname;
initreq = f_open(&file, name, FA_READ);
if (initreq == FR_OK) {
f_gets(buff, sizeof(buff), &file);
printf("%s:\r\n%s\r\n",name, buff);
f_close(&file);
}
}
}
initreq = f_open(&file, "foo.txt", FA_OPEN_APPEND | FA_WRITE);
if (initreq == FR_OK) {
for (i = 0; i < 100; i++) {
initreq = f_write(&file, buff, 8192*6, NULL);
if (initreq) {
initreq++;
}
}
initreq = f_write(&file, write_string, strlen(write_string), NULL);
initreq = f_close(&file);
}