Increment eeprom version
[betaflight.git] / lib / main / STM32F1 / Drivers / STM32F1xx_HAL_Driver / Src / stm32f1xx_hal_pccard.c
blob8090a6f68ce01549035ff04540702b375290b5b8
1 /**
2 ******************************************************************************
3 * @file stm32f1xx_hal_pccard.c
4 * @author MCD Application Team
5 * @version V1.1.1
6 * @date 12-May-2017
7 * @brief PCCARD HAL module driver.
8 * This file provides a generic firmware to drive PCCARD memories mounted
9 * as external device.
11 @verbatim
12 ===============================================================================
13 ##### How to use this driver #####
14 ===============================================================================
15 [..]
16 This driver is a generic layered driver which contains a set of APIs used to
17 control PCCARD/compact flash memories. It uses the FSMC/FSMC layer functions
18 to interface with PCCARD devices. This driver is used for:
20 (+) PCCARD/compact flash memory configuration sequence using the function
21 HAL_PCCARD_Init() with control and timing parameters for both common and
22 attribute spaces.
24 (+) Read PCCARD/compact flash memory maker and device IDs using the function
25 HAL_PCCARD_Read_ID(). The read information is stored in the CompactFlash_ID
26 structure declared by the function caller.
28 (+) Access PCCARD/compact flash memory by read/write operations using the functions
29 HAL_PCCARD_Read_Sector()/HAL_PCCARD_Write_Sector(), to read/write sector.
31 (+) Perform PCCARD/compact flash Reset chip operation using the function HAL_PCCARD_Reset().
33 (+) Perform PCCARD/compact flash erase sector operation using the function
34 HAL_PCCARD_Erase_Sector().
36 (+) Read the PCCARD/compact flash status operation using the function HAL_PCCARD_ReadStatus().
38 (+) You can monitor the PCCARD/compact flash device HAL state by calling the function
39 HAL_PCCARD_GetState()
41 [..]
42 (@) This driver is a set of generic APIs which handle standard PCCARD/compact flash
43 operations. If a PCCARD/compact flash device contains different operations
44 and/or implementations, it should be implemented separately.
46 @endverbatim
47 ******************************************************************************
48 * @attention
50 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
52 * Redistribution and use in source and binary forms, with or without modification,
53 * are permitted provided that the following conditions are met:
54 * 1. Redistributions of source code must retain the above copyright notice,
55 * this list of conditions and the following disclaimer.
56 * 2. Redistributions in binary form must reproduce the above copyright notice,
57 * this list of conditions and the following disclaimer in the documentation
58 * and/or other materials provided with the distribution.
59 * 3. Neither the name of STMicroelectronics nor the names of its contributors
60 * may be used to endorse or promote products derived from this software
61 * without specific prior written permission.
63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
64 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
66 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
67 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
69 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
70 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
71 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
72 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74 ******************************************************************************
75 */
77 /* Includes ------------------------------------------------------------------*/
78 #include "stm32f1xx_hal.h"
80 /** @addtogroup STM32F1xx_HAL_Driver
81 * @{
84 #ifdef HAL_PCCARD_MODULE_ENABLED
85 #if defined (STM32F101xE) || defined(STM32F103xE) || defined(STM32F101xG) || defined(STM32F103xG)
87 /** @defgroup PCCARD PCCARD
88 * @brief PCCARD HAL module driver
89 * @{
92 /* Private typedef -----------------------------------------------------------*/
93 /* Private define ------------------------------------------------------------*/
94 /** @defgroup PCCARD_Private_Constants PCCARD Private Constants
95 * @{
98 #define PCCARD_TIMEOUT_READ_ID 0x0000FFFFU
99 #define PCCARD_TIMEOUT_SECTOR 0x0000FFFFU
100 #define PCCARD_TIMEOUT_STATUS 0x01000000U
102 #define PCCARD_STATUS_OK (uint8_t)0x58
103 #define PCCARD_STATUS_WRITE_OK (uint8_t)0x50
105 * @}
108 /* Private macro -------------------------------------------------------------*/
109 /* Private variables ---------------------------------------------------------*/
110 /* Private function prototypes -----------------------------------------------*/
111 /* Exported functions ---------------------------------------------------------*/
113 /** @defgroup PCCARD_Exported_Functions PCCARD Exported Functions
114 * @{
117 /** @defgroup PCCARD_Exported_Functions_Group1 Initialization and de-initialization functions
118 * @brief Initialization and Configuration functions
120 @verbatim
121 ==============================================================================
122 ##### PCCARD Initialization and de-initialization functions #####
123 ==============================================================================
124 [..]
125 This section provides functions allowing to initialize/de-initialize
126 the PCCARD memory
128 @endverbatim
129 * @{
133 * @brief Perform the PCCARD memory Initialization sequence
134 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
135 * the configuration information for PCCARD module.
136 * @param ComSpaceTiming: Common space timing structure
137 * @param AttSpaceTiming: Attribute space timing structure
138 * @param IOSpaceTiming: IO space timing structure
139 * @retval HAL status
141 HAL_StatusTypeDef HAL_PCCARD_Init(PCCARD_HandleTypeDef *hpccard, FSMC_NAND_PCC_TimingTypeDef *ComSpaceTiming, FSMC_NAND_PCC_TimingTypeDef *AttSpaceTiming, FSMC_NAND_PCC_TimingTypeDef *IOSpaceTiming)
143 /* Check the PCCARD controller state */
144 if(hpccard == NULL)
146 return HAL_ERROR;
149 if(hpccard->State == HAL_PCCARD_STATE_RESET)
151 /* Allocate lock resource and initialize it */
152 hpccard->Lock = HAL_UNLOCKED;
154 /* Initialize the low level hardware (MSP) */
155 HAL_PCCARD_MspInit(hpccard);
158 /* Initialize the PCCARD state */
159 hpccard->State = HAL_PCCARD_STATE_BUSY;
161 /* Initialize PCCARD control Interface */
162 FSMC_PCCARD_Init(hpccard->Instance, &(hpccard->Init));
164 /* Init PCCARD common space timing Interface */
165 FSMC_PCCARD_CommonSpace_Timing_Init(hpccard->Instance, ComSpaceTiming);
167 /* Init PCCARD attribute space timing Interface */
168 FSMC_PCCARD_AttributeSpace_Timing_Init(hpccard->Instance, AttSpaceTiming);
170 /* Init PCCARD IO space timing Interface */
171 FSMC_PCCARD_IOSpace_Timing_Init(hpccard->Instance, IOSpaceTiming);
173 /* Enable the PCCARD device */
174 __FSMC_PCCARD_ENABLE(hpccard->Instance);
176 /* Update the PCCARD state */
177 hpccard->State = HAL_PCCARD_STATE_READY;
179 return HAL_OK;
184 * @brief Perform the PCCARD memory De-initialization sequence
185 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
186 * the configuration information for PCCARD module.
187 * @retval HAL status
189 HAL_StatusTypeDef HAL_PCCARD_DeInit(PCCARD_HandleTypeDef *hpccard)
191 /* De-Initialize the low level hardware (MSP) */
192 HAL_PCCARD_MspDeInit(hpccard);
194 /* Configure the PCCARD registers with their reset values */
195 FSMC_PCCARD_DeInit(hpccard->Instance);
197 /* Update the PCCARD controller state */
198 hpccard->State = HAL_PCCARD_STATE_RESET;
200 /* Release Lock */
201 __HAL_UNLOCK(hpccard);
203 return HAL_OK;
207 * @brief PCCARD MSP Init
208 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
209 * the configuration information for PCCARD module.
210 * @retval None
212 __weak void HAL_PCCARD_MspInit(PCCARD_HandleTypeDef *hpccard)
214 /* Prevent unused argument(s) compilation warning */
215 UNUSED(hpccard);
216 /* NOTE : This function Should not be modified, when the callback is needed,
217 the HAL_PCCARD_MspInit could be implemented in the user file
222 * @brief PCCARD MSP DeInit
223 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
224 * the configuration information for PCCARD module.
225 * @retval None
227 __weak void HAL_PCCARD_MspDeInit(PCCARD_HandleTypeDef *hpccard)
229 /* Prevent unused argument(s) compilation warning */
230 UNUSED(hpccard);
231 /* NOTE : This function Should not be modified, when the callback is needed,
232 the HAL_PCCARD_MspDeInit could be implemented in the user file
237 * @}
240 /** @defgroup PCCARD_Exported_Functions_Group2 Input Output and memory functions
241 * @brief Input Output and memory control functions
243 @verbatim
244 ==============================================================================
245 ##### PCCARD Input Output and memory functions #####
246 ==============================================================================
247 [..]
248 This section provides functions allowing to use and control the PCCARD memory
250 @endverbatim
251 * @{
255 * @brief Read Compact Flash's ID.
256 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
257 * the configuration information for PCCARD module.
258 * @param CompactFlash_ID: Compact flash ID structure.
259 * @param pStatus: pointer to compact flash status
260 * @retval HAL status
263 HAL_StatusTypeDef HAL_PCCARD_Read_ID(PCCARD_HandleTypeDef *hpccard, uint8_t CompactFlash_ID[], uint8_t *pStatus)
265 uint32_t timeout = PCCARD_TIMEOUT_READ_ID, index = 0U;
266 uint8_t status = 0U;
268 /* Process Locked */
269 __HAL_LOCK(hpccard);
271 /* Check the PCCARD controller state */
272 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
274 return HAL_BUSY;
277 /* Update the PCCARD controller state */
278 hpccard->State = HAL_PCCARD_STATE_BUSY;
280 /* Initialize the CF status */
281 *pStatus = PCCARD_READY;
283 /* Send the Identify Command */
284 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = 0xECECU;
286 /* Read CF IDs and timeout treatment */
289 /* Read the CF status */
290 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
292 timeout--;
293 }while((status != PCCARD_STATUS_OK) && timeout);
295 if(timeout == 0U)
297 *pStatus = PCCARD_TIMEOUT_ERROR;
299 else
301 /* Read CF ID bytes */
302 for(index = 0U; index < 16U; index++)
304 CompactFlash_ID[index] = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_DATA);
308 /* Update the PCCARD controller state */
309 hpccard->State = HAL_PCCARD_STATE_READY;
311 /* Process unlocked */
312 __HAL_UNLOCK(hpccard);
314 return HAL_OK;
318 * @brief Read sector from PCCARD memory
319 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
320 * the configuration information for PCCARD module.
321 * @param pBuffer: pointer to destination read buffer
322 * @param SectorAddress: Sector address to read
323 * @param pStatus: pointer to CF status
324 * @retval HAL status
326 HAL_StatusTypeDef HAL_PCCARD_Read_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t *pBuffer, uint16_t SectorAddress, uint8_t *pStatus)
328 uint32_t timeout = PCCARD_TIMEOUT_SECTOR, index = 0U;
329 uint8_t status = 0U;
331 /* Process Locked */
332 __HAL_LOCK(hpccard);
334 /* Check the PCCARD controller state */
335 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
337 return HAL_BUSY;
340 /* Update the PCCARD controller state */
341 hpccard->State = HAL_PCCARD_STATE_BUSY;
343 /* Initialize CF status */
344 *pStatus = PCCARD_READY;
346 /* Set the parameters to write a sector */
347 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_HIGH) = (uint16_t)0x00;
348 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_COUNT) = ((uint16_t)0x0100) | ((uint16_t)SectorAddress);
349 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = (uint16_t)0xE4A0;
353 /* wait till the Status = 0x80 */
354 status = *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
355 timeout--;
356 }while((status == 0x80U) && timeout);
358 if(timeout == 0U)
360 *pStatus = PCCARD_TIMEOUT_ERROR;
363 timeout = 0xFFFFU;
367 /* wait till the Status = PCCARD_STATUS_OK */
368 status = *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
369 timeout--;
370 }while((status != PCCARD_STATUS_OK) && timeout);
372 if(timeout == 0U)
374 *pStatus = PCCARD_TIMEOUT_ERROR;
377 /* Read bytes */
378 for(; index < PCCARD_SECTOR_SIZE; index++)
380 *(uint16_t *)pBuffer++ = *(uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR);
383 /* Update the PCCARD controller state */
384 hpccard->State = HAL_PCCARD_STATE_READY;
386 /* Process unlocked */
387 __HAL_UNLOCK(hpccard);
389 return HAL_OK;
394 * @brief Write sector to PCCARD memory
395 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
396 * the configuration information for PCCARD module.
397 * @param pBuffer: pointer to source write buffer
398 * @param SectorAddress: Sector address to write
399 * @param pStatus: pointer to CF status
400 * @retval HAL status
402 HAL_StatusTypeDef HAL_PCCARD_Write_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t *pBuffer, uint16_t SectorAddress, uint8_t *pStatus)
404 uint32_t timeout = PCCARD_TIMEOUT_SECTOR, index = 0U;
405 uint8_t status = 0U;
407 /* Process Locked */
408 __HAL_LOCK(hpccard);
410 /* Check the PCCARD controller state */
411 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
413 return HAL_BUSY;
416 /* Update the PCCARD controller state */
417 hpccard->State = HAL_PCCARD_STATE_BUSY;
419 /* Initialize CF status */
420 *pStatus = PCCARD_READY;
422 /* Set the parameters to write a sector */
423 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_HIGH) = (uint16_t)0x00;
424 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_COUNT) = ((uint16_t)0x0100) | ((uint16_t)SectorAddress);
425 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = (uint16_t)0x30A0;
429 /* Wait till the Status = PCCARD_STATUS_OK */
430 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
431 timeout--;
432 }while((status != PCCARD_STATUS_OK) && timeout);
434 if(timeout == 0U)
436 *pStatus = PCCARD_TIMEOUT_ERROR;
439 /* Write bytes */
440 for(; index < PCCARD_SECTOR_SIZE; index++)
442 *(uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR) = *(uint16_t *)pBuffer++;
447 /* Wait till the Status = PCCARD_STATUS_WRITE_OK */
448 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
449 timeout--;
450 }while((status != PCCARD_STATUS_WRITE_OK) && timeout);
452 if(timeout == 0U)
454 *pStatus = PCCARD_TIMEOUT_ERROR;
457 /* Update the PCCARD controller state */
458 hpccard->State = HAL_PCCARD_STATE_READY;
460 /* Process unlocked */
461 __HAL_UNLOCK(hpccard);
463 return HAL_OK;
468 * @brief Erase sector from PCCARD memory
469 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
470 * the configuration information for PCCARD module.
471 * @param SectorAddress: Sector address to erase
472 * @param pStatus: pointer to CF status
473 * @retval HAL status
475 HAL_StatusTypeDef HAL_PCCARD_Erase_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t SectorAddress, uint8_t *pStatus)
477 uint32_t timeout = 0x400U;
478 uint8_t status = 0;
480 /* Process Locked */
481 __HAL_LOCK(hpccard);
483 /* Check the PCCARD controller state */
484 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
486 return HAL_BUSY;
489 /* Update the PCCARD controller state */
490 hpccard->State = HAL_PCCARD_STATE_BUSY;
492 /* Initialize CF status */
493 *pStatus = PCCARD_READY;
495 /* Set the parameters to write a sector */
496 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_LOW) = 0x00;
497 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_HIGH) = 0x00;
498 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_NUMBER) = SectorAddress;
499 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_COUNT) = 0x01;
500 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CARD_HEAD) = 0xA0;
501 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = ATA_ERASE_SECTOR_CMD;
503 /* wait till the CF is ready */
504 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
506 while((status != PCCARD_STATUS_WRITE_OK) && timeout)
508 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
509 timeout--;
512 if(timeout == 0U)
514 *pStatus = PCCARD_TIMEOUT_ERROR;
517 /* Check the PCCARD controller state */
518 hpccard->State = HAL_PCCARD_STATE_READY;
520 /* Process unlocked */
521 __HAL_UNLOCK(hpccard);
523 return HAL_OK;
527 * @brief Reset the PCCARD memory
528 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
529 * the configuration information for PCCARD module.
530 * @retval HAL status
532 HAL_StatusTypeDef HAL_PCCARD_Reset(PCCARD_HandleTypeDef *hpccard)
534 /* Process Locked */
535 __HAL_LOCK(hpccard);
537 /* Check the PCCARD controller state */
538 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
540 return HAL_BUSY;
543 /* Provide an SW reset and Read and verify the:
544 - CF Configuration Option Register at address 0x98000200 --> 0x80
545 - Card Configuration and Status Register at address 0x98000202 --> 0x00
546 - Pin Replacement Register at address 0x98000204 --> 0x0C
547 - Socket and Copy Register at address 0x98000206 --> 0x00
550 /* Check the PCCARD controller state */
551 hpccard->State = HAL_PCCARD_STATE_BUSY;
553 *(__IO uint8_t *)(PCCARD_ATTRIBUTE_SPACE_ADDRESS | ATA_CARD_CONFIGURATION) = 0x01;
555 /* Check the PCCARD controller state */
556 hpccard->State = HAL_PCCARD_STATE_READY;
558 /* Process unlocked */
559 __HAL_UNLOCK(hpccard);
561 return HAL_OK;
565 * @brief This function handles PCCARD device interrupt request.
566 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
567 * the configuration information for PCCARD module.
568 * @retval HAL status
570 void HAL_PCCARD_IRQHandler(PCCARD_HandleTypeDef *hpccard)
572 /* Check PCCARD interrupt Rising edge flag */
573 if(__FSMC_PCCARD_GET_FLAG(hpccard->Instance, FSMC_FLAG_RISING_EDGE))
575 /* PCCARD interrupt callback*/
576 HAL_PCCARD_ITCallback(hpccard);
578 /* Clear PCCARD interrupt Rising edge pending bit */
579 __FSMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FSMC_FLAG_RISING_EDGE);
582 /* Check PCCARD interrupt Level flag */
583 if(__FSMC_PCCARD_GET_FLAG(hpccard->Instance, FSMC_FLAG_LEVEL))
585 /* PCCARD interrupt callback*/
586 HAL_PCCARD_ITCallback(hpccard);
588 /* Clear PCCARD interrupt Level pending bit */
589 __FSMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FSMC_FLAG_LEVEL);
592 /* Check PCCARD interrupt Falling edge flag */
593 if(__FSMC_PCCARD_GET_FLAG(hpccard->Instance, FSMC_FLAG_FALLING_EDGE))
595 /* PCCARD interrupt callback*/
596 HAL_PCCARD_ITCallback(hpccard);
598 /* Clear PCCARD interrupt Falling edge pending bit */
599 __FSMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FSMC_FLAG_FALLING_EDGE);
602 /* Check PCCARD interrupt FIFO empty flag */
603 if(__FSMC_PCCARD_GET_FLAG(hpccard->Instance, FSMC_FLAG_FEMPT))
605 /* PCCARD interrupt callback*/
606 HAL_PCCARD_ITCallback(hpccard);
608 /* Clear PCCARD interrupt FIFO empty pending bit */
609 __FSMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FSMC_FLAG_FEMPT);
615 * @brief PCCARD interrupt feature callback
616 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
617 * the configuration information for PCCARD module.
618 * @retval None
620 __weak void HAL_PCCARD_ITCallback(PCCARD_HandleTypeDef *hpccard)
622 /* Prevent unused argument(s) compilation warning */
623 UNUSED(hpccard);
624 /* NOTE : This function Should not be modified, when the callback is needed,
625 the HAL_PCCARD_ITCallback could be implemented in the user file
630 * @}
633 /** @defgroup PCCARD_Exported_Functions_Group3 Peripheral State functions
634 * @brief Peripheral State functions
636 @verbatim
637 ==============================================================================
638 ##### PCCARD Peripheral State functions #####
639 ==============================================================================
640 [..]
641 This subsection permits to get in run-time the status of the PCCARD controller
642 and the data flow.
644 @endverbatim
645 * @{
649 * @brief return the PCCARD controller state
650 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
651 * the configuration information for PCCARD module.
652 * @retval HAL state
654 HAL_PCCARD_StateTypeDef HAL_PCCARD_GetState(PCCARD_HandleTypeDef *hpccard)
656 return hpccard->State;
660 * @brief Get the compact flash memory status
661 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
662 * the configuration information for PCCARD module.
663 * @retval New status of the CF operation. This parameter can be:
664 * - CompactFlash_TIMEOUT_ERROR: when the previous operation generate
665 * a Timeout error
666 * - CompactFlash_READY: when memory is ready for the next operation
669 HAL_PCCARD_StatusTypeDef HAL_PCCARD_GetStatus(PCCARD_HandleTypeDef *hpccard)
671 uint32_t timeout = PCCARD_TIMEOUT_STATUS, status_cf = 0;
673 /* Check the PCCARD controller state */
674 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
676 return HAL_PCCARD_STATUS_ONGOING;
679 status_cf = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
681 while((status_cf == PCCARD_BUSY) && timeout)
683 status_cf = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
684 timeout--;
687 if(timeout == 0U)
689 status_cf = PCCARD_TIMEOUT_ERROR;
692 /* Return the operation status */
693 return (HAL_PCCARD_StatusTypeDef) status_cf;
697 * @brief Reads the Compact Flash memory status using the Read status command
698 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
699 * the configuration information for PCCARD module.
700 * @retval The status of the Compact Flash memory. This parameter can be:
701 * - CompactFlash_BUSY: when memory is busy
702 * - CompactFlash_READY: when memory is ready for the next operation
703 * - CompactFlash_ERROR: when the previous operation gererates error
705 HAL_PCCARD_StatusTypeDef HAL_PCCARD_ReadStatus(PCCARD_HandleTypeDef *hpccard)
707 uint8_t data = 0U, status_cf = PCCARD_BUSY;
709 /* Check the PCCARD controller state */
710 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
712 return HAL_PCCARD_STATUS_ONGOING;
715 /* Read status operation */
716 data = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
718 if((data & PCCARD_TIMEOUT_ERROR) == PCCARD_TIMEOUT_ERROR)
720 status_cf = PCCARD_TIMEOUT_ERROR;
722 else if((data & PCCARD_READY) == PCCARD_READY)
724 status_cf = PCCARD_READY;
727 return (HAL_PCCARD_StatusTypeDef) status_cf;
731 * @}
735 * @}
738 * @}
741 #endif /* STM32F101xE || STM32F103xE || STM32F101xG || STM32F103xG */
742 #endif /* HAL_PCCARD_MODULE_ENABLED */
745 * @}
748 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/