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