GD32F403xx User Manual
540
describes the structure of the command data block.
Table 20-31. Lock card data structure
Byte
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3
Bit 2
Bit 1
Bit 0
0
Reserved(all set to 0)
ERASE
LOCK_UNLOCK
CLR_PWD
SET_PWD
1
PWDS_LEN
2
Password data(PWD)
……
P1
ERASE
: 1 Defines Forced Erase Operation. In byte 0, bit 3 will be set to 1 (all other bits shall
be 0). All other bytes of this command will be ignored by the card.
LOCK/UNLOCK
: 1 = Locks the card. 0 = Unlock the card (note that it is valid to set this bit
together with SET_PWD but it is not allowed to set it together with CLR_PWD).
CLR_PWD
: 1 = Clears PWD.
SET_PWD
: 1 = Set new password to PWD.
PWDS_LEN
: Defines the following password(s) length (in bytes). In case of a password
change, this field includes the total password length of old and new passwords. The password
length is up to 16 bytes. In case of a password change, the total length of the old password
and the new password can be up to 32 bytes.
Password data
: In case of setting a new password, it contains the new password. In case of
a password change, it contains the old password followed by the new password.
Setting the password
⚫
Select a card (CMD7), if not previously selected.
⚫
Define the block length (CMD16), given by the 8-bit card lock/unlock mode, the 8-bit
password size (in bytes), and the number of bytes of the new password. In the case that
a password replacement is done, then the block size shall consider that both passwords
(the old and the new one) are sent with the command.
⚫
Send the Card Lock/Unlock command with the appropriate data block size on the data
line including the 16-bit CRC. The data block shall indicate the mode (SET_PWD), the
length (PWDS_LEN) and the password itself. In the case that a password replacement
is done, then the length value (PWDS_LEN) shall include both passwords (the old and
the new one) and the password data field shall include the old password (currently used)
followed by the new password. Note that the card shall handle the calculation of the new
password length internally by subtracting the old password length from PWDS_LEN field.
⚫
In the case that the sent old password is not correct (not equal in size and content), then
the LOCK_UNLOCK_FAILED error bit will be set in the status register and the old
password does not change. In the case that the sent old password is correct (equal in
size and content), then the given new password and its size will be saved in the PWD
and PWD_LEN registers, respectively.