diff --git a/src/utility/Sd2Card.cpp b/src/utility/Sd2Card.cpp index 7cfbe73..dd07c0c 100644 --- a/src/utility/Sd2Card.cpp +++ b/src/utility/Sd2Card.cpp @@ -331,6 +331,24 @@ uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) { goto fail; } } + + uint8_t status_ext; + status_ = cardCommand(CMD13, 0); + status_ext = spiRec(); + if ( status_ ) { + error(SD_CARD_ERROR_SEND_STATUS); + goto fail; + } else { + if (status_ext) { + if ( status_ext | 0X01 ) { + error(SD_CARD_ERROR_LOCKED); + } else { + error(SD_CARD_ERROR_SEND_STATUS); + } + goto fail; + } + } + // if SD2 read OCR register to check for SDHC card if (type() == SD_CARD_TYPE_SD2) { if (cardCommand(CMD58, 0)) { @@ -763,6 +781,74 @@ uint8_t Sd2Card::writeStop(void) { return false; } //------------------------------------------------------------------------------ +/** lock or unlock SD card by password + * + * \param[in] pwd si the pointer to password buffer + * \return The value one, true, is returned for success and + * the value zero, false, is returned for failure. + * + */ +uint8_t Sd2Card::lockUnlockCard(uint8_t flags, int pass_len, uint8_t* pwd) { + + + // select card + chipSelectLow(); + + // set block length + if ( cardCommand(CMD16, 18) ) { + error(SD_CARD_ERROR_CMD16); + goto fail; + } + + + // send the command + if (cardCommand(CMD42, 0)) { + error(SD_CARD_ERROR_CMD42); + goto fail; + } + + spiSend( 0xFE ); // Start Token + spiSend( flags ); // 4-zeros ERASE LOCK_UNLOCK CLR_PWD SET_PWD + spiSend( pass_len ); // password length + + // send password + for ( uint16_t i=0; i