Sd Card Initialization And Configuration; Sd Card Read Operation - ST STM32F2 User Manual

Description of stm32f2 hal and low layer drivers
Hide thumbs Also See for STM32F2:
Table of Contents

Advertisement

HAL SD Generic Driver
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 SDIO IP(STM32
side) and the SD Card, and put it into StandBy State (Ready for data transfer). This
function provide the following operations:
1.
Initialize the SDIO 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 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. This
phase of initialization is done through SDIO_Init() and SDIO_PowerState_ON() SDIO
low level APIs.
2.
Initialize the SD card. The API used is HAL_SD_InitCard(). This phase allows the card
initialization and identification and check the SD Card type (Standard Capacity or High
Capacity) The initialization flow is compatible with SD standard. This API
(HAL_SD_InitCard()) could be used also to reinitialize the card in case of plug-off
plug-in.
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 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_SD_GetCardState() function for SD card state.
You can read from SD card in DMA mode by using function
HAL_SD_ReadBlocks_DMA(). 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_SD_GetCardState()
function for SD card state. You could also check the DMA transfer process through the
SD Rx interrupt event.
You can read from SD card in Interrupt mode by using function
HAL_SD_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_SD_GetCardState() function for SD
card state. You could also check the IT transfer process through the SD Rx interrupt
event.
514/1371
SDIO interrupts pending bits are managed using the macros
__HAL_SD_GET_IT() and __HAL_SD_CLEAR_IT()
DocID028236 Rev 2
UM1940

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the STM32F2 and is the answer not in the manual?

Questions and answers

Table of Contents

Save PDF