Subversion Repositories EngineBay2

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 28
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32l1xx_hal_flash_ramfunc.c
3
  * @file    stm32l1xx_hal_flash_ramfunc.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @version V1.2.0
-
 
6
  * @date    01-July-2016
-
 
7
  * @brief   FLASH RAMFUNC driver.
5
  * @brief   FLASH RAMFUNC driver.
8
  *          This file provides a Flash firmware functions which should be
6
  *          This file provides a Flash firmware functions which should be
9
  *          executed from internal SRAM
7
  *          executed from internal SRAM
10
  *
8
  *
11
  *  @verbatim
9
  *  @verbatim
Line 30... Line 28...
30
 
28
 
31
@endverbatim
29
@endverbatim
32
  ******************************************************************************
30
  ******************************************************************************
33
  * @attention
31
  * @attention
34
  *
32
  *
35
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
33
  * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
-
 
34
  * All rights reserved.</center></h2>
36
  *
35
  *
37
  * Redistribution and use in source and binary forms, with or without modification,
36
  * This software component is licensed by ST under BSD 3-Clause license,
38
  * are permitted provided that the following conditions are met:
37
  * the "License"; You may not use this file except in compliance with the
39
  *   1. Redistributions of source code must retain the above copyright notice,
-
 
40
  *      this list of conditions and the following disclaimer.
-
 
41
  *   2. Redistributions in binary form must reproduce the above copyright notice,
-
 
42
  *      this list of conditions and the following disclaimer in the documentation
-
 
43
  *      and/or other materials provided with the distribution.
38
  * License. You may obtain a copy of the License at:
44
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
-
 
45
  *      may be used to endorse or promote products derived from this software
39
  *                        opensource.org/licenses/BSD-3-Clause
46
  *      without specific prior written permission.
-
 
47
  *
-
 
48
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
 
49
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
 
50
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-
 
51
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-
 
52
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-
 
53
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-
 
54
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-
 
55
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-
 
56
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-
 
57
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
58
  *
40
  *
59
  ******************************************************************************
41
  ******************************************************************************
60
  */
42
  */
61
 
43
 
62
/* Includes ------------------------------------------------------------------*/
44
/* Includes ------------------------------------------------------------------*/
Line 96... Line 78...
96
/* Private function prototypes -----------------------------------------------*/
78
/* Private function prototypes -----------------------------------------------*/
97
/** @defgroup FLASH_RAMFUNC_Private_Functions FLASH RAM Private Functions
79
/** @defgroup FLASH_RAMFUNC_Private_Functions FLASH RAM Private Functions
98
 * @{
80
 * @{
99
 */
81
 */
100
 
82
 
101
static __RAM_FUNC FLASHRAM_WaitForLastOperation(uint32_t Timeout);
83
static __RAM_FUNC HAL_StatusTypeDef FLASHRAM_WaitForLastOperation(uint32_t Timeout);
102
static __RAM_FUNC FLASHRAM_SetErrorCode(void);
84
static __RAM_FUNC HAL_StatusTypeDef FLASHRAM_SetErrorCode(void);
103
 
85
 
104
/**
86
/**
105
  * @}
87
  * @}
106
  */
88
  */
107
 
89
 
Line 128... Line 110...
128
/**
110
/**
129
  * @brief  Enable  the power down mode during RUN mode.
111
  * @brief  Enable  the power down mode during RUN mode.
130
  * @note  This function can be used only when the user code is running from Internal SRAM.
112
  * @note  This function can be used only when the user code is running from Internal SRAM.
131
  * @retval HAL status
113
  * @retval HAL status
132
  */
114
  */
133
__RAM_FUNC HAL_FLASHEx_EnableRunPowerDown(void)
115
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableRunPowerDown(void)
134
{
116
{
135
  /* Enable the Power Down in Run mode*/
117
  /* Enable the Power Down in Run mode*/
136
  __HAL_FLASH_POWER_DOWN_ENABLE();
118
  __HAL_FLASH_POWER_DOWN_ENABLE();
137
 
119
 
138
  return HAL_OK;
120
  return HAL_OK;
Line 141... Line 123...
141
/**
123
/**
142
  * @brief  Disable the power down mode during RUN mode.
124
  * @brief  Disable the power down mode during RUN mode.
143
  * @note  This function can be used only when the user code is running from Internal SRAM.
125
  * @note  This function can be used only when the user code is running from Internal SRAM.
144
  * @retval HAL status
126
  * @retval HAL status
145
  */
127
  */
146
__RAM_FUNC HAL_FLASHEx_DisableRunPowerDown(void)
128
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableRunPowerDown(void)
147
{
129
{
148
  /* Disable the Power Down in Run mode*/
130
  /* Disable the Power Down in Run mode*/
149
  __HAL_FLASH_POWER_DOWN_DISABLE();
131
  __HAL_FLASH_POWER_DOWN_DISABLE();
150
 
132
 
151
  return HAL_OK;  
133
  return HAL_OK;  
Line 178... Line 160...
178
  *         and FLASH_BANK2_END.
160
  *         and FLASH_BANK2_END.
179
  * @note   A Page is erased in the Program memory only if the address to load
161
  * @note   A Page is erased in the Program memory only if the address to load
180
  *         is the start address of a page (multiple of @ref FLASH_PAGE_SIZE bytes).
162
  *         is the start address of a page (multiple of @ref FLASH_PAGE_SIZE bytes).
181
  * @retval HAL status
163
  * @retval HAL status
182
  */
164
  */
183
__RAM_FUNC HAL_FLASHEx_EraseParallelPage(uint32_t Page_Address1, uint32_t Page_Address2)
165
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EraseParallelPage(uint32_t Page_Address1, uint32_t Page_Address2)
184
{
166
{
185
  HAL_StatusTypeDef status = HAL_OK;
167
  HAL_StatusTypeDef status = HAL_OK;
186
 
168
 
187
  /* Wait for last operation to be completed */
169
  /* Wait for last operation to be completed */
188
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
170
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
Line 193... Line 175...
193
    SET_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
175
    SET_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
194
    SET_BIT(FLASH->PECR, FLASH_PECR_ERASE);
176
    SET_BIT(FLASH->PECR, FLASH_PECR_ERASE);
195
    SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
177
    SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
196
 
178
 
197
    /* Write 00000000h to the first word of the first program page to erase */
179
    /* Write 00000000h to the first word of the first program page to erase */
198
    *(__IO uint32_t *)Page_Address1 = 0x00000000;
180
    *(__IO uint32_t *)Page_Address1 = 0x00000000U;
199
    /* Write 00000000h to the first word of the second program page to erase */    
181
    /* Write 00000000h to the first word of the second program page to erase */    
200
    *(__IO uint32_t *)Page_Address2 = 0x00000000;    
182
    *(__IO uint32_t *)Page_Address2 = 0x00000000U;
201
 
183
 
202
    /* Wait for last operation to be completed */
184
    /* Wait for last operation to be completed */
203
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
185
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
204
 
186
 
205
    /* If the erase operation is completed, disable the ERASE, PROG and PARALLBANK bits */
187
    /* If the erase operation is completed, disable the ERASE, PROG and PARALLBANK bits */
Line 239... Line 221...
239
  *         complete write operation is aborted. Software should then reset the
221
  *         complete write operation is aborted. Software should then reset the
240
  *         FPRG and PROG/DATA bits and restart the write operation from the
222
  *         FPRG and PROG/DATA bits and restart the write operation from the
241
  *         beginning.
223
  *         beginning.
242
  * @retval HAL status
224
  * @retval HAL status
243
  */
225
  */
244
__RAM_FUNC HAL_FLASHEx_ProgramParallelHalfPage(uint32_t Address1, uint32_t* pBuffer1, uint32_t Address2, uint32_t* pBuffer2)
226
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_ProgramParallelHalfPage(uint32_t Address1, uint32_t* pBuffer1, uint32_t Address2, uint32_t* pBuffer2)
245
{
227
{
-
 
228
  uint32_t primask_bit;
246
  uint32_t count = 0;
229
  uint32_t count = 0U;
247
  HAL_StatusTypeDef status = HAL_OK;
230
  HAL_StatusTypeDef status = HAL_OK;
248
 
231
 
249
  /* Set the DISMCYCINT[0] bit in the Auxillary Control Register (0xE000E008)
-
 
250
     This bit prevents the interruption of multicycle instructions and therefore
-
 
251
     will increase the interrupt latency. of Cortex-M3. */
-
 
252
  SET_BIT(SCnSCB->ACTLR, SCnSCB_ACTLR_DISMCYCINT_Msk);
-
 
253
 
-
 
254
  /* Wait for last operation to be completed */
232
  /* Wait for last operation to be completed */
255
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
233
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
256
 
234
 
257
  if(status == HAL_OK)
235
  if(status == HAL_OK)
258
  {
236
  {
-
 
237
    /* Disable all IRQs */
-
 
238
    primask_bit = __get_PRIMASK();
-
 
239
    __disable_irq();
-
 
240
   
259
    /* Proceed to program the new half page */
241
    /* Proceed to program the new half page */
260
    SET_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
242
    SET_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
261
    SET_BIT(FLASH->PECR, FLASH_PECR_FPRG);
243
    SET_BIT(FLASH->PECR, FLASH_PECR_FPRG);
262
    SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
244
    SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
263
 
245
 
264
    /* Wait for last operation to be completed */
246
    /* Write the first half page directly with 32 different words */
265
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
-
 
266
    if(status == HAL_OK)
247
    while(count < 32U)
267
    {
248
    {
268
      /* Disable all IRQs */
-
 
269
      __disable_irq();
-
 
270
 
-
 
271
      /* Write the first half page directly with 32 different words */
-
 
272
      while(count < 32)
-
 
273
      {
-
 
274
        *(__IO uint32_t*) ((uint32_t)(Address1 + (4 * count))) = *pBuffer1;
249
      *(__IO uint32_t*) ((uint32_t)(Address1 + (4 * count))) = *pBuffer1;
275
        pBuffer1++;
250
      pBuffer1++;
276
        count ++;  
-
 
277
      }
-
 
278
 
-
 
279
      /* Write the second half page directly with 32 different words */
-
 
280
      count = 0;
-
 
281
      while(count < 32)
-
 
282
      {
-
 
283
        *(__IO uint32_t*) ((uint32_t)(Address2 + (4 * count))) = *pBuffer2;
-
 
284
        pBuffer2++;
-
 
285
        count ++;  
251
      count ++;  
286
      }
-
 
287
 
-
 
288
      /* Enable IRQs */
-
 
289
      __enable_irq();
-
 
290
 
-
 
291
      /* Wait for last operation to be completed */
-
 
292
      status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
-
 
293
    }
252
    }
294
 
253
   
-
 
254
    /* Write the second half page directly with 32 different words */
-
 
255
    count = 0U;
-
 
256
    while(count < 32U)
-
 
257
    {
-
 
258
      *(__IO uint32_t*) ((uint32_t)(Address2 + (4 * count))) = *pBuffer2;
-
 
259
      pBuffer2++;
-
 
260
      count ++;  
-
 
261
    }
-
 
262
   
-
 
263
    /* Wait for last operation to be completed */
-
 
264
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
-
 
265
   
295
    /* if the write operation is completed, disable the PROG, FPRG and PARALLBANK bits */
266
    /* if the write operation is completed, disable the PROG, FPRG and PARALLBANK bits */
296
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_PROG);
267
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_PROG);
297
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_FPRG);
268
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_FPRG);
298
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
269
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_PARALLBANK);
-
 
270
 
-
 
271
    /* Enable IRQs */
-
 
272
    __set_PRIMASK(primask_bit);    
299
  }
273
  }
300
 
274
 
301
  CLEAR_BIT(SCnSCB->ACTLR, SCnSCB_ACTLR_DISMCYCINT_Msk);
-
 
302
   
-
 
303
  /* Return the Write Status */
275
  /* Return the Write Status */
304
  return status;
276
  return status;
305
}
277
}
306
#endif /* FLASH_PECR_PARALLBANK */
278
#endif /* FLASH_PECR_PARALLBANK */
307
 
279
 
308
/**
280
/**
309
  * @brief  Program a half page in program memory.
281
  * @brief  Program a half page in program memory.
310
  * @param  Address: specifies the address to be written.
282
  * @param  Address specifies the address to be written.
311
  * @param  pBuffer: pointer to the buffer  containing the data to be  written to
283
  * @param  pBuffer pointer to the buffer  containing the data to be  written to
312
  *         the half page.
284
  *         the half page.
313
  * @note   To correctly run this function, the @ref HAL_FLASH_Unlock() function
285
  * @note   To correctly run this function, the @ref HAL_FLASH_Unlock() function
314
  *         must be called before.
286
  *         must be called before.
315
  *         Call the @ref HAL_FLASH_Lock() to disable the flash memory access  
287
  *         Call the @ref HAL_FLASH_Lock() to disable the flash memory access  
316
  *         (recommended to protect the FLASH memory against possible unwanted operation)
288
  *         (recommended to protect the FLASH memory against possible unwanted operation)
Line 327... Line 299...
327
  *         complete write operation is aborted. Software should then reset the
299
  *         complete write operation is aborted. Software should then reset the
328
  *         FPRG and PROG/DATA bits and restart the write operation from the
300
  *         FPRG and PROG/DATA bits and restart the write operation from the
329
  *         beginning.
301
  *         beginning.
330
  * @retval HAL status
302
  * @retval HAL status
331
  */
303
  */
332
__RAM_FUNC HAL_FLASHEx_HalfPageProgram(uint32_t Address, uint32_t* pBuffer)
304
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_HalfPageProgram(uint32_t Address, uint32_t* pBuffer)
333
{
305
{
-
 
306
  uint32_t primask_bit;
334
  uint32_t count = 0;
307
  uint32_t count = 0U;
335
  HAL_StatusTypeDef status = HAL_OK;
308
  HAL_StatusTypeDef status = HAL_OK;
336
 
309
 
337
  /* Set the DISMCYCINT[0] bit in the Auxillary Control Register (0xE000E008)
-
 
338
     This bit prevents the interruption of multicycle instructions and therefore
-
 
339
     will increase the interrupt latency. of Cortex-M3. */
-
 
340
  SET_BIT(SCnSCB->ACTLR, SCnSCB_ACTLR_DISMCYCINT_Msk);
-
 
341
 
-
 
342
  /* Wait for last operation to be completed */
310
  /* Wait for last operation to be completed */
343
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
311
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
344
 
312
 
345
  if(status == HAL_OK)
313
  if(status == HAL_OK)
346
  {
314
  {
-
 
315
    /* Disable all IRQs */
-
 
316
    primask_bit = __get_PRIMASK();
-
 
317
    __disable_irq();
-
 
318
 
347
    /* Proceed to program the new half page */
319
    /* Proceed to program the new half page */
348
    SET_BIT(FLASH->PECR, FLASH_PECR_FPRG);
320
    SET_BIT(FLASH->PECR, FLASH_PECR_FPRG);
349
    SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
321
    SET_BIT(FLASH->PECR, FLASH_PECR_PROG);
350
   
322
   
351
    /* Disable all IRQs */
-
 
352
    __disable_irq();
-
 
353
 
-
 
354
    /* Write one half page directly with 32 different words */
323
    /* Write one half page directly with 32 different words */
355
    while(count < 32)
324
    while(count < 32U)
356
    {
325
    {
357
      *(__IO uint32_t*) ((uint32_t)(Address + (4 * count))) = *pBuffer;
326
      *(__IO uint32_t*) ((uint32_t)(Address + (4 * count))) = *pBuffer;
358
      pBuffer++;
327
      pBuffer++;
359
      count ++;  
328
      count ++;  
360
    }
329
    }
361
 
330
 
362
    /* Enable IRQs */
-
 
363
    __enable_irq();
-
 
364
 
-
 
365
    /* Wait for last operation to be completed */
331
    /* Wait for last operation to be completed */
366
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
332
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
367
 
333
 
368
    /* If the write operation is completed, disable the PROG and FPRG bits */
334
    /* If the write operation is completed, disable the PROG and FPRG bits */
369
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_PROG);
335
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_PROG);
370
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_FPRG);
336
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_FPRG);
371
  }
-
 
372
 
337
 
-
 
338
    /* Enable IRQs */
373
  CLEAR_BIT(SCnSCB->ACTLR, SCnSCB_ACTLR_DISMCYCINT_Msk);
339
    __set_PRIMASK(primask_bit);
-
 
340
  }
374
   
341
   
375
  /* Return the Write Status */
342
  /* Return the Write Status */
376
  return status;
343
  return status;
377
}
344
}
378
 
345
 
379
/**
346
/**
Line 424... Line 391...
424
  *            @arg @ref HAL_FLASH_ERROR_PGA     FLASH Programming Alignment error flag
391
  *            @arg @ref HAL_FLASH_ERROR_PGA     FLASH Programming Alignment error flag
425
  *            @arg @ref HAL_FLASH_ERROR_WRP     FLASH Write protected error flag
392
  *            @arg @ref HAL_FLASH_ERROR_WRP     FLASH Write protected error flag
426
  *            @arg @ref HAL_FLASH_ERROR_OPTV    FLASH Option valid error flag
393
  *            @arg @ref HAL_FLASH_ERROR_OPTV    FLASH Option valid error flag
427
  * @retval HAL Status
394
  * @retval HAL Status
428
  */
395
  */
429
__RAM_FUNC HAL_FLASHEx_GetError(uint32_t * Error)
396
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_GetError(uint32_t * Error)
430
{
397
{
431
  *Error = pFlash.ErrorCode;
398
  *Error = pFlash.ErrorCode;
432
  return HAL_OK;  
399
  return HAL_OK;  
433
}
400
}
434
 
401
 
Line 441... Line 408...
441
  * @{
408
  * @{
442
  */
409
  */
443
 
410
 
444
/**
411
/**
445
  * @brief  Erase a double word in data memory.
412
  * @brief  Erase a double word in data memory.
446
  * @param  Address: specifies the address to be erased.
413
  * @param  Address specifies the address to be erased.
447
  * @note   To correctly run this function, the HAL_FLASH_EEPROM_Unlock() function
414
  * @note   To correctly run this function, the HAL_FLASH_EEPROM_Unlock() function
448
  *         must be called before.
415
  *         must be called before.
449
  *         Call the HAL_FLASH_EEPROM_Lock() to he data EEPROM access
416
  *         Call the HAL_FLASH_EEPROM_Lock() to he data EEPROM access
450
  *         and Flash program erase control register access(recommended to protect
417
  *         and Flash program erase control register access(recommended to protect
451
  *         the DATA_EEPROM against possible unwanted operation).
418
  *         the DATA_EEPROM against possible unwanted operation).
Line 456... Line 423...
456
  *         forbidden (this includes DMA read operations and debugger read
423
  *         forbidden (this includes DMA read operations and debugger read
457
  *         operations such as breakpoints, periodic updates, etc.).
424
  *         operations such as breakpoints, periodic updates, etc.).
458
  * @retval HAL status
425
  * @retval HAL status
459
  */
426
  */
460
 
427
 
461
__RAM_FUNC HAL_FLASHEx_DATAEEPROM_EraseDoubleWord(uint32_t Address)
428
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_EraseDoubleWord(uint32_t Address)
462
{
429
{
-
 
430
  uint32_t primask_bit;
463
  HAL_StatusTypeDef status = HAL_OK;
431
  HAL_StatusTypeDef status = HAL_OK;
464
 
432
 
465
  /* Set the DISMCYCINT[0] bit in the Auxillary Control Register (0xE000E008)
-
 
466
     This bit prevents the interruption of multicycle instructions and therefore
-
 
467
     will increase the interrupt latency. of Cortex-M3. */
-
 
468
  SET_BIT(SCnSCB->ACTLR, SCnSCB_ACTLR_DISMCYCINT_Msk);
-
 
469
   
-
 
470
  /* Wait for last operation to be completed */
433
  /* Wait for last operation to be completed */
471
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
434
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
472
 
435
 
473
  if(status == HAL_OK)
436
  if(status == HAL_OK)
474
  {
437
  {
-
 
438
    /* Disable all IRQs */
-
 
439
    primask_bit = __get_PRIMASK();
-
 
440
    __disable_irq();
-
 
441
 
475
    /* If the previous operation is completed, proceed to erase the next double word */
442
    /* If the previous operation is completed, proceed to erase the next double word */
476
    /* Set the ERASE bit */
443
    /* Set the ERASE bit */
477
    SET_BIT(FLASH->PECR, FLASH_PECR_ERASE);
444
    SET_BIT(FLASH->PECR, FLASH_PECR_ERASE);
478
 
445
 
479
    /* Set DATA bit */
446
    /* Set DATA bit */
480
    SET_BIT(FLASH->PECR, FLASH_PECR_DATA);
447
    SET_BIT(FLASH->PECR, FLASH_PECR_DATA);
481
   
448
   
482
    /* Write 00000000h to the 2 words to erase */
449
    /* Write 00000000h to the 2 words to erase */
483
    *(__IO uint32_t *)Address = 0x00000000;
450
    *(__IO uint32_t *)Address = 0x00000000U;
484
    Address += 4;
451
    Address += 4U;
485
    *(__IO uint32_t *)Address = 0x00000000;
452
    *(__IO uint32_t *)Address = 0x00000000U;
486
   
453
   
487
    /* Wait for last operation to be completed */
454
    /* Wait for last operation to be completed */
488
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
455
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
489
   
456
   
490
    /* If the erase operation is completed, disable the ERASE and DATA bits */
457
    /* If the erase operation is completed, disable the ERASE and DATA bits */
491
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_ERASE);
458
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_ERASE);
492
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_DATA);
459
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_DATA);
-
 
460
 
-
 
461
    /* Enable IRQs */
-
 
462
    __set_PRIMASK(primask_bit);
-
 
463
 
493
  }  
464
  }  
494
 
-
 
495
  CLEAR_BIT(SCnSCB->ACTLR, SCnSCB_ACTLR_DISMCYCINT_Msk);
-
 
496
   
465
     
497
  /* Return the erase status */
466
  /* Return the erase status */
498
  return status;
467
  return status;
499
}
468
}
500
 
469
 
501
/**
470
/**
502
  * @brief  Write a double word in data memory without erase.
471
  * @brief  Write a double word in data memory without erase.
503
  * @param  Address: specifies the address to be written.
472
  * @param  Address specifies the address to be written.
504
  * @param  Data: specifies the data to be written.
473
  * @param  Data specifies the data to be written.
505
  * @note   To correctly run this function, the HAL_FLASH_EEPROM_Unlock() function
474
  * @note   To correctly run this function, the HAL_FLASH_EEPROM_Unlock() function
506
  *         must be called before.
475
  *         must be called before.
507
  *         Call the HAL_FLASH_EEPROM_Lock() to he data EEPROM access
476
  *         Call the HAL_FLASH_EEPROM_Lock() to he data EEPROM access
508
  *         and Flash program erase control register access(recommended to protect
477
  *         and Flash program erase control register access(recommended to protect
509
  *         the DATA_EEPROM against possible unwanted operation).
478
  *         the DATA_EEPROM against possible unwanted operation).
Line 514... Line 483...
514
  * @note   During the Data memory double word write, all read operations are
483
  * @note   During the Data memory double word write, all read operations are
515
  *         forbidden (this includes DMA read operations and debugger read
484
  *         forbidden (this includes DMA read operations and debugger read
516
  *         operations such as breakpoints, periodic updates, etc.).
485
  *         operations such as breakpoints, periodic updates, etc.).
517
  * @retval HAL status
486
  * @retval HAL status
518
  */
487
  */
519
__RAM_FUNC HAL_FLASHEx_DATAEEPROM_ProgramDoubleWord(uint32_t Address, uint64_t Data)
488
__RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_ProgramDoubleWord(uint32_t Address, uint64_t Data)
520
{
489
{
-
 
490
  uint32_t primask_bit;
521
  HAL_StatusTypeDef status = HAL_OK;
491
  HAL_StatusTypeDef status = HAL_OK;
522
 
492
 
523
  /* Set the DISMCYCINT[0] bit in the Auxillary Control Register (0xE000E008)
-
 
524
     This bit prevents the interruption of multicycle instructions and therefore
-
 
525
     will increase the interrupt latency. of Cortex-M3. */
-
 
526
  SET_BIT(SCnSCB->ACTLR, SCnSCB_ACTLR_DISMCYCINT_Msk);
-
 
527
   
-
 
528
  /* Wait for last operation to be completed */
493
  /* Wait for last operation to be completed */
529
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
494
  status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
530
 
495
 
531
  if(status == HAL_OK)
496
  if(status == HAL_OK)
532
  {
497
  {
-
 
498
    /* Disable all IRQs */
-
 
499
    primask_bit = __get_PRIMASK();
-
 
500
    __disable_irq();
-
 
501
 
533
    /* If the previous operation is completed, proceed to program the new data*/
502
    /* If the previous operation is completed, proceed to program the new data*/
534
    SET_BIT(FLASH->PECR, FLASH_PECR_FPRG);
503
    SET_BIT(FLASH->PECR, FLASH_PECR_FPRG);
535
    SET_BIT(FLASH->PECR, FLASH_PECR_DATA);
504
    SET_BIT(FLASH->PECR, FLASH_PECR_DATA);
536
   
505
   
537
    /* Write the 2 words */  
506
    /* Write the 2 words */  
538
     *(__IO uint32_t *)Address = (uint32_t) Data;
507
     *(__IO uint32_t *)Address = (uint32_t) Data;
539
     Address += 4;
508
     Address += 4U;
540
     *(__IO uint32_t *)Address = (uint32_t) (Data >> 32);
509
     *(__IO uint32_t *)Address = (uint32_t) (Data >> 32);
541
   
510
     
542
    /* Wait for last operation to be completed */
511
    /* Wait for last operation to be completed */
543
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
512
    status = FLASHRAM_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
544
   
513
   
545
    /* If the write operation is completed, disable the FPRG and DATA bits */
514
    /* If the write operation is completed, disable the FPRG and DATA bits */
546
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_FPRG);
515
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_FPRG);
547
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_DATA);    
516
    CLEAR_BIT(FLASH->PECR, FLASH_PECR_DATA);    
-
 
517
 
-
 
518
    /* Enable IRQs */
-
 
519
    __set_PRIMASK(primask_bit);
548
  }
520
  }
549
 
-
 
550
  CLEAR_BIT(SCnSCB->ACTLR, SCnSCB_ACTLR_DISMCYCINT_Msk);
-
 
551
   
521
     
552
  /* Return the Write Status */
522
  /* Return the Write Status */
553
  return status;
523
  return status;
554
}
524
}
555
 
525
 
556
/**
526
/**
Line 567... Line 537...
567
 
537
 
568
/**
538
/**
569
  * @brief  Set the specific FLASH error flag.
539
  * @brief  Set the specific FLASH error flag.
570
  * @retval HAL Status
540
  * @retval HAL Status
571
  */
541
  */
572
static __RAM_FUNC FLASHRAM_SetErrorCode(void)
542
static __RAM_FUNC HAL_StatusTypeDef FLASHRAM_SetErrorCode(void)
573
{
543
{
574
  uint32_t flags = 0;
544
  uint32_t flags = 0U;
575
 
545
 
576
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR))
546
  if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR))
577
  {
547
  {
578
    pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
548
    pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
579
    flags |= FLASH_FLAG_WRPERR;
549
    flags |= FLASH_FLAG_WRPERR;
Line 610... Line 580...
610
  return HAL_OK;
580
  return HAL_OK;
611
}  
581
}  
612
 
582
 
613
/**
583
/**
614
  * @brief  Wait for a FLASH operation to complete.
584
  * @brief  Wait for a FLASH operation to complete.
615
  * @param  Timeout: maximum flash operationtimeout
585
  * @param  Timeout maximum flash operationtimeout
616
  * @retval HAL status
586
  * @retval HAL status
617
  */
587
  */
618
static __RAM_FUNC  FLASHRAM_WaitForLastOperation(uint32_t Timeout)
588
static __RAM_FUNC HAL_StatusTypeDef FLASHRAM_WaitForLastOperation(uint32_t Timeout)
619
{
589
{
620
    /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
590
    /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
621
       Even if the FLASH operation fails, the BUSY flag will be reset and an error
591
       Even if the FLASH operation fails, the BUSY flag will be reset and an error
622
       flag will be set */
592
       flag will be set */
623
       
593
       
624
    while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) && (Timeout != 0x00))
594
    while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) && (Timeout != 0x00U))
625
    {
595
    {
626
      Timeout--;
596
      Timeout--;
627
    }
597
    }
628
   
598
   
629
    if(Timeout == 0x00 )
599
    if(Timeout == 0x00U)
630
    {
600
    {
631
      return HAL_TIMEOUT;
601
      return HAL_TIMEOUT;
632
    }
602
    }
633
   
603
   
634
  /* Check FLASH End of Operation flag  */
604
  /* Check FLASH End of Operation flag  */