2013-11-22 05:27 AM
Hi All,
Does anybody have an example how to lock/unlock SD card using SDIO and CMD42?2013-11-22 07:54 AM
Does anybody have an example how to lock/unlock SD card using SDIO and CMD42?
No, but I might entertain an offer, or bounty for such.2013-11-22 08:34 AM
Thanks clive!
2013-11-27 08:07 AM
void SD_SetPDW_Test(void){
SD_Error x = SD_Init();
errorstatus = SD_GetCardStatus(&cardstatus);SDIO_CmdInitStructure.SDIO_Argument = 10;
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN; SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No; SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable; SDIO_SendCommand(&SDIO_CmdInitStructure);errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
SDIO_CmdInitStructure.SDIO_Argument = 0;
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_LOCK_UNLOCK; SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No; SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable; SDIO_SendCommand(&SDIO_CmdInitStructure);SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
SDIO_DataInitStructure.SDIO_DataLength = 11; SDIO_DataInitStructure.SDIO_DataBlockSize = SDIO_DataBlockSize_16b; //SDIO_DataBlockSize_16b; SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToCard; SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block; SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable; SDIO_DataConfig(&SDIO_DataInitStructure);memset(tmp_buff, 0, 64);
memcpy(&(tmp_buff[3]), passw, sizeof(passw)); uint8_t csCalc[10] = {SD_SET_PWD_SDIO | SD_LOCK_UNLOCK_SDIO, 6, 'A', 'D' , '3', '2', '4', 'Z', 0x65, 0x41 }; //password is AD324Z and the checksum CRC/CCIT(16 bit) is 0x4165SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
SD_LowLevel_DMA_TxConfig((uint32_t *)csCalc, 10); SDIO_DMACmd(ENABLE);errorstatus = CmdResp1Error(SD_CMD_LOCK_UNLOCK); //here the status is SD_OK
errorstatus = SD_GetCardStatus(&cardstatus); //here the status is SD_OK but probably should be SD_LOCKED
} At the end SD card status returns SD_OK but I think that it should be SD_LOCKED. And the SD card is not locked.2018-11-09 01:05 AM
Do you have working code example Clive?
2018-11-09 05:39 AM
Nothing recent, I've done it with ATA devices previously.
What STM32 platform? What generation of cards or chips?
I personally prefer end-to-end encryption, it is less open to broken/compromised implementation, and government interference.