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