mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Nov 03 10:30:07 2014 +0000
Revision:
381:5460fc57b6e4
Synchronized with git revision 02478cd1f27fc7b9643486472635eb515b2bca81

Full URL: https://github.com/mbedmicro/mbed/commit/02478cd1f27fc7b9643486472635eb515b2bca81/

Target: LPC1549 - Fix serial interrupt issues (issue report #616)

Who changed what in which revision?

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