fix(sdmmc): release aligned DMA buffer on card deinit

This commit is contained in:
Adam Múdry
2026-08-04 15:38:11 +02:00
parent b2672c7937
commit e0c094da69
12 changed files with 171 additions and 18 deletions

View File

@@ -53,8 +53,10 @@ Using API with SD Memory Cards
:SOC_GPSPI_SUPPORTED: - To initialize the SDSPI host, call the host driver functions, e.g., :cpp:func:`sdspi_host_init`, :cpp:func:`sdspi_host_init_slot`.
- To initialize the card, call :cpp:func:`sdmmc_card_init` and pass to it the parameters ``host`` - the host driver information, and ``card`` - a pointer to the structure :cpp:class:`sdmmc_card_t` which will be filled with information about the card when the function completes.
- To read and write sectors of the card, use :cpp:func:`sdmmc_read_sectors` and :cpp:func:`sdmmc_write_sectors` respectively and pass to it the parameter ``card`` - a pointer to the card information structure.
- When the card is no longer used, call :cpp:func:`sdmmc_card_deinit` to release resources allocated by :cpp:func:`sdmmc_card_init`.
- Then call the host driver function to disable the host peripheral and free the resources allocated by the host driver (``sdmmc_host_deinit`` for SDMMC or ``sdspi_host_deinit`` for SDSPI). If the application allocated the :cpp:class:`sdmmc_card_t` structure, free it after deinitializing the card and host.
- If the card is not used anymore, call the host driver function to disable the host peripheral and free the resources allocated by the driver (``sdmmc_host_deinit`` for SDMMC or ``sdspi_host_deinit`` for SDSPI).
:cpp:func:`sdmmc_card_deinit` frees :cpp:member:`sdmmc_host_t::dma_aligned_buffer` only when :c:macro:`SDMMC_HOST_FLAG_ALLOC_ALIGNED_BUF` is set. If the application provides a pre-allocated buffer without setting this flag, the application retains ownership of the buffer and must free it after calling :cpp:func:`sdmmc_card_deinit`.
Unaligned Buffer Performance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@@ -53,8 +53,10 @@ SD/SDIO/MMC 驱动支持 SD 存储器、SDIO 卡和 eMMC 芯片。这是一个
:SOC_GPSPI_SUPPORTED: - 初始化 SDSPI 主机,请调用主机驱动函数,例如 :cpp:func:`sdspi_host_init` 和 :cpp:func:`sdspi_host_init_slot`。
- 初始化卡,请调用 :cpp:func:`sdmmc_card_init`,并将参数 ``host`` (主机驱动信息)和参数 ``card`` (指向 :cpp:class:`sdmmc_card_t` 结构体的指针)传递给此函数。函数运行结束后,将会向 :cpp:class:`sdmmc_card_t` 结构体填充该卡的信息。
- 读取或写入卡的扇区,请分别调用 :cpp:func:`sdmmc_read_sectors`:cpp:func:`sdmmc_write_sectors`,并将参数 ``card`` (指向卡信息结构的指针)传递给函数。
- 如果不再使用该卡,请调用 :cpp:func:`sdmmc_card_deinit`,释放 :cpp:func:`sdmmc_card_init` 分配的资源。
- 然后调用主机驱动函数以禁用主机外设并释放主机驱动分配的资源SDMMC 使用 ``sdmmc_host_deinit``SDSPI 使用 ``sdspi_host_deinit``)。如果应用程序分配了 :cpp:class:`sdmmc_card_t` 结构体,请在反初始化卡和主机后释放该结构体。
- 如果不再使用该卡,请调用主机驱动函数,例如 ``sdmmc_host_deinit````sdspi_host_deinit``以禁用SDMMC 主机外设或 SDSPI 主机外设,并释放驱动程序分配的资源。
仅当设置了 :c:macro:`SDMMC_HOST_FLAG_ALLOC_ALIGNED_BUF` 时,:cpp:func:`sdmmc_card_deinit` 才会释放 :cpp:member:`sdmmc_host_t::dma_aligned_buffer`。如果应用程序提供了预分配的 buffer 但未设置此标志,则应用程序保留 buffer 所有权,并必须在调用 :cpp:func:`sdmmc_card_deinit` 后将其释放。
未对齐 buffer 性能
^^^^^^^^^^^^^^^^^^^^^^^^^^^^