20 #define INIT_PORT() HAL_SPI_Init()
21 #define FAST_MODE() SYS_MMC_FastMode()
22 #define DLY_US(n) __delay_cycles(n * 12)
24 #define CS_H() SYS_MMC_DeselectCard()
25 #define CS_L() SYS_MMC_SelectCard()
56 #define ACMD41 (0x80 + 41)
61 #define ACMD13 (0x80 + 13)
66 #define ACMD23 (0x80 + 23)
116 int wait_ready (
void)
122 for (tmr = 5000; tmr; tmr--){
181 for (tmr = 1000; tmr; tmr--){
222 if ((d[0] & 0x1F) != 0x05){
247 n = send_cmd(
CMD55, 0);
261 buf[1] = (
BYTE)(arg >> 24);
262 buf[2] = (
BYTE)(arg >> 16);
263 buf[3] = (
BYTE)(arg >> 8);
283 while ((d & 0x80) && --n);
325 BYTE csd0[16], csd1[16], i;
329 if ((send_cmd(
CMD9, 0) == 0) && rcvr_datablock(csd0, 16)){
330 if ((send_cmd(
CMD9, 0) == 0) && rcvr_datablock(csd1, 16)){
333 for (i = 0; i <= 15; i++){
336 if (!((sum == 0) || (sum == 4096))){
342 if (csd0[i] != csd1[i]){
390 #pragma diag_suppress=Pe550
391 BYTE n, ty, cmd, buf[4];
405 for (n = 10; n; n--){rcvr_mmc(buf, 1);
408 if (send_cmd(
CMD0, 0) == 1){
409 if (send_cmd(
CMD8, 0x1AA) == 1){
411 if (buf[2] == 0x01 && buf[3] == 0xAA){
412 for (tmr = 1000; tmr; tmr--)
414 if (send_cmd(
ACMD41, 1UL << 30) == 0){
419 if (tmr && send_cmd(
CMD58, 0) == 0){
425 if (send_cmd(
ACMD41, 0) <= 1){
430 for (tmr = 1000; tmr; tmr--)
432 if (send_cmd(
ACMD41, 0) == 0){
437 if (!tmr || send_cmd(
CMD16, 512) != 0){
482 if ((send_cmd(
CMD17, sector) == 0)
483 && rcvr_datablock(buff, 512)){
487 if (send_cmd(
CMD18, sector) == 0){
489 if (!rcvr_datablock(buff, 512)){
533 if ((send_cmd(
CMD24, sector) == 0)
534 && xmit_datablock(buff, 0xFE)){
541 if (send_cmd(
CMD25, sector) == 0){
543 if (!xmit_datablock(buff, 0xFC)){
548 if (!xmit_datablock(0, 0xFD)){
590 if ((send_cmd(
CMD9, 0) == 0) && rcvr_datablock(csd, 16)){
591 if ((csd[0] >> 6) == 1){
592 cs = csd[9] + ((
WORD)csd[8] << 8) + 1;
593 *buff = ((
DWORD)cs) << 10;
597 15) + ((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2;
601 ((
WORD)csd[7] << 2) + ((
WORD)(csd[6] & 3) << 10) + 1;