cancel
Showing results for 
Search instead for 
Did you mean: 

SD card Lock/Unlock example

donev_g
Associate II
Posted on November 22, 2013 at 14:27

Hi All,

Does anybody have an example how to lock/unlock SD card using SDIO and CMD42?
5 REPLIES 5
Posted on November 22, 2013 at 16:54

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.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
donev_g
Associate II
Posted on November 22, 2013 at 17:34

Thanks clive!

donev_g
Associate II
Posted on November 27, 2013 at 17:07

Here is my code, if somebody can help:

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 0x4165

   SDIO_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.

Do you have working code example Clive?

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..