Skip to content

Commit beb89a4

Browse files
committed
disk: sdmmc_stm32: implement disk_access_erase
Add support for erasing blocks to the STM32 SDMMC driver. Signed-off-by: Jordan Yates <[email protected]>
1 parent a675627 commit beb89a4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

drivers/disk/sdmmc_stm32.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,29 @@ static int stm32_sdmmc_access_write(struct disk_info *disk,
553553
return err;
554554
}
555555

556+
static int stm32_sdmmc_access_erase(struct disk_info *disk, uint32_t sector, uint32_t count)
557+
{
558+
const struct device *dev = disk->dev;
559+
struct stm32_sdmmc_priv *priv = dev->data;
560+
int err;
561+
562+
k_sem_take(&priv->thread_lock, K_FOREVER);
563+
564+
err = HAL_SD_Erase(&priv->hsd, sector, sector + count);
565+
if (err != HAL_OK) {
566+
LOG_ERR("sd erase block failed %d", err);
567+
err = -EIO;
568+
goto end;
569+
}
570+
571+
while (!stm32_sdmmc_is_card_in_transfer(&priv->hsd)) {
572+
}
573+
574+
end:
575+
k_sem_give(&priv->thread_lock);
576+
return err;
577+
}
578+
556579
static int stm32_sdmmc_get_card_info(HandleTypeDef *hsd, CardInfoTypeDef *info)
557580
{
558581
#ifdef CONFIG_SDMMC_STM32_EMMC
@@ -606,6 +629,7 @@ static const struct disk_operations stm32_sdmmc_ops = {
606629
.status = stm32_sdmmc_access_status,
607630
.read = stm32_sdmmc_access_read,
608631
.write = stm32_sdmmc_access_write,
632+
.erase = stm32_sdmmc_access_erase,
609633
.ioctl = stm32_sdmmc_access_ioctl,
610634
};
611635

0 commit comments

Comments
 (0)