inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NYX 0:85b3fd62ea1a 1 /**
NYX 0:85b3fd62ea1a 2 ******************************************************************************
NYX 0:85b3fd62ea1a 3 * @file stm32f4xx_hal_pccard.c
NYX 0:85b3fd62ea1a 4 * @author MCD Application Team
NYX 0:85b3fd62ea1a 5 * @version V1.7.1
NYX 0:85b3fd62ea1a 6 * @date 14-April-2017
NYX 0:85b3fd62ea1a 7 * @brief PCCARD HAL module driver.
NYX 0:85b3fd62ea1a 8 * This file provides a generic firmware to drive PCCARD memories mounted
NYX 0:85b3fd62ea1a 9 * as external device.
NYX 0:85b3fd62ea1a 10 *
NYX 0:85b3fd62ea1a 11 @verbatim
NYX 0:85b3fd62ea1a 12 ===============================================================================
NYX 0:85b3fd62ea1a 13 ##### How to use this driver #####
NYX 0:85b3fd62ea1a 14 ===============================================================================
NYX 0:85b3fd62ea1a 15 [..]
NYX 0:85b3fd62ea1a 16 This driver is a generic layered driver which contains a set of APIs used to
NYX 0:85b3fd62ea1a 17 control PCCARD/compact flash memories. It uses the FMC/FSMC layer functions
NYX 0:85b3fd62ea1a 18 to interface with PCCARD devices. This driver is used for:
NYX 0:85b3fd62ea1a 19
NYX 0:85b3fd62ea1a 20 (+) PCCARD/Compact Flash memory configuration sequence using the function
NYX 0:85b3fd62ea1a 21 HAL_PCCARD_Init()/HAL_CF_Init() with control and timing parameters for
NYX 0:85b3fd62ea1a 22 both common and attribute spaces.
NYX 0:85b3fd62ea1a 23
NYX 0:85b3fd62ea1a 24 (+) Read PCCARD/Compact Flash memory maker and device IDs using the function
NYX 0:85b3fd62ea1a 25 HAL_PCCARD_Read_ID()/HAL_CF_Read_ID(). The read information is stored in
NYX 0:85b3fd62ea1a 26 the CompactFlash_ID structure declared by the function caller.
NYX 0:85b3fd62ea1a 27
NYX 0:85b3fd62ea1a 28 (+) Access PCCARD/Compact Flash memory by read/write operations using the functions
NYX 0:85b3fd62ea1a 29 HAL_PCCARD_Read_Sector()/ HAL_PCCARD_Write_Sector() -
NYX 0:85b3fd62ea1a 30 HAL_CF_Read_Sector()/HAL_CF_Write_Sector(), to read/write sector.
NYX 0:85b3fd62ea1a 31
NYX 0:85b3fd62ea1a 32 (+) Perform PCCARD/Compact Flash Reset chip operation using the function
NYX 0:85b3fd62ea1a 33 HAL_PCCARD_Reset()/HAL_CF_Reset.
NYX 0:85b3fd62ea1a 34
NYX 0:85b3fd62ea1a 35 (+) Perform PCCARD/Compact Flash erase sector operation using the function
NYX 0:85b3fd62ea1a 36 HAL_PCCARD_Erase_Sector()/HAL_CF_Erase_Sector.
NYX 0:85b3fd62ea1a 37
NYX 0:85b3fd62ea1a 38 (+) Read the PCCARD/Compact Flash status operation using the function
NYX 0:85b3fd62ea1a 39 HAL_PCCARD_ReadStatus()/HAL_CF_ReadStatus().
NYX 0:85b3fd62ea1a 40
NYX 0:85b3fd62ea1a 41 (+) You can monitor the PCCARD/Compact Flash device HAL state by calling
NYX 0:85b3fd62ea1a 42 the function HAL_PCCARD_GetState()/HAL_CF_GetState()
NYX 0:85b3fd62ea1a 43
NYX 0:85b3fd62ea1a 44 [..]
NYX 0:85b3fd62ea1a 45 (@) This driver is a set of generic APIs which handle standard PCCARD/compact flash
NYX 0:85b3fd62ea1a 46 operations. If a PCCARD/Compact Flash device contains different operations
NYX 0:85b3fd62ea1a 47 and/or implementations, it should be implemented separately.
NYX 0:85b3fd62ea1a 48
NYX 0:85b3fd62ea1a 49 @endverbatim
NYX 0:85b3fd62ea1a 50 ******************************************************************************
NYX 0:85b3fd62ea1a 51 * @attention
NYX 0:85b3fd62ea1a 52 *
NYX 0:85b3fd62ea1a 53 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
NYX 0:85b3fd62ea1a 54 *
NYX 0:85b3fd62ea1a 55 * Redistribution and use in source and binary forms, with or without modification,
NYX 0:85b3fd62ea1a 56 * are permitted provided that the following conditions are met:
NYX 0:85b3fd62ea1a 57 * 1. Redistributions of source code must retain the above copyright notice,
NYX 0:85b3fd62ea1a 58 * this list of conditions and the following disclaimer.
NYX 0:85b3fd62ea1a 59 * 2. Redistributions in binary form must reproduce the above copyright notice,
NYX 0:85b3fd62ea1a 60 * this list of conditions and the following disclaimer in the documentation
NYX 0:85b3fd62ea1a 61 * and/or other materials provided with the distribution.
NYX 0:85b3fd62ea1a 62 * 3. Neither the name of STMicroelectronics nor the names of its contributors
NYX 0:85b3fd62ea1a 63 * may be used to endorse or promote products derived from this software
NYX 0:85b3fd62ea1a 64 * without specific prior written permission.
NYX 0:85b3fd62ea1a 65 *
NYX 0:85b3fd62ea1a 66 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
NYX 0:85b3fd62ea1a 67 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
NYX 0:85b3fd62ea1a 68 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NYX 0:85b3fd62ea1a 69 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
NYX 0:85b3fd62ea1a 70 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
NYX 0:85b3fd62ea1a 71 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
NYX 0:85b3fd62ea1a 72 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
NYX 0:85b3fd62ea1a 73 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
NYX 0:85b3fd62ea1a 74 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
NYX 0:85b3fd62ea1a 75 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NYX 0:85b3fd62ea1a 76 *
NYX 0:85b3fd62ea1a 77 ******************************************************************************
NYX 0:85b3fd62ea1a 78 */
NYX 0:85b3fd62ea1a 79
NYX 0:85b3fd62ea1a 80 /* Includes ------------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 81 #include "stm32f4xx_hal.h"
NYX 0:85b3fd62ea1a 82
NYX 0:85b3fd62ea1a 83 /** @addtogroup STM32F4xx_HAL_Driver
NYX 0:85b3fd62ea1a 84 * @{
NYX 0:85b3fd62ea1a 85 */
NYX 0:85b3fd62ea1a 86
NYX 0:85b3fd62ea1a 87 #ifdef HAL_PCCARD_MODULE_ENABLED
NYX 0:85b3fd62ea1a 88 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
NYX 0:85b3fd62ea1a 89 defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
NYX 0:85b3fd62ea1a 90 /** @defgroup PCCARD PCCARD
NYX 0:85b3fd62ea1a 91 * @brief PCCARD HAL module driver
NYX 0:85b3fd62ea1a 92 * @{
NYX 0:85b3fd62ea1a 93 */
NYX 0:85b3fd62ea1a 94 /* Private typedef -----------------------------------------------------------*/
NYX 0:85b3fd62ea1a 95 /* Private define ------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 96
NYX 0:85b3fd62ea1a 97 /** @defgroup PCCARD_Private_Defines PCCARD Private Defines
NYX 0:85b3fd62ea1a 98 * @{
NYX 0:85b3fd62ea1a 99 */
NYX 0:85b3fd62ea1a 100 #define PCCARD_TIMEOUT_READ_ID 0x0000FFFFU
NYX 0:85b3fd62ea1a 101 #define PCCARD_TIMEOUT_READ_WRITE_SECTOR 0x0000FFFFU
NYX 0:85b3fd62ea1a 102 #define PCCARD_TIMEOUT_ERASE_SECTOR 0x00000400U
NYX 0:85b3fd62ea1a 103 #define PCCARD_TIMEOUT_STATUS 0x01000000U
NYX 0:85b3fd62ea1a 104
NYX 0:85b3fd62ea1a 105 #define PCCARD_STATUS_OK (uint8_t)0x58
NYX 0:85b3fd62ea1a 106 #define PCCARD_STATUS_WRITE_OK (uint8_t)0x50
NYX 0:85b3fd62ea1a 107 /**
NYX 0:85b3fd62ea1a 108 * @}
NYX 0:85b3fd62ea1a 109 */
NYX 0:85b3fd62ea1a 110
NYX 0:85b3fd62ea1a 111 /* Private macro -------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 112 /* Private variables ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 113 /* Private function ----------------------------------------------------------*/
NYX 0:85b3fd62ea1a 114 /* Exported functions --------------------------------------------------------*/
NYX 0:85b3fd62ea1a 115 /** @defgroup PCCARD_Exported_Functions PCCARD Exported Functions
NYX 0:85b3fd62ea1a 116 * @{
NYX 0:85b3fd62ea1a 117 */
NYX 0:85b3fd62ea1a 118
NYX 0:85b3fd62ea1a 119 /** @defgroup PCCARD_Exported_Functions_Group1 Initialization and de-initialization functions
NYX 0:85b3fd62ea1a 120 * @brief Initialization and Configuration functions
NYX 0:85b3fd62ea1a 121 *
NYX 0:85b3fd62ea1a 122 @verbatim
NYX 0:85b3fd62ea1a 123 ==============================================================================
NYX 0:85b3fd62ea1a 124 ##### PCCARD Initialization and de-initialization functions #####
NYX 0:85b3fd62ea1a 125 ==============================================================================
NYX 0:85b3fd62ea1a 126 [..]
NYX 0:85b3fd62ea1a 127 This section provides functions allowing to initialize/de-initialize
NYX 0:85b3fd62ea1a 128 the PCCARD memory
NYX 0:85b3fd62ea1a 129
NYX 0:85b3fd62ea1a 130 @endverbatim
NYX 0:85b3fd62ea1a 131 * @{
NYX 0:85b3fd62ea1a 132 */
NYX 0:85b3fd62ea1a 133
NYX 0:85b3fd62ea1a 134 /**
NYX 0:85b3fd62ea1a 135 * @brief Perform the PCCARD memory Initialization sequence
NYX 0:85b3fd62ea1a 136 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 137 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 138 * @param ComSpaceTiming: Common space timing structure
NYX 0:85b3fd62ea1a 139 * @param AttSpaceTiming: Attribute space timing structure
NYX 0:85b3fd62ea1a 140 * @param IOSpaceTiming: IO space timing structure
NYX 0:85b3fd62ea1a 141 * @retval HAL status
NYX 0:85b3fd62ea1a 142 */
NYX 0:85b3fd62ea1a 143 HAL_StatusTypeDef HAL_PCCARD_Init(PCCARD_HandleTypeDef *hpccard, FMC_NAND_PCC_TimingTypeDef *ComSpaceTiming, FMC_NAND_PCC_TimingTypeDef *AttSpaceTiming, FMC_NAND_PCC_TimingTypeDef *IOSpaceTiming)
NYX 0:85b3fd62ea1a 144 {
NYX 0:85b3fd62ea1a 145 /* Check the PCCARD controller state */
NYX 0:85b3fd62ea1a 146 if(hpccard == NULL)
NYX 0:85b3fd62ea1a 147 {
NYX 0:85b3fd62ea1a 148 return HAL_ERROR;
NYX 0:85b3fd62ea1a 149 }
NYX 0:85b3fd62ea1a 150
NYX 0:85b3fd62ea1a 151 if(hpccard->State == HAL_PCCARD_STATE_RESET)
NYX 0:85b3fd62ea1a 152 {
NYX 0:85b3fd62ea1a 153 /* Allocate lock resource and initialize it */
NYX 0:85b3fd62ea1a 154 hpccard->Lock = HAL_UNLOCKED;
NYX 0:85b3fd62ea1a 155 /* Initialize the low level hardware (MSP) */
NYX 0:85b3fd62ea1a 156 HAL_PCCARD_MspInit(hpccard);
NYX 0:85b3fd62ea1a 157 }
NYX 0:85b3fd62ea1a 158
NYX 0:85b3fd62ea1a 159 /* Initialize the PCCARD state */
NYX 0:85b3fd62ea1a 160 hpccard->State = HAL_PCCARD_STATE_BUSY;
NYX 0:85b3fd62ea1a 161
NYX 0:85b3fd62ea1a 162 /* Initialize PCCARD control Interface */
NYX 0:85b3fd62ea1a 163 FMC_PCCARD_Init(hpccard->Instance, &(hpccard->Init));
NYX 0:85b3fd62ea1a 164
NYX 0:85b3fd62ea1a 165 /* Init PCCARD common space timing Interface */
NYX 0:85b3fd62ea1a 166 FMC_PCCARD_CommonSpace_Timing_Init(hpccard->Instance, ComSpaceTiming);
NYX 0:85b3fd62ea1a 167
NYX 0:85b3fd62ea1a 168 /* Init PCCARD attribute space timing Interface */
NYX 0:85b3fd62ea1a 169 FMC_PCCARD_AttributeSpace_Timing_Init(hpccard->Instance, AttSpaceTiming);
NYX 0:85b3fd62ea1a 170
NYX 0:85b3fd62ea1a 171 /* Init PCCARD IO space timing Interface */
NYX 0:85b3fd62ea1a 172 FMC_PCCARD_IOSpace_Timing_Init(hpccard->Instance, IOSpaceTiming);
NYX 0:85b3fd62ea1a 173
NYX 0:85b3fd62ea1a 174 /* Enable the PCCARD device */
NYX 0:85b3fd62ea1a 175 __FMC_PCCARD_ENABLE(hpccard->Instance);
NYX 0:85b3fd62ea1a 176
NYX 0:85b3fd62ea1a 177 /* Update the PCCARD state */
NYX 0:85b3fd62ea1a 178 hpccard->State = HAL_PCCARD_STATE_READY;
NYX 0:85b3fd62ea1a 179
NYX 0:85b3fd62ea1a 180 return HAL_OK;
NYX 0:85b3fd62ea1a 181
NYX 0:85b3fd62ea1a 182 }
NYX 0:85b3fd62ea1a 183
NYX 0:85b3fd62ea1a 184 /**
NYX 0:85b3fd62ea1a 185 * @brief Perform the PCCARD memory De-initialization sequence
NYX 0:85b3fd62ea1a 186 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 187 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 188 * @retval HAL status
NYX 0:85b3fd62ea1a 189 */
NYX 0:85b3fd62ea1a 190 HAL_StatusTypeDef HAL_PCCARD_DeInit(PCCARD_HandleTypeDef *hpccard)
NYX 0:85b3fd62ea1a 191 {
NYX 0:85b3fd62ea1a 192 /* De-Initialize the low level hardware (MSP) */
NYX 0:85b3fd62ea1a 193 HAL_PCCARD_MspDeInit(hpccard);
NYX 0:85b3fd62ea1a 194
NYX 0:85b3fd62ea1a 195 /* Configure the PCCARD registers with their reset values */
NYX 0:85b3fd62ea1a 196 FMC_PCCARD_DeInit(hpccard->Instance);
NYX 0:85b3fd62ea1a 197
NYX 0:85b3fd62ea1a 198 /* Update the PCCARD controller state */
NYX 0:85b3fd62ea1a 199 hpccard->State = HAL_PCCARD_STATE_RESET;
NYX 0:85b3fd62ea1a 200
NYX 0:85b3fd62ea1a 201 /* Release Lock */
NYX 0:85b3fd62ea1a 202 __HAL_UNLOCK(hpccard);
NYX 0:85b3fd62ea1a 203
NYX 0:85b3fd62ea1a 204 return HAL_OK;
NYX 0:85b3fd62ea1a 205 }
NYX 0:85b3fd62ea1a 206
NYX 0:85b3fd62ea1a 207 /**
NYX 0:85b3fd62ea1a 208 * @brief PCCARD MSP Init
NYX 0:85b3fd62ea1a 209 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 210 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 211 * @retval None
NYX 0:85b3fd62ea1a 212 */
NYX 0:85b3fd62ea1a 213 __weak void HAL_PCCARD_MspInit(PCCARD_HandleTypeDef *hpccard)
NYX 0:85b3fd62ea1a 214 {
NYX 0:85b3fd62ea1a 215 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 216 UNUSED(hpccard);
NYX 0:85b3fd62ea1a 217 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 218 the HAL_PCCARD_MspInit could be implemented in the user file
NYX 0:85b3fd62ea1a 219 */
NYX 0:85b3fd62ea1a 220 }
NYX 0:85b3fd62ea1a 221
NYX 0:85b3fd62ea1a 222 /**
NYX 0:85b3fd62ea1a 223 * @brief PCCARD MSP DeInit
NYX 0:85b3fd62ea1a 224 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 225 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 226 * @retval None
NYX 0:85b3fd62ea1a 227 */
NYX 0:85b3fd62ea1a 228 __weak void HAL_PCCARD_MspDeInit(PCCARD_HandleTypeDef *hpccard)
NYX 0:85b3fd62ea1a 229 {
NYX 0:85b3fd62ea1a 230 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 231 UNUSED(hpccard);
NYX 0:85b3fd62ea1a 232 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 233 the HAL_PCCARD_MspDeInit could be implemented in the user file
NYX 0:85b3fd62ea1a 234 */
NYX 0:85b3fd62ea1a 235 }
NYX 0:85b3fd62ea1a 236
NYX 0:85b3fd62ea1a 237 /**
NYX 0:85b3fd62ea1a 238 * @}
NYX 0:85b3fd62ea1a 239 */
NYX 0:85b3fd62ea1a 240
NYX 0:85b3fd62ea1a 241 /** @defgroup PCCARD_Exported_Functions_Group2 Input and Output functions
NYX 0:85b3fd62ea1a 242 * @brief Input Output and memory control functions
NYX 0:85b3fd62ea1a 243 *
NYX 0:85b3fd62ea1a 244 @verbatim
NYX 0:85b3fd62ea1a 245 ==============================================================================
NYX 0:85b3fd62ea1a 246 ##### PCCARD Input and Output functions #####
NYX 0:85b3fd62ea1a 247 ==============================================================================
NYX 0:85b3fd62ea1a 248 [..]
NYX 0:85b3fd62ea1a 249 This section provides functions allowing to use and control the PCCARD memory
NYX 0:85b3fd62ea1a 250
NYX 0:85b3fd62ea1a 251 @endverbatim
NYX 0:85b3fd62ea1a 252 * @{
NYX 0:85b3fd62ea1a 253 */
NYX 0:85b3fd62ea1a 254
NYX 0:85b3fd62ea1a 255 /**
NYX 0:85b3fd62ea1a 256 * @brief Read Compact Flash's ID.
NYX 0:85b3fd62ea1a 257 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 258 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 259 * @param CompactFlash_ID: Compact flash ID structure.
NYX 0:85b3fd62ea1a 260 * @param pStatus: pointer to compact flash status
NYX 0:85b3fd62ea1a 261 * @retval HAL status
NYX 0:85b3fd62ea1a 262 *
NYX 0:85b3fd62ea1a 263 */
NYX 0:85b3fd62ea1a 264 HAL_StatusTypeDef HAL_PCCARD_Read_ID(PCCARD_HandleTypeDef *hpccard, uint8_t CompactFlash_ID[], uint8_t *pStatus)
NYX 0:85b3fd62ea1a 265 {
NYX 0:85b3fd62ea1a 266 uint32_t timeout = PCCARD_TIMEOUT_READ_ID, index = 0U;
NYX 0:85b3fd62ea1a 267 uint8_t status = 0;
NYX 0:85b3fd62ea1a 268
NYX 0:85b3fd62ea1a 269 /* Process Locked */
NYX 0:85b3fd62ea1a 270 __HAL_LOCK(hpccard);
NYX 0:85b3fd62ea1a 271
NYX 0:85b3fd62ea1a 272 /* Check the PCCARD controller state */
NYX 0:85b3fd62ea1a 273 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
NYX 0:85b3fd62ea1a 274 {
NYX 0:85b3fd62ea1a 275 return HAL_BUSY;
NYX 0:85b3fd62ea1a 276 }
NYX 0:85b3fd62ea1a 277
NYX 0:85b3fd62ea1a 278 /* Update the PCCARD controller state */
NYX 0:85b3fd62ea1a 279 hpccard->State = HAL_PCCARD_STATE_BUSY;
NYX 0:85b3fd62ea1a 280
NYX 0:85b3fd62ea1a 281 /* Initialize the PCCARD status */
NYX 0:85b3fd62ea1a 282 *pStatus = PCCARD_READY;
NYX 0:85b3fd62ea1a 283
NYX 0:85b3fd62ea1a 284 /* Send the Identify Command */
NYX 0:85b3fd62ea1a 285 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = 0xECEC;
NYX 0:85b3fd62ea1a 286
NYX 0:85b3fd62ea1a 287 /* Read PCCARD IDs and timeout treatment */
NYX 0:85b3fd62ea1a 288 do
NYX 0:85b3fd62ea1a 289 {
NYX 0:85b3fd62ea1a 290 /* Read the PCCARD status */
NYX 0:85b3fd62ea1a 291 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
NYX 0:85b3fd62ea1a 292
NYX 0:85b3fd62ea1a 293 timeout--;
NYX 0:85b3fd62ea1a 294 }while((status != PCCARD_STATUS_OK) && timeout);
NYX 0:85b3fd62ea1a 295
NYX 0:85b3fd62ea1a 296 if(timeout == 0U)
NYX 0:85b3fd62ea1a 297 {
NYX 0:85b3fd62ea1a 298 *pStatus = PCCARD_TIMEOUT_ERROR;
NYX 0:85b3fd62ea1a 299 }
NYX 0:85b3fd62ea1a 300 else
NYX 0:85b3fd62ea1a 301 {
NYX 0:85b3fd62ea1a 302 /* Read PCCARD ID bytes */
NYX 0:85b3fd62ea1a 303 for(index = 0U; index < 16U; index++)
NYX 0:85b3fd62ea1a 304 {
NYX 0:85b3fd62ea1a 305 CompactFlash_ID[index] = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_DATA);
NYX 0:85b3fd62ea1a 306 }
NYX 0:85b3fd62ea1a 307 }
NYX 0:85b3fd62ea1a 308
NYX 0:85b3fd62ea1a 309 /* Update the PCCARD controller state */
NYX 0:85b3fd62ea1a 310 hpccard->State = HAL_PCCARD_STATE_READY;
NYX 0:85b3fd62ea1a 311
NYX 0:85b3fd62ea1a 312 /* Process unlocked */
NYX 0:85b3fd62ea1a 313 __HAL_UNLOCK(hpccard);
NYX 0:85b3fd62ea1a 314
NYX 0:85b3fd62ea1a 315 return HAL_OK;
NYX 0:85b3fd62ea1a 316 }
NYX 0:85b3fd62ea1a 317
NYX 0:85b3fd62ea1a 318 /**
NYX 0:85b3fd62ea1a 319 * @brief Read sector from PCCARD memory
NYX 0:85b3fd62ea1a 320 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 321 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 322 * @param pBuffer: pointer to destination read buffer
NYX 0:85b3fd62ea1a 323 * @param SectorAddress: Sector address to read
NYX 0:85b3fd62ea1a 324 * @param pStatus: pointer to PCCARD status
NYX 0:85b3fd62ea1a 325 * @retval HAL status
NYX 0:85b3fd62ea1a 326 */
NYX 0:85b3fd62ea1a 327 HAL_StatusTypeDef HAL_PCCARD_Read_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t *pBuffer, uint16_t SectorAddress, uint8_t *pStatus)
NYX 0:85b3fd62ea1a 328 {
NYX 0:85b3fd62ea1a 329 uint32_t timeout = PCCARD_TIMEOUT_READ_WRITE_SECTOR, index = 0U;
NYX 0:85b3fd62ea1a 330 uint8_t status = 0;
NYX 0:85b3fd62ea1a 331
NYX 0:85b3fd62ea1a 332 /* Process Locked */
NYX 0:85b3fd62ea1a 333 __HAL_LOCK(hpccard);
NYX 0:85b3fd62ea1a 334
NYX 0:85b3fd62ea1a 335 /* Check the PCCARD controller state */
NYX 0:85b3fd62ea1a 336 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
NYX 0:85b3fd62ea1a 337 {
NYX 0:85b3fd62ea1a 338 return HAL_BUSY;
NYX 0:85b3fd62ea1a 339 }
NYX 0:85b3fd62ea1a 340
NYX 0:85b3fd62ea1a 341 /* Update the PCCARD controller state */
NYX 0:85b3fd62ea1a 342 hpccard->State = HAL_PCCARD_STATE_BUSY;
NYX 0:85b3fd62ea1a 343
NYX 0:85b3fd62ea1a 344 /* Initialize PCCARD status */
NYX 0:85b3fd62ea1a 345 *pStatus = PCCARD_READY;
NYX 0:85b3fd62ea1a 346
NYX 0:85b3fd62ea1a 347 /* Set the parameters to write a sector */
NYX 0:85b3fd62ea1a 348 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_HIGH) = (uint16_t)0x00;
NYX 0:85b3fd62ea1a 349 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_COUNT) = ((uint16_t)0x0100) | ((uint16_t)SectorAddress);
NYX 0:85b3fd62ea1a 350 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = (uint16_t)0xE4A0;
NYX 0:85b3fd62ea1a 351
NYX 0:85b3fd62ea1a 352 do
NYX 0:85b3fd62ea1a 353 {
NYX 0:85b3fd62ea1a 354 /* wait till the Status = 0x80 */
NYX 0:85b3fd62ea1a 355 status = *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
NYX 0:85b3fd62ea1a 356 timeout--;
NYX 0:85b3fd62ea1a 357 }while((status == 0x80) && timeout);
NYX 0:85b3fd62ea1a 358
NYX 0:85b3fd62ea1a 359 if(timeout == 0U)
NYX 0:85b3fd62ea1a 360 {
NYX 0:85b3fd62ea1a 361 *pStatus = PCCARD_TIMEOUT_ERROR;
NYX 0:85b3fd62ea1a 362 }
NYX 0:85b3fd62ea1a 363
NYX 0:85b3fd62ea1a 364 timeout = PCCARD_TIMEOUT_READ_WRITE_SECTOR;
NYX 0:85b3fd62ea1a 365
NYX 0:85b3fd62ea1a 366 do
NYX 0:85b3fd62ea1a 367 {
NYX 0:85b3fd62ea1a 368 /* wait till the Status = PCCARD_STATUS_OK */
NYX 0:85b3fd62ea1a 369 status = *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
NYX 0:85b3fd62ea1a 370 timeout--;
NYX 0:85b3fd62ea1a 371 }while((status != PCCARD_STATUS_OK) && timeout);
NYX 0:85b3fd62ea1a 372
NYX 0:85b3fd62ea1a 373 if(timeout == 0U)
NYX 0:85b3fd62ea1a 374 {
NYX 0:85b3fd62ea1a 375 *pStatus = PCCARD_TIMEOUT_ERROR;
NYX 0:85b3fd62ea1a 376 }
NYX 0:85b3fd62ea1a 377
NYX 0:85b3fd62ea1a 378 /* Read bytes */
NYX 0:85b3fd62ea1a 379 for(; index < PCCARD_SECTOR_SIZE; index++)
NYX 0:85b3fd62ea1a 380 {
NYX 0:85b3fd62ea1a 381 *(uint16_t *)pBuffer++ = *(uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR);
NYX 0:85b3fd62ea1a 382 }
NYX 0:85b3fd62ea1a 383
NYX 0:85b3fd62ea1a 384 /* Update the PCCARD controller state */
NYX 0:85b3fd62ea1a 385 hpccard->State = HAL_PCCARD_STATE_READY;
NYX 0:85b3fd62ea1a 386
NYX 0:85b3fd62ea1a 387 /* Process unlocked */
NYX 0:85b3fd62ea1a 388 __HAL_UNLOCK(hpccard);
NYX 0:85b3fd62ea1a 389
NYX 0:85b3fd62ea1a 390 return HAL_OK;
NYX 0:85b3fd62ea1a 391 }
NYX 0:85b3fd62ea1a 392
NYX 0:85b3fd62ea1a 393
NYX 0:85b3fd62ea1a 394 /**
NYX 0:85b3fd62ea1a 395 * @brief Write sector to PCCARD memory
NYX 0:85b3fd62ea1a 396 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 397 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 398 * @param pBuffer: pointer to source write buffer
NYX 0:85b3fd62ea1a 399 * @param SectorAddress: Sector address to write
NYX 0:85b3fd62ea1a 400 * @param pStatus: pointer to PCCARD status
NYX 0:85b3fd62ea1a 401 * @retval HAL status
NYX 0:85b3fd62ea1a 402 */
NYX 0:85b3fd62ea1a 403 HAL_StatusTypeDef HAL_PCCARD_Write_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t *pBuffer, uint16_t SectorAddress, uint8_t *pStatus)
NYX 0:85b3fd62ea1a 404 {
NYX 0:85b3fd62ea1a 405 uint32_t timeout = PCCARD_TIMEOUT_READ_WRITE_SECTOR, index = 0U;
NYX 0:85b3fd62ea1a 406 uint8_t status = 0;
NYX 0:85b3fd62ea1a 407
NYX 0:85b3fd62ea1a 408 /* Process Locked */
NYX 0:85b3fd62ea1a 409 __HAL_LOCK(hpccard);
NYX 0:85b3fd62ea1a 410
NYX 0:85b3fd62ea1a 411 /* Check the PCCARD controller state */
NYX 0:85b3fd62ea1a 412 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
NYX 0:85b3fd62ea1a 413 {
NYX 0:85b3fd62ea1a 414 return HAL_BUSY;
NYX 0:85b3fd62ea1a 415 }
NYX 0:85b3fd62ea1a 416
NYX 0:85b3fd62ea1a 417 /* Update the PCCARD controller state */
NYX 0:85b3fd62ea1a 418 hpccard->State = HAL_PCCARD_STATE_BUSY;
NYX 0:85b3fd62ea1a 419
NYX 0:85b3fd62ea1a 420 /* Initialize PCCARD status */
NYX 0:85b3fd62ea1a 421 *pStatus = PCCARD_READY;
NYX 0:85b3fd62ea1a 422
NYX 0:85b3fd62ea1a 423 /* Set the parameters to write a sector */
NYX 0:85b3fd62ea1a 424 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_HIGH) = (uint16_t)0x00;
NYX 0:85b3fd62ea1a 425 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_COUNT) = ((uint16_t)0x0100) | ((uint16_t)SectorAddress);
NYX 0:85b3fd62ea1a 426 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = (uint16_t)0x30A0;
NYX 0:85b3fd62ea1a 427
NYX 0:85b3fd62ea1a 428 do
NYX 0:85b3fd62ea1a 429 {
NYX 0:85b3fd62ea1a 430 /* Wait till the Status = PCCARD_STATUS_OK */
NYX 0:85b3fd62ea1a 431 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
NYX 0:85b3fd62ea1a 432 timeout--;
NYX 0:85b3fd62ea1a 433 }while((status != PCCARD_STATUS_OK) && timeout);
NYX 0:85b3fd62ea1a 434
NYX 0:85b3fd62ea1a 435 if(timeout == 0U)
NYX 0:85b3fd62ea1a 436 {
NYX 0:85b3fd62ea1a 437 *pStatus = PCCARD_TIMEOUT_ERROR;
NYX 0:85b3fd62ea1a 438 }
NYX 0:85b3fd62ea1a 439
NYX 0:85b3fd62ea1a 440 /* Write bytes */
NYX 0:85b3fd62ea1a 441 for(; index < PCCARD_SECTOR_SIZE; index++)
NYX 0:85b3fd62ea1a 442 {
NYX 0:85b3fd62ea1a 443 *(uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR) = *(uint16_t *)pBuffer++;
NYX 0:85b3fd62ea1a 444 }
NYX 0:85b3fd62ea1a 445
NYX 0:85b3fd62ea1a 446 do
NYX 0:85b3fd62ea1a 447 {
NYX 0:85b3fd62ea1a 448 /* Wait till the Status = PCCARD_STATUS_WRITE_OK */
NYX 0:85b3fd62ea1a 449 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
NYX 0:85b3fd62ea1a 450 timeout--;
NYX 0:85b3fd62ea1a 451 }while((status != PCCARD_STATUS_WRITE_OK) && timeout);
NYX 0:85b3fd62ea1a 452
NYX 0:85b3fd62ea1a 453 if(timeout == 0U)
NYX 0:85b3fd62ea1a 454 {
NYX 0:85b3fd62ea1a 455 *pStatus = PCCARD_TIMEOUT_ERROR;
NYX 0:85b3fd62ea1a 456 }
NYX 0:85b3fd62ea1a 457
NYX 0:85b3fd62ea1a 458 /* Update the PCCARD controller state */
NYX 0:85b3fd62ea1a 459 hpccard->State = HAL_PCCARD_STATE_READY;
NYX 0:85b3fd62ea1a 460
NYX 0:85b3fd62ea1a 461 /* Process unlocked */
NYX 0:85b3fd62ea1a 462 __HAL_UNLOCK(hpccard);
NYX 0:85b3fd62ea1a 463
NYX 0:85b3fd62ea1a 464 return HAL_OK;
NYX 0:85b3fd62ea1a 465 }
NYX 0:85b3fd62ea1a 466
NYX 0:85b3fd62ea1a 467
NYX 0:85b3fd62ea1a 468 /**
NYX 0:85b3fd62ea1a 469 * @brief Erase sector from PCCARD memory
NYX 0:85b3fd62ea1a 470 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 471 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 472 * @param SectorAddress: Sector address to erase
NYX 0:85b3fd62ea1a 473 * @param pStatus: pointer to PCCARD status
NYX 0:85b3fd62ea1a 474 * @retval HAL status
NYX 0:85b3fd62ea1a 475 */
NYX 0:85b3fd62ea1a 476 HAL_StatusTypeDef HAL_PCCARD_Erase_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t SectorAddress, uint8_t *pStatus)
NYX 0:85b3fd62ea1a 477 {
NYX 0:85b3fd62ea1a 478 uint32_t timeout = PCCARD_TIMEOUT_ERASE_SECTOR;
NYX 0:85b3fd62ea1a 479 uint8_t status = 0;
NYX 0:85b3fd62ea1a 480
NYX 0:85b3fd62ea1a 481 /* Process Locked */
NYX 0:85b3fd62ea1a 482 __HAL_LOCK(hpccard);
NYX 0:85b3fd62ea1a 483
NYX 0:85b3fd62ea1a 484 /* Check the PCCARD controller state */
NYX 0:85b3fd62ea1a 485 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
NYX 0:85b3fd62ea1a 486 {
NYX 0:85b3fd62ea1a 487 return HAL_BUSY;
NYX 0:85b3fd62ea1a 488 }
NYX 0:85b3fd62ea1a 489
NYX 0:85b3fd62ea1a 490 /* Update the PCCARD controller state */
NYX 0:85b3fd62ea1a 491 hpccard->State = HAL_PCCARD_STATE_BUSY;
NYX 0:85b3fd62ea1a 492
NYX 0:85b3fd62ea1a 493 /* Initialize PCCARD status */
NYX 0:85b3fd62ea1a 494 *pStatus = PCCARD_READY;
NYX 0:85b3fd62ea1a 495
NYX 0:85b3fd62ea1a 496 /* Set the parameters to write a sector */
NYX 0:85b3fd62ea1a 497 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_LOW) = 0x00;
NYX 0:85b3fd62ea1a 498 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_HIGH) = 0x00;
NYX 0:85b3fd62ea1a 499 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_NUMBER) = SectorAddress;
NYX 0:85b3fd62ea1a 500 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_COUNT) = 0x01;
NYX 0:85b3fd62ea1a 501 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CARD_HEAD) = 0xA0;
NYX 0:85b3fd62ea1a 502 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = ATA_ERASE_SECTOR_CMD;
NYX 0:85b3fd62ea1a 503
NYX 0:85b3fd62ea1a 504 /* wait till the PCCARD is ready */
NYX 0:85b3fd62ea1a 505 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
NYX 0:85b3fd62ea1a 506
NYX 0:85b3fd62ea1a 507 while((status != PCCARD_STATUS_WRITE_OK) && timeout)
NYX 0:85b3fd62ea1a 508 {
NYX 0:85b3fd62ea1a 509 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
NYX 0:85b3fd62ea1a 510 timeout--;
NYX 0:85b3fd62ea1a 511 }
NYX 0:85b3fd62ea1a 512
NYX 0:85b3fd62ea1a 513 if(timeout == 0U)
NYX 0:85b3fd62ea1a 514 {
NYX 0:85b3fd62ea1a 515 *pStatus = PCCARD_TIMEOUT_ERROR;
NYX 0:85b3fd62ea1a 516 }
NYX 0:85b3fd62ea1a 517
NYX 0:85b3fd62ea1a 518 /* Check the PCCARD controller state */
NYX 0:85b3fd62ea1a 519 hpccard->State = HAL_PCCARD_STATE_READY;
NYX 0:85b3fd62ea1a 520
NYX 0:85b3fd62ea1a 521 /* Process unlocked */
NYX 0:85b3fd62ea1a 522 __HAL_UNLOCK(hpccard);
NYX 0:85b3fd62ea1a 523
NYX 0:85b3fd62ea1a 524 return HAL_OK;
NYX 0:85b3fd62ea1a 525 }
NYX 0:85b3fd62ea1a 526
NYX 0:85b3fd62ea1a 527 /**
NYX 0:85b3fd62ea1a 528 * @brief Reset the PCCARD memory
NYX 0:85b3fd62ea1a 529 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 530 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 531 * @retval HAL status
NYX 0:85b3fd62ea1a 532 */
NYX 0:85b3fd62ea1a 533 HAL_StatusTypeDef HAL_PCCARD_Reset(PCCARD_HandleTypeDef *hpccard)
NYX 0:85b3fd62ea1a 534 {
NYX 0:85b3fd62ea1a 535 /* Process Locked */
NYX 0:85b3fd62ea1a 536 __HAL_LOCK(hpccard);
NYX 0:85b3fd62ea1a 537
NYX 0:85b3fd62ea1a 538 /* Check the PCCARD controller state */
NYX 0:85b3fd62ea1a 539 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
NYX 0:85b3fd62ea1a 540 {
NYX 0:85b3fd62ea1a 541 return HAL_BUSY;
NYX 0:85b3fd62ea1a 542 }
NYX 0:85b3fd62ea1a 543
NYX 0:85b3fd62ea1a 544 /* Provide a SW reset and Read and verify the:
NYX 0:85b3fd62ea1a 545 - PCCard Configuration Option Register at address 0x98000200 --> 0x80
NYX 0:85b3fd62ea1a 546 - Card Configuration and Status Register at address 0x98000202 --> 0x00
NYX 0:85b3fd62ea1a 547 - Pin Replacement Register at address 0x98000204 --> 0x0C
NYX 0:85b3fd62ea1a 548 - Socket and Copy Register at address 0x98000206 --> 0x00
NYX 0:85b3fd62ea1a 549 */
NYX 0:85b3fd62ea1a 550
NYX 0:85b3fd62ea1a 551 /* Check the PCCARD controller state */
NYX 0:85b3fd62ea1a 552 hpccard->State = HAL_PCCARD_STATE_BUSY;
NYX 0:85b3fd62ea1a 553
NYX 0:85b3fd62ea1a 554 *(__IO uint8_t *)(PCCARD_ATTRIBUTE_SPACE_ADDRESS | ATA_CARD_CONFIGURATION ) = 0x01;
NYX 0:85b3fd62ea1a 555
NYX 0:85b3fd62ea1a 556 /* Check the PCCARD controller state */
NYX 0:85b3fd62ea1a 557 hpccard->State = HAL_PCCARD_STATE_READY;
NYX 0:85b3fd62ea1a 558
NYX 0:85b3fd62ea1a 559 /* Process unlocked */
NYX 0:85b3fd62ea1a 560 __HAL_UNLOCK(hpccard);
NYX 0:85b3fd62ea1a 561
NYX 0:85b3fd62ea1a 562 return HAL_OK;
NYX 0:85b3fd62ea1a 563 }
NYX 0:85b3fd62ea1a 564
NYX 0:85b3fd62ea1a 565 /**
NYX 0:85b3fd62ea1a 566 * @brief This function handles PCCARD device interrupt request.
NYX 0:85b3fd62ea1a 567 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 568 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 569 * @retval HAL status
NYX 0:85b3fd62ea1a 570 */
NYX 0:85b3fd62ea1a 571 void HAL_PCCARD_IRQHandler(PCCARD_HandleTypeDef *hpccard)
NYX 0:85b3fd62ea1a 572 {
NYX 0:85b3fd62ea1a 573 /* Check PCCARD interrupt Rising edge flag */
NYX 0:85b3fd62ea1a 574 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_RISING_EDGE))
NYX 0:85b3fd62ea1a 575 {
NYX 0:85b3fd62ea1a 576 /* PCCARD interrupt callback*/
NYX 0:85b3fd62ea1a 577 HAL_PCCARD_ITCallback(hpccard);
NYX 0:85b3fd62ea1a 578
NYX 0:85b3fd62ea1a 579 /* Clear PCCARD interrupt Rising edge pending bit */
NYX 0:85b3fd62ea1a 580 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_RISING_EDGE);
NYX 0:85b3fd62ea1a 581 }
NYX 0:85b3fd62ea1a 582
NYX 0:85b3fd62ea1a 583 /* Check PCCARD interrupt Level flag */
NYX 0:85b3fd62ea1a 584 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_LEVEL))
NYX 0:85b3fd62ea1a 585 {
NYX 0:85b3fd62ea1a 586 /* PCCARD interrupt callback*/
NYX 0:85b3fd62ea1a 587 HAL_PCCARD_ITCallback(hpccard);
NYX 0:85b3fd62ea1a 588
NYX 0:85b3fd62ea1a 589 /* Clear PCCARD interrupt Level pending bit */
NYX 0:85b3fd62ea1a 590 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_LEVEL);
NYX 0:85b3fd62ea1a 591 }
NYX 0:85b3fd62ea1a 592
NYX 0:85b3fd62ea1a 593 /* Check PCCARD interrupt Falling edge flag */
NYX 0:85b3fd62ea1a 594 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_FALLING_EDGE))
NYX 0:85b3fd62ea1a 595 {
NYX 0:85b3fd62ea1a 596 /* PCCARD interrupt callback*/
NYX 0:85b3fd62ea1a 597 HAL_PCCARD_ITCallback(hpccard);
NYX 0:85b3fd62ea1a 598
NYX 0:85b3fd62ea1a 599 /* Clear PCCARD interrupt Falling edge pending bit */
NYX 0:85b3fd62ea1a 600 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_FALLING_EDGE);
NYX 0:85b3fd62ea1a 601 }
NYX 0:85b3fd62ea1a 602
NYX 0:85b3fd62ea1a 603 /* Check PCCARD interrupt FIFO empty flag */
NYX 0:85b3fd62ea1a 604 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_FEMPT))
NYX 0:85b3fd62ea1a 605 {
NYX 0:85b3fd62ea1a 606 /* PCCARD interrupt callback*/
NYX 0:85b3fd62ea1a 607 HAL_PCCARD_ITCallback(hpccard);
NYX 0:85b3fd62ea1a 608
NYX 0:85b3fd62ea1a 609 /* Clear PCCARD interrupt FIFO empty pending bit */
NYX 0:85b3fd62ea1a 610 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_FEMPT);
NYX 0:85b3fd62ea1a 611 }
NYX 0:85b3fd62ea1a 612 }
NYX 0:85b3fd62ea1a 613
NYX 0:85b3fd62ea1a 614 /**
NYX 0:85b3fd62ea1a 615 * @brief PCCARD interrupt feature callback
NYX 0:85b3fd62ea1a 616 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 617 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 618 * @retval None
NYX 0:85b3fd62ea1a 619 */
NYX 0:85b3fd62ea1a 620 __weak void HAL_PCCARD_ITCallback(PCCARD_HandleTypeDef *hpccard)
NYX 0:85b3fd62ea1a 621 {
NYX 0:85b3fd62ea1a 622 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 623 UNUSED(hpccard);
NYX 0:85b3fd62ea1a 624 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 625 the HAL_PCCARD_ITCallback could be implemented in the user file
NYX 0:85b3fd62ea1a 626 */
NYX 0:85b3fd62ea1a 627 }
NYX 0:85b3fd62ea1a 628
NYX 0:85b3fd62ea1a 629 /**
NYX 0:85b3fd62ea1a 630 * @}
NYX 0:85b3fd62ea1a 631 */
NYX 0:85b3fd62ea1a 632
NYX 0:85b3fd62ea1a 633 /** @defgroup PCCARD_Exported_Functions_Group3 State functions
NYX 0:85b3fd62ea1a 634 * @brief Peripheral State functions
NYX 0:85b3fd62ea1a 635 *
NYX 0:85b3fd62ea1a 636 @verbatim
NYX 0:85b3fd62ea1a 637 ==============================================================================
NYX 0:85b3fd62ea1a 638 ##### PCCARD State functions #####
NYX 0:85b3fd62ea1a 639 ==============================================================================
NYX 0:85b3fd62ea1a 640 [..]
NYX 0:85b3fd62ea1a 641 This subsection permits to get in run-time the status of the PCCARD controller
NYX 0:85b3fd62ea1a 642 and the data flow.
NYX 0:85b3fd62ea1a 643
NYX 0:85b3fd62ea1a 644 @endverbatim
NYX 0:85b3fd62ea1a 645 * @{
NYX 0:85b3fd62ea1a 646 */
NYX 0:85b3fd62ea1a 647
NYX 0:85b3fd62ea1a 648 /**
NYX 0:85b3fd62ea1a 649 * @brief return the PCCARD controller state
NYX 0:85b3fd62ea1a 650 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 651 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 652 * @retval HAL state
NYX 0:85b3fd62ea1a 653 */
NYX 0:85b3fd62ea1a 654 HAL_PCCARD_StateTypeDef HAL_PCCARD_GetState(PCCARD_HandleTypeDef *hpccard)
NYX 0:85b3fd62ea1a 655 {
NYX 0:85b3fd62ea1a 656 return hpccard->State;
NYX 0:85b3fd62ea1a 657 }
NYX 0:85b3fd62ea1a 658
NYX 0:85b3fd62ea1a 659 /**
NYX 0:85b3fd62ea1a 660 * @brief Get the compact flash memory status
NYX 0:85b3fd62ea1a 661 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 662 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 663 * @retval New status of the PCCARD operation. This parameter can be:
NYX 0:85b3fd62ea1a 664 * - CompactFlash_TIMEOUT_ERROR: when the previous operation generate
NYX 0:85b3fd62ea1a 665 * a Timeout error
NYX 0:85b3fd62ea1a 666 * - CompactFlash_READY: when memory is ready for the next operation
NYX 0:85b3fd62ea1a 667 */
NYX 0:85b3fd62ea1a 668 HAL_PCCARD_StatusTypeDef HAL_PCCARD_GetStatus(PCCARD_HandleTypeDef *hpccard)
NYX 0:85b3fd62ea1a 669 {
NYX 0:85b3fd62ea1a 670 uint32_t timeout = PCCARD_TIMEOUT_STATUS, status_pccard = 0U;
NYX 0:85b3fd62ea1a 671
NYX 0:85b3fd62ea1a 672 /* Check the PCCARD controller state */
NYX 0:85b3fd62ea1a 673 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
NYX 0:85b3fd62ea1a 674 {
NYX 0:85b3fd62ea1a 675 return HAL_PCCARD_STATUS_ONGOING;
NYX 0:85b3fd62ea1a 676 }
NYX 0:85b3fd62ea1a 677
NYX 0:85b3fd62ea1a 678 status_pccard = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
NYX 0:85b3fd62ea1a 679
NYX 0:85b3fd62ea1a 680 while((status_pccard == PCCARD_BUSY) && timeout)
NYX 0:85b3fd62ea1a 681 {
NYX 0:85b3fd62ea1a 682 status_pccard = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
NYX 0:85b3fd62ea1a 683 timeout--;
NYX 0:85b3fd62ea1a 684 }
NYX 0:85b3fd62ea1a 685
NYX 0:85b3fd62ea1a 686 if(timeout == 0U)
NYX 0:85b3fd62ea1a 687 {
NYX 0:85b3fd62ea1a 688 status_pccard = PCCARD_TIMEOUT_ERROR;
NYX 0:85b3fd62ea1a 689 }
NYX 0:85b3fd62ea1a 690
NYX 0:85b3fd62ea1a 691 /* Return the operation status */
NYX 0:85b3fd62ea1a 692 return (HAL_PCCARD_StatusTypeDef) status_pccard;
NYX 0:85b3fd62ea1a 693 }
NYX 0:85b3fd62ea1a 694
NYX 0:85b3fd62ea1a 695 /**
NYX 0:85b3fd62ea1a 696 * @brief Reads the Compact Flash memory status using the Read status command
NYX 0:85b3fd62ea1a 697 * @param hpccard: pointer to a PCCARD_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 698 * the configuration information for PCCARD module.
NYX 0:85b3fd62ea1a 699 * @retval The status of the Compact Flash memory. This parameter can be:
NYX 0:85b3fd62ea1a 700 * - CompactFlash_BUSY: when memory is busy
NYX 0:85b3fd62ea1a 701 * - CompactFlash_READY: when memory is ready for the next operation
NYX 0:85b3fd62ea1a 702 * - CompactFlash_ERROR: when the previous operation generates error
NYX 0:85b3fd62ea1a 703 */
NYX 0:85b3fd62ea1a 704 HAL_PCCARD_StatusTypeDef HAL_PCCARD_ReadStatus(PCCARD_HandleTypeDef *hpccard)
NYX 0:85b3fd62ea1a 705 {
NYX 0:85b3fd62ea1a 706 uint8_t data = 0U, status_pccard = PCCARD_BUSY;
NYX 0:85b3fd62ea1a 707
NYX 0:85b3fd62ea1a 708 /* Check the PCCARD controller state */
NYX 0:85b3fd62ea1a 709 if(hpccard->State == HAL_PCCARD_STATE_BUSY)
NYX 0:85b3fd62ea1a 710 {
NYX 0:85b3fd62ea1a 711 return HAL_PCCARD_STATUS_ONGOING;
NYX 0:85b3fd62ea1a 712 }
NYX 0:85b3fd62ea1a 713
NYX 0:85b3fd62ea1a 714 /* Read status operation */
NYX 0:85b3fd62ea1a 715 data = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE);
NYX 0:85b3fd62ea1a 716
NYX 0:85b3fd62ea1a 717 if((data & PCCARD_TIMEOUT_ERROR) == PCCARD_TIMEOUT_ERROR)
NYX 0:85b3fd62ea1a 718 {
NYX 0:85b3fd62ea1a 719 status_pccard = PCCARD_TIMEOUT_ERROR;
NYX 0:85b3fd62ea1a 720 }
NYX 0:85b3fd62ea1a 721 else if((data & PCCARD_READY) == PCCARD_READY)
NYX 0:85b3fd62ea1a 722 {
NYX 0:85b3fd62ea1a 723 status_pccard = PCCARD_READY;
NYX 0:85b3fd62ea1a 724 }
NYX 0:85b3fd62ea1a 725
NYX 0:85b3fd62ea1a 726 return (HAL_PCCARD_StatusTypeDef) status_pccard;
NYX 0:85b3fd62ea1a 727 }
NYX 0:85b3fd62ea1a 728
NYX 0:85b3fd62ea1a 729 /**
NYX 0:85b3fd62ea1a 730 * @}
NYX 0:85b3fd62ea1a 731 */
NYX 0:85b3fd62ea1a 732
NYX 0:85b3fd62ea1a 733 /**
NYX 0:85b3fd62ea1a 734 * @}
NYX 0:85b3fd62ea1a 735 */
NYX 0:85b3fd62ea1a 736 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx ||\
NYX 0:85b3fd62ea1a 737 STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
NYX 0:85b3fd62ea1a 738 #endif /* HAL_PCCARD_MODULE_ENABLED */
NYX 0:85b3fd62ea1a 739
NYX 0:85b3fd62ea1a 740 /**
NYX 0:85b3fd62ea1a 741 * @}
NYX 0:85b3fd62ea1a 742 */
NYX 0:85b3fd62ea1a 743
NYX 0:85b3fd62ea1a 744 /**
NYX 0:85b3fd62ea1a 745 * @}
NYX 0:85b3fd62ea1a 746 */
NYX 0:85b3fd62ea1a 747
NYX 0:85b3fd62ea1a 748 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/