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