@@ -214,15 +214,17 @@ void loop() {
214
214
// SD Card callbacks
215
215
// --------------------------------------------------------------------+
216
216
217
- int32_t sdcard_read_cb (uint32_t lba, void * buffer, uint32_t bufsize)
218
- {
219
- bool rc;
220
-
221
- #if SD_FAT_VERSION >= 20000
222
- rc = sd.card ()->readSectors (lba, (uint8_t *) buffer, bufsize/512 );
223
- #else
224
- rc = sd.card ()->readBlocks (lba, (uint8_t *) buffer, bufsize/512 );
225
- #endif
217
+ int32_t sdcard_read_cb (uint32_t lba, void * buffer, uint32_t bufsize) {
218
+ bool rc = true ;
219
+ uint8_t * buf = (uint8_t *)buffer;
220
+
221
+ // Perform each sector with a single-block CMD17
222
+ for (uint32_t i = 0 ; i < bufsize/512 ; i++) {
223
+ if (!sd.card ()->readBlock (lba + i, buf + i*512 )) {
224
+ rc = false ;
225
+ break ;
226
+ }
227
+ }
226
228
227
229
return rc ? bufsize : -1 ;
228
230
}
@@ -231,17 +233,19 @@ int32_t sdcard_read_cb (uint32_t lba, void* buffer, uint32_t bufsize)
231
233
// Process data in buffer to disk's storage and
232
234
// return number of written bytes (must be multiple of block size)
233
235
int32_t sdcard_write_cb (uint32_t lba, uint8_t * buffer, uint32_t bufsize) {
234
- bool rc;
236
+ bool rc = true ;
235
237
236
238
#ifdef LED_BUILTIN
237
239
digitalWrite (LED_BUILTIN, HIGH);
238
240
#endif
239
241
240
- #if SD_FAT_VERSION >= 20000
241
- rc = sd.card ()->writeSectors (lba, buffer, bufsize/512 );
242
- #else
243
- rc = sd.card ()->writeBlocks (lba, buffer, bufsize/512 );
244
- #endif
242
+ // Perform each 512-byte sector as a single-block CMD24
243
+ for (uint32_t i = 0 ; i < bufsize/512 ; i++) {
244
+ if (!sd.card ()->writeBlock (lba + i, buffer + i*512 )) {
245
+ rc = false ;
246
+ break ;
247
+ }
248
+ }
245
249
246
250
return rc ? bufsize : -1 ;
247
251
}
0 commit comments