
GD32F403xx User Manual
534
20.6.3.
Single block or multiple block write
During block write (CMD24 - 27) one or more blocks of data are transferred from the host to
the card. The block consists of start bits (1 or 4 bits LOW), data block, CRC and end bits(1 or
4 bits HIGH). If the CRC fails, the card indicates the failure on the SDIO_DAT line and the
transferred data are discarded and not written, and all further transmitted blocks are ignored.
If the host uses partial blocks whose accumulated length is not block aligned, block
misalignment is not allowed (CSD parameter WRITE_BLK_MISALIGN is not set), the card
will detect the block misalignment error before the beginning of the first misaligned block. The
card shall set the ADDRESS_ERROR error bit in the status register, and while ignoring all
further data transfer. The write operation will also be aborted if the host tries to write data on
a write protected area. In this case, however, the card will set the WP_VIOLATION bit (in the
status register).
Programming of the CID and CSD registers does not require a previous block length setting.
The transferred data is also CRC protected. If a part of the CSD or CID register is stored in
ROM, then this unchangeable part must match the corresponding part of the receive buffer.
If this match fails, then the card reports an error and does not change any register contents.
Some cards may require long and unpredictable time to write a block of data. After receiving
a block of data and completing the CRC check, the card will begin writing and hold the DAT0
line low if its write buffer is full and unable to accept new data from a new WRITE_BLOCK
command. The host may poll the status of the card with a SEND_STATUS command (CMD13)
at any time, and the card will respond with its status. The status bit READY_FOR_DATA
indicates whether the card can accept new data or whether the write process is still in
progress). The host may deselect the card by issuing CMD7 (to select a different card) which
will displace the card into the Disconnect State and release the DAT line without interrupting
the write operation. When reselecting the card, it will reactivate busy indication by pulling DAT
to low if programming is still in progress and the write buffer is unavailable.
For SD card. Setting a number of write blocks to be pre-erased (ACMD23) will make a
following Multiple Block Write operation faster compared to the same operation without
preceding ACMD23. The host will use this command to define how many number of write
blocks are going to be send in the next write operation.
Steps involved in a single-block or multiple-block write are:
1. Write the data size in bytes in the SDIO_DATALEN register.
2. Write the block size in bytes (BLKSZ) in the SDIO_DATACTL register; the host sends data
in blocks of size BLKSZ.
3. Program SDIO_CMDAGMT register with the data address to which data should be written.
4. Program the SDIO_CMDCTL register. For SD memory and MMC cards, use CMD24 for a
single-block write and CMD25 for a multiple-block write. For SD I/O cards, use CMD53 for
both single-block and multiple-block transfers. For CE-ATA, first use CMD60 to write the ATA