Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
cubexHal.pdf
Скачиваний:
111
Добавлен:
10.02.2016
Размер:
16.16 Mб
Скачать

UM1725

HAL SD Generic Driver

uint16_t RCA

uint8_t CardType

Field Documentation

HAL_SD_CSDTypedef HAL_SD_CardInfoTypedef::SD_csd

SD card specific data register

HAL_SD_CIDTypedef HAL_SD_CardInfoTypedef::SD_cid

SD card identification number register

uint64_t HAL_SD_CardInfoTypedef::CardCapacity

Card capacity

uint32_t HAL_SD_CardInfoTypedef::CardBlockSize

Card block size

uint16_t HAL_SD_CardInfoTypedef::RCA

SD relative card address

uint8_t HAL_SD_CardInfoTypedef::CardType

SD card type

53.2SD Firmware driver API description

53.2.1How 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 (SDIO and GPIO) are performed by the user in HAL_SD_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 SDIO memories which uses the HAL SDIO driver functions to interface with SD and uSD cards devices. It is used as follows:

1.Initialize the SDIO low level resources by implement the HAL_SD_MspInit() API:

a.Enable the SDIO interface clock using __HAL_RCC_SDIO_CLK_ENABLE();

b.SDIO pins configuration for SD card

Enable the clock for the SDIO GPIOs using the functions __HAL_RCC_GPIOx_CLK_ENABLE();

Configure these SDIO pins as alternate function pull-up using HAL_GPIO_Init() and according to your pin assignment;

c.DMA Configuration if you need to use DMA process

(HAL_SD_ReadBlocks_DMA() and HAL_SD_WriteBlocks_DMA() APIs).

Enable the DMAx interface clock using __HAL_RCC_DMAx_CLK_ENABLE();

Configure the DMA using the function HAL_DMA_Init() with predeclared and filled.

d. NVIC configuration if you need to use interrupt process when using DMA transfer.

Configure the SDIO and DMA interrupt priorities using functions

HAL_NVIC_SetPriority(); DMA priority is superior to SDIO's priority

Enable the NVIC DMA and SDIO IRQs using function HAL_NVIC_EnableIRQ()

SDIO interrupts are managed using the macros

__HAL_SD_SDIO_ENABLE_IT() and __HAL_SD_SDIO_DISABLE_IT() inside the communication process.

DOCID025834 Rev 2

701/900

HAL SD Generic Driver

UM1725

SDIO interrupts pending bits are managed using the macros __HAL_SD_SDIO_GET_IT() and __HAL_SD_SDIO_CLEAR_IT()

2. At this stage, you can perform SD read/write/erase operations after SD card initialization

SD Card Initialization and configuration

To initialize the SD Card, use the HAL_SD_Init() function. It Initializes the SD Card and put it into Standby State (Ready for data transfer). This function provide the following operations:

1.Apply the SD Card initialization process at 400KHz and check the SD Card type (Standard Capacity or High Capacity). You can change or adapt this frequency by adjusting the "ClockDiv" field. The SD Card frequency (SDIO_CK) is computed as follows: SDIO_CK = SDIOCLK / (ClockDiv + 2) In initialization mode and according to the SD Card standard, make sure that the SDIO_CK frequency doesn't exceed 400KHz.

2.Get the SD CID and CSD data. All these information are managed by the SDCardInfo structure. This structure provide also ready computed SD Card capacity and Block size. These information are stored in SD handle structure in case of future use.

3.Configure the SD Card Data transfer frequency. By Default, the card transfer frequency is set to 24MHz. You can change or adapt this frequency by adjusting the "ClockDiv" field. In transfer mode and according to the SD Card standard, make sure that the SDIO_CK frequency doesn't exceed 25MHz and 50MHz in High-speed mode switch. To be able to use a frequency higher than 24MHz, you should use the SDIO peripheral in bypass mode. Refer to the corresponding reference manual for more details.

4.Select the corresponding SD Card according to the address read with the step 2.

5.Configure the SD Card in wide bus mode: 4-bits data.

SD Card Read operation

You can read from SD card in polling mode by using function HAL_SD_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.

You can read from SD card in DMA mode by using function

HAL_SD_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 call the function HAL_SD_CheckReadOperation(), to insure that the read transfer is done correctly in both DMA and SD sides.

SD Card Write operation

You can write to SD card in polling mode by using function HAL_SD_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.

You can write to SD card in DMA mode by using function

HAL_SD_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"

702/900

DOCID025834 Rev 2

UM1725 HAL SD Generic Driver

parameter. After this, you have to call the function HAL_SD_CheckWriteOperation(), to insure that the write transfer is done correctly in both DMA and SD sides.

SD card status

At any time, you can check the SD Card status and get the SD card state by using the HAL_SD_GetStatus() function. This function checks first if the SD card is still connected and then get the internal SD Card transfer state.

You can also get the SD card SD Status register by using the

HAL_SD_SendSDStatus() function.

SD HAL driver macros list

You can refer to the SD HAL driver header file for more useful macros

53.2.2Initialization and de-initialization functions

This section provides functions allowing to initialize/de-initialize the SD card device to be ready for use.

This section contains the following APIs:

HAL_SD_Init()

HAL_SD_DeInit()

HAL_SD_MspInit()

HAL_SD_MspDeInit()

53.2.3IO operation functions

This subsection provides a set of functions allowing to manage the data transfer from/to SD card.

This section contains the following APIs:

HAL_SD_ReadBlocks()

HAL_SD_WriteBlocks()

HAL_SD_ReadBlocks_DMA()

HAL_SD_WriteBlocks_DMA()

HAL_SD_CheckReadOperation()

HAL_SD_CheckWriteOperation()

HAL_SD_Erase()

HAL_SD_IRQHandler()

HAL_SD_XferCpltCallback()

HAL_SD_XferErrorCallback()

HAL_SD_DMA_RxCpltCallback()

HAL_SD_DMA_RxErrorCallback()

HAL_SD_DMA_TxCpltCallback()

HAL_SD_DMA_TxErrorCallback()

53.2.4Peripheral Control functions

This subsection provides a set of functions allowing to control the SD card operations.

DOCID025834 Rev 2

703/900

HAL SD Generic Driver

UM1725

This section contains the following APIs:

 

HAL_SD_Get_CardInfo()

HAL_SD_WideBusOperation_Config()

HAL_SD_StopTransfer()

HAL_SD_HighSpeed()

53.2.5Peripheral State functions

This subsection permits to get in runtime the status of the peripheral and the data flow.

This section contains the following APIs:

HAL_SD_SendSDStatus()

HAL_SD_GetStatus()

HAL_SD_GetCardStatus()

53.2.6HAL_SD_Init

 

Function Name

HAL_SD_ErrorTypedef HAL_SD_Init (SD_HandleTypeDef *

 

 

hsd, HAL_SD_CardInfoTypedef * SDCardInfo)

 

Function Description

Initializes the SD card according to the specified parameters in the

 

 

SD_HandleTypeDef and create the associated handle.

 

Parameters

 

hsd: SD handle

 

 

SDCardInfo: HAL_SD_CardInfoTypedef structure for SD

 

 

 

card information

 

Return values

HAL SD error state

53.2.7

HAL_SD_DeInit

 

 

 

Function Name

HAL_StatusTypeDef HAL_SD_DeInit (SD_HandleTypeDef *

 

 

hsd)

 

 

Function Description

De-Initializes the SD card.

 

Parameters

 

hsd: SD handle

 

Return values

 

HAL status

53.2.8HAL_SD_MspInit

Function Name

void HAL_SD_MspInit (SD_HandleTypeDef * hsd)

Function Description

Initializes the SD MSP.

Parameters

 

hsd: SD handle

Return values

 

None

53.2.9HAL_SD_MspDeInit

Function Name

void HAL_SD_MspDeInit (SD_HandleTypeDef * hsd)

Function Description

De-Initialize SD MSP.

Parameters

 

hsd: SD handle

Return values

 

None

704/900

 

DOCID025834 Rev 2

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]