添加串口设置
添加sdio
This commit is contained in:
1 parent
90c74bc31a
commit
e1d94985a4
30 files changed
+32276
-86
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,353 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_mmc_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief MMC card Extended HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Secure Digital (MMC) peripheral:
|
||||
* + Extended features functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The MMC Extension HAL driver can be used as follows:
|
||||
(+) Configure Buffer0 and Buffer1 start address and Buffer size using HAL_MMCEx_ConfigDMAMultiBuffer() function.
|
||||
|
||||
(+) Start Read and Write for multibuffer mode using HAL_MMCEx_ReadBlocksDMAMultiBuffer() and
|
||||
HAL_MMCEx_WriteBlocksDMAMultiBuffer() functions.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup MMCEx MMCEx
|
||||
* @brief MMC Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined (SDMMC1) || defined (SDMMC2)
|
||||
#ifdef HAL_MMC_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup MMCEx_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup MMCEx_Exported_Functions_Group1
|
||||
* @brief Multibuffer functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Multibuffer functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to configure the multibuffer mode and start read and write
|
||||
multibuffer mode for MMC HAL driver.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure DMA Dual Buffer mode. The Data transfer is managed by an Internal DMA.
|
||||
* @param hmmc: MMC handle
|
||||
* @param pDataBuffer0: Pointer to the buffer0 that will contain/receive the transferred data
|
||||
* @param pDataBuffer1: Pointer to the buffer1 that will contain/receive the transferred data
|
||||
* @param BufferSize: Size of Buffer0 in Blocks. Buffer0 and Buffer1 must have the same size.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MMCEx_ConfigDMAMultiBuffer(MMC_HandleTypeDef *hmmc, uint32_t *pDataBuffer0,
|
||||
uint32_t *pDataBuffer1, uint32_t BufferSize)
|
||||
{
|
||||
if (hmmc->State == HAL_MMC_STATE_READY)
|
||||
{
|
||||
hmmc->Instance->IDMABASE0 = (uint32_t) pDataBuffer0 ;
|
||||
hmmc->Instance->IDMABASE1 = (uint32_t) pDataBuffer1 ;
|
||||
hmmc->Instance->IDMABSIZE = (uint32_t)(MMC_BLOCKSIZE * BufferSize);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads block(s) from a specified address in a card. The received Data will be stored in Buffer0 and Buffer1.
|
||||
* Buffer0, Buffer1 and BufferSize need to be configured by function HAL_MMCEx_ConfigDMAMultiBuffer before
|
||||
* call this function.
|
||||
* @param hmmc: MMC handle
|
||||
* @param BlockAdd: Block Address from where data is to be read
|
||||
* @param NumberOfBlocks: Total number of blocks to read
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MMCEx_ReadBlocksDMAMultiBuffer(MMC_HandleTypeDef *hmmc, uint32_t BlockAdd,
|
||||
uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDMMC_DataInitTypeDef config;
|
||||
uint32_t DmaBase0_reg;
|
||||
uint32_t DmaBase1_reg;
|
||||
uint32_t errorstate;
|
||||
uint32_t add = BlockAdd;
|
||||
|
||||
if (hmmc->State == HAL_MMC_STATE_READY)
|
||||
{
|
||||
if ((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
|
||||
{
|
||||
hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the case of 4kB blocks (field DATA SECTOR SIZE of extended CSD register) */
|
||||
if (((hmmc->Ext_CSD[(MMC_EXT_CSD_DATA_SEC_SIZE_INDEX / 4)] >> MMC_EXT_CSD_DATA_SEC_SIZE_POS) & 0x000000FFU) != 0x0U)
|
||||
{
|
||||
if ((NumberOfBlocks % 8U) != 0U)
|
||||
{
|
||||
/* The number of blocks should be a multiple of 8 sectors of 512 bytes = 4 KBytes */
|
||||
hmmc->ErrorCode |= HAL_MMC_ERROR_BLOCK_LEN_ERR;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if ((BlockAdd % 8U) != 0U)
|
||||
{
|
||||
/* The address should be aligned to 8 (corresponding to 4 KBytes blocks) */
|
||||
hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_MISALIGNED;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
DmaBase0_reg = hmmc->Instance->IDMABASE0;
|
||||
DmaBase1_reg = hmmc->Instance->IDMABASE1;
|
||||
|
||||
if ((hmmc->Instance->IDMABSIZE == 0U) || (DmaBase0_reg == 0U) || (DmaBase1_reg == 0U))
|
||||
{
|
||||
hmmc->ErrorCode = HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Initialize data control register */
|
||||
hmmc->Instance->DCTRL = 0;
|
||||
|
||||
hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
|
||||
hmmc->State = HAL_MMC_STATE_BUSY;
|
||||
|
||||
if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
|
||||
{
|
||||
add *= 512U;
|
||||
}
|
||||
|
||||
/* Configure the MMC DPSM (Data Path State Machine) */
|
||||
config.DataTimeOut = SDMMC_DATATIMEOUT;
|
||||
config.DataLength = MMC_BLOCKSIZE * NumberOfBlocks;
|
||||
config.DataBlockSize = SDMMC_DATABLOCK_SIZE_512B;
|
||||
config.TransferDir = SDMMC_TRANSFER_DIR_TO_SDMMC;
|
||||
config.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
|
||||
config.DPSM = SDMMC_DPSM_DISABLE;
|
||||
(void)SDMMC_ConfigData(hmmc->Instance, &config);
|
||||
|
||||
hmmc->Instance->DCTRL |= SDMMC_DCTRL_FIFORST;
|
||||
|
||||
__SDMMC_CMDTRANS_ENABLE(hmmc->Instance);
|
||||
|
||||
hmmc->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
|
||||
|
||||
/* Read Blocks in DMA mode */
|
||||
hmmc->Context = (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_DMA);
|
||||
|
||||
/* Read Multi Block command */
|
||||
errorstate = SDMMC_CmdReadMultiBlock(hmmc->Instance, add);
|
||||
if (errorstate != HAL_MMC_ERROR_NONE)
|
||||
{
|
||||
hmmc->State = HAL_MMC_STATE_READY;
|
||||
hmmc->ErrorCode |= errorstate;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
__HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_RXOVERR | SDMMC_IT_DATAEND |
|
||||
SDMMC_FLAG_IDMATE | SDMMC_FLAG_IDMABTC));
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write block(s) to a specified address in a card. The transferred Data are stored in Buffer0 and Buffer1.
|
||||
* Buffer0, Buffer1 and BufferSize need to be configured by function HAL_MMCEx_ConfigDMAMultiBuffer before
|
||||
* call this function.
|
||||
* @param hmmc: MMC handle
|
||||
* @param BlockAdd: Block Address from where data is to be read
|
||||
* @param NumberOfBlocks: Total number of blocks to read
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MMCEx_WriteBlocksDMAMultiBuffer(MMC_HandleTypeDef *hmmc, uint32_t BlockAdd,
|
||||
uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDMMC_DataInitTypeDef config;
|
||||
uint32_t errorstate;
|
||||
uint32_t DmaBase0_reg;
|
||||
uint32_t DmaBase1_reg;
|
||||
uint32_t add = BlockAdd;
|
||||
|
||||
if (hmmc->State == HAL_MMC_STATE_READY)
|
||||
{
|
||||
if ((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
|
||||
{
|
||||
hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Check the case of 4kB blocks (field DATA SECTOR SIZE of extended CSD register) */
|
||||
if (((hmmc->Ext_CSD[(MMC_EXT_CSD_DATA_SEC_SIZE_INDEX / 4)] >> MMC_EXT_CSD_DATA_SEC_SIZE_POS) & 0x000000FFU) != 0x0U)
|
||||
{
|
||||
if ((NumberOfBlocks % 8U) != 0U)
|
||||
{
|
||||
/* The number of blocks should be a multiple of 8 sectors of 512 bytes = 4 KBytes */
|
||||
hmmc->ErrorCode |= HAL_MMC_ERROR_BLOCK_LEN_ERR;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if ((BlockAdd % 8U) != 0U)
|
||||
{
|
||||
/* The address should be aligned to 8 (corresponding to 4 KBytes blocks) */
|
||||
hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_MISALIGNED;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
DmaBase0_reg = hmmc->Instance->IDMABASE0;
|
||||
DmaBase1_reg = hmmc->Instance->IDMABASE1;
|
||||
|
||||
if ((hmmc->Instance->IDMABSIZE == 0U) || (DmaBase0_reg == 0U) || (DmaBase1_reg == 0U))
|
||||
{
|
||||
hmmc->ErrorCode = HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Initialize data control register */
|
||||
hmmc->Instance->DCTRL = 0;
|
||||
|
||||
hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
|
||||
|
||||
hmmc->State = HAL_MMC_STATE_BUSY;
|
||||
|
||||
if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
|
||||
{
|
||||
add *= 512U;
|
||||
}
|
||||
|
||||
/* Configure the MMC DPSM (Data Path State Machine) */
|
||||
config.DataTimeOut = SDMMC_DATATIMEOUT;
|
||||
config.DataLength = MMC_BLOCKSIZE * NumberOfBlocks;
|
||||
config.DataBlockSize = SDMMC_DATABLOCK_SIZE_512B;
|
||||
config.TransferDir = SDMMC_TRANSFER_DIR_TO_CARD;
|
||||
config.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
|
||||
config.DPSM = SDMMC_DPSM_DISABLE;
|
||||
(void)SDMMC_ConfigData(hmmc->Instance, &config);
|
||||
|
||||
__SDMMC_CMDTRANS_ENABLE(hmmc->Instance);
|
||||
|
||||
hmmc->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
|
||||
|
||||
/* Write Blocks in DMA mode */
|
||||
hmmc->Context = (MMC_CONTEXT_WRITE_MULTIPLE_BLOCK | MMC_CONTEXT_DMA);
|
||||
|
||||
/* Write Multi Block command */
|
||||
errorstate = SDMMC_CmdWriteMultiBlock(hmmc->Instance, add);
|
||||
if (errorstate != HAL_MMC_ERROR_NONE)
|
||||
{
|
||||
hmmc->State = HAL_MMC_STATE_READY;
|
||||
hmmc->ErrorCode |= errorstate;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
__HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_TXUNDERR | SDMMC_IT_DATAEND |
|
||||
SDMMC_FLAG_IDMATE | SDMMC_FLAG_IDMABTC));
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Change the DMA Buffer0 or Buffer1 address on the fly.
|
||||
* @param hmmc: pointer to a MMC_HandleTypeDef structure.
|
||||
* @param Buffer: the buffer to be changed, This parameter can be one of
|
||||
* the following values: MMC_DMA_BUFFER0 or MMC_DMA_BUFFER1
|
||||
* @param pDataBuffer: The new address
|
||||
* @note The BUFFER0 address can be changed only when the current transfer use
|
||||
* BUFFER1 and the BUFFER1 address can be changed only when the current
|
||||
* transfer use BUFFER0.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_MMCEx_ChangeDMABuffer(MMC_HandleTypeDef *hmmc, HAL_MMCEx_DMABuffer_MemoryTypeDef Buffer,
|
||||
uint32_t *pDataBuffer)
|
||||
{
|
||||
if (Buffer == MMC_DMA_BUFFER0)
|
||||
{
|
||||
/* change the buffer0 address */
|
||||
hmmc->Instance->IDMABASE0 = (uint32_t)pDataBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* change the memory1 address */
|
||||
hmmc->Instance->IDMABASE1 = (uint32_t)pDataBuffer;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_MMC_MODULE_ENABLED */
|
||||
#endif /* SDMMC1 || SDMMC2 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,315 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_sd_ex.c
|
||||
* @author MCD Application Team
|
||||
* @brief SD card Extended HAL module driver.
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Secure Digital (SD) peripheral:
|
||||
* + Extended features functions
|
||||
*
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
The SD Extension HAL driver can be used as follows:
|
||||
(+) Configure Buffer0 and Buffer1 start address and Buffer size using HAL_SDEx_ConfigDMAMultiBuffer() function.
|
||||
(+) Start Read and Write for multibuffer mode using HAL_SDEx_ReadBlocksDMAMultiBuffer()
|
||||
and HAL_SDEx_WriteBlocksDMAMultiBuffer() functions.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup SDEx SDEx
|
||||
* @brief SD Extended HAL module driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined (SDMMC1) || defined (SDMMC2)
|
||||
#ifdef HAL_SD_MODULE_ENABLED
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
/** @addtogroup SDEx_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup SDEx_Exported_Functions_Group1
|
||||
* @brief Multibuffer functions
|
||||
*
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### Multibuffer functions #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This section provides functions allowing to configure the multibuffer mode and start read and write
|
||||
multibuffer mode for SD HAL driver.
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Configure DMA Dual Buffer mode. The Data transfer is managed by an Internal DMA.
|
||||
* @param hsd: SD handle
|
||||
* @param pDataBuffer0: Pointer to the buffer0 that will contain/receive the transferred data
|
||||
* @param pDataBuffer1: Pointer to the buffer1 that will contain/receive the transferred data
|
||||
* @param BufferSize: Size of Buffer0 in Blocks. Buffer0 and Buffer1 must have the same size.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDEx_ConfigDMAMultiBuffer(SD_HandleTypeDef *hsd, uint32_t *pDataBuffer0, uint32_t *pDataBuffer1,
|
||||
uint32_t BufferSize)
|
||||
{
|
||||
if (hsd->State == HAL_SD_STATE_READY)
|
||||
{
|
||||
hsd->Instance->IDMABASE0 = (uint32_t) pDataBuffer0;
|
||||
hsd->Instance->IDMABASE1 = (uint32_t) pDataBuffer1;
|
||||
hsd->Instance->IDMABSIZE = (uint32_t)(BLOCKSIZE * BufferSize);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads block(s) from a specified address in a card. The received Data will be stored in Buffer0 and Buffer1.
|
||||
* Buffer0, Buffer1 and BufferSize need to be configured by function HAL_SDEx_ConfigDMAMultiBuffer before
|
||||
* call this function.
|
||||
* @param hsd: SD handle
|
||||
* @param BlockAdd: Block Address from where data is to be read
|
||||
* @param NumberOfBlocks: Total number of blocks to read
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDEx_ReadBlocksDMAMultiBuffer(SD_HandleTypeDef *hsd, uint32_t BlockAdd, uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDMMC_DataInitTypeDef config;
|
||||
uint32_t errorstate;
|
||||
uint32_t DmaBase0_reg;
|
||||
uint32_t DmaBase1_reg;
|
||||
uint32_t add = BlockAdd;
|
||||
|
||||
if (hsd->State == HAL_SD_STATE_READY)
|
||||
{
|
||||
if ((add + NumberOfBlocks) > (hsd->SdCard.LogBlockNbr))
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
DmaBase0_reg = hsd->Instance->IDMABASE0;
|
||||
DmaBase1_reg = hsd->Instance->IDMABASE1;
|
||||
|
||||
if ((hsd->Instance->IDMABSIZE == 0U) || (DmaBase0_reg == 0U) || (DmaBase1_reg == 0U))
|
||||
{
|
||||
hsd->ErrorCode = HAL_SD_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Initialize data control register */
|
||||
hsd->Instance->DCTRL = 0;
|
||||
/* Clear old Flags*/
|
||||
__HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_DATA_FLAGS);
|
||||
|
||||
hsd->ErrorCode = HAL_SD_ERROR_NONE;
|
||||
hsd->State = HAL_SD_STATE_BUSY;
|
||||
|
||||
if (hsd->SdCard.CardType != CARD_SDHC_SDXC)
|
||||
{
|
||||
add *= 512U;
|
||||
}
|
||||
|
||||
/* Configure the SD DPSM (Data Path State Machine) */
|
||||
config.DataTimeOut = SDMMC_DATATIMEOUT;
|
||||
config.DataLength = BLOCKSIZE * NumberOfBlocks;
|
||||
config.DataBlockSize = SDMMC_DATABLOCK_SIZE_512B;
|
||||
config.TransferDir = SDMMC_TRANSFER_DIR_TO_SDMMC;
|
||||
config.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
|
||||
config.DPSM = SDMMC_DPSM_DISABLE;
|
||||
(void)SDMMC_ConfigData(hsd->Instance, &config);
|
||||
|
||||
hsd->Instance->DCTRL |= SDMMC_DCTRL_FIFORST;
|
||||
|
||||
__SDMMC_CMDTRANS_ENABLE(hsd->Instance);
|
||||
|
||||
hsd->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
|
||||
|
||||
/* Read Blocks in DMA mode */
|
||||
hsd->Context = (SD_CONTEXT_READ_MULTIPLE_BLOCK | SD_CONTEXT_DMA);
|
||||
|
||||
/* Read Multi Block command */
|
||||
errorstate = SDMMC_CmdReadMultiBlock(hsd->Instance, add);
|
||||
if (errorstate != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->State = HAL_SD_STATE_READY;
|
||||
hsd->ErrorCode |= errorstate;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
__HAL_SD_ENABLE_IT(hsd, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_RXOVERR | SDMMC_IT_DATAEND |
|
||||
SDMMC_IT_IDMABTC));
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write block(s) to a specified address in a card. The transferred Data are stored in Buffer0 and Buffer1.
|
||||
* Buffer0, Buffer1 and BufferSize need to be configured by function HAL_SDEx_ConfigDMAMultiBuffer before
|
||||
* call this function.
|
||||
* @param hsd: SD handle
|
||||
* @param BlockAdd: Block Address from where data is to be read
|
||||
* @param NumberOfBlocks: Total number of blocks to read
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDEx_WriteBlocksDMAMultiBuffer(SD_HandleTypeDef *hsd, uint32_t BlockAdd, uint32_t NumberOfBlocks)
|
||||
{
|
||||
SDMMC_DataInitTypeDef config;
|
||||
uint32_t errorstate;
|
||||
uint32_t DmaBase0_reg;
|
||||
uint32_t DmaBase1_reg;
|
||||
uint32_t add = BlockAdd;
|
||||
|
||||
if (hsd->State == HAL_SD_STATE_READY)
|
||||
{
|
||||
if ((add + NumberOfBlocks) > (hsd->SdCard.LogBlockNbr))
|
||||
{
|
||||
hsd->ErrorCode |= HAL_SD_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
DmaBase0_reg = hsd->Instance->IDMABASE0;
|
||||
DmaBase1_reg = hsd->Instance->IDMABASE1;
|
||||
if ((hsd->Instance->IDMABSIZE == 0U) || (DmaBase0_reg == 0U) || (DmaBase1_reg == 0U))
|
||||
{
|
||||
hsd->ErrorCode = HAL_SD_ERROR_ADDR_OUT_OF_RANGE;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Initialize data control register */
|
||||
hsd->Instance->DCTRL = 0;
|
||||
|
||||
hsd->ErrorCode = HAL_SD_ERROR_NONE;
|
||||
|
||||
hsd->State = HAL_SD_STATE_BUSY;
|
||||
|
||||
if (hsd->SdCard.CardType != CARD_SDHC_SDXC)
|
||||
{
|
||||
add *= 512U;
|
||||
}
|
||||
|
||||
/* Configure the SD DPSM (Data Path State Machine) */
|
||||
config.DataTimeOut = SDMMC_DATATIMEOUT;
|
||||
config.DataLength = BLOCKSIZE * NumberOfBlocks;
|
||||
config.DataBlockSize = SDMMC_DATABLOCK_SIZE_512B;
|
||||
config.TransferDir = SDMMC_TRANSFER_DIR_TO_CARD;
|
||||
config.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
|
||||
config.DPSM = SDMMC_DPSM_DISABLE;
|
||||
(void)SDMMC_ConfigData(hsd->Instance, &config);
|
||||
|
||||
__SDMMC_CMDTRANS_ENABLE(hsd->Instance);
|
||||
|
||||
hsd->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_DOUBLE_BUFF0;
|
||||
|
||||
/* Write Blocks in DMA mode */
|
||||
hsd->Context = (SD_CONTEXT_WRITE_MULTIPLE_BLOCK | SD_CONTEXT_DMA);
|
||||
|
||||
/* Write Multi Block command */
|
||||
errorstate = SDMMC_CmdWriteMultiBlock(hsd->Instance, add);
|
||||
if (errorstate != HAL_SD_ERROR_NONE)
|
||||
{
|
||||
hsd->State = HAL_SD_STATE_READY;
|
||||
hsd->ErrorCode |= errorstate;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
__HAL_SD_ENABLE_IT(hsd, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_TXUNDERR | SDMMC_IT_DATAEND |
|
||||
SDMMC_IT_IDMABTC));
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Change the DMA Buffer0 or Buffer1 address on the fly.
|
||||
* @param hsd: pointer to a SD_HandleTypeDef structure.
|
||||
* @param Buffer: the buffer to be changed, This parameter can be one of
|
||||
* the following values: SD_DMA_BUFFER0 or SD_DMA_BUFFER1
|
||||
* @param pDataBuffer: The new address
|
||||
* @note The BUFFER0 address can be changed only when the current transfer use
|
||||
* BUFFER1 and the BUFFER1 address can be changed only when the current
|
||||
* transfer use BUFFER0.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SDEx_ChangeDMABuffer(SD_HandleTypeDef *hsd, HAL_SDEx_DMABuffer_MemoryTypeDef Buffer,
|
||||
uint32_t *pDataBuffer)
|
||||
{
|
||||
if (Buffer == SD_DMA_BUFFER0)
|
||||
{
|
||||
/* change the buffer0 address */
|
||||
hsd->Instance->IDMABASE0 = (uint32_t)pDataBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* change the memory1 address */
|
||||
hsd->Instance->IDMABASE1 = (uint32_t)pDataBuffer;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* HAL_SD_MODULE_ENABLED */
|
||||
#endif /* SDMMC1 || SDMMC2 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,214 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_ll_delayblock.c
|
||||
* @author MCD Application Team
|
||||
* @brief DelayBlock Low Layer HAL module driver.
|
||||
*
|
||||
* This file provides firmware functions to manage the following
|
||||
* functionalities of the Delay Block peripheral:
|
||||
* + input clock frequency range 25MHz to 208MHz
|
||||
* + up to 12 oversampling phases
|
||||
*
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
==============================================================================
|
||||
##### DelayBlock peripheral features #####
|
||||
==============================================================================
|
||||
[..] The Delay block is used to generate an Output clock which is de-phased from the Input
|
||||
clock. The phase of the Output clock is programmed by FW. The Output clock is then used
|
||||
to clock the receive data in i.e. a SDMMC or QSPI interface.
|
||||
The delay is Voltage and Temperature dependent, which may require FW to do re-tuning
|
||||
and recenter the Output clock phase to the receive data.
|
||||
|
||||
[..] The Delay Block features include the following:
|
||||
(+) Input clock frequency range 25MHz to 208MHz.
|
||||
(+) Up to 12 oversampling phases.
|
||||
|
||||
##### How to use this driver #####
|
||||
==============================================================================
|
||||
[..]
|
||||
This driver is a considered as a driver of service for external devices drivers
|
||||
that interfaces with the DELAY peripheral.
|
||||
The DelayBlock_Enable() function, enables the DelayBlock instance, configure the delay line length
|
||||
and configure the Output clock phase.
|
||||
The DelayBlock_Disable() function, disables the DelayBlock instance by setting DEN flag to 0.
|
||||
|
||||
|
||||
@endverbatim
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
/** @addtogroup STM32H7xx_HAL_Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup DELAYBLOCK_LL DELAYBLOCK_LL
|
||||
* @brief Low layer module for Delay Block
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(HAL_SD_MODULE_ENABLED) || defined(HAL_QSPI_MODULE_ENABLED)
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/** @defgroup DelayBlock_LL_Private_Defines Delay Block Low Layer Private Defines
|
||||
* @{
|
||||
*/
|
||||
#define DLYB_TIMEOUT 0xFFU
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
|
||||
/** @defgroup DelayBlock_LL_Exported_Functions Delay Block Low Layer Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup HAL_DELAY_LL_Group1 Initialization de-initialization functions
|
||||
* @brief Initialization and Configuration functions
|
||||
*
|
||||
@verbatim
|
||||
===============================================================================
|
||||
##### Initialization and de-initialization functions #####
|
||||
===============================================================================
|
||||
[..] This section provides functions allowing to:
|
||||
|
||||
@endverbatim
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable the Delay Block instance.
|
||||
* @param DLYBx: Pointer to DLYB instance.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef DelayBlock_Enable(DLYB_TypeDef *DLYBx)
|
||||
{
|
||||
uint32_t unit = 0U;
|
||||
uint32_t sel = 0U;
|
||||
uint32_t sel_current;
|
||||
uint32_t unit_current;
|
||||
uint32_t tuning;
|
||||
uint32_t lng_mask;
|
||||
uint32_t tickstart;
|
||||
|
||||
DLYBx->CR = DLYB_CR_DEN | DLYB_CR_SEN;
|
||||
|
||||
for (sel_current = 0U; sel_current < DLYB_MAX_SELECT; sel_current++)
|
||||
{
|
||||
/* lng_mask is the mask bit for the LNG field to check the output of the UNITx*/
|
||||
lng_mask = DLYB_CFGR_LNG_0 << sel_current;
|
||||
tuning = 0U;
|
||||
for (unit_current = 0U; unit_current < DLYB_MAX_UNIT; unit_current++)
|
||||
{
|
||||
/* Set the Delay of the UNIT(s)*/
|
||||
DLYBx->CFGR = DLYB_MAX_SELECT | (unit_current << DLYB_CFGR_UNIT_Pos);
|
||||
|
||||
/* Waiting for a LNG valid value */
|
||||
tickstart = HAL_GetTick();
|
||||
while ((DLYBx->CFGR & DLYB_CFGR_LNGF) == 0U)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart) >= DLYB_TIMEOUT)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
if (tuning == 0U)
|
||||
{
|
||||
if ((DLYBx->CFGR & lng_mask) != 0U)
|
||||
{
|
||||
/* 1/2 period HIGH is detected */
|
||||
tuning = 1U;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 1/2 period LOW detected after the HIGH 1/2 period => FULL PERIOD passed*/
|
||||
if((DLYBx->CFGR & lng_mask ) == 0U)
|
||||
{
|
||||
/* Save the first result */
|
||||
if( unit == 0U )
|
||||
{
|
||||
unit = unit_current;
|
||||
sel = sel_current + 1U;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Apply the Tuning settings */
|
||||
DLYBx->CR = 0U;
|
||||
DLYBx->CR = DLYB_CR_DEN | DLYB_CR_SEN;
|
||||
DLYBx->CFGR = sel | (unit << DLYB_CFGR_UNIT_Pos);
|
||||
DLYBx->CR = DLYB_CR_DEN;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable the Delay Block instance.
|
||||
* @param DLYBx: Pointer to DLYB instance.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef DelayBlock_Disable(DLYB_TypeDef *DLYBx)
|
||||
{
|
||||
/* Disable DLYB */
|
||||
DLYBx->CR = 0U;
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure the Delay Block instance.
|
||||
* @param DLYBx: Pointer to DLYB instance.
|
||||
* @param PhaseSel: Phase selection [0..11].
|
||||
* @param Units: Delay units[0..127].
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef DelayBlock_Configure(DLYB_TypeDef *DLYBx,uint32_t PhaseSel, uint32_t Units )
|
||||
{
|
||||
/* Apply the delay settings */
|
||||
|
||||
DLYBx->CR = 0U;
|
||||
DLYBx->CR = DLYB_CR_DEN | DLYB_CR_SEN;
|
||||
DLYBx->CFGR = PhaseSel | (Units << DLYB_CFGR_UNIT_Pos);
|
||||
DLYBx->CR = DLYB_CR_DEN;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* (HAL_SD_MODULE_ENABLED) & (HAL_QSPI_MODULE_ENABLED)*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user