57 #if (defined(PDL_PERIPHERAL_SD_ACTIVE))
68 #define SD_PCG 0x4003C120
69 #define PCG_ENABLE (1UL<<8)
70 #define DELAYUNIT 5000
71 #define WAITTIME 50000
72 #define RETRYTIMES 100
110 volatile uint32_t u32i;
112 for(;u32Delay;--u32Delay)
134 FM4_GPIO->ADE &= ~(uint32_t)(1<<19);
135 FM4_GPIO->PFR0 |= 0x7E00;
136 FM4_GPIO->PFR6 |= 0x000C;
138 #if (BUSWIDTH == BIT4)
139 FM4_GPIO->PCR0 |= 0x1E00;
140 FM4_GPIO->PCR0 &= ~0x0400;
142 FM4_GPIO->PCR0 |= 0x0800;
145 FM4_GPIO->EPFR18 |= 0x01554000;
156 volatile uint32_t * p32Sdpcg = (uint32_t *)
SD_PCG;
177 *((uint32_t *)
SD_PCG) &= ~(1<<8);
190 #if (BUSWIDTH == BIT4 )
214 pstcCmdCfg->u32SysAddr_Arg2 = 0xFFFFFFFF;
287 while((pstcSd->SPRSTAT_f.CARDSTB == 0) && (waittime > 0))
293 if(1 == pstcSd->SPRSTAT_f.CARDINS)
332 pu32Buf[0] = pstcSd->SRESP0;
333 pu32Buf[0] |=((uint32_t)pstcSd->SRESP1<<16);
337 pu32Buf[0] = pstcSd->SRESP6;
338 pu32Buf[0] |=((uint32_t)pstcSd->SRESP7<<16);
341 pu32Buf[0] = pstcSd->SRESP0;
342 pu32Buf[0] |=(uint32_t)pstcSd->SRESP1<<16;
343 pu32Buf[1] = pstcSd->SRESP2;
344 pu32Buf[1] |=(uint32_t)pstcSd->SRESP3<<16;
345 pu32Buf[2] = pstcSd->SRESP4;
346 pu32Buf[2] |=(uint32_t)pstcSd->SRESP5<<16;
347 pu32Buf[3] = pstcSd->SRESP6;
348 pu32Buf[3] |=((uint32_t)pstcSd->SRESP7&0x00FF)<<16;
369 uint8_t u8Index = pstcCmdCfg->
u8Index & 0x3F;
373 while((
TRUE == pstcSd->SPRSTAT_f.CMDDATINH) && (waittime > 0))
382 while((
TRUE == pstcSd->SPRSTAT_f.CMDINH) && (waittime > 0))
390 pstcSd->STRSFMD_f.DTTRSFDIR = pstcCmdCfg->
enReadWrite;
397 pstcSd->SCMMD = 0x0002|(u8Index<<8)|0x0018|(pstcCmdCfg->
bDataPresent<<5);
402 pstcSd->SCMMD = 0x0003|(u8Index<<8)|0x0018;
405 pstcSd->SCMMD = 0x0001|(u8Index<<8)|0x0008;
408 pstcSd->SCMMD = 0x0002|(u8Index<<8);
411 pstcSd->SCMMD &= 0x0000;
418 while((
TRUE == pstcSd->SPRSTAT_f.CMDINH) && (waittime > 0))
427 while((
TRUE == pstcSd->SPRSTAT_f.CMDDATINH) && (waittime > 0))
459 uint8_t result =
FALSE;
462 pstcSd->SBSIZE_f.TRSFBLCKSZ =pstcCmdCfg->
u16BlockSize & 0x0FFF;
467 pstcSd->STRSFMD_f.BLCKCNTSEL = 0;
471 pstcSd->STRSFMD_f.BLCKCNTSEL = 1;
472 pstcSd->STRSFMD_f.BLCKCNTEN = 1;
473 pstcSd->STRSFMD_f.AUTOCMDEN = pstcCmdCfg->
enAutoCmd;
474 pstcSd->SBLCNT = blockcount;
498 uint32_t* pbuf = pu32Buf;
499 uint8_t result =
FALSE;
501 while(
TRUE != pstcSd->SNINTST_f.BUFWRRDY);
503 pstcSd->SNINTST_f.BUFWRRDY = 0;
505 for(i=u16blocksize>>2;i!=0;i--)
507 if((pstcSd->SEINTST_f.DTTOERR == 1)
508 ||(pstcSd->SEINTST_f.DTEBERR == 1)
509 ||(pstcSd->SEINTST_f.DTCRCERR == 1))
512 pstcSd->SEINTST_f.DTTOERR = 1;
513 pstcSd->SEINTST_f.DTEBERR = 1;
514 pstcSd->SEINTST_f.DTCRCERR = 1;
518 while(pstcSd->SPRSTAT_f.BUFWREN == 0) ;
519 pstcSd->SBUFDP = *pbuf;
584 uint32_t* pbuf = pu32Buf;
585 uint8_t result =
FALSE;
587 while(
TRUE != pstcSd->SNINTST_f.BUFRDRDY);
589 for(i=u16blocksize>>2;i!=0;i--)
591 if((pstcSd->SEINTST_f.DTTOERR == 1)
592 ||(pstcSd->SEINTST_f.DTEBERR==1)
593 ||(pstcSd->SEINTST_f.DTCRCERR==1))
596 pstcSd->SEINTST_f.DTTOERR = 1;
597 pstcSd->SEINTST_f.DTEBERR=1;
598 pstcSd->SEINTST_f.DTCRCERR=1;
602 while(pstcSd->SPRSTAT_f .BUFRDEN == 0) ;
603 *pbuf = pstcSd->SBUFDP;
632 pstcSd->SNINTSTE_f.BUFRDRDYS = 1;
633 pstcSd->SNINTSTE_f.BUFWRRDYS = 1;
636 pstcSd->SNINTSTE_f.TRSFCMPLTS = 1;
637 pstcSd->SNINTSTE_f.CMDCMPLTS = 1;
659 pstcSd->SNINTSTE_f.BUFRDRDYS = 0;
660 pstcSd->SNINTSTE_f.BUFWRRDYS = 0;
663 pstcSd->SNINTSTE_f.TRSFCMPLTS = 0;
664 pstcSd->SNINTSTE_f.CMDCMPLTS = 0;
682 if(NULL == pstcCmdCfg)
702 u8baseclock = pstcSd->CAPBLTY0_f.SDBASECLK;
712 if(u8baseclock== enClk)
718 u16divider = (u8baseclock>>1)/enClk;
721 pstcSd->SCLKCTL_f.SDCLKSEL = (uint8_t)(u16divider &0x00FF);
722 pstcSd->SCLKCTL_f.UPSDCLKSEL = (u16divider &0x0300)>>8;
726 pstcSd->SHCTL2_f.PREVALEN = 1;
729 pstcSd->SCLKCTL_f.INTLCLCKEN = 1;
731 while (!pstcSd->SCLKCTL_f.INTLCLCKST);
733 pstcSd->SCLKCTL_f.SDCLCKEN = 1;
752 pstcSd->SCLKCTL_f.SDCLCKEN = 0;
767 if((NULL == pstcSd) || (enVoltage >
V3_3) || (enVoltage <
V1_8))
772 pstcSd->SPWRCTL_f.SDBUSVLSEL = enVoltage;
773 pstcSd->SPWRCTL_f.SDBUSPWR = 1;
802 result =
SdRxRsp(pstcSd,pstcCmdCfg,pu32Buf);
808 result =
SdRxRsp(pstcSd,pstcCmdCfg,pu32Buf);
836 result =
SdTxData(pstcSd,pstcCmdCfg,pu32Buf);
860 while((0 == pstcSd->SPRSTAT_f.BUFRDEN) && (waittime > 0))
869 result =
SdRxData(pstcSd,pstcCmdCfg,pu32Buf);
897 pstcSd->SSRST |= u8reset;
899 while(pstcSd->SSRST & (~u8reset));
901 pstcSd->SSRST &= ~u8reset;
968 #endif // #if (defined(PDL_PERIPHERAL_SD_ACTIVE))