Subversion Repositories DashDisplay

Rev

Rev 50 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
77 mjames 1
/**
2
  ******************************************************************************
3
  * @file    stm32l1xx_hal_flash_ramfunc.c
4
  * @author  MCD Application Team
5
  * @brief   FLASH RAMFUNC driver.
6
  *          This file provides a Flash firmware functions which should be
7
  *          executed from internal SRAM
8
  *
9
  *  @verbatim
10
 
11
    *** ARM Compiler ***
12
    --------------------
13
    [..] RAM functions are defined using the toolchain options.
14
         Functions that are be executed in RAM should reside in a separate
15
         source module. Using the 'Options for File' dialog you can simply change
16
         the 'Code / Const' area of a module to a memory space in physical RAM.
17
         Available memory areas are declared in the 'Target' tab of the
18
         Options for Target' dialog.
19
 
20
    *** ICCARM Compiler ***
21
    -----------------------
22
    [..] RAM functions are defined using a specific toolchain keyword "__ramfunc".
23
 
24
    *** GNU Compiler ***
25
    --------------------
26
    [..] RAM functions are defined using a specific toolchain attribute
27
         "__attribute__((section(".RamFunc")))".
28
 
29
@endverbatim
30
  ******************************************************************************
31
  * @attention
32
  *
33
  * Copyright (c) 2017 STMicroelectronics.
34
  * All rights reserved.
35
  *
36
  * This software is licensed under terms that can be found in the LICENSE file in
37
  * the root directory of this software component.
38
  * If no LICENSE file comes with this software, it is provided AS-IS.
39
  ******************************************************************************
40
  */
41
 
42
/* Includes ------------------------------------------------------------------*/
43
#include "stm32l1xx_hal.h"
44
 
45
/** @addtogroup STM32L1xx_HAL_Driver
46
  * @{
47
  */
48
 
49
#ifdef HAL_FLASH_MODULE_ENABLED
50
 
51
/** @addtogroup FLASH
52
  * @{
53
  */
54
/** @addtogroup FLASH_Private_Variables
55
 * @{
56
 */
57
extern FLASH_ProcessTypeDef pFlash;
58
/**
59
  * @}
60
  */
61
 
62
/**
63
  * @}
64
  */
65
 
66
/** @defgroup FLASH_RAMFUNC FLASH_RAMFUNC
67
  * @brief FLASH functions executed from RAM
68
  * @{
69
  */
70
 
71
 
72
/* Private typedef -----------------------------------------------------------*/
73
/* Private define ------------------------------------------------------------*/
74
/* Private macro -------------------------------------------------------------*/
75
/* Private variables ---------------------------------------------------------*/
76
/* Private function prototypes -----------------------------------------------*/
77
/** @defgroup FLASH_RAMFUNC_Private_Functions FLASH RAM Private Functions
78
 * @{
79
 */
80
 
81
static __RAM_FUNC HAL_StatusTypeDef FLASHRAM_WaitForLastOperation(uint32_t Timeout);
82
static __RAM_FUNC HAL_StatusTypeDef FLASHRAM_SetErrorCode(void);
83
 
84
/**
85
  * @}
86
  */
87
 
88
/* Private functions ---------------------------------------------------------*/
89
 
90
/** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH RAM Exported Functions
91
 *
92
@verbatim  
93
 ===============================================================================
94
                      ##### ramfunc functions #####
95
 ===============================================================================  
96
    [..]
97
    This subsection provides a set of functions that should be executed from RAM
98
    transfers.
99
 
100
@endverbatim
101
  * @{
102
  */
103
 
104
/** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions
105
  * @{
106
  */  
107
 
108
/**
109
  * @brief  Enable  the power down mode during RUN mode.
110
  * @note  This function can be used only when the user code is running from Internal SRAM.
111
  * @retval HAL status
112
  */
113
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableRunPowerDown(void)
114
{
115
  /* Enable the Power Down in Run mode*/
116
  __HAL_FLASH_POWER_DOWN_ENABLE();
117
 
118
  return HAL_OK;
119
}
120
 
121
/**
122
  * @brief  Disable the power down mode during RUN mode.
123
  * @note  This function can be used only when the user code is running from Internal SRAM.
124
  * @retval HAL status
125
  */
126
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableRunPowerDown(void)
127
{
128
  /* Disable the Power Down in Run mode*/
129
  __HAL_FLASH_POWER_DOWN_DISABLE();
130
 
131
  return HAL_OK;  
132
}
133
 
134
/**
135
  * @}
136
  */
137
 
138
/** @defgroup FLASH_RAMFUNC_Exported_Functions_Group2 Programming and erasing operation functions
139
 *
140
@verbatim  
141
@endverbatim
142
  * @{
143
  */
144
 
145
#if defined(FLASH_PECR_PARALLBANK)
146
/**
147
  * @brief  Erases a specified 2 pages in program memory in parallel.
148
  * @note   This function can be used only for STM32L151xD, STM32L152xD), STM32L162xD and Cat5  devices.
149
  *         To correctly run this function, the @ref HAL_FLASH_Unlock() function
150
  *         must be called before.
151
  *         Call the @ref HAL_FLASH_Lock() to disable the flash memory access
152
  *        (recommended to protect the FLASH memory against possible unwanted operation).
153
  * @param  Page_Address1: The page address in program memory to be erased in
154
  *         the first Bank (BANK1). This parameter should be between FLASH_BASE
155
  *         and FLASH_BANK1_END.
156
  * @param  Page_Address2: The page address in program memory to be erased in
157
  *         the second Bank (BANK2). This parameter should be between FLASH_BANK2_BASE
158
  *         and FLASH_BANK2_END.
159
  * @note   A Page is erased in the Program memory only if the address to load
160
  *         is the start address of a page (multiple of @ref FLASH_PAGE_SIZE bytes).
161
  * @retval HAL status
162
  */
163
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EraseParallelPage(uint32_t Page_Address1, uint32_t Page_Address2)
164
{
165
  HAL_StatusTypeDef status = HAL_OK;
166
 
167
  /* Wait for last operation to be completed */
168
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
169
 
170
  if(status == HAL_OK)
171
  {
172
    /* Proceed to erase the page */
173
    SET_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
174
    SET_BIT(FLASH->PECR, FLASH_PECR_ERASE);
175
    SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
176
 
177
    /* Write 00000000h to the first word of the first program page to erase */
178
    *(__IO uint32_t *)Page_Address1 = 0x00000000U;
179
    /* Write 00000000h to the first word of the second program page to erase */    
180
    *(__IO uint32_t *)Page_Address2 = 0x00000000U;
181
 
182
    /* Wait for last operation to be completed */
183
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
184
 
185
    /* If the erase operation is completed, disable the ERASE, PROG and PARALLBANK bits */
186
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_PROG);
187
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_ERASE);
188
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
189
  }    
190
  /* Return the Erase Status */
191
  return status;
192
}
193
 
194
/**
195
  * @brief  Program 2 half pages in program memory in parallel (half page size is 32 Words).
196
  * @note   This function can be used only for STM32L151xD, STM32L152xD), STM32L162xD and Cat5  devices.
197
  * @param  Address1: specifies the first address to be written in the first bank
198
  *        (BANK1). This parameter should be between FLASH_BASE and (FLASH_BANK1_END - FLASH_PAGE_SIZE).
199
  * @param  pBuffer1: pointer to the buffer  containing the data to be  written
200
  *         to the first half page in the first bank.
201
  * @param  Address2: specifies the second address to be written in the second bank
202
  *        (BANK2). This parameter should be between FLASH_BANK2_BASE and (FLASH_BANK2_END - FLASH_PAGE_SIZE).
203
  * @param  pBuffer2: pointer to the buffer containing the data to be  written
204
  *         to the second half page in the second bank.
205
  * @note   To correctly run this function, the @ref HAL_FLASH_Unlock() function
206
  *         must be called before.
207
  *         Call the @ref HAL_FLASH_Lock() to disable the flash memory access  
208
  *         (recommended to protect the FLASH memory against possible unwanted operation).
209
  * @note   Half page write is possible only from SRAM.
210
  * @note   If there are more than 32 words to write, after 32 words another
211
  *         Half Page programming operation starts and has to be finished.
212
  * @note   A half page is written to the program memory only if the first
213
  *         address to load is the start address of a half page (multiple of 128
214
  *         bytes) and the 31 remaining words to load are in the same half page.
215
  * @note   During the Program memory half page write all read operations are
216
  *         forbidden (this includes DMA read operations and debugger read
217
  *         operations such as breakpoints, periodic updates, etc.).
218
  * @note   If a PGAERR is set during a Program memory half page write, the
219
  *         complete write operation is aborted. Software should then reset the
220
  *         FPRG and PROG/DATA bits and restart the write operation from the
221
  *         beginning.
222
  * @retval HAL status
223
  */
224
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_ProgramParallelHalfPage(uint32_t Address1, uint32_t* pBuffer1, uint32_t Address2, uint32_t* pBuffer2)
225
{
226
  uint32_t primask_bit;
227
  uint32_t count = 0U;
228
  HAL_StatusTypeDef status = HAL_OK;
229
 
230
  /* Wait for last operation to be completed */
231
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
232
 
233
  if(status == HAL_OK)
234
  {
235
    /* Disable all IRQs */
236
    primask_bit = __get_PRIMASK();
237
    __disable_irq();
238
 
239
    /* Proceed to program the new half page */
240
    SET_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
241
    SET_BIT(FLASH->PECR, FLASH_PECR_FPRG);
242
    SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
243
 
244
    /* Write the first half page directly with 32 different words */
245
    while(count < 32U)
246
    {
247
      *(__IO uint32_t*) ((uint32_t)(Address1 + (4 * count))) = *pBuffer1;
248
      pBuffer1++;
249
      count ++;  
250
    }
251
 
252
    /* Write the second half page directly with 32 different words */
253
    count = 0U;
254
    while(count < 32U)
255
    {
256
      *(__IO uint32_t*) ((uint32_t)(Address2 + (4 * count))) = *pBuffer2;
257
      pBuffer2++;
258
      count ++;  
259
    }
260
 
261
    /* Wait for last operation to be completed */
262
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
263
 
264
    /* if the write operation is completed, disable the PROG, FPRG and PARALLBANK bits */
265
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_PROG);
266
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_FPRG);
267
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
268
 
269
    /* Enable IRQs */
270
    __set_PRIMASK(primask_bit);    
271
  }
272
 
273
  /* Return the Write Status */
274
  return status;
275
}
276
#endif /* FLASH_PECR_PARALLBANK */
277
 
278
/**
279
  * @brief  Program a half page in program memory.
280
  * @param  Address specifies the address to be written.
281
  * @param  pBuffer pointer to the buffer  containing the data to be  written to
282
  *         the half page.
283
  * @note   To correctly run this function, the @ref HAL_FLASH_Unlock() function
284
  *         must be called before.
285
  *         Call the @ref HAL_FLASH_Lock() to disable the flash memory access  
286
  *         (recommended to protect the FLASH memory against possible unwanted operation)
287
  * @note   Half page write is possible only from SRAM.
288
  * @note   If there are more than 32 words to write, after 32 words another
289
  *         Half Page programming operation starts and has to be finished.
290
  * @note   A half page is written to the program memory only if the first
291
  *         address to load is the start address of a half page (multiple of 128
292
  *         bytes) and the 31 remaining words to load are in the same half page.
293
  * @note   During the Program memory half page write all read operations are
294
  *         forbidden (this includes DMA read operations and debugger read
295
  *         operations such as breakpoints, periodic updates, etc.).
296
  * @note   If a PGAERR is set during a Program memory half page write, the
297
  *         complete write operation is aborted. Software should then reset the
298
  *         FPRG and PROG/DATA bits and restart the write operation from the
299
  *         beginning.
300
  * @retval HAL status
301
  */
302
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_HalfPageProgram(uint32_t Address, uint32_t* pBuffer)
303
{
304
  uint32_t primask_bit;
305
  uint32_t count = 0U;
306
  HAL_StatusTypeDef status = HAL_OK;
307
 
308
  /* Wait for last operation to be completed */
309
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
310
 
311
  if(status == HAL_OK)
312
  {
313
    /* Disable all IRQs */
314
    primask_bit = __get_PRIMASK();
315
    __disable_irq();
316
 
317
    /* Proceed to program the new half page */
318
    SET_BIT(FLASH->PECR, FLASH_PECR_FPRG);
319
    SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
320
 
321
    /* Write one half page directly with 32 different words */
322
    while(count < 32U)
323
    {
324
      *(__IO uint32_t*) ((uint32_t)(Address + (4 * count))) = *pBuffer;
325
      pBuffer++;
326
      count ++;  
327
    }
328
 
329
    /* Wait for last operation to be completed */
330
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
331
 
332
    /* If the write operation is completed, disable the PROG and FPRG bits */
333
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_PROG);
334
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_FPRG);
335
 
336
    /* Enable IRQs */
337
    __set_PRIMASK(primask_bit);
338
  }
339
 
340
  /* Return the Write Status */
341
  return status;
342
}
343
 
344
/**
345
  * @}
346
  */
347
 
348
/** @defgroup FLASH_RAMFUNC_Exported_Functions_Group3 Peripheral errors functions
349
 *  @brief    Peripheral errors functions
350
 *
351
@verbatim  
352
 ===============================================================================
353
                      ##### Peripheral errors functions #####
354
 ===============================================================================  
355
    [..]
356
    This subsection permit to get in run-time errors of  the FLASH peripheral.
357
 
358
@endverbatim
359
  * @{
360
  */
361
 
362
/**
363
  * @brief  Get the specific FLASH errors flag.
364
  * @param  Error pointer is the error value. It can be a mixed of:
365
@if STM32L100xB
366
@elif STM32L100xBA
367
  *            @arg @ref HAL_FLASH_ERROR_RD      FLASH Read Protection error flag (PCROP)
368
@elif STM32L151xB
369
@elif STM32L151xBA
370
  *            @arg @ref HAL_FLASH_ERROR_RD      FLASH Read Protection error flag (PCROP)
371
@elif STM32L152xB
372
@elif STM32L152xBA
373
  *            @arg @ref HAL_FLASH_ERROR_RD      FLASH Read Protection error flag (PCROP)
374
@elif STM32L100xC
375
  *            @arg @ref HAL_FLASH_ERROR_RD      FLASH Read Protection error flag (PCROP)
376
  *            @arg @ref HAL_FLASH_ERROR_OPTVUSR FLASH Option User validity error
377
@elif STM32L151xC
378
  *            @arg @ref HAL_FLASH_ERROR_RD      FLASH Read Protection error flag (PCROP)
379
  *            @arg @ref HAL_FLASH_ERROR_OPTVUSR FLASH Option User validity error
380
@elif STM32L152xC
381
  *            @arg @ref HAL_FLASH_ERROR_RD      FLASH Read Protection error flag (PCROP)
382
  *            @arg @ref HAL_FLASH_ERROR_OPTVUSR FLASH Option User validity error
383
@elif STM32L162xC
384
  *            @arg @ref HAL_FLASH_ERROR_RD      FLASH Read Protection error flag (PCROP)
385
  *            @arg @ref HAL_FLASH_ERROR_OPTVUSR FLASH Option User validity error
386
@else
387
  *            @arg @ref HAL_FLASH_ERROR_OPTVUSR FLASH Option User validity error
388
@endif
389
  *            @arg @ref HAL_FLASH_ERROR_PGA     FLASH Programming Alignment error flag
390
  *            @arg @ref HAL_FLASH_ERROR_WRP     FLASH Write protected error flag
391
  *            @arg @ref HAL_FLASH_ERROR_OPTV    FLASH Option valid error flag
392
  * @retval HAL Status
393
  */
394
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_GetError(uint32_t * Error)
395
{
396
  *Error = pFlash.ErrorCode;
397
  return HAL_OK;  
398
}
399
 
400
/**
401
  * @}
402
  */
403
 
404
/** @defgroup FLASH_RAMFUNC_Exported_Functions_Group4 DATA EEPROM functions
405
  *
406
  * @{
407
  */
408
 
409
/**
410
  * @brief  Erase a double word in data memory.
411
  * @param  Address specifies the address to be erased.
412
  * @note   To correctly run this function, the HAL_FLASH_EEPROM_Unlock() function
413
  *         must be called before.
414
  *         Call the HAL_FLASH_EEPROM_Lock() to he data EEPROM access
415
  *         and Flash program erase control register access(recommended to protect
416
  *         the DATA_EEPROM against possible unwanted operation).
417
  * @note   Data memory double word erase is possible only from SRAM.
418
  * @note   A double word is erased to the data memory only if the first address
419
  *         to load is the start address of a double word (multiple of 8 bytes).
420
  * @note   During the Data memory double word erase, all read operations are
421
  *         forbidden (this includes DMA read operations and debugger read
422
  *         operations such as breakpoints, periodic updates, etc.).
423
  * @retval HAL status
424
  */
425
 
426
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_EraseDoubleWord(uint32_t Address)
427
{
428
  uint32_t primask_bit;
429
  HAL_StatusTypeDef status = HAL_OK;
430
 
431
  /* Wait for last operation to be completed */
432
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
433
 
434
  if(status == HAL_OK)
435
  {
436
    /* Disable all IRQs */
437
    primask_bit = __get_PRIMASK();
438
    __disable_irq();
439
 
440
    /* If the previous operation is completed, proceed to erase the next double word */
441
    /* Set the ERASE bit */
442
    SET_BIT(FLASH->PECR, FLASH_PECR_ERASE);
443
 
444
    /* Set DATA bit */
445
    SET_BIT(FLASH->PECR, FLASH_PECR_DATA);
446
 
447
    /* Write 00000000h to the 2 words to erase */
448
    *(__IO uint32_t *)Address = 0x00000000U;
449
    Address += 4U;
450
    *(__IO uint32_t *)Address = 0x00000000U;
451
 
452
    /* Wait for last operation to be completed */
453
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
454
 
455
    /* If the erase operation is completed, disable the ERASE and DATA bits */
456
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_ERASE);
457
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_DATA);
458
 
459
    /* Enable IRQs */
460
    __set_PRIMASK(primask_bit);
461
 
462
  }  
463
 
464
  /* Return the erase status */
465
  return status;
466
}
467
 
468
/**
469
  * @brief  Write a double word in data memory without erase.
470
  * @param  Address specifies the address to be written.
471
  * @param  Data specifies the data to be written.
472
  * @note   To correctly run this function, the HAL_FLASH_EEPROM_Unlock() function
473
  *         must be called before.
474
  *         Call the HAL_FLASH_EEPROM_Lock() to he data EEPROM access
475
  *         and Flash program erase control register access(recommended to protect
476
  *         the DATA_EEPROM against possible unwanted operation).
477
  * @note   Data memory double word write is possible only from SRAM.
478
  * @note   A data memory double word is written to the data memory only if the
479
  *         first address to load is the start address of a double word (multiple
480
  *         of double word).
481
  * @note   During the Data memory double word write, all read operations are
482
  *         forbidden (this includes DMA read operations and debugger read
483
  *         operations such as breakpoints, periodic updates, etc.).
484
  * @retval HAL status
485
  */
486
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_ProgramDoubleWord(uint32_t Address, uint64_t Data)
487
{
488
  uint32_t primask_bit;
489
  HAL_StatusTypeDef status = HAL_OK;
490
 
491
  /* Wait for last operation to be completed */
492
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
493
 
494
  if(status == HAL_OK)
495
  {
496
    /* Disable all IRQs */
497
    primask_bit = __get_PRIMASK();
498
    __disable_irq();
499
 
500
    /* If the previous operation is completed, proceed to program the new data*/
501
    SET_BIT(FLASH->PECR, FLASH_PECR_FPRG);
502
    SET_BIT(FLASH->PECR, FLASH_PECR_DATA);
503
 
504
    /* Write the 2 words */  
505
     *(__IO uint32_t *)Address = (uint32_t) Data;
506
     Address += 4U;
507
     *(__IO uint32_t *)Address = (uint32_t) (Data >> 32);
508
 
509
    /* Wait for last operation to be completed */
510
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
511
 
512
    /* If the write operation is completed, disable the FPRG and DATA bits */
513
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_FPRG);
514
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_DATA);    
515
 
516
    /* Enable IRQs */
517
    __set_PRIMASK(primask_bit);
518
  }
519
 
520
  /* Return the Write Status */
521
  return status;
522
}
523
 
524
/**
525
  * @}
526
  */
527
 
528
/**
529
  * @}
530
  */
531
 
532
/** @addtogroup FLASH_RAMFUNC_Private_Functions
533
  * @{
534
  */
535
 
536
/**
537
  * @brief  Set the specific FLASH error flag.
538
  * @retval HAL Status
539
  */
540
static __RAM_FUNC HAL_StatusTypeDef FLASHRAM_SetErrorCode(void)
541
{
542
  uint32_t flags = 0U;
543
 
544
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR))
545
  {
546
    pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
547
    flags |= FLASH_FLAG_WRPERR;
548
  }
549
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR))
550
  {
551
    pFlash.ErrorCode |= HAL_FLASH_ERROR_PGA;
552
    flags |= FLASH_FLAG_PGAERR;
553
  }
554
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR))
555
  {
556
    pFlash.ErrorCode |= HAL_FLASH_ERROR_OPTV;
557
    flags |= FLASH_FLAG_OPTVERR;
558
  }
559
 
560
#if defined(FLASH_SR_RDERR)
561
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR))
562
  {
563
    pFlash.ErrorCode |= HAL_FLASH_ERROR_RD;
564
    flags |= FLASH_FLAG_RDERR;
565
  }
566
#endif /* FLASH_SR_RDERR */
567
#if defined(FLASH_SR_OPTVERRUSR)
568
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERRUSR))
569
  {
570
    pFlash.ErrorCode |= HAL_FLASH_ERROR_OPTVUSR;
571
    flags |= FLASH_FLAG_OPTVERRUSR;
572
  }
573
#endif /* FLASH_SR_OPTVERRUSR */
574
 
575
  /* Clear FLASH error pending bits */
576
  __HAL_FLASH_CLEAR_FLAG(flags);
577
 
578
  return HAL_OK;
579
}  
580
 
581
/**
582
  * @brief  Wait for a FLASH operation to complete.
583
  * @param  Timeout maximum flash operationtimeout
584
  * @retval HAL status
585
  */
586
static __RAM_FUNC HAL_StatusTypeDef FLASHRAM_WaitForLastOperation(uint32_t Timeout)
587
{
588
    /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
589
       Even if the FLASH operation fails, the BUSY flag will be reset and an error
590
       flag will be set */
591
 
592
    while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) && (Timeout != 0x00U))
593
    {
594
      Timeout--;
595
    }
596
 
597
    if(Timeout == 0x00U)
598
    {
599
      return HAL_TIMEOUT;
600
    }
601
 
602
  /* Check FLASH End of Operation flag  */
603
  if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
604
  {
605
    /* Clear FLASH End of Operation pending bit */
606
    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
607
  }
608
 
609
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR)  ||
610
     __HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR) ||
611
#if defined(FLASH_SR_RDERR)
612
      __HAL_FLASH_GET_FLAG(FLASH_FLAG_RDERR) ||
613
#endif /* FLASH_SR_RDERR */
614
#if defined(FLASH_SR_OPTVERRUSR)
615
      __HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERRUSR) ||
616
#endif /* FLASH_SR_OPTVERRUSR */
617
     __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGAERR))
618
  {
619
    /*Save the error code*/
620
    FLASHRAM_SetErrorCode();
621
    return HAL_ERROR;
622
  }
623
 
624
  /* There is no error flag set */
625
  return HAL_OK;
626
}
627
 
628
/**
629
  * @}
630
  */
631
 
632
/**
633
  * @}
634
  */
635
 
636
#endif /* HAL_FLASH_MODULE_ENABLED */
637
/**
638
  * @}
639
  */
640