147
147
#include " mbed_debug.h"
148
148
#include < errno.h>
149
149
150
- /* Required version: 5.5.4 and above */
150
+ /* Required version: 5.6.1 and above */
151
151
#ifdef MBED_MAJOR_VERSION
152
- #if (MBED_VERSION < MBED_ENCODE_VERSION(5,5,4 ))
152
+ #if (MBED_VERSION < MBED_ENCODE_VERSION(5,6,1 ))
153
153
#error "Incompatible mbed-os version detected! Required 5.5.4 and above"
154
154
#endif
155
155
#else
156
- #warning "mbed-os version 5.5.4 or above required"
156
+ #warning "mbed-os version 5.6.1 or above required"
157
157
#endif
158
158
159
159
#define SD_COMMAND_TIMEOUT 5000 /* !< Timeout in ms for response */
@@ -513,9 +513,17 @@ int SDBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
513
513
return status;
514
514
}
515
515
516
- int SDBlockDevice::erase (bd_addr_t addr, bd_size_t size)
516
+ bool SDBlockDevice::_is_valid_trim (bd_addr_t addr, bd_size_t size)
517
517
{
518
- if (!is_valid_erase (addr, size)) {
518
+ return (
519
+ addr % _erase_size == 0 &&
520
+ size % _erase_size == 0 &&
521
+ addr + size <= this ->size ());
522
+ }
523
+
524
+ int SDBlockDevice::trim (bd_addr_t addr, bd_size_t size)
525
+ {
526
+ if (!_is_valid_trim (addr, size)) {
519
527
return SD_BLOCK_DEVICE_ERROR_PARAMETER;
520
528
}
521
529
@@ -526,15 +534,7 @@ int SDBlockDevice::erase(bd_addr_t addr, bd_size_t size)
526
534
}
527
535
int status = BD_ERROR_OK;
528
536
529
- // Toss out erases that are too small, this is fine as the block device api
530
- // doesn't garuntee the final state of erased bytes and a following program
531
- // will still work fine.
532
- if (size < _erase_size) {
533
- _lock.unlock ();
534
- return status;
535
- }
536
-
537
- size -= _erase_size;
537
+ size -= _block_size;
538
538
// SDSC Card (CCS=0) uses byte unit address
539
539
// SDHC and SDXC Cards (CCS=1) use block unit address (512 Bytes unit)
540
540
if (SDCARD_V2HC == _card_type) {
@@ -568,11 +568,6 @@ bd_size_t SDBlockDevice::get_program_size() const
568
568
return _block_size;
569
569
}
570
570
571
- bd_size_t SDBlockDevice::get_erase_size () const
572
- {
573
- return _block_size;
574
- }
575
-
576
571
bd_size_t SDBlockDevice::size () const
577
572
{
578
573
bd_size_t sectors = 0 ;
0 commit comments