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