90 if (buff[2] == 0X01 && buff[3] == 0XAA) {
95 }
while(r1 && retry--);
109 }
while(r1 && retry--);}
157 if ((t & 0x1F) != 0x05)
return 2;}
196 if ((csd[0] &0xC0) == 0x40) {
197 csize = csd[9] + ((
u16) csd[8] << 8) + 1;
201 n = (csd[5] &15) + ((csd[10] &128) >> 7) + ((csd[9] &3) << 1) + 2;
202 csize = (csd[8] >> 6) + ((
u16) csd[7] << 2) + ((
u16) (csd[6] &3) << 10) + 1;
213 if (r1 != 0x00)
return r1;
217 if (r1 != 0x00)
return r1;
344 buf += 512;}
while(--cnt && r1 == 0);
368 while(--cnt && r1 == 0);
375 HAL_SPI_TransmitReceive(
hspi, &Txdata, &Rxdata, 1, 0xFF);
384 hspi->Init.BaudRatePrescaler = speed;}
394 u8 sectorBuff[512] = { 0 };
395 u64 sectorBuffptr = 0;
397 u64 sectorSour = offset / 512;
398 u64 sectorSourlen = offset % 512;
402 sectorBuffptr = sectorSourlen;
403 for (
u64 i = 0; i < datlen; i++) {
405 sectorBuff[sectorBuffptr] = dat[i];
408 if (sectorBuffptr == 512 || i == datlen - 1) {
412 if (i != datlen - 1)
SD_ReadDisk(sectorBuff,sectorSour,1);}}
424 u8 sectorBuff[512] = { 0 };
425 u64 sectorBuffptr = 0;
427 u64 sectorSour = offset / 512;
428 u64 sectorSourlen = offset % 512;
432 sectorBuffptr = sectorSourlen;
433 for (
u64 i = 0; i < datlen; i++) {
435 dat[i]=sectorBuff[sectorBuffptr];
438 if (sectorBuffptr == 512 || i == datlen - 1) {
441 if (i != datlen - 1)
SD_ReadDisk(sectorBuff,sectorSour,1);}}
448 SPI_HandleTypeDef *hspi,
449 GPIO_TypeDef *GPIOx_CS,
450 uint16_t GPIO_Pin_CS){
MSD_CARDINFO SD0_CardInfo
u8 offsetWrite(u64 offset, u8 *dat, u64 datlen)
写入连贯的数据
u8 offsetRead(u64 offset, u8 *dat, u64 datlen)
读取连贯的数据
u8 SD_ReceiveData(u8 *data, u16 len)
读取SD卡指定长度信息
u8 SD_GETCID(u8 *cid_data)
获取CID信息
u8 SD_SendBlock(u8 *buf, u8 cmd)
向SD卡写入一个扇区
u8 spi_readwrite(u8 Txdata)
void SPI_setspeed(u8 speed)
设置SPI的速率
u32 SD_GetSectorCount(void)
获取SD卡的总扇区数
u8 SD_ReadDisk(u8 *buf, u32 sector, u8 cnt)
读SD卡
bsp_SD(SPI_HandleTypeDef *hspi, GPIO_TypeDef *GPIOx_CS, uint16_t GPIO_Pin_CS)
MSD_CARDINFO SD0_CardInfo
int MSD0_GetCardInfo(PMSD_CARDINFO SD0_CardInfo)
u32 SD_sendcmd(u8 cmd, u32 arg, u8 crc)
写SD卡
u8 SD_GETCSD(u8 *csd_data)
获取CSD信息
u8 SD_WriteDisk(u8 *buf, u32 sector, u8 cnt)
写SD卡