Yihui Xiong / nrf51822_fix_i2c_spi_conflict

Dependencies:   BLE_API eMPL_MPU6050 nRF51822

Fork of Seeed_Tiny_BLE_Flash by Darren Huang

Committer:
yihui
Date:
Tue Nov 17 07:48:56 2015 +0000
Revision:
5:b8c02645e6af
fix i2c & spi conflict

Who changed what in which revision?

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