HAL MMC Overview

Introducing MMC

group MMC_Introduction

  • The MMC Hardware Abstraction Layer provides a high-level interface to the STM32 SDMMC peripheral for communicating with MMC cards and embedded MMC (eMMC) devices.

  • This HAL driver is built on top of the SDMMC core layer and simplifies peripheral initialization, device identification, configuration, and transition to the transfer state.

  • It supports the main data operations required by storage applications, including single-block and multi-block read/write transfers, erase control, transfer abort management, and access to device status and configuration information.

  • The driver supports polling, interrupt, DMA, and, when enabled, linked-list or double-buffer DMA transfer modes, allowing the application to balance CPU load, throughput, and responsiveness.

  • It also provides services to manage device insertion and removal events, configure transfer timing and, when available, FIFO threshold parameters.

  • This abstraction layer improves portability across STM32 devices embedding the SDMMC peripheral and eases the integration of MMC and eMMC storage into embedded applications.

Module and files

The following diagram illustrates the MMC module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the MMC module. It shows the interactions between the user application, HAL drivers, low-level drivers, and the hardware components.


@startuml

!$use_mmc_core = 1
!$use_mmc_ll = 1
!$use_mmc_hal = 1

!$use_api_itf = 1
!$use_hal_itf = 1
!$use_ll_itf = 1
!$use_core_itf = 1

!$use_mmc_isr = 1

!$use_hal_service = 1
!$use_hal_rcc = 1
!$use_hal_dma = 0

!$use_ll_rcc = 0

!$mmc    = "MMC"
!$mmc_lc = "mmc"
!$hal_api_itf = "HAL " + $mmc + " API"
!$appli_itf = "User Callback"
!$mmc_name = "HAL_"+$mmc
!$mmc_ISR = $mmc+" ISR"
!$core_mmc = "sd"+$mmc_lc+"_core"
!$core_dlyb = "dlyb"+"_core"
!$hal_dma_itf = "HAL_DMA_StartDirectXfer()\nHAL_DMA_Abort_IT"
!$hal_rcc_itf = "\n\t\t\t\tHAL_RCC_"+$mmc+"_EnableClock()"
!$hal_mmc_itf = "DMA CallBacks\nDMA Half transfer complete CallBack\nError CallBacks"
!$hal_generic_itf = "HAL_GetTick()"
!$core_mmc_itf = "core " + $mmc +" API"
!$core_dlyb_itf = "core " + "DLYB" +" API"
!$mmc_xIRQ = $mmc+"x_IRQ"

<style>
componentDiagram {
arrow {
FontSize 8
}
interface {
FontSize 8
}
}
</style>

title $mmc Software Component Diagram

Package "Application Layer" #DarkMagenta {

component [Appli]
interface "$appli_itf" as APPLI_Interface
[Appli] -r- APPLI_Interface
}

package "HAL" #DarkOrange {
[$mmc_name]
!if ($use_hal_dma == 1)
interface "$hal_mmc_itf" as HAL_MMC_Interface
[$mmc_name] -d- HAL_MMC_Interface
!endif
interface "$hal_api_itf" as HAL_MMC_APPLI_Interface
[$mmc_name] -u- HAL_MMC_APPLI_Interface

!if ($use_hal_service == 1)
  [HAL_SERVICE]
  interface "$hal_generic_itf" as HAL_Service_Interface
  [HAL_SERVICE] -r- HAL_Service_Interface
  [$mmc_name] -l-( HAL_Service_Interface
!endif  

!if ($use_hal_dma == 1)
  [HAL_DMA]
  interface "$hal_dma_itf" as HAL_DMA_Interface
  [HAL_DMA] -u- HAL_DMA_Interface
  [HAL_DMA] -u-( HAL_MMC_Interface
  [$mmc_name] --( HAL_DMA_Interface
!endif
!if ($use_hal_rcc == 1)
  [HAL_RCC]
  interface "$hal_rcc_itf" as HAL_RCC_Interface
  [HAL_RCC] -l- HAL_RCC_Interface
  [$mmc_name] -r-( HAL_RCC_Interface
!endif
}

[Appli] -d-( HAL_MMC_APPLI_Interface
[$mmc_name] -u-( APPLI_Interface

package "Low Layer" #Technology {

!if ($use_mmc_ll == 1)
  [$core_mmc]
  interface "$core_mmc_itf" as LL_MMC_Interface
  [$core_mmc]  -u- LL_MMC_Interface
  [$core_dlyb]
  interface "$core_dlyb_itf" as LL_DLYB_Interface
  [$core_dlyb]  -u- LL_DLYB_Interface
!endif 

!if ($use_mmc_isr == 1) 
interface "$mmc_ISR" as MMC_ISR
[$mmc_ISR] -U- MMC_ISR
[$mmc_ISR]
!endif

[CMSIS-Devices]
!if ($use_ll_rcc == 1)
  [LL_RCC]
  interface "LL RCC API" as LL_RCC_API
  [LL_RCC] -u- LL_RCC_API
  [HAL_RCC] -d-(LL_RCC_API
!endif

!if ($use_hal_dma == 1)
  [DMA ISR]
  interface "DMA ISR" as DMA_ISR
  [DMA ISR] -u- DMA_ISR
!endif  
}

package "HW" #LightCyan {
[STM32_HW]
!if ($use_mmc_isr == 1)
interface "$mmc_xIRQ" as MMCx_IRQ
[STM32_HW] -u- MMCx_IRQ
!endif
!if ($use_hal_dma == 1)
interface "DMAx_IRQ_Ch" as DMA_IRQ_CH
[STM32_HW] -u- DMA_IRQ_CH
[DMA ISR] -d-( DMA_IRQ_CH
[HAL_DMA] --( DMA_ISR
!endif
}
!if ($use_mmc_ll == 1)
[$mmc_name] -d-( LL_MMC_Interface
[$mmc_name] -d-( LL_DLYB_Interface
[$core_mmc] .r.> [CMSIS-Devices]: $mmc register def
[$core_dlyb] .r.> [CMSIS-Devices]: DLYB register def
[STM32_HW] <.u. [$core_mmc] : $mmc registers R/W
[STM32_HW] <.u. [$core_dlyb] : $mmc registers R/W
!else
[$mmc_name] .d.> [CMSIS-Devices]: $mmc register def
[STM32_HW] <.l. [$mmc_name] : $mmc registers R/W
!endif
!if ($use_mmc_isr == 1)
[$mmc_ISR] -d-( MMCx_IRQ
[$mmc_name] -d-( MMC_ISR
!endif
!if ($use_ll_rcc == 1)
[STM32_HW] <.u. [LL_RCC] : RCC registers R/W
!endif

@enduml

Configuration table

The following table lists the configuration defines for the HAL MMC module, specifying their locations, default values, and descriptions:

group MMC_Configuration_Table

Configuration inside the MMC driver

Config defines

Description

Default value

Note

USE_ASSERT_DBG_PARAM

from the IDE

NONE

Allows to use the assert checks parameters.

USE_ASSERT_DBG_STATE

from the IDE

NONE

Allows to use the assert checks states.

USE_HAL_CHECK_PARAM

from hal_conf.h

0

Allows to use the runtime checks parameters.

USE_HAL_MMC_AUTO_DETECTION_FREQUENCY

from hal_conf.h

0

Allows to Enable/Disable MMC Custom Frequency.

USE_HAL_MMC_REGISTER_CALLBACKS

from hal_conf.h

0

Allows to provide specific callback functions.

USE_HAL_MMC_LINKEDLIST

from hal_conf.h

1

Allows to use the MMC in linked-list mode.

USE_HAL_MMC_GET_CID

from hal_conf.h

1

Allows to get MMC Card identification.

USE_HAL_MMC_GET_SPEC_VERSION

from hal_conf.h

1

Allows to get the MMC Card version.

USE_HAL_MMC_GET_LAST_ERRORS

from hal_conf.h

1

Allows to get last errors codes.

USE_HAL_MMC_USER_DATA

from hal_conf.h

0

Allows to enable/disable user data.

USE_HAL_MMC_CLK_ENABLE_MODEL

from hal_conf.h

HAL_CLK_ENABLE_NO

Allows to enable the clock model for the MMC.

USE_HAL_MMC_RPMB_FEATURE

from hal_conf.h

0

Allows to enable the RPMB feature for the MMC.