2 ******************************************************************************
3 * @file stm32f1xx_hal_pccard.c
4 * @author MCD Application Team
6 * @date 15-December-2014
7 * @brief PCCARD HAL module driver.
8 * This file provides a generic firmware to drive PCCARD memories mounted
12 ===============================================================================
13 ##### How to use this driver #####
14 ===============================================================================
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
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
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.
47 ******************************************************************************
50 * <h2><center>© COPYRIGHT(c) 2014 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 ******************************************************************************
77 /* Includes ------------------------------------------------------------------*/
78 #include "stm32f1xx_hal.h"
80 /** @addtogroup STM32F1xx_HAL_Driver
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
92 /* Private typedef -----------------------------------------------------------*/
93 /* Private define ------------------------------------------------------------*/
94 /** @defgroup PCCARD_Private_Constants PCCARD Private Constants
98 #define PCCARD_TIMEOUT_READ_ID (uint32_t)0x0000FFFF
99 #define PCCARD_TIMEOUT_SECTOR (uint32_t)0x0000FFFF
100 #define PCCARD_TIMEOUT_STATUS (uint32_t)0x01000000
102 #define PCCARD_STATUS_OK (uint8_t)0x58
103 #define PCCARD_STATUS_WRITE_OK (uint8_t)0x50
108 /* Private macro -------------------------------------------------------------*/
109 /* Private variables ---------------------------------------------------------*/
110 /* Private function prototypes -----------------------------------------------*/
111 /* Exported functions ---------------------------------------------------------*/
113 /** @defgroup PCCARD_Exported_Functions PCCARD Exported Functions
117 /** @defgroup PCCARD_Exported_Functions_Group1 Initialization and de-initialization functions
118 * @brief Initialization and Configuration functions
121 ==============================================================================
122 ##### PCCARD Initialization and de-initialization functions #####
123 ==============================================================================
125 This section provides functions allowing to initialize/de-initialize
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
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 */
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
;
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.
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
;
201 __HAL_UNLOCK(hpccard
);
207 * @brief PCCARD MSP Init
208 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
209 * the configuration information for PCCARD module.
212 __weak
void HAL_PCCARD_MspInit(PCCARD_HandleTypeDef
*hpccard
)
214 /* NOTE : This function Should not be modified, when the callback is needed,
215 the HAL_PCCARD_MspInit could be implemented in the user file
220 * @brief PCCARD MSP DeInit
221 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
222 * the configuration information for PCCARD module.
225 __weak
void HAL_PCCARD_MspDeInit(PCCARD_HandleTypeDef
*hpccard
)
227 /* NOTE : This function Should not be modified, when the callback is needed,
228 the HAL_PCCARD_MspDeInit could be implemented in the user file
236 /** @defgroup PCCARD_Exported_Functions_Group2 Input Output and memory functions
237 * @brief Input Output and memory control functions
240 ==============================================================================
241 ##### PCCARD Input Output and memory functions #####
242 ==============================================================================
244 This section provides functions allowing to use and control the PCCARD memory
251 * @brief Read Compact Flash's ID.
252 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
253 * the configuration information for PCCARD module.
254 * @param CompactFlash_ID: Compact flash ID structure.
255 * @param pStatus: pointer to compact flash status
259 HAL_StatusTypeDef
HAL_PCCARD_Read_ID(PCCARD_HandleTypeDef
*hpccard
, uint8_t CompactFlash_ID
[], uint8_t *pStatus
)
261 uint32_t timeout
= PCCARD_TIMEOUT_READ_ID
, index
= 0;
267 /* Check the PCCARD controller state */
268 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
273 /* Update the PCCARD controller state */
274 hpccard
->State
= HAL_PCCARD_STATE_BUSY
;
276 /* Initialize the CF status */
277 *pStatus
= PCCARD_READY
;
279 /* Send the Identify Command */
280 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD
) = 0xECEC;
282 /* Read CF IDs and timeout treatment */
285 /* Read the CF status */
286 status
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
289 }while((status
!= PCCARD_STATUS_OK
) && timeout
);
293 *pStatus
= PCCARD_TIMEOUT_ERROR
;
297 /* Read CF ID bytes */
298 for(index
= 0; index
< 16; index
++)
300 CompactFlash_ID
[index
] = *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_DATA
);
304 /* Update the PCCARD controller state */
305 hpccard
->State
= HAL_PCCARD_STATE_READY
;
307 /* Process unlocked */
308 __HAL_UNLOCK(hpccard
);
314 * @brief Read sector from PCCARD memory
315 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
316 * the configuration information for PCCARD module.
317 * @param pBuffer: pointer to destination read buffer
318 * @param SectorAddress: Sector address to read
319 * @param pStatus: pointer to CF status
322 HAL_StatusTypeDef
HAL_PCCARD_Read_Sector(PCCARD_HandleTypeDef
*hpccard
, uint16_t *pBuffer
, uint16_t SectorAddress
, uint8_t *pStatus
)
324 uint32_t timeout
= PCCARD_TIMEOUT_SECTOR
, index
= 0;
330 /* Check the PCCARD controller state */
331 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
336 /* Update the PCCARD controller state */
337 hpccard
->State
= HAL_PCCARD_STATE_BUSY
;
339 /* Initialize CF status */
340 *pStatus
= PCCARD_READY
;
342 /* Set the parameters to write a sector */
343 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_CYLINDER_HIGH
) = (uint16_t)0x00;
344 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_SECTOR_COUNT
) = ((uint16_t)0x0100 ) | ((uint16_t)SectorAddress
);
345 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD
) = (uint16_t)0xE4A0;
349 /* wait till the Status = 0x80 */
350 status
= *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
352 }while((status
== 0x80) && timeout
);
356 *pStatus
= PCCARD_TIMEOUT_ERROR
;
363 /* wait till the Status = PCCARD_STATUS_OK */
364 status
= *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
366 }while((status
!= PCCARD_STATUS_OK
) && timeout
);
370 *pStatus
= PCCARD_TIMEOUT_ERROR
;
374 for(; index
< PCCARD_SECTOR_SIZE
; index
++)
376 *(uint16_t *)pBuffer
++ = *(uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
);
379 /* Update the PCCARD controller state */
380 hpccard
->State
= HAL_PCCARD_STATE_READY
;
382 /* Process unlocked */
383 __HAL_UNLOCK(hpccard
);
390 * @brief Write sector to PCCARD memory
391 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
392 * the configuration information for PCCARD module.
393 * @param pBuffer: pointer to source write buffer
394 * @param SectorAddress: Sector address to write
395 * @param pStatus: pointer to CF status
398 HAL_StatusTypeDef
HAL_PCCARD_Write_Sector(PCCARD_HandleTypeDef
*hpccard
, uint16_t *pBuffer
, uint16_t SectorAddress
, uint8_t *pStatus
)
400 uint32_t timeout
= PCCARD_TIMEOUT_SECTOR
, index
= 0;
406 /* Check the PCCARD controller state */
407 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
412 /* Update the PCCARD controller state */
413 hpccard
->State
= HAL_PCCARD_STATE_BUSY
;
415 /* Initialize CF status */
416 *pStatus
= PCCARD_READY
;
418 /* Set the parameters to write a sector */
419 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_CYLINDER_HIGH
) = (uint16_t)0x00;
420 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_SECTOR_COUNT
) = ((uint16_t)0x0100 ) | ((uint16_t)SectorAddress
);
421 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD
) = (uint16_t)0x30A0;
425 /* Wait till the Status = PCCARD_STATUS_OK */
426 status
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
428 }while((status
!= PCCARD_STATUS_OK
) && timeout
);
432 *pStatus
= PCCARD_TIMEOUT_ERROR
;
436 for(; index
< PCCARD_SECTOR_SIZE
; index
++)
438 *(uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
) = *(uint16_t *)pBuffer
++;
443 /* Wait till the Status = PCCARD_STATUS_WRITE_OK */
444 status
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
446 }while((status
!= PCCARD_STATUS_WRITE_OK
) && timeout
);
450 *pStatus
= PCCARD_TIMEOUT_ERROR
;
453 /* Update the PCCARD controller state */
454 hpccard
->State
= HAL_PCCARD_STATE_READY
;
456 /* Process unlocked */
457 __HAL_UNLOCK(hpccard
);
464 * @brief Erase sector from PCCARD memory
465 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
466 * the configuration information for PCCARD module.
467 * @param SectorAddress: Sector address to erase
468 * @param pStatus: pointer to CF status
471 HAL_StatusTypeDef
HAL_PCCARD_Erase_Sector(PCCARD_HandleTypeDef
*hpccard
, uint16_t SectorAddress
, uint8_t *pStatus
)
473 uint32_t timeout
= 0x400;
479 /* Check the PCCARD controller state */
480 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
485 /* Update the PCCARD controller state */
486 hpccard
->State
= HAL_PCCARD_STATE_BUSY
;
488 /* Initialize CF status */
489 *pStatus
= PCCARD_READY
;
491 /* Set the parameters to write a sector */
492 *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_CYLINDER_LOW
) = 0x00;
493 *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_CYLINDER_HIGH
) = 0x00;
494 *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_SECTOR_NUMBER
) = SectorAddress
;
495 *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_SECTOR_COUNT
) = 0x01;
496 *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_CARD_HEAD
) = 0xA0;
497 *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD
) = ATA_ERASE_SECTOR_CMD
;
499 /* wait till the CF is ready */
500 status
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
502 while((status
!= PCCARD_STATUS_WRITE_OK
) && timeout
)
504 status
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
510 *pStatus
= PCCARD_TIMEOUT_ERROR
;
513 /* Check the PCCARD controller state */
514 hpccard
->State
= HAL_PCCARD_STATE_READY
;
516 /* Process unlocked */
517 __HAL_UNLOCK(hpccard
);
523 * @brief Reset the PCCARD memory
524 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
525 * the configuration information for PCCARD module.
528 HAL_StatusTypeDef
HAL_PCCARD_Reset(PCCARD_HandleTypeDef
*hpccard
)
533 /* Check the PCCARD controller state */
534 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
539 /* Provide an SW reset and Read and verify the:
540 - CF Configuration Option Register at address 0x98000200 --> 0x80
541 - Card Configuration and Status Register at address 0x98000202 --> 0x00
542 - Pin Replacement Register at address 0x98000204 --> 0x0C
543 - Socket and Copy Register at address 0x98000206 --> 0x00
546 /* Check the PCCARD controller state */
547 hpccard
->State
= HAL_PCCARD_STATE_BUSY
;
549 *(__IO
uint8_t *)(PCCARD_ATTRIBUTE_SPACE_ADDRESS
| ATA_CARD_CONFIGURATION
) = 0x01;
551 /* Check the PCCARD controller state */
552 hpccard
->State
= HAL_PCCARD_STATE_READY
;
554 /* Process unlocked */
555 __HAL_UNLOCK(hpccard
);
561 * @brief This function handles PCCARD device interrupt request.
562 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
563 * the configuration information for PCCARD module.
566 void HAL_PCCARD_IRQHandler(PCCARD_HandleTypeDef
*hpccard
)
568 /* Check PCCARD interrupt Rising edge flag */
569 if(__FSMC_PCCARD_GET_FLAG(hpccard
->Instance
, FSMC_FLAG_RISING_EDGE
))
571 /* PCCARD interrupt callback*/
572 HAL_PCCARD_ITCallback(hpccard
);
574 /* Clear PCCARD interrupt Rising edge pending bit */
575 __FSMC_PCCARD_CLEAR_FLAG(hpccard
->Instance
, FSMC_FLAG_RISING_EDGE
);
578 /* Check PCCARD interrupt Level flag */
579 if(__FSMC_PCCARD_GET_FLAG(hpccard
->Instance
, FSMC_FLAG_LEVEL
))
581 /* PCCARD interrupt callback*/
582 HAL_PCCARD_ITCallback(hpccard
);
584 /* Clear PCCARD interrupt Level pending bit */
585 __FSMC_PCCARD_CLEAR_FLAG(hpccard
->Instance
, FSMC_FLAG_LEVEL
);
588 /* Check PCCARD interrupt Falling edge flag */
589 if(__FSMC_PCCARD_GET_FLAG(hpccard
->Instance
, FSMC_FLAG_FALLING_EDGE
))
591 /* PCCARD interrupt callback*/
592 HAL_PCCARD_ITCallback(hpccard
);
594 /* Clear PCCARD interrupt Falling edge pending bit */
595 __FSMC_PCCARD_CLEAR_FLAG(hpccard
->Instance
, FSMC_FLAG_FALLING_EDGE
);
598 /* Check PCCARD interrupt FIFO empty flag */
599 if(__FSMC_PCCARD_GET_FLAG(hpccard
->Instance
, FSMC_FLAG_FEMPT
))
601 /* PCCARD interrupt callback*/
602 HAL_PCCARD_ITCallback(hpccard
);
604 /* Clear PCCARD interrupt FIFO empty pending bit */
605 __FSMC_PCCARD_CLEAR_FLAG(hpccard
->Instance
, FSMC_FLAG_FEMPT
);
611 * @brief PCCARD interrupt feature callback
612 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
613 * the configuration information for PCCARD module.
616 __weak
void HAL_PCCARD_ITCallback(PCCARD_HandleTypeDef
*hpccard
)
618 /* NOTE : This function Should not be modified, when the callback is needed,
619 the HAL_PCCARD_ITCallback could be implemented in the user file
627 /** @defgroup PCCARD_Exported_Functions_Group3 Peripheral State functions
628 * @brief Peripheral State functions
631 ==============================================================================
632 ##### PCCARD Peripheral State functions #####
633 ==============================================================================
635 This subsection permits to get in run-time the status of the PCCARD controller
643 * @brief return the PCCARD controller state
644 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
645 * the configuration information for PCCARD module.
648 HAL_PCCARD_StateTypeDef
HAL_PCCARD_GetState(PCCARD_HandleTypeDef
*hpccard
)
650 return hpccard
->State
;
654 * @brief Get the compact flash memory status
655 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
656 * the configuration information for PCCARD module.
657 * @retval New status of the CF operation. This parameter can be:
658 * - CompactFlash_TIMEOUT_ERROR: when the previous operation generate
660 * - CompactFlash_READY: when memory is ready for the next operation
663 HAL_PCCARD_StatusTypeDef
HAL_PCCARD_GetStatus(PCCARD_HandleTypeDef
*hpccard
)
665 uint32_t timeout
= PCCARD_TIMEOUT_STATUS
, status_cf
= 0;
667 /* Check the PCCARD controller state */
668 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
670 return HAL_PCCARD_STATUS_ONGOING
;
673 status_cf
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
675 while((status_cf
== PCCARD_BUSY
) && timeout
)
677 status_cf
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
683 status_cf
= PCCARD_TIMEOUT_ERROR
;
686 /* Return the operation status */
687 return (HAL_PCCARD_StatusTypeDef
) status_cf
;
691 * @brief Reads the Compact Flash memory status using the Read status command
692 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
693 * the configuration information for PCCARD module.
694 * @retval The status of the Compact Flash memory. This parameter can be:
695 * - CompactFlash_BUSY: when memory is busy
696 * - CompactFlash_READY: when memory is ready for the next operation
697 * - CompactFlash_ERROR: when the previous operation gererates error
699 HAL_PCCARD_StatusTypeDef
HAL_PCCARD_ReadStatus(PCCARD_HandleTypeDef
*hpccard
)
701 uint8_t data
= 0, status_cf
= PCCARD_BUSY
;
703 /* Check the PCCARD controller state */
704 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
706 return HAL_PCCARD_STATUS_ONGOING
;
709 /* Read status operation */
710 data
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
712 if((data
& PCCARD_TIMEOUT_ERROR
) == PCCARD_TIMEOUT_ERROR
)
714 status_cf
= PCCARD_TIMEOUT_ERROR
;
716 else if((data
& PCCARD_READY
) == PCCARD_READY
)
718 status_cf
= PCCARD_READY
;
721 return (HAL_PCCARD_StatusTypeDef
) status_cf
;
735 #endif /* STM32F101xE || STM32F103xE || STM32F101xG || STM32F103xG */
736 #endif /* HAL_PCCARD_MODULE_ENABLED */
742 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/