STM32H735xx HAL User Manual
Defines | Functions
stm32h7xx_hal_mmc.c File Reference

MMC card HAL module driver. This file provides firmware functions to manage the following functionalities of the Secure Digital (MMC) peripheral: + Initialization and de-initialization functions + IO operation functions + Peripheral Control functions + MMC card Control functions. More...

#include "stm32h7xx_hal.h"

Go to the source code of this file.

Defines

#define MMC_VOLTAGE_RANGE   EMMC_HIGH_VOLTAGE_RANGE
#define MMC_EXT_CSD_PWR_CL_26_INDEX   203
#define MMC_EXT_CSD_PWR_CL_52_INDEX   202
#define MMC_EXT_CSD_PWR_CL_DDR_52_INDEX   239
#define MMC_EXT_CSD_PWR_CL_26_POS   24
#define MMC_EXT_CSD_PWR_CL_52_POS   16
#define MMC_EXT_CSD_PWR_CL_DDR_52_POS   24
#define MMC_EXT_CSD_SLEEP_NOTIFICATION_TIME_INDEX   216
#define MMC_EXT_CSD_SLEEP_NOTIFICATION_TIME_POS   0
#define MMC_EXT_CSD_S_A_TIMEOUT_INDEX   217
#define MMC_EXT_CSD_S_A_TIMEOUT_POS   8
#define MMC_INIT_FREQ   400000U /* Initialization phase : 400 kHz max */
#define MMC_HIGH_SPEED_FREQ   52000000U /* High speed phase : 52 MHz max */

Functions

static uint32_t MMC_InitCard (MMC_HandleTypeDef *hmmc)
 Initializes the mmc card.
static uint32_t MMC_PowerON (MMC_HandleTypeDef *hmmc)
 Enquires cards about their operating voltage and configures clock controls and stores MMC information that will be needed in future in the MMC handle.
static uint32_t MMC_SendStatus (MMC_HandleTypeDef *hmmc, uint32_t *pCardStatus)
 Returns the current card's status.
static void MMC_PowerOFF (MMC_HandleTypeDef *hmmc)
 Turns the SDMMC output signals off.
static void MMC_Write_IT (MMC_HandleTypeDef *hmmc)
 Wrap up writing in non-blocking mode.
static void MMC_Read_IT (MMC_HandleTypeDef *hmmc)
 Wrap up reading in non-blocking mode.
static uint32_t MMC_HighSpeed (MMC_HandleTypeDef *hmmc, FunctionalState state)
 Switches the MMC card to high speed mode.
static uint32_t MMC_DDR_Mode (MMC_HandleTypeDef *hmmc, FunctionalState state)
 Switches the MMC card to Double Data Rate (DDR) mode.
static HAL_StatusTypeDef MMC_ReadExtCSD (MMC_HandleTypeDef *hmmc, uint32_t *pFieldData, uint16_t FieldIndex, uint32_t Timeout)
 Reads extended CSD register to get the sectors number of the device.
static uint32_t MMC_PwrClassUpdate (MMC_HandleTypeDef *hmmc, uint32_t Wide, uint32_t Speed)
 Update the power class of the device.
HAL_StatusTypeDef HAL_MMC_Init (MMC_HandleTypeDef *hmmc)
 Initializes the MMC according to the specified parameters in the MMC_HandleTypeDef and create the associated handle.
HAL_StatusTypeDef HAL_MMC_InitCard (MMC_HandleTypeDef *hmmc)
 Initializes the MMC Card.
HAL_StatusTypeDef HAL_MMC_DeInit (MMC_HandleTypeDef *hmmc)
 De-Initializes the MMC card.
__weak void HAL_MMC_MspInit (MMC_HandleTypeDef *hmmc)
 Initializes the MMC MSP.
__weak void HAL_MMC_MspDeInit (MMC_HandleTypeDef *hmmc)
 De-Initialize MMC MSP.
HAL_StatusTypeDef HAL_MMC_ReadBlocks (MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout)
 Reads block(s) from a specified address in a card.
HAL_StatusTypeDef HAL_MMC_WriteBlocks (MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout)
 Allows to write block(s) to a specified address in a card.
HAL_StatusTypeDef HAL_MMC_ReadBlocks_IT (MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)
 Reads block(s) from a specified address in a card.
HAL_StatusTypeDef HAL_MMC_WriteBlocks_IT (MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)
 Writes block(s) to a specified address in a card.
HAL_StatusTypeDef HAL_MMC_ReadBlocks_DMA (MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)
 Reads block(s) from a specified address in a card.
HAL_StatusTypeDef HAL_MMC_WriteBlocks_DMA (MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)
 Writes block(s) to a specified address in a card.
HAL_StatusTypeDef HAL_MMC_Erase (MMC_HandleTypeDef *hmmc, uint32_t BlockStartAdd, uint32_t BlockEndAdd)
 Erases the specified memory area of the given MMC card.
void HAL_MMC_IRQHandler (MMC_HandleTypeDef *hmmc)
 This function handles MMC card interrupt request.
HAL_MMC_StateTypeDef HAL_MMC_GetState (MMC_HandleTypeDef *hmmc)
 return the MMC state
uint32_t HAL_MMC_GetError (MMC_HandleTypeDef *hmmc)
 Return the MMC error code.
__weak void HAL_MMC_TxCpltCallback (MMC_HandleTypeDef *hmmc)
 Tx Transfer completed callbacks.
__weak void HAL_MMC_RxCpltCallback (MMC_HandleTypeDef *hmmc)
 Rx Transfer completed callbacks.
__weak void HAL_MMC_ErrorCallback (MMC_HandleTypeDef *hmmc)
 MMC error callbacks.
__weak void HAL_MMC_AbortCallback (MMC_HandleTypeDef *hmmc)
 MMC Abort callbacks.
HAL_StatusTypeDef HAL_MMC_RegisterCallback (MMC_HandleTypeDef *hmmc, HAL_MMC_CallbackIDTypeDef CallbackId, pMMC_CallbackTypeDef pCallback)
 Register a User MMC Callback To be used instead of the weak (surcharged) predefined callback.
HAL_StatusTypeDef HAL_MMC_UnRegisterCallback (MMC_HandleTypeDef *hmmc, HAL_MMC_CallbackIDTypeDef CallbackId)
 Unregister a User MMC Callback MMC Callback is redirected to the weak (surcharged) predefined callback.
HAL_StatusTypeDef HAL_MMC_GetCardCID (MMC_HandleTypeDef *hmmc, HAL_MMC_CardCIDTypeDef *pCID)
 Returns information the information of the card which are stored on the CID register.
HAL_StatusTypeDef HAL_MMC_GetCardCSD (MMC_HandleTypeDef *hmmc, HAL_MMC_CardCSDTypeDef *pCSD)
 Returns information the information of the card which are stored on the CSD register.
HAL_StatusTypeDef HAL_MMC_GetCardInfo (MMC_HandleTypeDef *hmmc, HAL_MMC_CardInfoTypeDef *pCardInfo)
 Gets the MMC card info.
HAL_StatusTypeDef HAL_MMC_GetCardExtCSD (MMC_HandleTypeDef *hmmc, uint32_t *pExtCSD, uint32_t Timeout)
 Returns information the information of the card which are stored on the Extended CSD register.
HAL_StatusTypeDef HAL_MMC_ConfigWideBusOperation (MMC_HandleTypeDef *hmmc, uint32_t WideMode)
 Enables wide bus operation for the requested card if supported by card.
HAL_StatusTypeDef HAL_MMC_ConfigSpeedBusOperation (MMC_HandleTypeDef *hmmc, uint32_t SpeedMode)
 Configure the speed bus mode.
HAL_MMC_CardStateTypeDef HAL_MMC_GetCardState (MMC_HandleTypeDef *hmmc)
 Gets the current mmc card data state.
HAL_StatusTypeDef HAL_MMC_Abort (MMC_HandleTypeDef *hmmc)
 Abort the current transfer and disable the MMC.
HAL_StatusTypeDef HAL_MMC_Abort_IT (MMC_HandleTypeDef *hmmc)
 Abort the current transfer and disable the MMC (IT mode).
HAL_StatusTypeDef HAL_MMC_EraseSequence (MMC_HandleTypeDef *hmmc, uint32_t EraseType, uint32_t BlockStartAdd, uint32_t BlockEndAdd)
 Perform specific commands sequence for the different type of erase.
HAL_StatusTypeDef HAL_MMC_Sanitize (MMC_HandleTypeDef *hmmc)
 Perform sanitize operation on the device.
HAL_StatusTypeDef HAL_MMC_ConfigSecRemovalType (MMC_HandleTypeDef *hmmc, uint32_t SRTMode)
 Configure the Secure Removal Type (SRT) in the Extended CSD register.
HAL_StatusTypeDef HAL_MMC_GetSupportedSecRemovalType (MMC_HandleTypeDef *hmmc, uint32_t *SupportedSRT)
 Gets the supported values of the the Secure Removal Type (SRT).
HAL_StatusTypeDef HAL_MMC_SleepDevice (MMC_HandleTypeDef *hmmc)
 Switch the device from Standby State to Sleep State.
HAL_StatusTypeDef HAL_MMC_AwakeDevice (MMC_HandleTypeDef *hmmc)
 Switch the device from Sleep State to Standby State.
__weak void HAL_MMCEx_Read_DMADoubleBuf0CpltCallback (MMC_HandleTypeDef *hmmc)
 Read DMA Buffer 0 Transfer completed callbacks.
__weak void HAL_MMCEx_Read_DMADoubleBuf1CpltCallback (MMC_HandleTypeDef *hmmc)
 Read DMA Buffer 1 Transfer completed callbacks.
__weak void HAL_MMCEx_Write_DMADoubleBuf0CpltCallback (MMC_HandleTypeDef *hmmc)
 Write DMA Buffer 0 Transfer completed callbacks.
__weak void HAL_MMCEx_Write_DMADoubleBuf1CpltCallback (MMC_HandleTypeDef *hmmc)
 Write DMA Buffer 1 Transfer completed callbacks.

Detailed Description

MMC card HAL module driver. This file provides firmware functions to manage the following functionalities of the Secure Digital (MMC) peripheral: + Initialization and de-initialization functions + IO operation functions + Peripheral Control functions + MMC card Control functions.

Author:
MCD Application Team
Attention:

Copyright (c) 2017 STMicroelectronics. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.

  ==============================================================================
                        ##### How to use this driver #####
  ==============================================================================
  [..]
    This driver implements a high level communication layer for read and write from/to
    this memory. The needed STM32 hardware resources (SDMMC and GPIO) are performed by
    the user in HAL_MMC_MspInit() function (MSP layer).
    Basically, the MSP layer configuration should be the same as we provide in the
    examples.
    You can easily tailor this configuration according to hardware resources.

  [..]
    This driver is a generic layered driver for SDMMC memories which uses the HAL
    SDMMC driver functions to interface with MMC and eMMC cards devices.
    It is used as follows:

    (#)Initialize the SDMMC low level resources by implement the HAL_MMC_MspInit() API:
        (##) Enable the SDMMC interface clock using __HAL_RCC_SDMMC_CLK_ENABLE();
        (##) SDMMC pins configuration for MMC card
            (+++) Enable the clock for the SDMMC GPIOs using the functions __HAL_RCC_GPIOx_CLK_ENABLE();
            (+++) Configure these SDMMC pins as alternate function pull-up using HAL_GPIO_Init()
                  and according to your pin assignment;
        (##) NVIC configuration if you need to use interrupt process (HAL_MMC_ReadBlocks_IT()
             and HAL_MMC_WriteBlocks_IT() APIs).
            (+++) Configure the SDMMC interrupt priorities using function HAL_NVIC_SetPriority();
            (+++) Enable the NVIC SDMMC IRQs using function HAL_NVIC_EnableIRQ()
            (+++) SDMMC interrupts are managed using the macros __HAL_MMC_ENABLE_IT()
                  and __HAL_MMC_DISABLE_IT() inside the communication process.
            (+++) SDMMC interrupts pending bits are managed using the macros __HAL_MMC_GET_IT()
                  and __HAL_MMC_CLEAR_IT()
        (##) No general propose DMA Configuration is needed, an Internal DMA for SDMMC Peripheral are used.

    (#) At this stage, you can perform MMC read/write/erase operations after MMC card initialization


  *** MMC Card Initialization and configuration ***
  ================================================
  [..]
    To initialize the MMC Card, use the HAL_MMC_Init() function. It Initializes
    SDMMC Peripheral (STM32 side) and the MMC Card, and put it into StandBy State (Ready for data transfer).
    This function provide the following operations:

    (#) Initialize the SDMMC peripheral interface with defaullt configuration.
        The initialization process is done at 400KHz. You can change or adapt
        this frequency by adjusting the "ClockDiv" field.
        The MMC Card frequency (SDMMC_CK) is computed as follows:

           SDMMC_CK = SDMMCCLK / (2 * ClockDiv)

        In initialization mode and according to the MMC Card standard,
        make sure that the SDMMC_CK frequency doesn't exceed 400KHz.

        This phase of initialization is done through SDMMC_Init() and
        SDMMC_PowerState_ON() SDMMC low level APIs.

    (#) Initialize the MMC card. The API used is HAL_MMC_InitCard().
        This phase allows the card initialization and identification
        and check the MMC Card type (Standard Capacity or High Capacity)
        The initialization flow is compatible with MMC standard.

        This API (HAL_MMC_InitCard()) could be used also to reinitialize the card in case
        of plug-off plug-in.

    (#) Configure the MMC Card Data transfer frequency. By Default, the card transfer
        frequency by adjusting the "ClockDiv" field.
        In transfer mode and according to the MMC Card standard, make sure that the
        SDMMC_CK frequency doesn't exceed 25MHz and 100MHz in High-speed mode switch.

    (#) Select the corresponding MMC Card according to the address read with the step 2.

    (#) Configure the MMC Card in wide bus mode: 4-bits data.

  *** MMC Card Read operation ***
  ==============================
  [..]
    (+) You can read from MMC card in polling mode by using function HAL_MMC_ReadBlocks().
        This function support only 512-bytes block length (the block size should be
        chosen as 512 bytes).
        You can choose either one block read operation or multiple block read operation
        by adjusting the "NumberOfBlocks" parameter.
        After this, you have to ensure that the transfer is done correctly. The check is done
        through HAL_MMC_GetCardState() function for MMC card state.

    (+) You can read from MMC card in DMA mode by using function HAL_MMC_ReadBlocks_DMA().
        This function support only 512-bytes block length (the block size should be
        chosen as 512 bytes).
        You can choose either one block read operation or multiple block read operation
        by adjusting the "NumberOfBlocks" parameter.
        After this, you have to ensure that the transfer is done correctly. The check is done
        through HAL_MMC_GetCardState() function for MMC card state.
        You could also check the DMA transfer process through the MMC Rx interrupt event.

    (+) You can read from MMC card in Interrupt mode by using function HAL_MMC_ReadBlocks_IT().
        This function allows the read of 512 bytes blocks.
        You can choose either one block read operation or multiple block read operation
        by adjusting the "NumberOfBlocks" parameter.
        After this, you have to ensure that the transfer is done correctly. The check is done
        through HAL_MMC_GetCardState() function for MMC card state.
        You could also check the IT transfer process through the MMC Rx interrupt event.

  *** MMC Card Write operation ***
  ===============================
  [..]
    (+) You can write to MMC card in polling mode by using function HAL_MMC_WriteBlocks().
        This function support only 512-bytes block length (the block size should be
        chosen as 512 bytes).
        You can choose either one block read operation or multiple block read operation
        by adjusting the "NumberOfBlocks" parameter.
        After this, you have to ensure that the transfer is done correctly. The check is done
        through HAL_MMC_GetCardState() function for MMC card state.

    (+) You can write to MMC card in DMA mode by using function HAL_MMC_WriteBlocks_DMA().
        This function support only 512-bytes block length (the block size should be
        chosen as 512 byte).
        You can choose either one block read operation or multiple block read operation
        by adjusting the "NumberOfBlocks" parameter.
        After this, you have to ensure that the transfer is done correctly. The check is done
        through HAL_MMC_GetCardState() function for MMC card state.
        You could also check the DMA transfer process through the MMC Tx interrupt event.

    (+) You can write to MMC card in Interrupt mode by using function HAL_MMC_WriteBlocks_IT().
        This function allows the read of 512 bytes blocks.
        You can choose either one block read operation or multiple block read operation
        by adjusting the "NumberOfBlocks" parameter.
        After this, you have to ensure that the transfer is done correctly. The check is done
        through HAL_MMC_GetCardState() function for MMC card state.
        You could also check the IT transfer process through the MMC Tx interrupt event.

  *** MMC card information ***
  ===========================
  [..]
    (+) To get MMC card information, you can use the function HAL_MMC_GetCardInfo().
        It returns useful information about the MMC card such as block size, card type,
        block number ...

  *** MMC card CSD register ***
  ============================
  [..]
    (+) The HAL_MMC_GetCardCSD() API allows to get the parameters of the CSD register.
        Some of the CSD parameters are useful for card initialization and identification.

  *** MMC card CID register ***
  ============================
  [..]
    (+) The HAL_MMC_GetCardCID() API allows to get the parameters of the CID register.
        Some of the CID parameters are useful for card initialization and identification.

  *** MMC HAL driver macros list ***
  ==================================
  [..]
    Below the list of most used macros in MMC HAL driver.

    (+) __HAL_MMC_ENABLE_IT: Enable the MMC device interrupt
    (+) __HAL_MMC_DISABLE_IT: Disable the MMC device interrupt
    (+) __HAL_MMC_GET_FLAG:Check whether the specified MMC flag is set or not
    (+) __HAL_MMC_CLEAR_FLAG: Clear the MMC's pending flags

  [..]
    (@) You can refer to the MMC HAL driver header file for more useful macros

  *** Callback registration ***
  =============================================
  [..]
    The compilation define USE_HAL_MMC_REGISTER_CALLBACKS when set to 1
    allows the user to configure dynamically the driver callbacks.

    Use Functions HAL_MMC_RegisterCallback() to register a user callback,
    it allows to register following callbacks:
      (+) TxCpltCallback : callback when a transmission transfer is completed.
      (+) RxCpltCallback : callback when a reception transfer is completed.
      (+) ErrorCallback : callback when error occurs.
      (+) AbortCpltCallback : callback when abort is completed.
      (+) Read_DMADblBuf0CpltCallback : callback when the DMA reception of first buffer is completed.
      (+) Read_DMADblBuf1CpltCallback : callback when the DMA reception of second buffer is completed.
      (+) Write_DMADblBuf0CpltCallback : callback when the DMA transmission of first buffer is completed.
      (+) Write_DMADblBuf1CpltCallback : callback when the DMA transmission of second buffer is completed.
      (+) MspInitCallback    : MMC MspInit.
      (+) MspDeInitCallback  : MMC MspDeInit.
    This function takes as parameters the HAL peripheral handle, the Callback ID
    and a pointer to the user callback function.

    Use function HAL_MMC_UnRegisterCallback() to reset a callback to the default
    weak (surcharged) function. It allows to reset following callbacks:
      (+) TxCpltCallback : callback when a transmission transfer is completed.
      (+) RxCpltCallback : callback when a reception transfer is completed.
      (+) ErrorCallback : callback when error occurs.
      (+) AbortCpltCallback : callback when abort is completed.
      (+) Read_DMADblBuf0CpltCallback : callback when the DMA reception of first buffer is completed.
      (+) Read_DMADblBuf1CpltCallback : callback when the DMA reception of second buffer is completed.
      (+) Write_DMADblBuf0CpltCallback : callback when the DMA transmission of first buffer is completed.
      (+) Write_DMADblBuf1CpltCallback : callback when the DMA transmission of second buffer is completed.
      (+) MspInitCallback    : MMC MspInit.
      (+) MspDeInitCallback  : MMC MspDeInit.
    This function) takes as parameters the HAL peripheral handle and the Callback ID.

    By default, after the HAL_MMC_Init and if the state is HAL_MMC_STATE_RESET
    all callbacks are reset to the corresponding legacy weak (surcharged) functions.
    Exception done for MspInit and MspDeInit callbacks that are respectively
    reset to the legacy weak (surcharged) functions in the HAL_MMC_Init
    and HAL_MMC_DeInit only when these callbacks are null (not registered beforehand).
    If not, MspInit or MspDeInit are not null, the HAL_MMC_Init and HAL_MMC_DeInit
    keep and use the user MspInit/MspDeInit callbacks (registered beforehand)

    Callbacks can be registered/unregistered in READY state only.
    Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
    in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
    during the Init/DeInit.
    In that case first register the MspInit/MspDeInit user callbacks
    using HAL_MMC_RegisterCallback before calling HAL_MMC_DeInit
    or HAL_MMC_Init function.

    When The compilation define USE_HAL_MMC_REGISTER_CALLBACKS is set to 0 or
    not defined, the callback registering feature is not available
    and weak (surcharged) callbacks are used.

  

Definition in file stm32h7xx_hal_mmc.c.