Programming SD card
Posted: Wed Oct 18, 2023 3:39 pm
Hi,
I got stuck at reading sector 0 of the card from Realtek SD card reader (5260). I send READ_SINGLE_BLOCK (0x11) command to the controller. Here is the code:
After sending command 17 I read from the ping pong buffer:
After executing the code above, the command buffer of the controller becomes filled with zeroes, which is definitely not the expected content of the first sector of the card. At the moment, I am completely out of ideas regarding what might be wrong with the code, don't even have an approach to debug the issue. Any help?
Thanks!
I got stuck at reading sector 0 of the card from Realtek SD card reader (5260). I send READ_SINGLE_BLOCK (0x11) command to the controller. Here is the code:
Code: Select all
init_cmd(hDev);
add_cmd(hDev, WRITE_REG, 0xFDA9, 0xFFu, 0x51u); //SD_CMD0
add_cmd(hDev, WRITE_REG, 0xFDAA, 0xFFu, 0); //SD_CMD1
add_cmd(hDev, WRITE_REG, 0xFDAB, 0xFFu, 0); //SD_CMD2
add_cmd(hDev, WRITE_REG, 0xFDAC, 0xFFu, 0); //SD_CMD3
add_cmd(hDev, WRITE_REG, 0xFDAD, 0xFFu, 0); //SD_CMD4
add_cmd(hDev, WRITE_REG, 0xFDAF, 0xFFu, 0x0); //SD_BYTE_CNT_L
add_cmd(hDev, WRITE_REG, 0xFDB0, 0xFFu, 0x2); //SD_BYTE_CNT_H
add_cmd(hDev, WRITE_REG, 0xFDB1, 0xFFu, 0x1); //SD_BLOCK_CNT_L
add_cmd(hDev, WRITE_REG, 0xFDB2, 0xFFu, 0x0); //SD_BLOCK_CNT_H
add_cmd(hDev, WRITE_REG, 0xFDA0, 0x3u, 0x1); //SD_CFG1 : bus width
add_cmd(hDev, WRITE_REG, 0xFDA1, 0xFFu, 0x1); //SD_CFG2 : 1 : SD_RSP_TYPE_R1
add_cmd(hDev, WRITE_REG, 0xFD5B, 1, 1); //CARD_DATA_SOURCE : 1 : RTSX_PINGPONG_BUFFER
add_cmd(hDev, WRITE_REG, 0xFDB3, 0xFFu, 0x80 | 0xC); //SD_TRANSFER : SD_TRANSFER_START | SD_TM_NORMAL_READ
add_cmd(hDev, CHECK_REG, 0xFDB3, 0x40u, 0x40); //SD_TRANSFER : SD_TRANSFER_END
send_cmd(hDev);
Code: Select all
init_cmd(hDev);
DWORD reg = 0xFA00;
for (DWORD i = 0; i < 0x100; i++)
{
add_cmd(hDev, 0, reg, 0, 0);
reg++;
}
send_cmd(hDev);
Thanks!