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