You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1583 lines
49 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_ll_sdmmc.c
  4. * @author MCD Application Team
  5. * @brief SDMMC Low Layer HAL module driver.
  6. *
  7. * This file provides firmware functions to manage the following
  8. * functionalities of the SDMMC peripheral:
  9. * + Initialization/de-initialization functions
  10. * + I/O operation functions
  11. * + Peripheral Control functions
  12. * + Peripheral State functions
  13. *
  14. @verbatim
  15. ==============================================================================
  16. ##### SDMMC peripheral features #####
  17. ==============================================================================
  18. [..] The SD/SDMMC MMC card host interface (SDMMC) provides an interface between the AHB
  19. peripheral bus and MultiMedia cards (MMCs), SD memory cards, SDMMC cards and CE-ATA
  20. devices.
  21. [..] The SDMMC features include the following:
  22. (+) Full compliance with MultiMediaCard System Specification Version 4.51. Card support
  23. for three different databus modes: 1-bit (default), 4-bit and 8-bit.
  24. (+) Full compatibility with previous versions of MultiMediaCards (backward compatibility).
  25. (+) Full compliance with SD memory card specifications version 4.1.
  26. (SDR104 SDMMC_CK speed limited to maximum allowed IO speed, SPI mode and
  27. UHS-II mode not supported).
  28. (+) Full compliance with SDIO card specification version 4.0. Card support
  29. for two different databus modes: 1-bit (default) and 4-bit.
  30. (SDR104 SDMMC_CK speed limited to maximum allowed IO speed, SPI mode and
  31. UHS-II mode not supported).
  32. (+) Data transfer up to 208 Mbyte/s for the 8 bit mode. (depending maximum allowed IO speed).
  33. (+) Data and command output enable signals to control external bidirectional drivers
  34. ##### How to use this driver #####
  35. ==============================================================================
  36. [..]
  37. This driver is a considered as a driver of service for external devices drivers
  38. that interfaces with the SDMMC peripheral.
  39. According to the device used (SD card/ MMC card / SDMMC card ...), a set of APIs
  40. is used in the device's driver to perform SDMMC operations and functionalities.
  41. This driver is almost transparent for the final user, it is only used to implement other
  42. functionalities of the external device.
  43. [..]
  44. (+) The SDMMC clock is coming from output of PLL1_Q or PLL2_R.
  45. Before start working with SDMMC peripheral make sure that the PLL is well configured.
  46. The SDMMC peripheral uses two clock signals:
  47. (++) PLL1_Q bus clock (default after reset)
  48. (++) PLL2_R bus clock
  49. (+) Enable/Disable peripheral clock using RCC peripheral macros related to SDMMC
  50. peripheral.
  51. (+) Enable the Power ON State using the SDMMC_PowerState_ON(SDMMCx)
  52. function and disable it using the function SDMMC_PowerState_OFF(SDMMCx).
  53. (+) Enable/Disable the peripheral interrupts using the macros __SDMMC_ENABLE_IT(hSDMMC, IT)
  54. and __SDMMC_DISABLE_IT(hSDMMC, IT) if you need to use interrupt mode.
  55. (+) When using the DMA mode
  56. (++) Configure the IDMA mode (Single buffer or double)
  57. (++) Configure the buffer address
  58. (++) Configure Data Path State Machine
  59. (+) To control the CPSM (Command Path State Machine) and send
  60. commands to the card use the SDMMC_SendCommand(SDMMCx),
  61. SDMMC_GetCommandResponse() and SDMMC_GetResponse() functions. First, user has
  62. to fill the command structure (pointer to SDMMC_CmdInitTypeDef) according
  63. to the selected command to be sent.
  64. The parameters that should be filled are:
  65. (++) Command Argument
  66. (++) Command Index
  67. (++) Command Response type
  68. (++) Command Wait
  69. (++) CPSM Status (Enable or Disable).
  70. -@@- To check if the command is well received, read the SDMMC_CMDRESP
  71. register using the SDMMC_GetCommandResponse().
  72. The SDMMC responses registers (SDMMC_RESP1 to SDMMC_RESP2), use the
  73. SDMMC_GetResponse() function.
  74. (+) To control the DPSM (Data Path State Machine) and send/receive
  75. data to/from the card use the SDMMC_DataConfig(), SDMMC_GetDataCounter(),
  76. SDMMC_ReadFIFO(), SDMMC_WriteFIFO() and SDMMC_GetFIFOCount() functions.
  77. *** Read Operations ***
  78. =======================
  79. [..]
  80. (#) First, user has to fill the data structure (pointer to
  81. SDMMC_DataInitTypeDef) according to the selected data type to be received.
  82. The parameters that should be filled are:
  83. (++) Data TimeOut
  84. (++) Data Length
  85. (++) Data Block size
  86. (++) Data Transfer direction: should be from card (To SDMMC)
  87. (++) Data Transfer mode
  88. (++) DPSM Status (Enable or Disable)
  89. (#) Configure the SDMMC resources to receive the data from the card
  90. according to selected transfer mode (Refer to Step 8, 9 and 10).
  91. (#) Send the selected Read command (refer to step 11).
  92. (#) Use the SDMMC flags/interrupts to check the transfer status.
  93. *** Write Operations ***
  94. ========================
  95. [..]
  96. (#) First, user has to fill the data structure (pointer to
  97. SDMMC_DataInitTypeDef) according to the selected data type to be received.
  98. The parameters that should be filled are:
  99. (++) Data TimeOut
  100. (++) Data Length
  101. (++) Data Block size
  102. (++) Data Transfer direction: should be to card (To CARD)
  103. (++) Data Transfer mode
  104. (++) DPSM Status (Enable or Disable)
  105. (#) Configure the SDMMC resources to send the data to the card according to
  106. selected transfer mode.
  107. (#) Send the selected Write command.
  108. (#) Use the SDMMC flags/interrupts to check the transfer status.
  109. *** Command management operations ***
  110. =====================================
  111. [..]
  112. (#) The commands used for Read/Write/Erase operations are managed in
  113. separate functions.
  114. Each function allows to send the needed command with the related argument,
  115. then check the response.
  116. By the same approach, you could implement a command and check the response.
  117. @endverbatim
  118. ******************************************************************************
  119. * @attention
  120. *
  121. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  122. * All rights reserved.</center></h2>
  123. *
  124. * This software component is licensed by ST under BSD 3-Clause license,
  125. * the "License"; You may not use this file except in compliance with the
  126. * License. You may obtain a copy of the License at:
  127. * opensource.org/licenses/BSD-3-Clause
  128. *
  129. ******************************************************************************
  130. */
  131. /* Includes ------------------------------------------------------------------*/
  132. #include "stm32h7xx_hal.h"
  133. /** @addtogroup STM32H7xx_HAL_Driver
  134. * @{
  135. */
  136. /** @defgroup SDMMC_LL SDMMC Low Layer
  137. * @brief Low layer module for SD
  138. * @{
  139. */
  140. #if defined (HAL_SD_MODULE_ENABLED) || defined (HAL_MMC_MODULE_ENABLED)
  141. /* Private typedef -----------------------------------------------------------*/
  142. /* Private define ------------------------------------------------------------*/
  143. /* Private macro -------------------------------------------------------------*/
  144. /* Private variables ---------------------------------------------------------*/
  145. /* Private function prototypes -----------------------------------------------*/
  146. static uint32_t SDMMC_GetCmdError(SDMMC_TypeDef *SDMMCx);
  147. static uint32_t SDMMC_GetCmdResp1(SDMMC_TypeDef *SDMMCx, uint8_t SD_CMD, uint32_t Timeout);
  148. static uint32_t SDMMC_GetCmdResp2(SDMMC_TypeDef *SDMMCx);
  149. static uint32_t SDMMC_GetCmdResp3(SDMMC_TypeDef *SDMMCx);
  150. static uint32_t SDMMC_GetCmdResp7(SDMMC_TypeDef *SDMMCx);
  151. static uint32_t SDMMC_GetCmdResp6(SDMMC_TypeDef *SDMMCx, uint8_t SD_CMD, uint16_t *pRCA);
  152. /* Exported functions --------------------------------------------------------*/
  153. /** @defgroup SDMMC_LL_Exported_Functions SDMMC Low Layer Exported Functions
  154. * @{
  155. */
  156. /** @defgroup HAL_SDMMC_LL_Group1 Initialization de-initialization functions
  157. * @brief Initialization and Configuration functions
  158. *
  159. @verbatim
  160. ===============================================================================
  161. ##### Initialization/de-initialization functions #####
  162. ===============================================================================
  163. [..] This section provides functions allowing to:
  164. @endverbatim
  165. * @{
  166. */
  167. /**
  168. * @brief Initializes the SDMMC according to the specified
  169. * parameters in the SDMMC_InitTypeDef and create the associated handle.
  170. * @param SDMMCx: Pointer to SDMMC register base
  171. * @param Init: SDMMC initialization structure
  172. * @retval HAL status
  173. */
  174. HAL_StatusTypeDef SDMMC_Init(SDMMC_TypeDef *SDMMCx, SDMMC_InitTypeDef Init)
  175. {
  176. uint32_t tmpreg = 0;
  177. /* Check the parameters */
  178. assert_param(IS_SDMMC_ALL_INSTANCE(SDMMCx));
  179. assert_param(IS_SDMMC_CLOCK_EDGE(Init.ClockEdge));
  180. assert_param(IS_SDMMC_CLOCK_POWER_SAVE(Init.ClockPowerSave));
  181. assert_param(IS_SDMMC_BUS_WIDE(Init.BusWide));
  182. assert_param(IS_SDMMC_HARDWARE_FLOW_CONTROL(Init.HardwareFlowControl));
  183. assert_param(IS_SDMMC_CLKDIV(Init.ClockDiv));
  184. /* Set SDMMC configuration parameters */
  185. tmpreg |= (Init.ClockEdge |\
  186. Init.ClockPowerSave |\
  187. Init.BusWide |\
  188. Init.HardwareFlowControl |\
  189. Init.ClockDiv
  190. );
  191. /* Write to SDMMC CLKCR */
  192. MODIFY_REG(SDMMCx->CLKCR, CLKCR_CLEAR_MASK, tmpreg);
  193. return HAL_OK;
  194. }
  195. /**
  196. * @}
  197. */
  198. /** @defgroup HAL_SDMMC_LL_Group2 IO operation functions
  199. * @brief Data transfers functions
  200. *
  201. @verbatim
  202. ===============================================================================
  203. ##### I/O operation functions #####
  204. ===============================================================================
  205. [..]
  206. This subsection provides a set of functions allowing to manage the SDMMC data
  207. transfers.
  208. @endverbatim
  209. * @{
  210. */
  211. /**
  212. * @brief Read data (word) from Rx FIFO in blocking mode (polling)
  213. * @param SDMMCx: Pointer to SDMMC register base
  214. * @retval HAL status
  215. */
  216. uint32_t SDMMC_ReadFIFO(SDMMC_TypeDef *SDMMCx)
  217. {
  218. /* Read data from Rx FIFO */
  219. return (SDMMCx->FIFO);
  220. }
  221. /**
  222. * @brief Write data (word) to Tx FIFO in blocking mode (polling)
  223. * @param SDMMCx: Pointer to SDMMC register base
  224. * @param pWriteData: pointer to data to write
  225. * @retval HAL status
  226. */
  227. HAL_StatusTypeDef SDMMC_WriteFIFO(SDMMC_TypeDef *SDMMCx, uint32_t *pWriteData)
  228. {
  229. /* Write data to FIFO */
  230. SDMMCx->FIFO = *pWriteData;
  231. return HAL_OK;
  232. }
  233. /**
  234. * @}
  235. */
  236. /** @defgroup HAL_SDMMC_LL_Group3 Peripheral Control functions
  237. * @brief management functions
  238. *
  239. @verbatim
  240. ===============================================================================
  241. ##### Peripheral Control functions #####
  242. ===============================================================================
  243. [..]
  244. This subsection provides a set of functions allowing to control the SDMMC data
  245. transfers.
  246. @endverbatim
  247. * @{
  248. */
  249. /**
  250. * @brief Set SDMMC Power state to ON.
  251. * @param SDMMCx: Pointer to SDMMC register base
  252. * @retval HAL status
  253. */
  254. HAL_StatusTypeDef SDMMC_PowerState_ON(SDMMC_TypeDef *SDMMCx)
  255. {
  256. /* Set power state to ON */
  257. SDMMCx->POWER |= SDMMC_POWER_PWRCTRL;
  258. return HAL_OK;
  259. }
  260. /**
  261. * @brief Set SDMMC Power state to Power-Cycle.
  262. * @param SDMMCx: Pointer to SDMMC register base
  263. * @retval HAL status
  264. */
  265. HAL_StatusTypeDef SDMMC_PowerState_Cycle(SDMMC_TypeDef *SDMMCx)
  266. {
  267. /* Set power state to Power Cycle*/
  268. SDMMCx->POWER |= SDMMC_POWER_PWRCTRL_1;
  269. return HAL_OK;
  270. }
  271. /**
  272. * @brief Set SDMMC Power state to OFF.
  273. * @param SDMMCx: Pointer to SDMMC register base
  274. * @retval HAL status
  275. */
  276. HAL_StatusTypeDef SDMMC_PowerState_OFF(SDMMC_TypeDef *SDMMCx)
  277. {
  278. /* Set power state to OFF */
  279. SDMMCx->POWER &= ~(SDMMC_POWER_PWRCTRL);
  280. return HAL_OK;
  281. }
  282. /**
  283. * @brief Get SDMMC Power state.
  284. * @param SDMMCx: Pointer to SDMMC register base
  285. * @retval Power status of the controller. The returned value can be one of the
  286. * following values:
  287. * - 0x00: Power OFF
  288. * - 0x02: Power UP
  289. * - 0x03: Power ON
  290. */
  291. uint32_t SDMMC_GetPowerState(SDMMC_TypeDef *SDMMCx)
  292. {
  293. return (SDMMCx->POWER & SDMMC_POWER_PWRCTRL);
  294. }
  295. /**
  296. * @brief Configure the SDMMC command path according to the specified parameters in
  297. * SDMMC_CmdInitTypeDef structure and send the command
  298. * @param SDMMCx: Pointer to SDMMC register base
  299. * @param Command: pointer to a SDMMC_CmdInitTypeDef structure that contains
  300. * the configuration information for the SDMMC command
  301. * @retval HAL status
  302. */
  303. HAL_StatusTypeDef SDMMC_SendCommand(SDMMC_TypeDef *SDMMCx, SDMMC_CmdInitTypeDef *Command)
  304. {
  305. uint32_t tmpreg = 0;
  306. /* Check the parameters */
  307. assert_param(IS_SDMMC_CMD_INDEX(Command->CmdIndex));
  308. assert_param(IS_SDMMC_RESPONSE(Command->Response));
  309. assert_param(IS_SDMMC_WAIT(Command->WaitForInterrupt));
  310. assert_param(IS_SDMMC_CPSM(Command->CPSM));
  311. /* Set the SDMMC Argument value */
  312. SDMMCx->ARG = Command->Argument;
  313. /* Set SDMMC command parameters */
  314. tmpreg |= (uint32_t)(Command->CmdIndex |\
  315. Command->Response |\
  316. Command->WaitForInterrupt |\
  317. Command->CPSM);
  318. /* Write to SDMMC CMD register */
  319. MODIFY_REG(SDMMCx->CMD, CMD_CLEAR_MASK, tmpreg);
  320. return HAL_OK;
  321. }
  322. /**
  323. * @brief Return the command index of last command for which response received
  324. * @param SDMMCx: Pointer to SDMMC register base
  325. * @retval Command index of the last command response received
  326. */
  327. uint8_t SDMMC_GetCommandResponse(SDMMC_TypeDef *SDMMCx)
  328. {
  329. return (uint8_t)(SDMMCx->RESPCMD);
  330. }
  331. /**
  332. * @brief Return the response received from the card for the last command
  333. * @param SDMMCx: Pointer to SDMMC register base
  334. * @param Response: Specifies the SDMMC response register.
  335. * This parameter can be one of the following values:
  336. * @arg SDMMC_RESP1: Response Register 1
  337. * @arg SDMMC_RESP2: Response Register 2
  338. * @arg SDMMC_RESP3: Response Register 3
  339. * @arg SDMMC_RESP4: Response Register 4
  340. * @retval The Corresponding response register value
  341. */
  342. uint32_t SDMMC_GetResponse(SDMMC_TypeDef *SDMMCx, uint32_t Response)
  343. {
  344. uint32_t tmp;
  345. /* Check the parameters */
  346. assert_param(IS_SDMMC_RESP(Response));
  347. /* Get the response */
  348. tmp = (uint32_t)(&(SDMMCx->RESP1)) + Response;
  349. return (*(__IO uint32_t *) tmp);
  350. }
  351. /**
  352. * @brief Configure the SDMMC data path according to the specified
  353. * parameters in the SDMMC_DataInitTypeDef.
  354. * @param SDMMCx: Pointer to SDMMC register base
  355. * @param Data : pointer to a SDMMC_DataInitTypeDef structure
  356. * that contains the configuration information for the SDMMC data.
  357. * @retval HAL status
  358. */
  359. HAL_StatusTypeDef SDMMC_ConfigData(SDMMC_TypeDef *SDMMCx, SDMMC_DataInitTypeDef* Data)
  360. {
  361. uint32_t tmpreg = 0;
  362. /* Check the parameters */
  363. assert_param(IS_SDMMC_DATA_LENGTH(Data->DataLength));
  364. assert_param(IS_SDMMC_BLOCK_SIZE(Data->DataBlockSize));
  365. assert_param(IS_SDMMC_TRANSFER_DIR(Data->TransferDir));
  366. assert_param(IS_SDMMC_TRANSFER_MODE(Data->TransferMode));
  367. assert_param(IS_SDMMC_DPSM(Data->DPSM));
  368. /* Set the SDMMC Data TimeOut value */
  369. SDMMCx->DTIMER = Data->DataTimeOut;
  370. /* Set the SDMMC DataLength value */
  371. SDMMCx->DLEN = Data->DataLength;
  372. /* Set the SDMMC data configuration parameters */
  373. tmpreg |= (uint32_t)(Data->DataBlockSize |\
  374. Data->TransferDir |\
  375. Data->TransferMode |\
  376. Data->DPSM);
  377. /* Write to SDMMC DCTRL */
  378. MODIFY_REG(SDMMCx->DCTRL, DCTRL_CLEAR_MASK, tmpreg);
  379. return HAL_OK;
  380. }
  381. /**
  382. * @brief Returns number of remaining data bytes to be transferred.
  383. * @param SDMMCx: Pointer to SDMMC register base
  384. * @retval Number of remaining data bytes to be transferred
  385. */
  386. uint32_t SDMMC_GetDataCounter(SDMMC_TypeDef *SDMMCx)
  387. {
  388. return (SDMMCx->DCOUNT);
  389. }
  390. /**
  391. * @brief Get the FIFO data
  392. * @param SDMMCx: Pointer to SDMMC register base
  393. * @retval Data received
  394. */
  395. uint32_t SDMMC_GetFIFOCount(SDMMC_TypeDef *SDMMCx)
  396. {
  397. return (SDMMCx->FIFO);
  398. }
  399. /**
  400. * @brief Sets one of the two options of inserting read wait interval.
  401. * @param SDMMCx: Pointer to SDMMC register base
  402. * @param SDMMC_ReadWaitMode: SDMMC Read Wait operation mode.
  403. * This parameter can be:
  404. * @arg SDMMC_READ_WAIT_MODE_CLK: Read Wait control by stopping SDMMCCLK
  405. * @arg SDMMC_READ_WAIT_MODE_DATA2: Read Wait control using SDMMC_DATA2
  406. * @retval None
  407. */
  408. HAL_StatusTypeDef SDMMC_SetSDMMCReadWaitMode(SDMMC_TypeDef *SDMMCx, uint32_t SDMMC_ReadWaitMode)
  409. {
  410. /* Check the parameters */
  411. assert_param(IS_SDMMC_READWAIT_MODE(SDMMC_ReadWaitMode));
  412. /* Set SDMMC read wait mode */
  413. MODIFY_REG(SDMMCx->DCTRL, SDMMC_DCTRL_RWMOD, SDMMC_ReadWaitMode);
  414. return HAL_OK;
  415. }
  416. /**
  417. * @}
  418. */
  419. /** @defgroup HAL_SDMMC_LL_Group4 Command management functions
  420. * @brief Data transfers functions
  421. *
  422. @verbatim
  423. ===============================================================================
  424. ##### Commands management functions #####
  425. ===============================================================================
  426. [..]
  427. This subsection provides a set of functions allowing to manage the needed commands.
  428. @endverbatim
  429. * @{
  430. */
  431. /**
  432. * @brief Send the Data Block Lenght command and check the response
  433. * @param SDMMCx: Pointer to SDMMC register base
  434. * @retval HAL status
  435. */
  436. uint32_t SDMMC_CmdBlockLength(SDMMC_TypeDef *SDMMCx, uint32_t BlockSize)
  437. {
  438. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  439. uint32_t errorstate;
  440. /* Set Block Size for Card */
  441. sdmmc_cmdinit.Argument = (uint32_t)BlockSize;
  442. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SET_BLOCKLEN;
  443. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  444. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  445. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  446. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  447. /* Check for error conditions */
  448. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SET_BLOCKLEN, SDMMC_CMDTIMEOUT);
  449. return errorstate;
  450. }
  451. /**
  452. * @brief Send the Read Single Block command and check the response
  453. * @param SDMMCx: Pointer to SDMMC register base
  454. * @retval HAL status
  455. */
  456. uint32_t SDMMC_CmdReadSingleBlock(SDMMC_TypeDef *SDMMCx, uint32_t ReadAdd)
  457. {
  458. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  459. uint32_t errorstate;
  460. /* Set Block Size for Card */
  461. sdmmc_cmdinit.Argument = (uint32_t)ReadAdd;
  462. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_READ_SINGLE_BLOCK;
  463. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  464. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  465. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  466. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  467. /* Check for error conditions */
  468. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_READ_SINGLE_BLOCK, SDMMC_CMDTIMEOUT);
  469. return errorstate;
  470. }
  471. /**
  472. * @brief Send the Read Multi Block command and check the response
  473. * @param SDMMCx: Pointer to SDMMC register base
  474. * @retval HAL status
  475. */
  476. uint32_t SDMMC_CmdReadMultiBlock(SDMMC_TypeDef *SDMMCx, uint32_t ReadAdd)
  477. {
  478. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  479. uint32_t errorstate;
  480. /* Set Block Size for Card */
  481. sdmmc_cmdinit.Argument = (uint32_t)ReadAdd;
  482. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_READ_MULT_BLOCK;
  483. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  484. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  485. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  486. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  487. /* Check for error conditions */
  488. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_READ_MULT_BLOCK, SDMMC_CMDTIMEOUT);
  489. return errorstate;
  490. }
  491. /**
  492. * @brief Send the Write Single Block command and check the response
  493. * @param SDMMCx: Pointer to SDMMC register base
  494. * @retval HAL status
  495. */
  496. uint32_t SDMMC_CmdWriteSingleBlock(SDMMC_TypeDef *SDMMCx, uint32_t WriteAdd)
  497. {
  498. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  499. uint32_t errorstate;
  500. /* Set Block Size for Card */
  501. sdmmc_cmdinit.Argument = (uint32_t)WriteAdd;
  502. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_WRITE_SINGLE_BLOCK;
  503. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  504. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  505. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  506. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  507. /* Check for error conditions */
  508. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_WRITE_SINGLE_BLOCK, SDMMC_CMDTIMEOUT);
  509. return errorstate;
  510. }
  511. /**
  512. * @brief Send the Write Multi Block command and check the response
  513. * @param SDMMCx: Pointer to SDMMC register base
  514. * @retval HAL status
  515. */
  516. uint32_t SDMMC_CmdWriteMultiBlock(SDMMC_TypeDef *SDMMCx, uint32_t WriteAdd)
  517. {
  518. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  519. uint32_t errorstate;
  520. /* Set Block Size for Card */
  521. sdmmc_cmdinit.Argument = (uint32_t)WriteAdd;
  522. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_WRITE_MULT_BLOCK;
  523. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  524. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  525. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  526. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  527. /* Check for error conditions */
  528. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_WRITE_MULT_BLOCK, SDMMC_CMDTIMEOUT);
  529. return errorstate;
  530. }
  531. /**
  532. * @brief Send the Start Address Erase command for SD and check the response
  533. * @param SDMMCx: Pointer to SDMMC register base
  534. * @retval HAL status
  535. */
  536. uint32_t SDMMC_CmdSDEraseStartAdd(SDMMC_TypeDef *SDMMCx, uint32_t StartAdd)
  537. {
  538. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  539. uint32_t errorstate;
  540. /* Set Block Size for Card */
  541. sdmmc_cmdinit.Argument = (uint32_t)StartAdd;
  542. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SD_ERASE_GRP_START;
  543. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  544. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  545. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  546. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  547. /* Check for error conditions */
  548. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SD_ERASE_GRP_START, SDMMC_CMDTIMEOUT);
  549. return errorstate;
  550. }
  551. /**
  552. * @brief Send the End Address Erase command for SD and check the response
  553. * @param SDMMCx: Pointer to SDMMC register base
  554. * @retval HAL status
  555. */
  556. uint32_t SDMMC_CmdSDEraseEndAdd(SDMMC_TypeDef *SDMMCx, uint32_t EndAdd)
  557. {
  558. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  559. uint32_t errorstate;
  560. /* Set Block Size for Card */
  561. sdmmc_cmdinit.Argument = (uint32_t)EndAdd;
  562. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SD_ERASE_GRP_END;
  563. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  564. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  565. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  566. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  567. /* Check for error conditions */
  568. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SD_ERASE_GRP_END, SDMMC_CMDTIMEOUT);
  569. return errorstate;
  570. }
  571. /**
  572. * @brief Send the Start Address Erase command and check the response
  573. * @param SDMMCx: Pointer to SDMMC register base
  574. * @retval HAL status
  575. */
  576. uint32_t SDMMC_CmdEraseStartAdd(SDMMC_TypeDef *SDMMCx, uint32_t StartAdd)
  577. {
  578. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  579. uint32_t errorstate;
  580. /* Set Block Size for Card */
  581. sdmmc_cmdinit.Argument = (uint32_t)StartAdd;
  582. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_ERASE_GRP_START;
  583. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  584. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  585. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  586. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  587. /* Check for error conditions */
  588. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_ERASE_GRP_START, SDMMC_CMDTIMEOUT);
  589. return errorstate;
  590. }
  591. /**
  592. * @brief Send the End Address Erase command and check the response
  593. * @param SDMMCx: Pointer to SDMMC register base
  594. * @retval HAL status
  595. */
  596. uint32_t SDMMC_CmdEraseEndAdd(SDMMC_TypeDef *SDMMCx, uint32_t EndAdd)
  597. {
  598. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  599. uint32_t errorstate;
  600. /* Set Block Size for Card */
  601. sdmmc_cmdinit.Argument = (uint32_t)EndAdd;
  602. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_ERASE_GRP_END;
  603. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  604. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  605. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  606. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  607. /* Check for error conditions */
  608. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_ERASE_GRP_END, SDMMC_CMDTIMEOUT);
  609. return errorstate;
  610. }
  611. /**
  612. * @brief Send the Erase command and check the response
  613. * @param SDMMCx: Pointer to SDMMC register base
  614. * @retval HAL status
  615. */
  616. uint32_t SDMMC_CmdErase(SDMMC_TypeDef *SDMMCx)
  617. {
  618. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  619. uint32_t errorstate;
  620. /* Set Block Size for Card */
  621. sdmmc_cmdinit.Argument = 0U;
  622. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_ERASE;
  623. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  624. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  625. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  626. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  627. /* Check for error conditions */
  628. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_ERASE, SDMMC_MAXERASETIMEOUT);
  629. return errorstate;
  630. }
  631. /**
  632. * @brief Send the Stop Transfer command and check the response.
  633. * @param SDMMCx: Pointer to SDMMC register base
  634. * @retval HAL status
  635. */
  636. uint32_t SDMMC_CmdStopTransfer(SDMMC_TypeDef *SDMMCx)
  637. {
  638. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  639. uint32_t errorstate;
  640. /* Send CMD12 STOP_TRANSMISSION */
  641. sdmmc_cmdinit.Argument = 0U;
  642. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_STOP_TRANSMISSION;
  643. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  644. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  645. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  646. __SDMMC_CMDSTOP_ENABLE(SDMMCx);
  647. __SDMMC_CMDTRANS_DISABLE(SDMMCx);
  648. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  649. /* Check for error conditions */
  650. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_STOP_TRANSMISSION, SDMMC_STOPTRANSFERTIMEOUT);
  651. __SDMMC_CMDSTOP_DISABLE(SDMMCx);
  652. /* Ignore Address Out Of Range Error, Not relevant at end of memory */
  653. if (errorstate == SDMMC_ERROR_ADDR_OUT_OF_RANGE)
  654. {
  655. errorstate = SDMMC_ERROR_NONE;
  656. }
  657. return errorstate;
  658. }
  659. /**
  660. * @brief Send the Select Deselect command and check the response.
  661. * @param SDMMCx: Pointer to SDMMC register base
  662. * @param addr: Address of the card to be selected
  663. * @retval HAL status
  664. */
  665. uint32_t SDMMC_CmdSelDesel(SDMMC_TypeDef *SDMMCx, uint64_t Addr)
  666. {
  667. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  668. uint32_t errorstate;
  669. /* Send CMD7 SDMMC_SEL_DESEL_CARD */
  670. sdmmc_cmdinit.Argument = (uint32_t)Addr;
  671. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SEL_DESEL_CARD;
  672. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  673. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  674. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  675. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  676. /* Check for error conditions */
  677. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SEL_DESEL_CARD, SDMMC_CMDTIMEOUT);
  678. return errorstate;
  679. }
  680. /**
  681. * @brief Send the Go Idle State command and check the response.
  682. * @param SDMMCx: Pointer to SDMMC register base
  683. * @retval HAL status
  684. */
  685. uint32_t SDMMC_CmdGoIdleState(SDMMC_TypeDef *SDMMCx)
  686. {
  687. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  688. uint32_t errorstate;
  689. sdmmc_cmdinit.Argument = 0U;
  690. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_GO_IDLE_STATE;
  691. sdmmc_cmdinit.Response = SDMMC_RESPONSE_NO;
  692. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  693. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  694. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  695. /* Check for error conditions */
  696. errorstate = SDMMC_GetCmdError(SDMMCx);
  697. return errorstate;
  698. }
  699. /**
  700. * @brief Send the Operating Condition command and check the response.
  701. * @param SDMMCx: Pointer to SDMMC register base
  702. * @retval HAL status
  703. */
  704. uint32_t SDMMC_CmdOperCond(SDMMC_TypeDef *SDMMCx)
  705. {
  706. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  707. uint32_t errorstate;
  708. /* Send CMD8 to verify SD card interface operating condition */
  709. /* Argument: - [31:12]: Reserved (shall be set to '0')
  710. - [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)
  711. - [7:0]: Check Pattern (recommended 0xAA) */
  712. /* CMD Response: R7 */
  713. sdmmc_cmdinit.Argument = SDMMC_CHECK_PATTERN;
  714. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_HS_SEND_EXT_CSD;
  715. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  716. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  717. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  718. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  719. /* Check for error conditions */
  720. errorstate = SDMMC_GetCmdResp7(SDMMCx);
  721. return errorstate;
  722. }
  723. /**
  724. * @brief Send the Application command to verify that that the next command
  725. * is an application specific com-mand rather than a standard command
  726. * and check the response.
  727. * @param SDMMCx: Pointer to SDMMC register base
  728. * @param Argument: Command Argument
  729. * @retval HAL status
  730. */
  731. uint32_t SDMMC_CmdAppCommand(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
  732. {
  733. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  734. uint32_t errorstate;
  735. sdmmc_cmdinit.Argument = (uint32_t)Argument;
  736. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_APP_CMD;
  737. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  738. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  739. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  740. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  741. /* Check for error conditions */
  742. /* If there is a HAL_ERROR, it is a MMC card, else
  743. it is a SD card: SD card 2.0 (voltage range mismatch)
  744. or SD card 1.x */
  745. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_APP_CMD, SDMMC_CMDTIMEOUT);
  746. return errorstate;
  747. }
  748. /**
  749. * @brief Send the command asking the accessed card to send its operating
  750. * condition register (OCR)
  751. * @param SDMMCx: Pointer to SDMMC register base
  752. * @param Argument: Command Argument
  753. * @retval HAL status
  754. */
  755. uint32_t SDMMC_CmdAppOperCommand(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
  756. {
  757. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  758. uint32_t errorstate;
  759. sdmmc_cmdinit.Argument = Argument;
  760. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SD_APP_OP_COND;
  761. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  762. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  763. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  764. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  765. /* Check for error conditions */
  766. errorstate = SDMMC_GetCmdResp3(SDMMCx);
  767. return errorstate;
  768. }
  769. /**
  770. * @brief Send the Bus Width command and check the response.
  771. * @param SDMMCx: Pointer to SDMMC register base
  772. * @param BusWidth: BusWidth
  773. * @retval HAL status
  774. */
  775. uint32_t SDMMC_CmdBusWidth(SDMMC_TypeDef *SDMMCx, uint32_t BusWidth)
  776. {
  777. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  778. uint32_t errorstate;
  779. sdmmc_cmdinit.Argument = (uint32_t)BusWidth;
  780. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_APP_SD_SET_BUSWIDTH;
  781. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  782. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  783. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  784. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  785. /* Check for error conditions */
  786. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_APP_SD_SET_BUSWIDTH, SDMMC_CMDTIMEOUT);
  787. return errorstate;
  788. }
  789. /**
  790. * @brief Send the Send SCR command and check the response.
  791. * @param SDMMCx: Pointer to SDMMC register base
  792. * @retval HAL status
  793. */
  794. uint32_t SDMMC_CmdSendSCR(SDMMC_TypeDef *SDMMCx)
  795. {
  796. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  797. uint32_t errorstate;
  798. /* Send CMD51 SD_APP_SEND_SCR */
  799. sdmmc_cmdinit.Argument = 0U;
  800. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SD_APP_SEND_SCR;
  801. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  802. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  803. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  804. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  805. /* Check for error conditions */
  806. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SD_APP_SEND_SCR, SDMMC_CMDTIMEOUT);
  807. return errorstate;
  808. }
  809. /**
  810. * @brief Send the Send CID command and check the response.
  811. * @param SDMMCx: Pointer to SDMMC register base
  812. * @retval HAL status
  813. */
  814. uint32_t SDMMC_CmdSendCID(SDMMC_TypeDef *SDMMCx)
  815. {
  816. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  817. uint32_t errorstate;
  818. /* Send CMD2 ALL_SEND_CID */
  819. sdmmc_cmdinit.Argument = 0U;
  820. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_ALL_SEND_CID;
  821. sdmmc_cmdinit.Response = SDMMC_RESPONSE_LONG;
  822. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  823. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  824. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  825. /* Check for error conditions */
  826. errorstate = SDMMC_GetCmdResp2(SDMMCx);
  827. return errorstate;
  828. }
  829. /**
  830. * @brief Send the Send CSD command and check the response.
  831. * @param SDMMCx: Pointer to SDMMC register base
  832. * @param Argument: Command Argument
  833. * @retval HAL status
  834. */
  835. uint32_t SDMMC_CmdSendCSD(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
  836. {
  837. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  838. uint32_t errorstate;
  839. /* Send CMD9 SEND_CSD */
  840. sdmmc_cmdinit.Argument = Argument;
  841. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SEND_CSD;
  842. sdmmc_cmdinit.Response = SDMMC_RESPONSE_LONG;
  843. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  844. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  845. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  846. /* Check for error conditions */
  847. errorstate = SDMMC_GetCmdResp2(SDMMCx);
  848. return errorstate;
  849. }
  850. /**
  851. * @brief Send the Send CSD command and check the response.
  852. * @param SDMMCx: Pointer to SDMMC register base
  853. * @param pRCA: Card RCA
  854. * @retval HAL status
  855. */
  856. uint32_t SDMMC_CmdSetRelAdd(SDMMC_TypeDef *SDMMCx, uint16_t *pRCA)
  857. {
  858. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  859. uint32_t errorstate;
  860. /* Send CMD3 SD_CMD_SET_REL_ADDR */
  861. sdmmc_cmdinit.Argument = 0U;
  862. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SET_REL_ADDR;
  863. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  864. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  865. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  866. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  867. /* Check for error conditions */
  868. errorstate = SDMMC_GetCmdResp6(SDMMCx, SDMMC_CMD_SET_REL_ADDR, pRCA);
  869. return errorstate;
  870. }
  871. /**
  872. * @brief Send the Status command and check the response.
  873. * @param SDMMCx: Pointer to SDMMC register base
  874. * @param Argument: Command Argument
  875. * @retval HAL status
  876. */
  877. uint32_t SDMMC_CmdSendStatus(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
  878. {
  879. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  880. uint32_t errorstate;
  881. sdmmc_cmdinit.Argument = Argument;
  882. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SEND_STATUS;
  883. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  884. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  885. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  886. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  887. /* Check for error conditions */
  888. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SEND_STATUS, SDMMC_CMDTIMEOUT);
  889. return errorstate;
  890. }
  891. /**
  892. * @brief Send the Status register command and check the response.
  893. * @param SDMMCx: Pointer to SDMMC register base
  894. * @retval HAL status
  895. */
  896. uint32_t SDMMC_CmdStatusRegister(SDMMC_TypeDef *SDMMCx)
  897. {
  898. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  899. uint32_t errorstate;
  900. sdmmc_cmdinit.Argument = 0U;
  901. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SD_APP_STATUS;
  902. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  903. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  904. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  905. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  906. /* Check for error conditions */
  907. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SD_APP_STATUS, SDMMC_CMDTIMEOUT);
  908. return errorstate;
  909. }
  910. /**
  911. * @brief Sends host capacity support information and activates the card's
  912. * initialization process. Send SDMMC_CMD_SEND_OP_COND command
  913. * @param SDMMCx: Pointer to SDMMC register base
  914. * @parame Argument: Argument used for the command
  915. * @retval HAL status
  916. */
  917. uint32_t SDMMC_CmdOpCondition(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
  918. {
  919. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  920. uint32_t errorstate;
  921. sdmmc_cmdinit.Argument = Argument;
  922. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SEND_OP_COND;
  923. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  924. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  925. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  926. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  927. /* Check for error conditions */
  928. errorstate = SDMMC_GetCmdResp3(SDMMCx);
  929. return errorstate;
  930. }
  931. /**
  932. * @brief Checks switchable function and switch card function. SDMMC_CMD_HS_SWITCH comand
  933. * @param SDMMCx: Pointer to SDMMC register base
  934. * @parame Argument: Argument used for the command
  935. * @retval HAL status
  936. */
  937. uint32_t SDMMC_CmdSwitch(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
  938. {
  939. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  940. uint32_t errorstate;
  941. /* Send CMD6 to activate SDR50 Mode and Power Limit 1.44W */
  942. /* CMD Response: R1 */
  943. sdmmc_cmdinit.Argument = Argument; /* SDMMC_SDR25_SWITCH_PATTERN;*/
  944. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_HS_SWITCH;
  945. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  946. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  947. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  948. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  949. /* Check for error conditions */
  950. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_HS_SWITCH, SDMMC_CMDTIMEOUT);
  951. return errorstate;
  952. }
  953. /**
  954. * @brief Send the command asking the accessed card to send its operating
  955. * condition register (OCR)
  956. * @param None
  957. * @retval HAL status
  958. */
  959. uint32_t SDMMC_CmdVoltageSwitch(SDMMC_TypeDef *SDMMCx)
  960. {
  961. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  962. uint32_t errorstate;
  963. sdmmc_cmdinit.Argument = 0x00000000;
  964. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_VOLTAGE_SWITCH;
  965. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  966. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  967. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  968. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  969. /* Check for error conditions */
  970. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_VOLTAGE_SWITCH, SDMMC_CMDTIMEOUT);
  971. return errorstate;
  972. }
  973. /**
  974. * @brief Send the Send EXT_CSD command and check the response.
  975. * @param SDMMCx: Pointer to SDMMC register base
  976. * @param Argument: Command Argument
  977. * @retval HAL status
  978. */
  979. uint32_t SDMMC_CmdSendEXTCSD(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
  980. {
  981. SDMMC_CmdInitTypeDef sdmmc_cmdinit;
  982. uint32_t errorstate;
  983. /* Send CMD9 SEND_CSD */
  984. sdmmc_cmdinit.Argument = Argument;
  985. sdmmc_cmdinit.CmdIndex = SDMMC_CMD_HS_SEND_EXT_CSD;
  986. sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
  987. sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
  988. sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
  989. (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
  990. /* Check for error conditions */
  991. errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_HS_SEND_EXT_CSD,SDMMC_CMDTIMEOUT);
  992. return errorstate;
  993. }
  994. /**
  995. * @}
  996. */
  997. /* Private function ----------------------------------------------------------*/
  998. /** @addtogroup SD_Private_Functions
  999. * @{
  1000. */
  1001. /**
  1002. * @brief Checks for error conditions for CMD0.
  1003. * @param hsd: SD handle
  1004. * @retval SD Card error state
  1005. */
  1006. static uint32_t SDMMC_GetCmdError(SDMMC_TypeDef *SDMMCx)
  1007. {
  1008. /* 8 is the number of required instructions cycles for the below loop statement.
  1009. The SDMMC_CMDTIMEOUT is expressed in ms */
  1010. register uint32_t count = SDMMC_CMDTIMEOUT * (SystemCoreClock / 8U /1000U);
  1011. do
  1012. {
  1013. if (count-- == 0U)
  1014. {
  1015. return SDMMC_ERROR_TIMEOUT;
  1016. }
  1017. }while(!__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CMDSENT));
  1018. /* Clear all the static flags */
  1019. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_STATIC_CMD_FLAGS);
  1020. return SDMMC_ERROR_NONE;
  1021. }
  1022. /**
  1023. * @brief Checks for error conditions for R1 response.
  1024. * @param hsd: SD handle
  1025. * @param SD_CMD: The sent command index
  1026. * @retval SD Card error state
  1027. */
  1028. static uint32_t SDMMC_GetCmdResp1(SDMMC_TypeDef *SDMMCx, uint8_t SD_CMD, uint32_t Timeout)
  1029. {
  1030. uint32_t response_r1;
  1031. uint32_t sta_reg;
  1032. /* 8 is the number of required instructions cycles for the below loop statement.
  1033. The Timeout is expressed in ms */
  1034. register uint32_t count = Timeout * (SystemCoreClock / 8U /1000U);
  1035. do
  1036. {
  1037. if (count-- == 0U)
  1038. {
  1039. return SDMMC_ERROR_TIMEOUT;
  1040. }
  1041. sta_reg = SDMMCx->STA;
  1042. }while(((sta_reg & (SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CMDREND | SDMMC_FLAG_CTIMEOUT | SDMMC_FLAG_BUSYD0END)) == 0U) ||
  1043. ((sta_reg & SDMMC_FLAG_CMDACT) != 0U ));
  1044. if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT))
  1045. {
  1046. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT);
  1047. return SDMMC_ERROR_CMD_RSP_TIMEOUT;
  1048. }
  1049. else if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL))
  1050. {
  1051. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL);
  1052. return SDMMC_ERROR_CMD_CRC_FAIL;
  1053. }
  1054. else
  1055. {
  1056. /* Nothing to do */
  1057. }
  1058. /* Clear all the static flags */
  1059. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_STATIC_CMD_FLAGS);
  1060. /* Check response received is of desired command */
  1061. if(SDMMC_GetCommandResponse(SDMMCx) != SD_CMD)
  1062. {
  1063. return SDMMC_ERROR_CMD_CRC_FAIL;
  1064. }
  1065. /* We have received response, retrieve it for analysis */
  1066. response_r1 = SDMMC_GetResponse(SDMMCx, SDMMC_RESP1);
  1067. if((response_r1 & SDMMC_OCR_ERRORBITS) == SDMMC_ALLZERO)
  1068. {
  1069. return SDMMC_ERROR_NONE;
  1070. }
  1071. else if((response_r1 & SDMMC_OCR_ADDR_OUT_OF_RANGE) == SDMMC_OCR_ADDR_OUT_OF_RANGE)
  1072. {
  1073. return SDMMC_ERROR_ADDR_OUT_OF_RANGE;
  1074. }
  1075. else if((response_r1 & SDMMC_OCR_ADDR_MISALIGNED) == SDMMC_OCR_ADDR_MISALIGNED)
  1076. {
  1077. return SDMMC_ERROR_ADDR_MISALIGNED;
  1078. }
  1079. else if((response_r1 & SDMMC_OCR_BLOCK_LEN_ERR) == SDMMC_OCR_BLOCK_LEN_ERR)
  1080. {
  1081. return SDMMC_ERROR_BLOCK_LEN_ERR;
  1082. }
  1083. else if((response_r1 & SDMMC_OCR_ERASE_SEQ_ERR) == SDMMC_OCR_ERASE_SEQ_ERR)
  1084. {
  1085. return SDMMC_ERROR_ERASE_SEQ_ERR;
  1086. }
  1087. else if((response_r1 & SDMMC_OCR_BAD_ERASE_PARAM) == SDMMC_OCR_BAD_ERASE_PARAM)
  1088. {
  1089. return SDMMC_ERROR_BAD_ERASE_PARAM;
  1090. }
  1091. else if((response_r1 & SDMMC_OCR_WRITE_PROT_VIOLATION) == SDMMC_OCR_WRITE_PROT_VIOLATION)
  1092. {
  1093. return SDMMC_ERROR_WRITE_PROT_VIOLATION;
  1094. }
  1095. else if((response_r1 & SDMMC_OCR_LOCK_UNLOCK_FAILED) == SDMMC_OCR_LOCK_UNLOCK_FAILED)
  1096. {
  1097. return SDMMC_ERROR_LOCK_UNLOCK_FAILED;
  1098. }
  1099. else if((response_r1 & SDMMC_OCR_COM_CRC_FAILED) == SDMMC_OCR_COM_CRC_FAILED)
  1100. {
  1101. return SDMMC_ERROR_COM_CRC_FAILED;
  1102. }
  1103. else if((response_r1 & SDMMC_OCR_ILLEGAL_CMD) == SDMMC_OCR_ILLEGAL_CMD)
  1104. {
  1105. return SDMMC_ERROR_ILLEGAL_CMD;
  1106. }
  1107. else if((response_r1 & SDMMC_OCR_CARD_ECC_FAILED) == SDMMC_OCR_CARD_ECC_FAILED)
  1108. {
  1109. return SDMMC_ERROR_CARD_ECC_FAILED;
  1110. }
  1111. else if((response_r1 & SDMMC_OCR_CC_ERROR) == SDMMC_OCR_CC_ERROR)
  1112. {
  1113. return SDMMC_ERROR_CC_ERR;
  1114. }
  1115. else if((response_r1 & SDMMC_OCR_STREAM_READ_UNDERRUN) == SDMMC_OCR_STREAM_READ_UNDERRUN)
  1116. {
  1117. return SDMMC_ERROR_STREAM_READ_UNDERRUN;
  1118. }
  1119. else if((response_r1 & SDMMC_OCR_STREAM_WRITE_OVERRUN) == SDMMC_OCR_STREAM_WRITE_OVERRUN)
  1120. {
  1121. return SDMMC_ERROR_STREAM_WRITE_OVERRUN;
  1122. }
  1123. else if((response_r1 & SDMMC_OCR_CID_CSD_OVERWRITE) == SDMMC_OCR_CID_CSD_OVERWRITE)
  1124. {
  1125. return SDMMC_ERROR_CID_CSD_OVERWRITE;
  1126. }
  1127. else if((response_r1 & SDMMC_OCR_WP_ERASE_SKIP) == SDMMC_OCR_WP_ERASE_SKIP)
  1128. {
  1129. return SDMMC_ERROR_WP_ERASE_SKIP;
  1130. }
  1131. else if((response_r1 & SDMMC_OCR_CARD_ECC_DISABLED) == SDMMC_OCR_CARD_ECC_DISABLED)
  1132. {
  1133. return SDMMC_ERROR_CARD_ECC_DISABLED;
  1134. }
  1135. else if((response_r1 & SDMMC_OCR_ERASE_RESET) == SDMMC_OCR_ERASE_RESET)
  1136. {
  1137. return SDMMC_ERROR_ERASE_RESET;
  1138. }
  1139. else if((response_r1 & SDMMC_OCR_AKE_SEQ_ERROR) == SDMMC_OCR_AKE_SEQ_ERROR)
  1140. {
  1141. return SDMMC_ERROR_AKE_SEQ_ERR;
  1142. }
  1143. else
  1144. {
  1145. return SDMMC_ERROR_GENERAL_UNKNOWN_ERR;
  1146. }
  1147. }
  1148. /**
  1149. * @brief Checks for error conditions for R2 (CID or CSD) response.
  1150. * @param hsd: SD handle
  1151. * @retval SD Card error state
  1152. */
  1153. static uint32_t SDMMC_GetCmdResp2(SDMMC_TypeDef *SDMMCx)
  1154. {
  1155. uint32_t sta_reg;
  1156. /* 8 is the number of required instructions cycles for the below loop statement.
  1157. The SDMMC_CMDTIMEOUT is expressed in ms */
  1158. register uint32_t count = SDMMC_CMDTIMEOUT * (SystemCoreClock / 8U /1000U);
  1159. do
  1160. {
  1161. if (count-- == 0U)
  1162. {
  1163. return SDMMC_ERROR_TIMEOUT;
  1164. }
  1165. sta_reg = SDMMCx->STA;
  1166. }while(((sta_reg & (SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CMDREND | SDMMC_FLAG_CTIMEOUT)) == 0U) ||
  1167. ((sta_reg & SDMMC_FLAG_CMDACT) != 0U ));
  1168. if (__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT))
  1169. {
  1170. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT);
  1171. return SDMMC_ERROR_CMD_RSP_TIMEOUT;
  1172. }
  1173. else if (__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL))
  1174. {
  1175. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL);
  1176. return SDMMC_ERROR_CMD_CRC_FAIL;
  1177. }
  1178. else
  1179. {
  1180. /* No error flag set */
  1181. /* Clear all the static flags */
  1182. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_STATIC_CMD_FLAGS);
  1183. }
  1184. return SDMMC_ERROR_NONE;
  1185. }
  1186. /**
  1187. * @brief Checks for error conditions for R3 (OCR) response.
  1188. * @param hsd: SD handle
  1189. * @retval SD Card error state
  1190. */
  1191. static uint32_t SDMMC_GetCmdResp3(SDMMC_TypeDef *SDMMCx)
  1192. {
  1193. uint32_t sta_reg;
  1194. /* 8 is the number of required instructions cycles for the below loop statement.
  1195. The SDMMC_CMDTIMEOUT is expressed in ms */
  1196. register uint32_t count = SDMMC_CMDTIMEOUT * (SystemCoreClock / 8U /1000U);
  1197. do
  1198. {
  1199. if (count-- == 0U)
  1200. {
  1201. return SDMMC_ERROR_TIMEOUT;
  1202. }
  1203. sta_reg = SDMMCx->STA;
  1204. }while(((sta_reg & (SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CMDREND | SDMMC_FLAG_CTIMEOUT)) == 0U) ||
  1205. ((sta_reg & SDMMC_FLAG_CMDACT) != 0U ));
  1206. if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT))
  1207. {
  1208. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT);
  1209. return SDMMC_ERROR_CMD_RSP_TIMEOUT;
  1210. }
  1211. else
  1212. {
  1213. /* Clear all the static flags */
  1214. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_STATIC_CMD_FLAGS);
  1215. }
  1216. return SDMMC_ERROR_NONE;
  1217. }
  1218. /**
  1219. * @brief Checks for error conditions for R6 (RCA) response.
  1220. * @param hsd: SD handle
  1221. * @param SD_CMD: The sent command index
  1222. * @param pRCA: Pointer to the variable that will contain the SD card relative
  1223. * address RCA
  1224. * @retval SD Card error state
  1225. */
  1226. static uint32_t SDMMC_GetCmdResp6(SDMMC_TypeDef *SDMMCx, uint8_t SD_CMD, uint16_t *pRCA)
  1227. {
  1228. uint32_t response_r1;
  1229. uint32_t sta_reg;
  1230. /* 8 is the number of required instructions cycles for the below loop statement.
  1231. The SDMMC_CMDTIMEOUT is expressed in ms */
  1232. register uint32_t count = SDMMC_CMDTIMEOUT * (SystemCoreClock / 8U /1000U);
  1233. do
  1234. {
  1235. if (count-- == 0U)
  1236. {
  1237. return SDMMC_ERROR_TIMEOUT;
  1238. }
  1239. sta_reg = SDMMCx->STA;
  1240. }while(((sta_reg & (SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CMDREND | SDMMC_FLAG_CTIMEOUT)) == 0U) ||
  1241. ((sta_reg & SDMMC_FLAG_CMDACT) != 0U ));
  1242. if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT))
  1243. {
  1244. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT);
  1245. return SDMMC_ERROR_CMD_RSP_TIMEOUT;
  1246. }
  1247. else if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL))
  1248. {
  1249. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL);
  1250. return SDMMC_ERROR_CMD_CRC_FAIL;
  1251. }
  1252. else
  1253. {
  1254. /* Nothing to do */
  1255. }
  1256. /* Check response received is of desired command */
  1257. if(SDMMC_GetCommandResponse(SDMMCx) != SD_CMD)
  1258. {
  1259. return SDMMC_ERROR_CMD_CRC_FAIL;
  1260. }
  1261. /* Clear all the static flags */
  1262. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_STATIC_CMD_FLAGS);
  1263. /* We have received response, retrieve it. */
  1264. response_r1 = SDMMC_GetResponse(SDMMCx, SDMMC_RESP1);
  1265. if((response_r1 & (SDMMC_R6_GENERAL_UNKNOWN_ERROR | SDMMC_R6_ILLEGAL_CMD | SDMMC_R6_COM_CRC_FAILED)) == SDMMC_ALLZERO)
  1266. {
  1267. *pRCA = (uint16_t) (response_r1 >> 16);
  1268. return SDMMC_ERROR_NONE;
  1269. }
  1270. else if((response_r1 & SDMMC_R6_ILLEGAL_CMD) == SDMMC_R6_ILLEGAL_CMD)
  1271. {
  1272. return SDMMC_ERROR_ILLEGAL_CMD;
  1273. }
  1274. else if((response_r1 & SDMMC_R6_COM_CRC_FAILED) == SDMMC_R6_COM_CRC_FAILED)
  1275. {
  1276. return SDMMC_ERROR_COM_CRC_FAILED;
  1277. }
  1278. else
  1279. {
  1280. return SDMMC_ERROR_GENERAL_UNKNOWN_ERR;
  1281. }
  1282. }
  1283. /**
  1284. * @brief Checks for error conditions for R7 response.
  1285. * @param hsd: SD handle
  1286. * @retval SD Card error state
  1287. */
  1288. static uint32_t SDMMC_GetCmdResp7(SDMMC_TypeDef *SDMMCx)
  1289. {
  1290. uint32_t sta_reg;
  1291. /* 8 is the number of required instructions cycles for the below loop statement.
  1292. The SDMMC_CMDTIMEOUT is expressed in ms */
  1293. register uint32_t count = SDMMC_CMDTIMEOUT * (SystemCoreClock / 8U /1000U);
  1294. do
  1295. {
  1296. if (count-- == 0U)
  1297. {
  1298. return SDMMC_ERROR_TIMEOUT;
  1299. }
  1300. sta_reg = SDMMCx->STA;
  1301. }while(((sta_reg & (SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CMDREND | SDMMC_FLAG_CTIMEOUT)) == 0U) ||
  1302. ((sta_reg & SDMMC_FLAG_CMDACT) != 0U ));
  1303. if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT))
  1304. {
  1305. /* Card is SD V2.0 compliant */
  1306. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT);
  1307. return SDMMC_ERROR_CMD_RSP_TIMEOUT;
  1308. }
  1309. else if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL))
  1310. {
  1311. /* Card is SD V2.0 compliant */
  1312. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL);
  1313. return SDMMC_ERROR_CMD_CRC_FAIL;
  1314. }
  1315. else
  1316. {
  1317. /* Nothing to do */
  1318. }
  1319. if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CMDREND))
  1320. {
  1321. /* Card is SD V2.0 compliant */
  1322. __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CMDREND);
  1323. }
  1324. return SDMMC_ERROR_NONE;
  1325. }
  1326. /**
  1327. * @}
  1328. */
  1329. #endif /* HAL_SD_MODULE_ENABLED || HAL_MMC_MODULE_ENABLED */
  1330. /**
  1331. * @}
  1332. */
  1333. /**
  1334. * @}
  1335. */
  1336. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/