* Write a 512 byte block to an SD card. * * \param[in] blockNumber Logical block to be written. * \param[in] src Pointer to the location of the data to be written. * \return true for success, false for failure. */
| 624 | * \return true for success, false for failure. |
| 625 | */ |
| 626 | bool DiskIODriver_SPI_SD::writeBlock(uint32_t blockNumber, const uint8_t * const src) { |
| 627 | if (ENABLED(SDCARD_READONLY)) return false; |
| 628 | |
| 629 | #if IS_TEENSY_35_36 || IS_TEENSY_40_41 |
| 630 | return 0 == SDHC_CardWriteBlock(src, blockNumber); |
| 631 | #endif |
| 632 | |
| 633 | if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9; // Use address if not SDHC card |
| 634 | bool success = !cardCommand(CMD24, blockNumber); |
| 635 | if (!success) { |
| 636 | error(SD_CARD_ERROR_CMD24); |
| 637 | } |
| 638 | else if (writeData(DATA_START_BLOCK, src)) { |
| 639 | #if SD_WRITE_TIMEOUT |
| 640 | success = waitNotBusy(SD_WRITE_TIMEOUT); // Wait for flashing to complete |
| 641 | if (!success) error(SD_CARD_ERROR_WRITE_TIMEOUT); |
| 642 | #else |
| 643 | while (spiRec() != 0xFF) {} |
| 644 | #endif |
| 645 | if (success) { |
| 646 | success = !(cardCommand(CMD13, 0) || spiRec()); // Response is r2 so get and check two bytes for nonzero |
| 647 | if (!success) error(SD_CARD_ERROR_WRITE_PROGRAMMING); |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | chipDeselect(); |
| 652 | return success; |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * Write one data block in a multiple block write sequence |
no test coverage detected