F1 and F3 HAL / LL libraries
[betaflight.git] / lib / main / STM32F3 / Drivers / STM32F3xx_HAL_Driver / Src / stm32f3xx_hal_pccard.c
blobe1cae18e5ad7c98ee3716681583585b1b0371bc0
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_hal_pccard.c
4 * @author MCD Application Team
5 * @brief PCCARD HAL module driver.
6 * This file provides a generic firmware to drive PCCARD memories mounted
7 * as external device.
8 *
9 @verbatim
10 ===============================================================================
11 ##### How to use this driver #####
12 ===============================================================================
13 [..]
14 This driver is a generic layered driver which contains a set of APIs used to
15 control PCCARD/compact flash memories. It uses the FMC layer functions
16 to interface with PCCARD devices. This driver is used for:
18 (+) PCCARD/compact flash memory configuration sequence using the function
19 HAL_PCCARD_Init() with control and timing parameters for both common and
20 attribute spaces.
22 (+) Read PCCARD/compact flash memory maker and device IDs using the function
23 HAL_PCCARD_Read_ID(). The read information is stored in the CompactFlash_ID
24 structure declared by the function caller.
26 (+) Access PCCARD/compact flash memory by read/write operations using the functions
27 HAL_PCCARD_Read_Sector()/HAL_PCCARD_Write_Sector(), to read/write sector.
29 (+) Perform PCCARD/compact flash Reset chip operation using the function HAL_PCCARD_Reset().
31 (+) Perform PCCARD/compact flash erase sector operation using the function
32 HAL_PCCARD_Erase_Sector().
34 (+) Read the PCCARD/compact flash status operation using the function HAL_PCCARD_ReadStatus().
36 (+) You can monitor the PCCARD/compact flash device HAL state by calling the function
37 HAL_PCCARD_GetState()
39 [..]
40 (@) This driver is a set of generic APIs which handle standard PCCARD/compact flash
41 operations. If a PCCARD/compact flash device contains different operations
42 and/or implementations, it should be implemented separately.
44 @endverbatim
45 ******************************************************************************
46 * @attention
48 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
50 * Redistribution and use in source and binary forms, with or without modification,
51 * are permitted provided that the following conditions are met:
52 * 1. Redistributions of source code must retain the above copyright notice,
53 * this list of conditions and the following disclaimer.
54 * 2. Redistributions in binary form must reproduce the above copyright notice,
55 * this list of conditions and the following disclaimer in the documentation
56 * and/or other materials provided with the distribution.
57 * 3. Neither the name of STMicroelectronics nor the names of its contributors
58 * may be used to endorse or promote products derived from this software
59 * without specific prior written permission.
61 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
62 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
64 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
65 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
67 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
68 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
69 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
70 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72 ******************************************************************************
73 */
75 /* Includes ------------------------------------------------------------------*/
76 #include "stm32f3xx_hal.h"
78 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx)
79 /** @addtogroup STM32F3xx_HAL_Driver
80 * @{
83 #ifdef HAL_PCCARD_MODULE_ENABLED
85 /** @defgroup PCCARD PCCARD
86 * @brief PCCARD HAL module driver
87 * @{
90 /* Private typedef -----------------------------------------------------------*/
91 /* Private define ------------------------------------------------------------*/
92 /** @defgroup PCCARD_Private_Constants PCCARD Private Constants
93 * @{
96 #define PCCARD_TIMEOUT_READ_ID 0x0000FFFF
97 #define PCCARD_TIMEOUT_SECTOR 0x0000FFFF
98 #define PCCARD_TIMEOUT_STATUS 0x01000000
100 #define PCCARD_STATUS_OK (uint8_t)0x58
101 #define PCCARD_STATUS_WRITE_OK (uint8_t)0x50
103 * @}
106 /* Private macro -------------------------------------------------------------*/
107 /* Private variables ---------------------------------------------------------*/
108 /* Private function prototypes -----------------------------------------------*/
109 /* Exported functions ---------------------------------------------------------*/
111 /** @defgroup PCCARD_Exported_Functions PCCARD Exported Functions
112 * @{
115 /** @defgroup PCCARD_Exported_Functions_Group1 Initialization and de-initialization functions
116 * @brief Initialization and Configuration functions
118 @verbatim
119 ==============================================================================
120 ##### PCCARD Initialization and de-initialization functions #####
121 ==============================================================================
122 [..]
123 This section provides functions allowing to initialize/de-initialize
124 the PCCARD memory
126 @endverbatim
127 * @{
131 * @brief Perform the PCCARD memory Initialization sequence
132 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains
133 * the configuration information for PCCARD module.
134 * @param ComSpaceTiming Common space timing structure
135 * @param AttSpaceTiming Attribute space timing structure
136 * @param IOSpaceTiming IO space timing structure
137 * @retval HAL status
139 HAL_StatusTypeDef HAL_PCCARD_Init(PCCARD_HandleTypeDef *hpccard, FMC_NAND_PCC_TimingTypeDef *ComSpaceTiming, FMC_NAND_PCC_TimingTypeDef *AttSpaceTiming, FMC_NAND_PCC_TimingTypeDef *IOSpaceTiming)
141 /* Check the PCCARD controller state */
142 if(hpccard == NULL)
144 return HAL_ERROR;
147 if(hpccard->State == HAL_PCCARD_STATE_RESET)
149 /* Allocate lock resource and initialize it */
150 hpccard->Lock = HAL_UNLOCKED;
152 /* Initialize the low level hardware (MSP) */
153 HAL_PCCARD_MspInit(hpccard);
156 /* Initialize the PCCARD state */
157 hpccard->State = HAL_PCCARD_STATE_BUSY;
159 /* Initialize PCCARD control Interface */
160 FMC_PCCARD_Init(hpccard->Instance, &(hpccard->Init));
162 /* Init PCCARD common space timing Interface */
163 FMC_PCCARD_CommonSpace_Timing_Init(hpccard->Instance, ComSpaceTiming);
165 /* Init PCCARD attribute space timing Interface */
166 FMC_PCCARD_AttributeSpace_Timing_Init(hpccard->Instance, AttSpaceTiming);
168 /* Init PCCARD IO space timing Interface */
169 FMC_PCCARD_IOSpace_Timing_Init(hpccard->Instance, IOSpaceTiming);
171 /* Enable the PCCARD device */
172 __FMC_PCCARD_ENABLE(hpccard->Instance);
174 /* Update the PCCARD state */
175 hpccard->State = HAL_PCCARD_STATE_READY;
177 return HAL_OK;
182 * @brief Perform the PCCARD memory De-initialization sequence
183 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains
184 * the configuration information for PCCARD module.
185 * @retval HAL status
187 HAL_StatusTypeDef HAL_PCCARD_DeInit(PCCARD_HandleTypeDef *hpccard)
189 /* De-Initialize the low level hardware (MSP) */
190 HAL_PCCARD_MspDeInit(hpccard);
192 /* Configure the PCCARD registers with their reset values */
193 FMC_PCCARD_DeInit(hpccard->Instance);
195 /* Update the PCCARD controller state */
196 hpccard->State = HAL_PCCARD_STATE_RESET;
198 /* Release Lock */
199 __HAL_UNLOCK(hpccard);
201 return HAL_OK;
205 * @brief PCCARD MSP Init
206 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains
207 * the configuration information for PCCARD module.
208 * @retval None
210 __weak void HAL_PCCARD_MspInit(PCCARD_HandleTypeDef *hpccard)
212 /* Prevent unused argument(s) compilation warning */
213 UNUSED(hpccard);
215 /* NOTE : This function Should not be modified, when the callback is needed,
216 the HAL_PCCARD_MspInit could be implemented in the user file
221 * @brief PCCARD MSP DeInit
222 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains
223 * the configuration information for PCCARD module.
224 * @retval None
226 __weak void HAL_PCCARD_MspDeInit(PCCARD_HandleTypeDef *hpccard)
228 /* Prevent unused argument(s) compilation warning */
229 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) = 0xECEC;
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 = 0x80U */
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 = 0U;
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 0x98000200U --> 0x80
545 - Card Configuration and Status Register at address 0x98000202U --> 0x00
546 - Pin Replacement Register at address 0x98000204U --> 0x0C
547 - Socket and Copy Register at address 0x98000206U --> 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(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_RISING_EDGE))
575 /* PCCARD interrupt callback*/
576 HAL_PCCARD_ITCallback(hpccard);
578 /* Clear PCCARD interrupt Rising edge pending bit */
579 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_RISING_EDGE);
582 /* Check PCCARD interrupt Level flag */
583 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_LEVEL))
585 /* PCCARD interrupt callback*/
586 HAL_PCCARD_ITCallback(hpccard);
588 /* Clear PCCARD interrupt Level pending bit */
589 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_LEVEL);
592 /* Check PCCARD interrupt Falling edge flag */
593 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_FALLING_EDGE))
595 /* PCCARD interrupt callback*/
596 HAL_PCCARD_ITCallback(hpccard);
598 /* Clear PCCARD interrupt Falling edge pending bit */
599 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_FALLING_EDGE);
602 /* Check PCCARD interrupt FIFO empty flag */
603 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_FEMPT))
605 /* PCCARD interrupt callback*/
606 HAL_PCCARD_ITCallback(hpccard);
608 /* Clear PCCARD interrupt FIFO empty pending bit */
609 __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.
618 * @retval None
620 __weak void HAL_PCCARD_ITCallback(PCCARD_HandleTypeDef *hpccard)
622 /* Prevent unused argument(s) compilation warning */
623 UNUSED(hpccard);
625 /* NOTE : This function Should not be modified, when the callback is needed,
626 the HAL_PCCARD_ITCallback could be implemented in the user file
631 * @}
634 /** @defgroup PCCARD_Exported_Functions_Group3 Peripheral State functions
635 * @brief Peripheral State functions
637 @verbatim
638 ==============================================================================
639 ##### PCCARD Peripheral State functions #####
640 ==============================================================================
641 [..]
642 This subsection permits to get in run-time the status of the PCCARD controller
643 and the data flow.
645 @endverbatim
646 * @{
650 * @brief return the PCCARD controller state
651 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains
652 * the configuration information for PCCARD module.
653 * @retval HAL state
655 HAL_PCCARD_StateTypeDef HAL_PCCARD_GetState(PCCARD_HandleTypeDef *hpccard)
657 return hpccard->State;
661 * @brief Get the compact flash memory status
662 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains
663 * the configuration information for PCCARD module.
664 * @retval New status of the CF operation. This parameter can be:
665 * - CompactFlash_TIMEOUT_ERROR: when the previous operation generate
666 * a Timeout error
667 * - CompactFlash_READY: when memory is ready for the next operation
670 HAL_PCCARD_StatusTypeDef HAL_PCCARD_GetStatus(PCCARD_HandleTypeDef *hpccard)
672 uint32_t timeout = PCCARD_TIMEOUT_STATUS, status_cf = 0U;
674 /* Check the PCCARD controller state */
675 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
677 return HAL_PCCARD_STATUS_ONGOING;
680 status_cf = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
682 while((status_cf == PCCARD_BUSY) && timeout)
684 status_cf = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
685 timeout--;
688 if(timeout == 0U)
690 status_cf = PCCARD_TIMEOUT_ERROR;
693 /* Return the operation status */
694 return (HAL_PCCARD_StatusTypeDef) status_cf;
698 * @brief Reads the Compact Flash memory status using the Read status command
699 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains
700 * the configuration information for PCCARD module.
701 * @retval The status of the Compact Flash memory. This parameter can be:
702 * - CompactFlash_BUSY: when memory is busy
703 * - CompactFlash_READY: when memory is ready for the next operation
704 * - CompactFlash_ERROR: when the previous operation gererates error
706 HAL_PCCARD_StatusTypeDef HAL_PCCARD_ReadStatus(PCCARD_HandleTypeDef *hpccard)
708 uint8_t data = 0U, status_cf = PCCARD_BUSY;
710 /* Check the PCCARD controller state */
711 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
713 return HAL_PCCARD_STATUS_ONGOING;
716 /* Read status operation */
717 data = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
719 if((data & PCCARD_TIMEOUT_ERROR) == PCCARD_TIMEOUT_ERROR)
721 status_cf = PCCARD_TIMEOUT_ERROR;
723 else if((data & PCCARD_READY) == PCCARD_READY)
725 status_cf = PCCARD_READY;
728 return (HAL_PCCARD_StatusTypeDef) status_cf;
732 * @}
736 * @}
739 * @}
742 #endif /* HAL_PCCARD_MODULE_ENABLED */
745 * @}
747 #endif /* STM32F302xE || STM32F303xE || STM32F398xx */
749 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/