Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is STM32 SDIO?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you what STM32 SDIO is, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to understand it!

1. Introduction to SDIO

SDIO, full name: Secure Digital Input and Output, that is, secure digital input and output interface. It is developed on the basis of SD card interface, it can be compatible with previous SD cards, and can connect SDIO interface devices, such as Bluetooth, WIFI, camera and so on.

An important difference between SDIO and SD card specifications is the addition of low-speed standards. The target application of the low-speed card is to support the low-speed Icano capability with minimal hardware expenditure. Low-speed cards support applications such as modems, bar code scanners and GPS receivers.

STM32's SDIO controller supports multimedia cards (MMC cards), SD memory cards, SDI/ O cards and CE-ATA devices.

SDIO block diagram

After reset, SDIO_D0 is used for data transmission. The host can change the width of the data bus after initialization (set by the ACMD6 command)

If a multimedia card is connected to the bus, SDIO_D0, SDIO_D [3:0] or SDIO_D [7:0] can be used for data transmission.

MMC version V3.31 and previous versions of the protocol only support 1-bit data lines, so we can only use SDIO_D0 (for generality, we set it to 1-bit bus data whenever we detect an MMC card in the program)

02. Characteristics of SDIO

① is fully compatible with version 4.2 of the multimedia card system specification. Three different data bus modes are supported: 1-bit (default), 4-bit and 8-bit.

② is fully compatible with earlier multimedia card system specifications (forward compatibility).

③ is fully compatible with SD memory card specification version 2.0.

④ is fully compatible with SDI/ O card specification version 2.0: supports two different data bus modes: 1-bit (default) and 4-bit.

⑤ fully supports the CE-ATA feature (fully compatible with CE-ATA digital protocol version 1.1). The data transfer rate can reach 48MHz in 8-bit bus mode.

⑥ data and commands output enable signals for controlling external bi-directional drivers.

03, SDIO clock

Card clock (SDIO_CK): each clock cycle transmits 1-bit command or data on the command and data line. For SD or SD I / O cards, the clock rate can vary from 0MHz to 25MHz.

SDIO Adapter clock (SDIOCLK): this clock is used to drive the SDIO adapter and can be used to generate SDIO_CK clocks. SDIOCLK is from PLL48CK (48Mhz).

APB2 bus interface clock (PCLK2): this clock is used to drive the APB2 bus interface of the SDIO at a frequency of PCLK2=84Mhz.

SDIO_CK calculation formula: SDIO_CK=SDIOCLK/ (2+CLKDIV)

Note: when initializing SD card, SDIO_CK cannot exceed 400Khz. After initialization, it can be set to the maximum frequency (but not more than the maximum operating frequency of SD card).

04. Command and response of SDIO

Command

The command of SDIO is divided into two parts: application related command (ACMD) and general command (CMD). When sending ACMD, you need to send CMD55 first.

All SDIO commands and responses are transmitted on the SDIO_CMD pin, and the command length is fixed at 48 bits. The format of the SDIO command is shown in the following table:

The format of STM32 SDIO long response (136bit) is shown in the following table

After receiving the R1 response, we can read the command index and card status information from the SDIO_RESPCMD register and the SDIO_RESP1 register, respectively. For an introduction to other responses, please refer to the CD-ROM: "SD Card 2.0 Protocol .pdf"

05. SDIO block data transmission

Multi-data block read operation

The communication between SDIO and SD card is generally transmitted in the form of data blocks, and SDIO (multiple) data block read operations, as shown in the following figure.

The data block write operation is basically similar to the data block read operation, except that when the data block is written, there is a busy judgment, and the new data block must be sent when the SD card is not busy. The busy signal here is pulled down the SDIO_D0 by the SD card to indicate that it is busy. The SDIO hardware is automatically controlled and does not need our software processing.

Note: when the SDIO_CK frequency is too fast, it may cause the SD card communication to fail. At this time, it is recommended to try to lower the SDIO_CK.

06, Code

The SDIO controller driver of STM32 is still very complex. ST provides the stm32f2x_sdio_sd.c driver file, and our group needs to modify the corresponding GPIO driver.

/ * * @ brief Initializes the SD Card and put it into StandBy State (Ready for * data transfer) * @ param None * @ retval None * / void SD_LowLevel_Init (void) {GPIO_InitTypeDef GPIO_InitStructure; / * GPIOC and GPIOD Periph clock enable * / RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | SD_DETECT_GPIO_CLK, ENABLE); GPIO_PinAFConfig (GPIOC, GPIO_PinSource8, GPIO_AF_SDIO); GPIO_PinAFConfig (GPIOC, GPIO_PinSource9, GPIO_AF_SDIO); GPIO_PinAFConfig (GPIOC, GPIO_PinSource10, GPIO_AF_SDIO) GPIO_PinAFConfig (GPIOC, GPIO_PinSource11, GPIO_AF_SDIO); GPIO_PinAFConfig (GPIOC, GPIO_PinSource12, GPIO_AF_SDIO); GPIO_PinAFConfig (GPIOD, GPIO_PinSource2, GPIO_AF_SDIO); / * Configure PC.08, PC.09, PC.10, PC.11 pins: D0, D1, D2, D3 pins * / GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init (GPIOC, & GPIO_InitStructure); / * Configure PD.02 CMD line * / GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_Init (GPIOD, & GPIO_InitStructure) / * Configure PC.12 pin: CLK pin * / GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init (GPIOC, & GPIO_InitStructure); / *! < Configure SD_SPI_DETECT_PIN pin: SD Card detect pin * / / * GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP GPIO_Init (SD_DETECT_GPIO_PORT, & GPIO_InitStructure); * / * Enable the SDIO APB2 Clock * / RCC_APB2PeriphClockCmd (RCC_APB2Periph_SDIO, ENABLE); / * Enable the DMA2 Clock * / RCC_AHB1PeriphClockCmd (SD_SDIO_DMA_CLK, ENABLE);}

DMA and other configurations can be configured by default.

The function interfaces we need to use are

SD_Error SD_Init (void); SD_Error SD_Erase (uint32_t startaddr, uint32_t endaddr); SD_Error SD_WriteBlock (uint8_t * writebuff, uint32_t WriteAddr, uint16_t BlockSize); SD_Error SD_ReadBlock (uint8_t * readbuff, uint32_t ReadAddr, uint16_t BlockSize); above is all the content of this article, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report