2 ******************************************************************************
3 * @file stm32f4xx_hal_pccard.c
4 * @author MCD Application Team
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 FMC/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()/HAL_CF_Init() with control and timing parameters for
22 both common and attribute spaces.
24 (+) Read PCCARD/Compact Flash memory maker and device IDs using the function
25 HAL_PCCARD_Read_ID()/HAL_CF_Read_ID(). The read information is stored in
26 the CompactFlash_ID 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() -
30 HAL_CF_Read_Sector()/HAL_CF_Write_Sector(), to read/write sector.
32 (+) Perform PCCARD/Compact Flash Reset chip operation using the function
33 HAL_PCCARD_Reset()/HAL_CF_Reset.
35 (+) Perform PCCARD/Compact Flash erase sector operation using the function
36 HAL_PCCARD_Erase_Sector()/HAL_CF_Erase_Sector.
38 (+) Read the PCCARD/Compact Flash status operation using the function
39 HAL_PCCARD_ReadStatus()/HAL_CF_ReadStatus().
41 (+) You can monitor the PCCARD/Compact Flash device HAL state by calling
42 the function HAL_PCCARD_GetState()/HAL_CF_GetState()
45 (@) This driver is a set of generic APIs which handle standard PCCARD/compact flash
46 operations. If a PCCARD/Compact Flash device contains different operations
47 and/or implementations, it should be implemented separately.
50 ******************************************************************************
53 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
55 * Redistribution and use in source and binary forms, with or without modification,
56 * are permitted provided that the following conditions are met:
57 * 1. Redistributions of source code must retain the above copyright notice,
58 * this list of conditions and the following disclaimer.
59 * 2. Redistributions in binary form must reproduce the above copyright notice,
60 * this list of conditions and the following disclaimer in the documentation
61 * and/or other materials provided with the distribution.
62 * 3. Neither the name of STMicroelectronics nor the names of its contributors
63 * may be used to endorse or promote products derived from this software
64 * without specific prior written permission.
66 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
67 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
68 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
69 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
70 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
71 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
72 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
73 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
74 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
75 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
77 ******************************************************************************
80 /* Includes ------------------------------------------------------------------*/
81 #include "stm32f4xx_hal.h"
83 /** @addtogroup STM32F4xx_HAL_Driver
87 #ifdef HAL_PCCARD_MODULE_ENABLED
88 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
89 defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
90 /** @defgroup PCCARD PCCARD
91 * @brief PCCARD HAL module driver
94 /* Private typedef -----------------------------------------------------------*/
95 /* Private define ------------------------------------------------------------*/
97 /** @defgroup PCCARD_Private_Defines PCCARD Private Defines
100 #define PCCARD_TIMEOUT_READ_ID 0x0000FFFFU
101 #define PCCARD_TIMEOUT_READ_WRITE_SECTOR 0x0000FFFFU
102 #define PCCARD_TIMEOUT_ERASE_SECTOR 0x00000400U
103 #define PCCARD_TIMEOUT_STATUS 0x01000000U
105 #define PCCARD_STATUS_OK (uint8_t)0x58
106 #define PCCARD_STATUS_WRITE_OK (uint8_t)0x50
111 /* Private macro -------------------------------------------------------------*/
112 /* Private variables ---------------------------------------------------------*/
113 /* Private function ----------------------------------------------------------*/
114 /* Exported functions --------------------------------------------------------*/
115 /** @defgroup PCCARD_Exported_Functions PCCARD Exported Functions
119 /** @defgroup PCCARD_Exported_Functions_Group1 Initialization and de-initialization functions
120 * @brief Initialization and Configuration functions
123 ==============================================================================
124 ##### PCCARD Initialization and de-initialization functions #####
125 ==============================================================================
127 This section provides functions allowing to initialize/de-initialize
135 * @brief Perform the PCCARD memory Initialization sequence
136 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
137 * the configuration information for PCCARD module.
138 * @param ComSpaceTiming: Common space timing structure
139 * @param AttSpaceTiming: Attribute space timing structure
140 * @param IOSpaceTiming: IO space timing structure
143 HAL_StatusTypeDef
HAL_PCCARD_Init(PCCARD_HandleTypeDef
*hpccard
, FMC_NAND_PCC_TimingTypeDef
*ComSpaceTiming
, FMC_NAND_PCC_TimingTypeDef
*AttSpaceTiming
, FMC_NAND_PCC_TimingTypeDef
*IOSpaceTiming
)
145 /* Check the PCCARD controller state */
151 if(hpccard
->State
== HAL_PCCARD_STATE_RESET
)
153 /* Allocate lock resource and initialize it */
154 hpccard
->Lock
= HAL_UNLOCKED
;
155 /* Initialize the low level hardware (MSP) */
156 HAL_PCCARD_MspInit(hpccard
);
159 /* Initialize the PCCARD state */
160 hpccard
->State
= HAL_PCCARD_STATE_BUSY
;
162 /* Initialize PCCARD control Interface */
163 FMC_PCCARD_Init(hpccard
->Instance
, &(hpccard
->Init
));
165 /* Init PCCARD common space timing Interface */
166 FMC_PCCARD_CommonSpace_Timing_Init(hpccard
->Instance
, ComSpaceTiming
);
168 /* Init PCCARD attribute space timing Interface */
169 FMC_PCCARD_AttributeSpace_Timing_Init(hpccard
->Instance
, AttSpaceTiming
);
171 /* Init PCCARD IO space timing Interface */
172 FMC_PCCARD_IOSpace_Timing_Init(hpccard
->Instance
, IOSpaceTiming
);
174 /* Enable the PCCARD device */
175 __FMC_PCCARD_ENABLE(hpccard
->Instance
);
177 /* Update the PCCARD state */
178 hpccard
->State
= HAL_PCCARD_STATE_READY
;
185 * @brief Perform the PCCARD memory De-initialization sequence
186 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
187 * the configuration information for PCCARD module.
190 HAL_StatusTypeDef
HAL_PCCARD_DeInit(PCCARD_HandleTypeDef
*hpccard
)
192 /* De-Initialize the low level hardware (MSP) */
193 HAL_PCCARD_MspDeInit(hpccard
);
195 /* Configure the PCCARD registers with their reset values */
196 FMC_PCCARD_DeInit(hpccard
->Instance
);
198 /* Update the PCCARD controller state */
199 hpccard
->State
= HAL_PCCARD_STATE_RESET
;
202 __HAL_UNLOCK(hpccard
);
208 * @brief PCCARD MSP Init
209 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
210 * the configuration information for PCCARD module.
213 __weak
void HAL_PCCARD_MspInit(PCCARD_HandleTypeDef
*hpccard
)
215 /* Prevent unused argument(s) compilation warning */
217 /* NOTE : This function Should not be modified, when the callback is needed,
218 the HAL_PCCARD_MspInit could be implemented in the user file
223 * @brief PCCARD MSP DeInit
224 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
225 * the configuration information for PCCARD module.
228 __weak
void HAL_PCCARD_MspDeInit(PCCARD_HandleTypeDef
*hpccard
)
230 /* Prevent unused argument(s) compilation warning */
232 /* NOTE : This function Should not be modified, when the callback is needed,
233 the HAL_PCCARD_MspDeInit could be implemented in the user file
241 /** @defgroup PCCARD_Exported_Functions_Group2 Input and Output functions
242 * @brief Input Output and memory control functions
245 ==============================================================================
246 ##### PCCARD Input and Output functions #####
247 ==============================================================================
249 This section provides functions allowing to use and control the PCCARD memory
256 * @brief Read Compact Flash's ID.
257 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
258 * the configuration information for PCCARD module.
259 * @param CompactFlash_ID: Compact flash ID structure.
260 * @param pStatus: pointer to compact flash status
264 HAL_StatusTypeDef
HAL_PCCARD_Read_ID(PCCARD_HandleTypeDef
*hpccard
, uint8_t CompactFlash_ID
[], uint8_t *pStatus
)
266 uint32_t timeout
= PCCARD_TIMEOUT_READ_ID
, index
= 0U;
272 /* Check the PCCARD controller state */
273 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
278 /* Update the PCCARD controller state */
279 hpccard
->State
= HAL_PCCARD_STATE_BUSY
;
281 /* Initialize the PCCARD status */
282 *pStatus
= PCCARD_READY
;
284 /* Send the Identify Command */
285 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD
) = 0xECEC;
287 /* Read PCCARD IDs and timeout treatment */
290 /* Read the PCCARD status */
291 status
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
294 }while((status
!= PCCARD_STATUS_OK
) && timeout
);
298 *pStatus
= PCCARD_TIMEOUT_ERROR
;
302 /* Read PCCARD ID bytes */
303 for(index
= 0U; index
< 16U; index
++)
305 CompactFlash_ID
[index
] = *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_DATA
);
309 /* Update the PCCARD controller state */
310 hpccard
->State
= HAL_PCCARD_STATE_READY
;
312 /* Process unlocked */
313 __HAL_UNLOCK(hpccard
);
319 * @brief Read sector from PCCARD memory
320 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
321 * the configuration information for PCCARD module.
322 * @param pBuffer: pointer to destination read buffer
323 * @param SectorAddress: Sector address to read
324 * @param pStatus: pointer to PCCARD status
327 HAL_StatusTypeDef
HAL_PCCARD_Read_Sector(PCCARD_HandleTypeDef
*hpccard
, uint16_t *pBuffer
, uint16_t SectorAddress
, uint8_t *pStatus
)
329 uint32_t timeout
= PCCARD_TIMEOUT_READ_WRITE_SECTOR
, index
= 0U;
335 /* Check the PCCARD controller state */
336 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
341 /* Update the PCCARD controller state */
342 hpccard
->State
= HAL_PCCARD_STATE_BUSY
;
344 /* Initialize PCCARD status */
345 *pStatus
= PCCARD_READY
;
347 /* Set the parameters to write a sector */
348 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_CYLINDER_HIGH
) = (uint16_t)0x00;
349 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_SECTOR_COUNT
) = ((uint16_t)0x0100) | ((uint16_t)SectorAddress
);
350 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD
) = (uint16_t)0xE4A0;
354 /* wait till the Status = 0x80 */
355 status
= *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
357 }while((status
== 0x80) && timeout
);
361 *pStatus
= PCCARD_TIMEOUT_ERROR
;
364 timeout
= PCCARD_TIMEOUT_READ_WRITE_SECTOR
;
368 /* wait till the Status = PCCARD_STATUS_OK */
369 status
= *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
371 }while((status
!= PCCARD_STATUS_OK
) && timeout
);
375 *pStatus
= PCCARD_TIMEOUT_ERROR
;
379 for(; index
< PCCARD_SECTOR_SIZE
; index
++)
381 *(uint16_t *)pBuffer
++ = *(uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
);
384 /* Update the PCCARD controller state */
385 hpccard
->State
= HAL_PCCARD_STATE_READY
;
387 /* Process unlocked */
388 __HAL_UNLOCK(hpccard
);
395 * @brief Write sector to PCCARD memory
396 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
397 * the configuration information for PCCARD module.
398 * @param pBuffer: pointer to source write buffer
399 * @param SectorAddress: Sector address to write
400 * @param pStatus: pointer to PCCARD status
403 HAL_StatusTypeDef
HAL_PCCARD_Write_Sector(PCCARD_HandleTypeDef
*hpccard
, uint16_t *pBuffer
, uint16_t SectorAddress
, uint8_t *pStatus
)
405 uint32_t timeout
= PCCARD_TIMEOUT_READ_WRITE_SECTOR
, index
= 0U;
411 /* Check the PCCARD controller state */
412 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
417 /* Update the PCCARD controller state */
418 hpccard
->State
= HAL_PCCARD_STATE_BUSY
;
420 /* Initialize PCCARD status */
421 *pStatus
= PCCARD_READY
;
423 /* Set the parameters to write a sector */
424 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_CYLINDER_HIGH
) = (uint16_t)0x00;
425 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_SECTOR_COUNT
) = ((uint16_t)0x0100) | ((uint16_t)SectorAddress
);
426 *(__IO
uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD
) = (uint16_t)0x30A0;
430 /* Wait till the Status = PCCARD_STATUS_OK */
431 status
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
433 }while((status
!= PCCARD_STATUS_OK
) && timeout
);
437 *pStatus
= PCCARD_TIMEOUT_ERROR
;
441 for(; index
< PCCARD_SECTOR_SIZE
; index
++)
443 *(uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
) = *(uint16_t *)pBuffer
++;
448 /* Wait till the Status = PCCARD_STATUS_WRITE_OK */
449 status
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
451 }while((status
!= PCCARD_STATUS_WRITE_OK
) && timeout
);
455 *pStatus
= PCCARD_TIMEOUT_ERROR
;
458 /* Update the PCCARD controller state */
459 hpccard
->State
= HAL_PCCARD_STATE_READY
;
461 /* Process unlocked */
462 __HAL_UNLOCK(hpccard
);
469 * @brief Erase sector from PCCARD memory
470 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
471 * the configuration information for PCCARD module.
472 * @param SectorAddress: Sector address to erase
473 * @param pStatus: pointer to PCCARD status
476 HAL_StatusTypeDef
HAL_PCCARD_Erase_Sector(PCCARD_HandleTypeDef
*hpccard
, uint16_t SectorAddress
, uint8_t *pStatus
)
478 uint32_t timeout
= PCCARD_TIMEOUT_ERASE_SECTOR
;
484 /* Check the PCCARD controller state */
485 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
490 /* Update the PCCARD controller state */
491 hpccard
->State
= HAL_PCCARD_STATE_BUSY
;
493 /* Initialize PCCARD status */
494 *pStatus
= PCCARD_READY
;
496 /* Set the parameters to write a sector */
497 *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_CYLINDER_LOW
) = 0x00;
498 *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_CYLINDER_HIGH
) = 0x00;
499 *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_SECTOR_NUMBER
) = SectorAddress
;
500 *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_SECTOR_COUNT
) = 0x01;
501 *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_CARD_HEAD
) = 0xA0;
502 *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD
) = ATA_ERASE_SECTOR_CMD
;
504 /* wait till the PCCARD is ready */
505 status
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
507 while((status
!= PCCARD_STATUS_WRITE_OK
) && timeout
)
509 status
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
515 *pStatus
= PCCARD_TIMEOUT_ERROR
;
518 /* Check the PCCARD controller state */
519 hpccard
->State
= HAL_PCCARD_STATE_READY
;
521 /* Process unlocked */
522 __HAL_UNLOCK(hpccard
);
528 * @brief Reset the PCCARD memory
529 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
530 * the configuration information for PCCARD module.
533 HAL_StatusTypeDef
HAL_PCCARD_Reset(PCCARD_HandleTypeDef
*hpccard
)
538 /* Check the PCCARD controller state */
539 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
544 /* Provide a SW reset and Read and verify the:
545 - PCCard Configuration Option Register at address 0x98000200 --> 0x80
546 - Card Configuration and Status Register at address 0x98000202 --> 0x00
547 - Pin Replacement Register at address 0x98000204 --> 0x0C
548 - Socket and Copy Register at address 0x98000206 --> 0x00
551 /* Check the PCCARD controller state */
552 hpccard
->State
= HAL_PCCARD_STATE_BUSY
;
554 *(__IO
uint8_t *)(PCCARD_ATTRIBUTE_SPACE_ADDRESS
| ATA_CARD_CONFIGURATION
) = 0x01;
556 /* Check the PCCARD controller state */
557 hpccard
->State
= HAL_PCCARD_STATE_READY
;
559 /* Process unlocked */
560 __HAL_UNLOCK(hpccard
);
566 * @brief This function handles PCCARD device interrupt request.
567 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
568 * the configuration information for PCCARD module.
571 void HAL_PCCARD_IRQHandler(PCCARD_HandleTypeDef
*hpccard
)
573 /* Check PCCARD interrupt Rising edge flag */
574 if(__FMC_PCCARD_GET_FLAG(hpccard
->Instance
, FMC_FLAG_RISING_EDGE
))
576 /* PCCARD interrupt callback*/
577 HAL_PCCARD_ITCallback(hpccard
);
579 /* Clear PCCARD interrupt Rising edge pending bit */
580 __FMC_PCCARD_CLEAR_FLAG(hpccard
->Instance
, FMC_FLAG_RISING_EDGE
);
583 /* Check PCCARD interrupt Level flag */
584 if(__FMC_PCCARD_GET_FLAG(hpccard
->Instance
, FMC_FLAG_LEVEL
))
586 /* PCCARD interrupt callback*/
587 HAL_PCCARD_ITCallback(hpccard
);
589 /* Clear PCCARD interrupt Level pending bit */
590 __FMC_PCCARD_CLEAR_FLAG(hpccard
->Instance
, FMC_FLAG_LEVEL
);
593 /* Check PCCARD interrupt Falling edge flag */
594 if(__FMC_PCCARD_GET_FLAG(hpccard
->Instance
, FMC_FLAG_FALLING_EDGE
))
596 /* PCCARD interrupt callback*/
597 HAL_PCCARD_ITCallback(hpccard
);
599 /* Clear PCCARD interrupt Falling edge pending bit */
600 __FMC_PCCARD_CLEAR_FLAG(hpccard
->Instance
, FMC_FLAG_FALLING_EDGE
);
603 /* Check PCCARD interrupt FIFO empty flag */
604 if(__FMC_PCCARD_GET_FLAG(hpccard
->Instance
, FMC_FLAG_FEMPT
))
606 /* PCCARD interrupt callback*/
607 HAL_PCCARD_ITCallback(hpccard
);
609 /* Clear PCCARD interrupt FIFO empty pending bit */
610 __FMC_PCCARD_CLEAR_FLAG(hpccard
->Instance
, FMC_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.
620 __weak
void HAL_PCCARD_ITCallback(PCCARD_HandleTypeDef
*hpccard
)
622 /* Prevent unused argument(s) compilation warning */
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
633 /** @defgroup PCCARD_Exported_Functions_Group3 State functions
634 * @brief Peripheral State functions
637 ==============================================================================
638 ##### PCCARD State functions #####
639 ==============================================================================
641 This subsection permits to get in run-time the status of the PCCARD controller
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.
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 PCCARD operation. This parameter can be:
664 * - CompactFlash_TIMEOUT_ERROR: when the previous operation generate
666 * - CompactFlash_READY: when memory is ready for the next operation
668 HAL_PCCARD_StatusTypeDef
HAL_PCCARD_GetStatus(PCCARD_HandleTypeDef
*hpccard
)
670 uint32_t timeout
= PCCARD_TIMEOUT_STATUS
, status_pccard
= 0U;
672 /* Check the PCCARD controller state */
673 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
675 return HAL_PCCARD_STATUS_ONGOING
;
678 status_pccard
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
680 while((status_pccard
== PCCARD_BUSY
) && timeout
)
682 status_pccard
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
688 status_pccard
= PCCARD_TIMEOUT_ERROR
;
691 /* Return the operation status */
692 return (HAL_PCCARD_StatusTypeDef
) status_pccard
;
696 * @brief Reads the Compact Flash memory status using the Read status command
697 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
698 * the configuration information for PCCARD module.
699 * @retval The status of the Compact Flash memory. This parameter can be:
700 * - CompactFlash_BUSY: when memory is busy
701 * - CompactFlash_READY: when memory is ready for the next operation
702 * - CompactFlash_ERROR: when the previous operation generates error
704 HAL_PCCARD_StatusTypeDef
HAL_PCCARD_ReadStatus(PCCARD_HandleTypeDef
*hpccard
)
706 uint8_t data
= 0U, status_pccard
= PCCARD_BUSY
;
708 /* Check the PCCARD controller state */
709 if(hpccard
->State
== HAL_PCCARD_STATE_BUSY
)
711 return HAL_PCCARD_STATUS_ONGOING
;
714 /* Read status operation */
715 data
= *(__IO
uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR
| ATA_STATUS_CMD_ALTERNATE
);
717 if((data
& PCCARD_TIMEOUT_ERROR
) == PCCARD_TIMEOUT_ERROR
)
719 status_pccard
= PCCARD_TIMEOUT_ERROR
;
721 else if((data
& PCCARD_READY
) == PCCARD_READY
)
723 status_pccard
= PCCARD_READY
;
726 return (HAL_PCCARD_StatusTypeDef
) status_pccard
;
736 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx ||\
737 STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
738 #endif /* HAL_PCCARD_MODULE_ENABLED */
748 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/