STM32F439xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_hal_pccard.c 00004 * @author MCD Application Team 00005 * @brief PCCARD HAL module driver. 00006 * This file provides a generic firmware to drive PCCARD memories mounted 00007 * as external device. 00008 * 00009 @verbatim 00010 =============================================================================== 00011 ##### How to use this driver ##### 00012 =============================================================================== 00013 [..] 00014 This driver is a generic layered driver which contains a set of APIs used to 00015 control PCCARD/compact flash memories. It uses the FMC/FSMC layer functions 00016 to interface with PCCARD devices. This driver is used for: 00017 00018 (+) PCCARD/Compact Flash memory configuration sequence using the function 00019 HAL_PCCARD_Init()/HAL_CF_Init() with control and timing parameters for 00020 both common and attribute spaces. 00021 00022 (+) Read PCCARD/Compact Flash memory maker and device IDs using the function 00023 HAL_PCCARD_Read_ID()/HAL_CF_Read_ID(). The read information is stored in 00024 the CompactFlash_ID structure declared by the function caller. 00025 00026 (+) Access PCCARD/Compact Flash memory by read/write operations using the functions 00027 HAL_PCCARD_Read_Sector()/ HAL_PCCARD_Write_Sector() - 00028 HAL_CF_Read_Sector()/HAL_CF_Write_Sector(), to read/write sector. 00029 00030 (+) Perform PCCARD/Compact Flash Reset chip operation using the function 00031 HAL_PCCARD_Reset()/HAL_CF_Reset. 00032 00033 (+) Perform PCCARD/Compact Flash erase sector operation using the function 00034 HAL_PCCARD_Erase_Sector()/HAL_CF_Erase_Sector. 00035 00036 (+) Read the PCCARD/Compact Flash status operation using the function 00037 HAL_PCCARD_ReadStatus()/HAL_CF_ReadStatus(). 00038 00039 (+) You can monitor the PCCARD/Compact Flash device HAL state by calling 00040 the function HAL_PCCARD_GetState()/HAL_CF_GetState() 00041 00042 [..] 00043 (@) This driver is a set of generic APIs which handle standard PCCARD/compact flash 00044 operations. If a PCCARD/Compact Flash device contains different operations 00045 and/or implementations, it should be implemented separately. 00046 00047 @endverbatim 00048 ****************************************************************************** 00049 * @attention 00050 * 00051 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00052 * 00053 * Redistribution and use in source and binary forms, with or without modification, 00054 * are permitted provided that the following conditions are met: 00055 * 1. Redistributions of source code must retain the above copyright notice, 00056 * this list of conditions and the following disclaimer. 00057 * 2. Redistributions in binary form must reproduce the above copyright notice, 00058 * this list of conditions and the following disclaimer in the documentation 00059 * and/or other materials provided with the distribution. 00060 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00061 * may be used to endorse or promote products derived from this software 00062 * without specific prior written permission. 00063 * 00064 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00065 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00066 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00067 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00068 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00069 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00070 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00071 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00072 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00073 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00074 * 00075 ****************************************************************************** 00076 */ 00077 00078 /* Includes ------------------------------------------------------------------*/ 00079 #include "stm32f4xx_hal.h" 00080 00081 /** @addtogroup STM32F4xx_HAL_Driver 00082 * @{ 00083 */ 00084 00085 #ifdef HAL_PCCARD_MODULE_ENABLED 00086 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\ 00087 defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) 00088 /** @defgroup PCCARD PCCARD 00089 * @brief PCCARD HAL module driver 00090 * @{ 00091 */ 00092 /* Private typedef -----------------------------------------------------------*/ 00093 /* Private define ------------------------------------------------------------*/ 00094 00095 /** @defgroup PCCARD_Private_Defines PCCARD Private Defines 00096 * @{ 00097 */ 00098 #define PCCARD_TIMEOUT_READ_ID 0x0000FFFFU 00099 #define PCCARD_TIMEOUT_READ_WRITE_SECTOR 0x0000FFFFU 00100 #define PCCARD_TIMEOUT_ERASE_SECTOR 0x00000400U 00101 #define PCCARD_TIMEOUT_STATUS 0x01000000U 00102 00103 #define PCCARD_STATUS_OK (uint8_t)0x58 00104 #define PCCARD_STATUS_WRITE_OK (uint8_t)0x50 00105 /** 00106 * @} 00107 */ 00108 00109 /* Private macro -------------------------------------------------------------*/ 00110 /* Private variables ---------------------------------------------------------*/ 00111 /* Private function ----------------------------------------------------------*/ 00112 /* Exported functions --------------------------------------------------------*/ 00113 /** @defgroup PCCARD_Exported_Functions PCCARD Exported Functions 00114 * @{ 00115 */ 00116 00117 /** @defgroup PCCARD_Exported_Functions_Group1 Initialization and de-initialization functions 00118 * @brief Initialization and Configuration functions 00119 * 00120 @verbatim 00121 ============================================================================== 00122 ##### PCCARD Initialization and de-initialization functions ##### 00123 ============================================================================== 00124 [..] 00125 This section provides functions allowing to initialize/de-initialize 00126 the PCCARD memory 00127 00128 @endverbatim 00129 * @{ 00130 */ 00131 00132 /** 00133 * @brief Perform the PCCARD memory Initialization sequence 00134 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00135 * the configuration information for PCCARD module. 00136 * @param ComSpaceTiming Common space timing structure 00137 * @param AttSpaceTiming Attribute space timing structure 00138 * @param IOSpaceTiming IO space timing structure 00139 * @retval HAL status 00140 */ 00141 HAL_StatusTypeDef HAL_PCCARD_Init(PCCARD_HandleTypeDef *hpccard, FMC_NAND_PCC_TimingTypeDef *ComSpaceTiming, FMC_NAND_PCC_TimingTypeDef *AttSpaceTiming, FMC_NAND_PCC_TimingTypeDef *IOSpaceTiming) 00142 { 00143 /* Check the PCCARD controller state */ 00144 if(hpccard == NULL) 00145 { 00146 return HAL_ERROR; 00147 } 00148 00149 if(hpccard->State == HAL_PCCARD_STATE_RESET) 00150 { 00151 /* Allocate lock resource and initialize it */ 00152 hpccard->Lock = HAL_UNLOCKED; 00153 /* Initialize the low level hardware (MSP) */ 00154 HAL_PCCARD_MspInit(hpccard); 00155 } 00156 00157 /* Initialize the PCCARD state */ 00158 hpccard->State = HAL_PCCARD_STATE_BUSY; 00159 00160 /* Initialize PCCARD control Interface */ 00161 FMC_PCCARD_Init(hpccard->Instance, &(hpccard->Init)); 00162 00163 /* Init PCCARD common space timing Interface */ 00164 FMC_PCCARD_CommonSpace_Timing_Init(hpccard->Instance, ComSpaceTiming); 00165 00166 /* Init PCCARD attribute space timing Interface */ 00167 FMC_PCCARD_AttributeSpace_Timing_Init(hpccard->Instance, AttSpaceTiming); 00168 00169 /* Init PCCARD IO space timing Interface */ 00170 FMC_PCCARD_IOSpace_Timing_Init(hpccard->Instance, IOSpaceTiming); 00171 00172 /* Enable the PCCARD device */ 00173 __FMC_PCCARD_ENABLE(hpccard->Instance); 00174 00175 /* Update the PCCARD state */ 00176 hpccard->State = HAL_PCCARD_STATE_READY; 00177 00178 return HAL_OK; 00179 00180 } 00181 00182 /** 00183 * @brief Perform the PCCARD memory De-initialization sequence 00184 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00185 * the configuration information for PCCARD module. 00186 * @retval HAL status 00187 */ 00188 HAL_StatusTypeDef HAL_PCCARD_DeInit(PCCARD_HandleTypeDef *hpccard) 00189 { 00190 /* De-Initialize the low level hardware (MSP) */ 00191 HAL_PCCARD_MspDeInit(hpccard); 00192 00193 /* Configure the PCCARD registers with their reset values */ 00194 FMC_PCCARD_DeInit(hpccard->Instance); 00195 00196 /* Update the PCCARD controller state */ 00197 hpccard->State = HAL_PCCARD_STATE_RESET; 00198 00199 /* Release Lock */ 00200 __HAL_UNLOCK(hpccard); 00201 00202 return HAL_OK; 00203 } 00204 00205 /** 00206 * @brief PCCARD MSP Init 00207 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00208 * the configuration information for PCCARD module. 00209 * @retval None 00210 */ 00211 __weak void HAL_PCCARD_MspInit(PCCARD_HandleTypeDef *hpccard) 00212 { 00213 /* Prevent unused argument(s) compilation warning */ 00214 UNUSED(hpccard); 00215 /* NOTE : This function Should not be modified, when the callback is needed, 00216 the HAL_PCCARD_MspInit could be implemented in the user file 00217 */ 00218 } 00219 00220 /** 00221 * @brief PCCARD MSP DeInit 00222 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00223 * the configuration information for PCCARD module. 00224 * @retval None 00225 */ 00226 __weak void HAL_PCCARD_MspDeInit(PCCARD_HandleTypeDef *hpccard) 00227 { 00228 /* Prevent unused argument(s) compilation warning */ 00229 UNUSED(hpccard); 00230 /* NOTE : This function Should not be modified, when the callback is needed, 00231 the HAL_PCCARD_MspDeInit could be implemented in the user file 00232 */ 00233 } 00234 00235 /** 00236 * @} 00237 */ 00238 00239 /** @defgroup PCCARD_Exported_Functions_Group2 Input and Output functions 00240 * @brief Input Output and memory control functions 00241 * 00242 @verbatim 00243 ============================================================================== 00244 ##### PCCARD Input and Output functions ##### 00245 ============================================================================== 00246 [..] 00247 This section provides functions allowing to use and control the PCCARD memory 00248 00249 @endverbatim 00250 * @{ 00251 */ 00252 00253 /** 00254 * @brief Read Compact Flash's ID. 00255 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00256 * the configuration information for PCCARD module. 00257 * @param CompactFlash_ID Compact flash ID structure. 00258 * @param pStatus pointer to compact flash status 00259 * @retval HAL status 00260 * 00261 */ 00262 HAL_StatusTypeDef HAL_PCCARD_Read_ID(PCCARD_HandleTypeDef *hpccard, uint8_t CompactFlash_ID[], uint8_t *pStatus) 00263 { 00264 uint32_t timeout = PCCARD_TIMEOUT_READ_ID, index = 0U; 00265 uint8_t status = 0; 00266 00267 /* Process Locked */ 00268 __HAL_LOCK(hpccard); 00269 00270 /* Check the PCCARD controller state */ 00271 if(hpccard->State == HAL_PCCARD_STATE_BUSY) 00272 { 00273 return HAL_BUSY; 00274 } 00275 00276 /* Update the PCCARD controller state */ 00277 hpccard->State = HAL_PCCARD_STATE_BUSY; 00278 00279 /* Initialize the PCCARD status */ 00280 *pStatus = PCCARD_READY; 00281 00282 /* Send the Identify Command */ 00283 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = 0xECEC; 00284 00285 /* Read PCCARD IDs and timeout treatment */ 00286 do 00287 { 00288 /* Read the PCCARD status */ 00289 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); 00290 00291 timeout--; 00292 }while((status != PCCARD_STATUS_OK) && timeout); 00293 00294 if(timeout == 0U) 00295 { 00296 *pStatus = PCCARD_TIMEOUT_ERROR; 00297 } 00298 else 00299 { 00300 /* Read PCCARD ID bytes */ 00301 for(index = 0U; index < 16U; index++) 00302 { 00303 CompactFlash_ID[index] = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_DATA); 00304 } 00305 } 00306 00307 /* Update the PCCARD controller state */ 00308 hpccard->State = HAL_PCCARD_STATE_READY; 00309 00310 /* Process unlocked */ 00311 __HAL_UNLOCK(hpccard); 00312 00313 return HAL_OK; 00314 } 00315 00316 /** 00317 * @brief Read sector from PCCARD memory 00318 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00319 * the configuration information for PCCARD module. 00320 * @param pBuffer pointer to destination read buffer 00321 * @param SectorAddress Sector address to read 00322 * @param pStatus pointer to PCCARD status 00323 * @retval HAL status 00324 */ 00325 HAL_StatusTypeDef HAL_PCCARD_Read_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t *pBuffer, uint16_t SectorAddress, uint8_t *pStatus) 00326 { 00327 uint32_t timeout = PCCARD_TIMEOUT_READ_WRITE_SECTOR, index = 0U; 00328 uint8_t status = 0; 00329 00330 /* Process Locked */ 00331 __HAL_LOCK(hpccard); 00332 00333 /* Check the PCCARD controller state */ 00334 if(hpccard->State == HAL_PCCARD_STATE_BUSY) 00335 { 00336 return HAL_BUSY; 00337 } 00338 00339 /* Update the PCCARD controller state */ 00340 hpccard->State = HAL_PCCARD_STATE_BUSY; 00341 00342 /* Initialize PCCARD status */ 00343 *pStatus = PCCARD_READY; 00344 00345 /* Set the parameters to write a sector */ 00346 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_HIGH) = (uint16_t)0x00; 00347 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_COUNT) = ((uint16_t)0x0100) | ((uint16_t)SectorAddress); 00348 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = (uint16_t)0xE4A0; 00349 00350 do 00351 { 00352 /* wait till the Status = 0x80 */ 00353 status = *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); 00354 timeout--; 00355 }while((status == 0x80) && timeout); 00356 00357 if(timeout == 0U) 00358 { 00359 *pStatus = PCCARD_TIMEOUT_ERROR; 00360 } 00361 00362 timeout = PCCARD_TIMEOUT_READ_WRITE_SECTOR; 00363 00364 do 00365 { 00366 /* wait till the Status = PCCARD_STATUS_OK */ 00367 status = *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); 00368 timeout--; 00369 }while((status != PCCARD_STATUS_OK) && timeout); 00370 00371 if(timeout == 0U) 00372 { 00373 *pStatus = PCCARD_TIMEOUT_ERROR; 00374 } 00375 00376 /* Read bytes */ 00377 for(; index < PCCARD_SECTOR_SIZE; index++) 00378 { 00379 *(uint16_t *)pBuffer++ = *(uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR); 00380 } 00381 00382 /* Update the PCCARD controller state */ 00383 hpccard->State = HAL_PCCARD_STATE_READY; 00384 00385 /* Process unlocked */ 00386 __HAL_UNLOCK(hpccard); 00387 00388 return HAL_OK; 00389 } 00390 00391 00392 /** 00393 * @brief Write sector to PCCARD memory 00394 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00395 * the configuration information for PCCARD module. 00396 * @param pBuffer pointer to source write buffer 00397 * @param SectorAddress Sector address to write 00398 * @param pStatus pointer to PCCARD status 00399 * @retval HAL status 00400 */ 00401 HAL_StatusTypeDef HAL_PCCARD_Write_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t *pBuffer, uint16_t SectorAddress, uint8_t *pStatus) 00402 { 00403 uint32_t timeout = PCCARD_TIMEOUT_READ_WRITE_SECTOR, index = 0U; 00404 uint8_t status = 0; 00405 00406 /* Process Locked */ 00407 __HAL_LOCK(hpccard); 00408 00409 /* Check the PCCARD controller state */ 00410 if(hpccard->State == HAL_PCCARD_STATE_BUSY) 00411 { 00412 return HAL_BUSY; 00413 } 00414 00415 /* Update the PCCARD controller state */ 00416 hpccard->State = HAL_PCCARD_STATE_BUSY; 00417 00418 /* Initialize PCCARD status */ 00419 *pStatus = PCCARD_READY; 00420 00421 /* Set the parameters to write a sector */ 00422 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_HIGH) = (uint16_t)0x00; 00423 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_COUNT) = ((uint16_t)0x0100) | ((uint16_t)SectorAddress); 00424 *(__IO uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = (uint16_t)0x30A0; 00425 00426 do 00427 { 00428 /* Wait till the Status = PCCARD_STATUS_OK */ 00429 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); 00430 timeout--; 00431 }while((status != PCCARD_STATUS_OK) && timeout); 00432 00433 if(timeout == 0U) 00434 { 00435 *pStatus = PCCARD_TIMEOUT_ERROR; 00436 } 00437 00438 /* Write bytes */ 00439 for(; index < PCCARD_SECTOR_SIZE; index++) 00440 { 00441 *(uint16_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR) = *(uint16_t *)pBuffer++; 00442 } 00443 00444 do 00445 { 00446 /* Wait till the Status = PCCARD_STATUS_WRITE_OK */ 00447 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); 00448 timeout--; 00449 }while((status != PCCARD_STATUS_WRITE_OK) && timeout); 00450 00451 if(timeout == 0U) 00452 { 00453 *pStatus = PCCARD_TIMEOUT_ERROR; 00454 } 00455 00456 /* Update the PCCARD controller state */ 00457 hpccard->State = HAL_PCCARD_STATE_READY; 00458 00459 /* Process unlocked */ 00460 __HAL_UNLOCK(hpccard); 00461 00462 return HAL_OK; 00463 } 00464 00465 00466 /** 00467 * @brief Erase sector from PCCARD memory 00468 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00469 * the configuration information for PCCARD module. 00470 * @param SectorAddress Sector address to erase 00471 * @param pStatus pointer to PCCARD status 00472 * @retval HAL status 00473 */ 00474 HAL_StatusTypeDef HAL_PCCARD_Erase_Sector(PCCARD_HandleTypeDef *hpccard, uint16_t SectorAddress, uint8_t *pStatus) 00475 { 00476 uint32_t timeout = PCCARD_TIMEOUT_ERASE_SECTOR; 00477 uint8_t status = 0; 00478 00479 /* Process Locked */ 00480 __HAL_LOCK(hpccard); 00481 00482 /* Check the PCCARD controller state */ 00483 if(hpccard->State == HAL_PCCARD_STATE_BUSY) 00484 { 00485 return HAL_BUSY; 00486 } 00487 00488 /* Update the PCCARD controller state */ 00489 hpccard->State = HAL_PCCARD_STATE_BUSY; 00490 00491 /* Initialize PCCARD status */ 00492 *pStatus = PCCARD_READY; 00493 00494 /* Set the parameters to write a sector */ 00495 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_LOW) = 0x00; 00496 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CYLINDER_HIGH) = 0x00; 00497 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_NUMBER) = SectorAddress; 00498 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_SECTOR_COUNT) = 0x01; 00499 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_CARD_HEAD) = 0xA0; 00500 *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD) = ATA_ERASE_SECTOR_CMD; 00501 00502 /* wait till the PCCARD is ready */ 00503 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); 00504 00505 while((status != PCCARD_STATUS_WRITE_OK) && timeout) 00506 { 00507 status = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); 00508 timeout--; 00509 } 00510 00511 if(timeout == 0U) 00512 { 00513 *pStatus = PCCARD_TIMEOUT_ERROR; 00514 } 00515 00516 /* Check the PCCARD controller state */ 00517 hpccard->State = HAL_PCCARD_STATE_READY; 00518 00519 /* Process unlocked */ 00520 __HAL_UNLOCK(hpccard); 00521 00522 return HAL_OK; 00523 } 00524 00525 /** 00526 * @brief Reset the PCCARD memory 00527 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00528 * the configuration information for PCCARD module. 00529 * @retval HAL status 00530 */ 00531 HAL_StatusTypeDef HAL_PCCARD_Reset(PCCARD_HandleTypeDef *hpccard) 00532 { 00533 /* Process Locked */ 00534 __HAL_LOCK(hpccard); 00535 00536 /* Check the PCCARD controller state */ 00537 if(hpccard->State == HAL_PCCARD_STATE_BUSY) 00538 { 00539 return HAL_BUSY; 00540 } 00541 00542 /* Provide a SW reset and Read and verify the: 00543 - PCCard Configuration Option Register at address 0x98000200 --> 0x80 00544 - Card Configuration and Status Register at address 0x98000202 --> 0x00 00545 - Pin Replacement Register at address 0x98000204 --> 0x0C 00546 - Socket and Copy Register at address 0x98000206 --> 0x00 00547 */ 00548 00549 /* Check the PCCARD controller state */ 00550 hpccard->State = HAL_PCCARD_STATE_BUSY; 00551 00552 *(__IO uint8_t *)(PCCARD_ATTRIBUTE_SPACE_ADDRESS | ATA_CARD_CONFIGURATION ) = 0x01; 00553 00554 /* Check the PCCARD controller state */ 00555 hpccard->State = HAL_PCCARD_STATE_READY; 00556 00557 /* Process unlocked */ 00558 __HAL_UNLOCK(hpccard); 00559 00560 return HAL_OK; 00561 } 00562 00563 /** 00564 * @brief This function handles PCCARD device interrupt request. 00565 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00566 * the configuration information for PCCARD module. 00567 * @retval HAL status 00568 */ 00569 void HAL_PCCARD_IRQHandler(PCCARD_HandleTypeDef *hpccard) 00570 { 00571 /* Check PCCARD interrupt Rising edge flag */ 00572 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_RISING_EDGE)) 00573 { 00574 /* PCCARD interrupt callback*/ 00575 HAL_PCCARD_ITCallback(hpccard); 00576 00577 /* Clear PCCARD interrupt Rising edge pending bit */ 00578 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_RISING_EDGE); 00579 } 00580 00581 /* Check PCCARD interrupt Level flag */ 00582 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_LEVEL)) 00583 { 00584 /* PCCARD interrupt callback*/ 00585 HAL_PCCARD_ITCallback(hpccard); 00586 00587 /* Clear PCCARD interrupt Level pending bit */ 00588 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_LEVEL); 00589 } 00590 00591 /* Check PCCARD interrupt Falling edge flag */ 00592 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_FALLING_EDGE)) 00593 { 00594 /* PCCARD interrupt callback*/ 00595 HAL_PCCARD_ITCallback(hpccard); 00596 00597 /* Clear PCCARD interrupt Falling edge pending bit */ 00598 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_FALLING_EDGE); 00599 } 00600 00601 /* Check PCCARD interrupt FIFO empty flag */ 00602 if(__FMC_PCCARD_GET_FLAG(hpccard->Instance, FMC_FLAG_FEMPT)) 00603 { 00604 /* PCCARD interrupt callback*/ 00605 HAL_PCCARD_ITCallback(hpccard); 00606 00607 /* Clear PCCARD interrupt FIFO empty pending bit */ 00608 __FMC_PCCARD_CLEAR_FLAG(hpccard->Instance, FMC_FLAG_FEMPT); 00609 } 00610 } 00611 00612 /** 00613 * @brief PCCARD interrupt feature callback 00614 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00615 * the configuration information for PCCARD module. 00616 * @retval None 00617 */ 00618 __weak void HAL_PCCARD_ITCallback(PCCARD_HandleTypeDef *hpccard) 00619 { 00620 /* Prevent unused argument(s) compilation warning */ 00621 UNUSED(hpccard); 00622 /* NOTE : This function Should not be modified, when the callback is needed, 00623 the HAL_PCCARD_ITCallback could be implemented in the user file 00624 */ 00625 } 00626 00627 /** 00628 * @} 00629 */ 00630 00631 /** @defgroup PCCARD_Exported_Functions_Group3 State functions 00632 * @brief Peripheral State functions 00633 * 00634 @verbatim 00635 ============================================================================== 00636 ##### PCCARD State functions ##### 00637 ============================================================================== 00638 [..] 00639 This subsection permits to get in run-time the status of the PCCARD controller 00640 and the data flow. 00641 00642 @endverbatim 00643 * @{ 00644 */ 00645 00646 /** 00647 * @brief return the PCCARD controller state 00648 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00649 * the configuration information for PCCARD module. 00650 * @retval HAL state 00651 */ 00652 HAL_PCCARD_StateTypeDef HAL_PCCARD_GetState(PCCARD_HandleTypeDef *hpccard) 00653 { 00654 return hpccard->State; 00655 } 00656 00657 /** 00658 * @brief Get the compact flash memory status 00659 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00660 * the configuration information for PCCARD module. 00661 * @retval New status of the PCCARD operation. This parameter can be: 00662 * - CompactFlash_TIMEOUT_ERROR: when the previous operation generate 00663 * a Timeout error 00664 * - CompactFlash_READY: when memory is ready for the next operation 00665 */ 00666 HAL_PCCARD_StatusTypeDef HAL_PCCARD_GetStatus(PCCARD_HandleTypeDef *hpccard) 00667 { 00668 uint32_t timeout = PCCARD_TIMEOUT_STATUS, status_pccard = 0U; 00669 00670 /* Check the PCCARD controller state */ 00671 if(hpccard->State == HAL_PCCARD_STATE_BUSY) 00672 { 00673 return HAL_PCCARD_STATUS_ONGOING; 00674 } 00675 00676 status_pccard = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); 00677 00678 while((status_pccard == PCCARD_BUSY) && timeout) 00679 { 00680 status_pccard = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); 00681 timeout--; 00682 } 00683 00684 if(timeout == 0U) 00685 { 00686 status_pccard = PCCARD_TIMEOUT_ERROR; 00687 } 00688 00689 /* Return the operation status */ 00690 return (HAL_PCCARD_StatusTypeDef) status_pccard; 00691 } 00692 00693 /** 00694 * @brief Reads the Compact Flash memory status using the Read status command 00695 * @param hpccard pointer to a PCCARD_HandleTypeDef structure that contains 00696 * the configuration information for PCCARD module. 00697 * @retval The status of the Compact Flash memory. This parameter can be: 00698 * - CompactFlash_BUSY: when memory is busy 00699 * - CompactFlash_READY: when memory is ready for the next operation 00700 * - CompactFlash_ERROR: when the previous operation generates error 00701 */ 00702 HAL_PCCARD_StatusTypeDef HAL_PCCARD_ReadStatus(PCCARD_HandleTypeDef *hpccard) 00703 { 00704 uint8_t data = 0U, status_pccard = PCCARD_BUSY; 00705 00706 /* Check the PCCARD controller state */ 00707 if(hpccard->State == HAL_PCCARD_STATE_BUSY) 00708 { 00709 return HAL_PCCARD_STATUS_ONGOING; 00710 } 00711 00712 /* Read status operation */ 00713 data = *(__IO uint8_t *)(PCCARD_IO_SPACE_PRIMARY_ADDR | ATA_STATUS_CMD_ALTERNATE); 00714 00715 if((data & PCCARD_TIMEOUT_ERROR) == PCCARD_TIMEOUT_ERROR) 00716 { 00717 status_pccard = PCCARD_TIMEOUT_ERROR; 00718 } 00719 else if((data & PCCARD_READY) == PCCARD_READY) 00720 { 00721 status_pccard = PCCARD_READY; 00722 } 00723 00724 return (HAL_PCCARD_StatusTypeDef) status_pccard; 00725 } 00726 00727 /** 00728 * @} 00729 */ 00730 00731 /** 00732 * @} 00733 */ 00734 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx ||\ 00735 STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */ 00736 #endif /* HAL_PCCARD_MODULE_ENABLED */ 00737 00738 /** 00739 * @} 00740 */ 00741 00742 /** 00743 * @} 00744 */ 00745 00746 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/