Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 5 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | ****************************************************************************** |
2 | ****************************************************************************** |
3 | * @file stm32f1xx_hal_flash_ex.c |
3 | * @file stm32f1xx_hal_flash_ex.c |
4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
5 | * @version V1.0.1 |
5 | * @version V1.0.4 |
6 | * @date 31-July-2015 |
6 | * @date 29-April-2016 |
7 | * @brief Extended FLASH HAL module driver. |
7 | * @brief Extended FLASH HAL module driver. |
8 | * |
8 | * |
9 | * This file provides firmware functions to manage the following |
9 | * This file provides firmware functions to manage the following |
10 | * functionalities of the FLASH peripheral: |
10 | * functionalities of the FLASH peripheral: |
11 | * + Extended Initialization/de-initialization functions |
11 | * + Extended Initialization/de-initialization functions |
Line 28... | Line 28... | ||
28 | |
28 | |
29 | @endverbatim |
29 | @endverbatim |
30 | ****************************************************************************** |
30 | ****************************************************************************** |
31 | * @attention |
31 | * @attention |
32 | * |
32 | * |
33 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
33 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
34 | * |
34 | * |
35 | * Redistribution and use in source and binary forms, with or without modification, |
35 | * Redistribution and use in source and binary forms, with or without modification, |
36 | * are permitted provided that the following conditions are met: |
36 | * are permitted provided that the following conditions are met: |
37 | * 1. Redistributions of source code must retain the above copyright notice, |
37 | * 1. Redistributions of source code must retain the above copyright notice, |
38 | * this list of conditions and the following disclaimer. |
38 | * this list of conditions and the following disclaimer. |
Line 80... | Line 80... | ||
80 | /** |
80 | /** |
81 | * @} |
81 | * @} |
82 | */ |
82 | */ |
83 | 83 | ||
84 | /** @defgroup FLASHEx FLASHEx |
84 | /** @defgroup FLASHEx FLASHEx |
85 | * @brief FLASH Extended HAL module driver |
85 | * @brief FLASH HAL Extension module driver |
86 | * @{ |
86 | * @{ |
87 | */ |
87 | */ |
88 | 88 | ||
89 | /* Private typedef -----------------------------------------------------------*/ |
89 | /* Private typedef -----------------------------------------------------------*/ |
90 | /* Private define ------------------------------------------------------------*/ |
90 | /* Private define ------------------------------------------------------------*/ |
91 | /** @defgroup FLASHEx_Private_Constants FLASHEx Private Constants |
91 | /** @defgroup FLASHEx_Private_Constants FLASHEx Private Constants |
92 | * @{ |
92 | * @{ |
93 | */ |
93 | */ |
94 | #define FLASH_POSITION_IWDGSW_BIT (uint32_t)POSITION_VAL(FLASH_OBR_IWDG_SW) |
94 | #define FLASH_POSITION_IWDGSW_BIT (uint32_t)POSITION_VAL(FLASH_OBR_IWDG_SW) |
- | 95 | #define FLASH_POSITION_OB_USERDATA0_BIT (uint32_t)POSITION_VAL(FLASH_OBR_DATA0) |
|
- | 96 | #define FLASH_POSITION_OB_USERDATA1_BIT (uint32_t)POSITION_VAL(FLASH_OBR_DATA1) |
|
95 | /** |
97 | /** |
96 | * @} |
98 | * @} |
97 | */ |
99 | */ |
98 | 100 | ||
99 | /* Private macro -------------------------------------------------------------*/ |
101 | /* Private macro -------------------------------------------------------------*/ |
Line 129... | Line 131... | ||
129 | /* Exported functions ---------------------------------------------------------*/ |
131 | /* Exported functions ---------------------------------------------------------*/ |
130 | /** @defgroup FLASHEx_Exported_Functions FLASHEx Exported Functions |
132 | /** @defgroup FLASHEx_Exported_Functions FLASHEx Exported Functions |
131 | * @{ |
133 | * @{ |
132 | */ |
134 | */ |
133 | 135 | ||
134 | /** @defgroup FLASHEx_Exported_Functions_Group1 Extended Input and Output operation functions |
136 | /** @defgroup FLASHEx_Exported_Functions_Group1 FLASHEx Memory Erasing functions |
135 | * @brief I/O operation functions |
137 | * @brief FLASH Memory Erasing functions |
136 | * |
138 | * |
137 | @verbatim |
139 | @verbatim |
138 | =============================================================================== |
140 | ============================================================================== |
139 | ##### IO operation functions ##### |
141 | ##### FLASH Erasing Programming functions ##### |
140 | =============================================================================== |
142 | ============================================================================== |
- | 143 | ||
- | 144 | [..] The FLASH Memory Erasing functions, includes the following functions: |
|
- | 145 | (+) @ref HAL_FLASHEx_Erase: return only when erase has been done |
|
- | 146 | (+) @ref HAL_FLASHEx_Erase_IT: end of erase is done when @ref HAL_FLASH_EndOfOperationCallback |
|
- | 147 | is called with parameter 0xFFFFFFFF |
|
- | 148 | ||
- | 149 | [..] Any operation of erase should follow these steps: |
|
- | 150 | (#) Call the @ref HAL_FLASH_Unlock() function to enable the flash control register and |
|
- | 151 | program memory access. |
|
- | 152 | (#) Call the desired function to erase page. |
|
- | 153 | (#) Call the @ref HAL_FLASH_Lock() to disable the flash program memory access |
|
- | 154 | (recommended to protect the FLASH memory against possible unwanted operation). |
|
141 | 155 | ||
142 | @endverbatim |
156 | @endverbatim |
143 | * @{ |
157 | * @{ |
144 | */ |
158 | */ |
145 | 159 | ||
146 | 160 | ||
147 | /** |
161 | /** |
148 | * @brief Perform a mass erase or erase the specified FLASH memory pages |
162 | * @brief Perform a mass erase or erase the specified FLASH memory pages |
149 | * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
163 | * @note To correctly run this function, the @ref HAL_FLASH_Unlock() function |
- | 164 | * must be called before. |
|
150 | * The function HAL_FLASH_Lock() should be called after to lock the FLASH interface |
165 | * Call the @ref HAL_FLASH_Lock() to disable the flash memory access |
- | 166 | * (recommended to protect the FLASH memory against possible unwanted operation) |
|
151 | * @param[in] pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that |
167 | * @param[in] pEraseInit pointer to an FLASH_EraseInitTypeDef structure that |
152 | * contains the configuration information for the erasing. |
168 | * contains the configuration information for the erasing. |
153 | * |
169 | * |
154 | * @param[out] PageError: pointer to variable that |
170 | * @param[out] PageError pointer to variable that |
155 | * contains the configuration information on faulty page in case of error |
171 | * contains the configuration information on faulty page in case of error |
156 | * (0xFFFFFFFF means that all the pages have been correctly erased) |
172 | * (0xFFFFFFFF means that all the pages have been correctly erased) |
157 | * |
173 | * |
158 | * @retval HAL_StatusTypeDef HAL Status |
174 | * @retval HAL_StatusTypeDef HAL Status |
159 | */ |
175 | */ |
Line 266... | Line 282... | ||
266 | } |
282 | } |
267 | } |
283 | } |
268 | } |
284 | } |
269 | else |
285 | else |
270 | #endif /* FLASH_BANK2_END */ |
286 | #endif /* FLASH_BANK2_END */ |
271 | { |
287 | { |
272 | /* Page Erase requested on address located on bank1 */ |
288 | /* Page Erase requested on address located on bank1 */ |
273 | /* Wait for last operation to be completed */ |
289 | /* Wait for last operation to be completed */ |
274 | if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) |
290 | if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) |
275 | { |
291 | { |
276 | /*Initialization of PageError variable*/ |
292 | /*Initialization of PageError variable*/ |
277 | *PageError = 0xFFFFFFFF; |
293 | *PageError = 0xFFFFFFFF; |
278 | 294 | ||
279 | /* Erase by page by page to be done*/ |
295 | /* Erase page by page to be done*/ |
280 | for(address = pEraseInit->PageAddress; |
296 | for(address = pEraseInit->PageAddress; |
281 | address < (pEraseInit->PageAddress + (pEraseInit->NbPages)*FLASH_PAGE_SIZE); |
297 | address < ((pEraseInit->NbPages * FLASH_PAGE_SIZE) + pEraseInit->PageAddress); |
282 | address += FLASH_PAGE_SIZE) |
298 | address += FLASH_PAGE_SIZE) |
283 | { |
299 | { |
284 | FLASH_PageErase(address); |
300 | FLASH_PageErase(address); |
285 | 301 | ||
286 | /* Wait for last operation to be completed */ |
302 | /* Wait for last operation to be completed */ |
Line 305... | Line 321... | ||
305 | 321 | ||
306 | return status; |
322 | return status; |
307 | } |
323 | } |
308 | 324 | ||
309 | /** |
325 | /** |
310 | * @brief Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled |
326 | * @brief Perform a mass erase or erase the specified FLASH memory pages with interrupt enabled |
311 | * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
327 | * @note To correctly run this function, the @ref HAL_FLASH_Unlock() function |
- | 328 | * must be called before. |
|
312 | * The function HAL_FLASH_Lock() should be called after to lock the FLASH interface |
329 | * Call the @ref HAL_FLASH_Lock() to disable the flash memory access |
- | 330 | * (recommended to protect the FLASH memory against possible unwanted operation) |
|
313 | * @param pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that |
331 | * @param pEraseInit pointer to an FLASH_EraseInitTypeDef structure that |
314 | * contains the configuration information for the erasing. |
332 | * contains the configuration information for the erasing. |
315 | * |
333 | * |
316 | * @retval HAL_StatusTypeDef HAL Status |
334 | * @retval HAL_StatusTypeDef HAL Status |
317 | */ |
335 | */ |
318 | HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) |
336 | HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) |
Line 365... | Line 383... | ||
365 | } |
383 | } |
366 | 384 | ||
367 | /** |
385 | /** |
368 | * @} |
386 | * @} |
369 | */ |
387 | */ |
370 | 388 | ||
371 | /** @defgroup FLASHEx_Exported_Functions_Group2 Extended Peripheral Control functions |
389 | /** @defgroup FLASHEx_Exported_Functions_Group2 Option Bytes Programming functions |
372 | * @brief Peripheral Control functions |
390 | * @brief Option Bytes Programming functions |
373 | * |
391 | * |
374 | @verbatim |
392 | @verbatim |
375 | =============================================================================== |
393 | ============================================================================== |
376 | ##### Peripheral Control functions ##### |
394 | ##### Option Bytes Programming functions ##### |
377 | =============================================================================== |
395 | ============================================================================== |
378 | [..] |
396 | [..] |
379 | This subsection provides a set of functions allowing to control the FLASH |
397 | This subsection provides a set of functions allowing to control the FLASH |
380 | memory operations. |
398 | option bytes operations. |
381 | 399 | ||
382 | @endverbatim |
400 | @endverbatim |
383 | * @{ |
401 | * @{ |
384 | */ |
402 | */ |
385 | 403 | ||
386 | /** |
404 | /** |
387 | * @brief Erases the FLASH option bytes. |
405 | * @brief Erases the FLASH option bytes. |
388 | * @note This functions erases all option bytes except the Read protection (RDP). |
406 | * @note This functions erases all option bytes except the Read protection (RDP). |
389 | * The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
407 | * The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
390 | * The function HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes |
408 | * The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes |
391 | * The function HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes |
409 | * The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes |
392 | * (system reset will occur) |
410 | * (system reset will occur) |
393 | * @retval HAL status |
411 | * @retval HAL status |
394 | */ |
412 | */ |
395 | 413 | ||
396 | HAL_StatusTypeDef HAL_FLASHEx_OBErase(void) |
414 | HAL_StatusTypeDef HAL_FLASHEx_OBErase(void) |
Line 430... | Line 448... | ||
430 | return status; |
448 | return status; |
431 | } |
449 | } |
432 | 450 | ||
433 | /** |
451 | /** |
434 | * @brief Program option bytes |
452 | * @brief Program option bytes |
435 | * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
453 | * @note The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
436 | * The function HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes |
454 | * The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes |
437 | * The function HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes |
455 | * The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes |
438 | * (system reset will occur) |
456 | * (system reset will occur) |
439 | * |
457 | * |
440 | * @param pOBInit: pointer to an FLASH_OBInitStruct structure that |
458 | * @param pOBInit pointer to an FLASH_OBInitStruct structure that |
441 | * contains the configuration information for the programming. |
459 | * contains the configuration information for the programming. |
442 | * |
460 | * |
443 | * @retval HAL_StatusTypeDef HAL Status |
461 | * @retval HAL_StatusTypeDef HAL Status |
444 | */ |
462 | */ |
445 | HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit) |
463 | HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit) |
446 | { |
464 | { |
447 | HAL_StatusTypeDef status = HAL_ERROR; |
465 | HAL_StatusTypeDef status = HAL_ERROR; |
448 | 466 | ||
- | 467 | /* Process Locked */ |
|
- | 468 | __HAL_LOCK(&pFlash); |
|
- | 469 | ||
449 | /* Check the parameters */ |
470 | /* Check the parameters */ |
450 | assert_param(IS_OPTIONBYTE(pOBInit->OptionType)); |
471 | assert_param(IS_OPTIONBYTE(pOBInit->OptionType)); |
451 | 472 | ||
452 | /* Write protection configuration */ |
473 | /* Write protection configuration */ |
453 | if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP) |
474 | if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP) |
Line 461... | Line 482... | ||
461 | else |
482 | else |
462 | { |
483 | { |
463 | /* Disable of Write protection on the selected page */ |
484 | /* Disable of Write protection on the selected page */ |
464 | status = FLASH_OB_DisableWRP(pOBInit->WRPPage); |
485 | status = FLASH_OB_DisableWRP(pOBInit->WRPPage); |
465 | } |
486 | } |
- | 487 | if (status != HAL_OK) |
|
- | 488 | { |
|
- | 489 | /* Process Unlocked */ |
|
- | 490 | __HAL_UNLOCK(&pFlash); |
|
- | 491 | return status; |
|
- | 492 | } |
|
466 | } |
493 | } |
467 | 494 | ||
468 | /* Read protection configuration */ |
495 | /* Read protection configuration */ |
469 | if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP) |
496 | if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP) |
470 | { |
497 | { |
471 | status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel); |
498 | status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel); |
- | 499 | if (status != HAL_OK) |
|
- | 500 | { |
|
- | 501 | /* Process Unlocked */ |
|
- | 502 | __HAL_UNLOCK(&pFlash); |
|
- | 503 | return status; |
|
- | 504 | } |
|
472 | } |
505 | } |
473 | 506 | ||
474 | /* USER configuration */ |
507 | /* USER configuration */ |
475 | if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER) |
508 | if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER) |
476 | { |
509 | { |
477 | status = FLASH_OB_UserConfig(pOBInit->USERConfig); |
510 | status = FLASH_OB_UserConfig(pOBInit->USERConfig); |
- | 511 | if (status != HAL_OK) |
|
- | 512 | { |
|
- | 513 | /* Process Unlocked */ |
|
- | 514 | __HAL_UNLOCK(&pFlash); |
|
- | 515 | return status; |
|
- | 516 | } |
|
478 | } |
517 | } |
479 | 518 | ||
480 | /* DATA configuration*/ |
519 | /* DATA configuration*/ |
481 | if((pOBInit->OptionType & OPTIONBYTE_DATA) == OPTIONBYTE_DATA) |
520 | if((pOBInit->OptionType & OPTIONBYTE_DATA) == OPTIONBYTE_DATA) |
482 | { |
521 | { |
483 | status = FLASH_OB_ProgramData(pOBInit->DATAAddress, pOBInit->DATAData); |
522 | status = FLASH_OB_ProgramData(pOBInit->DATAAddress, pOBInit->DATAData); |
- | 523 | if (status != HAL_OK) |
|
- | 524 | { |
|
- | 525 | /* Process Unlocked */ |
|
- | 526 | __HAL_UNLOCK(&pFlash); |
|
- | 527 | return status; |
|
- | 528 | } |
|
484 | } |
529 | } |
485 | 530 | ||
- | 531 | /* Process Unlocked */ |
|
- | 532 | __HAL_UNLOCK(&pFlash); |
|
- | 533 | ||
486 | return status; |
534 | return status; |
487 | } |
535 | } |
488 | 536 | ||
489 | /** |
537 | /** |
490 | * @brief Get the Option byte configuration |
538 | * @brief Get the Option byte configuration |
491 | * @param pOBInit: pointer to an FLASH_OBInitStruct structure that |
539 | * @param pOBInit pointer to an FLASH_OBInitStruct structure that |
492 | * contains the configuration information for the programming. |
540 | * contains the configuration information for the programming. |
493 | * |
541 | * |
494 | * @retval None |
542 | * @retval None |
495 | */ |
543 | */ |
496 | void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) |
544 | void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) |
Line 506... | Line 554... | ||
506 | /*Get USER*/ |
554 | /*Get USER*/ |
507 | pOBInit->USERConfig = FLASH_OB_GetUser(); |
555 | pOBInit->USERConfig = FLASH_OB_GetUser(); |
508 | } |
556 | } |
509 | 557 | ||
510 | /** |
558 | /** |
- | 559 | * @brief Get the Option byte user data |
|
- | 560 | * @param DATAAdress Address of the option byte DATA |
|
- | 561 | * This parameter can be one of the following values: |
|
- | 562 | * @arg @ref OB_DATA_ADDRESS_DATA0 |
|
- | 563 | * @arg @ref OB_DATA_ADDRESS_DATA1 |
|
- | 564 | * @retval Value programmed in USER data |
|
- | 565 | */ |
|
- | 566 | uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress) |
|
- | 567 | { |
|
- | 568 | uint32_t value = 0; |
|
- | 569 | ||
- | 570 | if (DATAAdress == OB_DATA_ADDRESS_DATA0) |
|
- | 571 | { |
|
- | 572 | /* Get value programmed in OB USER Data0 */ |
|
- | 573 | value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA0) >> FLASH_POSITION_OB_USERDATA0_BIT; |
|
- | 574 | } |
|
- | 575 | else |
|
- | 576 | { |
|
- | 577 | /* Get value programmed in OB USER Data1 */ |
|
- | 578 | value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA1) >> FLASH_POSITION_OB_USERDATA1_BIT; |
|
- | 579 | } |
|
- | 580 | ||
- | 581 | return value; |
|
- | 582 | } |
|
- | 583 | ||
- | 584 | /** |
|
511 | * @} |
585 | * @} |
512 | */ |
586 | */ |
513 | 587 | ||
514 | /** |
588 | /** |
515 | * @} |
589 | * @} |
Line 519... | Line 593... | ||
519 | * @{ |
593 | * @{ |
520 | */ |
594 | */ |
521 | 595 | ||
522 | /** |
596 | /** |
523 | * @brief Full erase of FLASH memory Bank |
597 | * @brief Full erase of FLASH memory Bank |
524 | * @param Banks: Banks to be erased |
598 | * @param Banks Banks to be erased |
525 | * This parameter can be one of the following values: |
599 | * This parameter can be one of the following values: |
526 | * @arg FLASH_BANK_1: Bank1 to be erased |
600 | * @arg @ref FLASH_BANK_1 Bank1 to be erased |
- | 601 | @if STM32F101xG |
|
- | 602 | * @arg @ref FLASH_BANK_2 Bank2 to be erased |
|
- | 603 | * @arg @ref FLASH_BANK_BOTH Bank1 and Bank2 to be erased |
|
- | 604 | @endif |
|
- | 605 | @if STM32F103xG |
|
527 | * @arg FLASH_BANK_2: Bank2 to be erased |
606 | * @arg @ref FLASH_BANK_2 Bank2 to be erased |
528 | * @arg FLASH_BANK_BOTH: Bank1 and Bank2 to be erased |
607 | * @arg @ref FLASH_BANK_BOTH Bank1 and Bank2 to be erased |
- | 608 | @endif |
|
529 | * |
609 | * |
530 | * @retval None |
610 | * @retval None |
531 | */ |
611 | */ |
532 | static void FLASH_MassErase(uint32_t Banks) |
612 | static void FLASH_MassErase(uint32_t Banks) |
533 | { |
613 | { |
Line 568... | Line 648... | ||
568 | * @note An option byte erase is done automatically in this function. |
648 | * @note An option byte erase is done automatically in this function. |
569 | * @note When the memory read protection level is selected (RDP level = 1), |
649 | * @note When the memory read protection level is selected (RDP level = 1), |
570 | * it is not possible to program or erase the flash page i if |
650 | * it is not possible to program or erase the flash page i if |
571 | * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
651 | * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
572 | * |
652 | * |
573 | * @param WriteProtectPage: specifies the page(s) to be write protected. |
653 | * @param WriteProtectPage specifies the page(s) to be write protected. |
574 | * The value of this parameter depend on device used within the same series |
654 | * The value of this parameter depend on device used within the same series |
575 | * @retval HAL status |
655 | * @retval HAL status |
576 | */ |
656 | */ |
577 | static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage) |
657 | static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage) |
578 | { |
658 | { |
Line 691... | Line 771... | ||
691 | * @note An option byte erase is done automatically in this function. |
771 | * @note An option byte erase is done automatically in this function. |
692 | * @note When the memory read protection level is selected (RDP level = 1), |
772 | * @note When the memory read protection level is selected (RDP level = 1), |
693 | * it is not possible to program or erase the flash page i if |
773 | * it is not possible to program or erase the flash page i if |
694 | * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
774 | * debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
695 | * |
775 | * |
696 | * @param WriteProtectPage: specifies the page(s) to be write unprotected. |
776 | * @param WriteProtectPage specifies the page(s) to be write unprotected. |
697 | * The value of this parameter depend on device used within the same series |
777 | * The value of this parameter depend on device used within the same series |
698 | * @retval HAL status |
778 | * @retval HAL status |
699 | */ |
779 | */ |
700 | static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage) |
780 | static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage) |
701 | { |
781 | { |
Line 808... | Line 888... | ||
808 | return status; |
888 | return status; |
809 | } |
889 | } |
810 | 890 | ||
811 | /** |
891 | /** |
812 | * @brief Set the read protection level. |
892 | * @brief Set the read protection level. |
813 | * @param ReadProtectLevel: specifies the read protection level. |
893 | * @param ReadProtectLevel specifies the read protection level. |
814 | * This parameter can be one of the following values: |
894 | * This parameter can be one of the following values: |
815 | * @arg OB_RDP_LEVEL_0: No protection |
895 | * @arg @ref OB_RDP_LEVEL_0 No protection |
816 | * @arg OB_RDP_LEVEL_1: Read protection of the memory |
896 | * @arg @ref OB_RDP_LEVEL_1 Read protection of the memory |
817 | * @retval HAL status |
897 | * @retval HAL status |
818 | */ |
898 | */ |
819 | static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel) |
899 | static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel) |
820 | { |
900 | { |
821 | HAL_StatusTypeDef status = HAL_OK; |
901 | HAL_StatusTypeDef status = HAL_OK; |
Line 860... | Line 940... | ||
860 | } |
940 | } |
861 | 941 | ||
862 | /** |
942 | /** |
863 | * @brief Program the FLASH User Option Byte. |
943 | * @brief Program the FLASH User Option Byte. |
864 | * @note Programming of the OB should be performed only after an erase (otherwise PGERR occurs) |
944 | * @note Programming of the OB should be performed only after an erase (otherwise PGERR occurs) |
865 | * @param UserConfig: The FLASH User Option Bytes values: FLASH_OBR_IWDG_SW(Bit2), |
945 | * @param UserConfig The FLASH User Option Bytes values FLASH_OBR_IWDG_SW(Bit2), |
866 | * FLASH_OBR_nRST_STOP(Bit3),FLASH_OBR_nRST_STDBY(Bit4). |
946 | * FLASH_OBR_nRST_STOP(Bit3),FLASH_OBR_nRST_STDBY(Bit4). |
867 | * And BFBF2(Bit5) for STM32F101xG and STM32F103xG . |
947 | * And BFBF2(Bit5) for STM32F101xG and STM32F103xG . |
868 | * @retval HAL status |
948 | * @retval HAL status |
869 | */ |
949 | */ |
870 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig) |
950 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig) |
Line 906... | Line 986... | ||
906 | return status; |
986 | return status; |
907 | } |
987 | } |
908 | 988 | ||
909 | /** |
989 | /** |
910 | * @brief Programs a half word at a specified Option Byte Data address. |
990 | * @brief Programs a half word at a specified Option Byte Data address. |
911 | * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
991 | * @note The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
912 | * The function HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes |
992 | * The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes |
913 | * The function HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes |
993 | * The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes |
914 | * (system reset will occur) |
994 | * (system reset will occur) |
915 | * Programming of the OB should be performed only after an erase (otherwise PGERR occurs) |
995 | * Programming of the OB should be performed only after an erase (otherwise PGERR occurs) |
916 | * @param Address: specifies the address to be programmed. |
996 | * @param Address specifies the address to be programmed. |
917 | * This parameter can be 0x1FFFF804 or 0x1FFFF806. |
997 | * This parameter can be 0x1FFFF804 or 0x1FFFF806. |
918 | * @param Data: specifies the data to be programmed. |
998 | * @param Data specifies the data to be programmed. |
919 | * @retval HAL status |
999 | * @retval HAL status |
920 | */ |
1000 | */ |
921 | static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data) |
1001 | static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data) |
922 | { |
1002 | { |
923 | HAL_StatusTypeDef status = HAL_ERROR; |
1003 | HAL_StatusTypeDef status = HAL_ERROR; |
Line 959... | Line 1039... | ||
959 | 1039 | ||
960 | /** |
1040 | /** |
961 | * @brief Returns the FLASH Read Protection level. |
1041 | * @brief Returns the FLASH Read Protection level. |
962 | * @retval FLASH ReadOut Protection Status: |
1042 | * @retval FLASH ReadOut Protection Status: |
963 | * This parameter can be one of the following values: |
1043 | * This parameter can be one of the following values: |
964 | * @arg OB_RDP_LEVEL_0: No protection |
1044 | * @arg @ref OB_RDP_LEVEL_0 No protection |
965 | * @arg OB_RDP_LEVEL_1: Read protection of the memory |
1045 | * @arg @ref OB_RDP_LEVEL_1 Read protection of the memory |
966 | */ |
1046 | */ |
967 | static uint32_t FLASH_OB_GetRDP(void) |
1047 | static uint32_t FLASH_OB_GetRDP(void) |
968 | { |
1048 | { |
969 | uint32_t readstatus = OB_RDP_LEVEL_0; |
1049 | uint32_t readstatus = OB_RDP_LEVEL_0; |
970 | uint32_t tmp_reg = 0; |
1050 | uint32_t tmp_reg = 0; |
Line 1006... | Line 1086... | ||
1006 | 1086 | ||
1007 | /** @addtogroup FLASH |
1087 | /** @addtogroup FLASH |
1008 | * @{ |
1088 | * @{ |
1009 | */ |
1089 | */ |
1010 | 1090 | ||
1011 | - | ||
1012 | /** @addtogroup FLASH_Private_Functions |
1091 | /** @addtogroup FLASH_Private_Functions |
1013 | * @{ |
1092 | * @{ |
1014 | */ |
1093 | */ |
1015 | 1094 | ||
1016 | /** |
1095 | /** |
1017 | * @brief Erase the specified FLASH memory page |
1096 | * @brief Erase the specified FLASH memory page |
1018 | * @param PageAddress: FLASH page to erase |
1097 | * @param PageAddress FLASH page to erase |
1019 | * The value of this parameter depend on device used within the same series |
1098 | * The value of this parameter depend on device used within the same series |
1020 | * |
1099 | * |
1021 | * @retval None |
1100 | * @retval None |
1022 | */ |
1101 | */ |
1023 | void FLASH_PageErase(uint32_t PageAddress) |
1102 | void FLASH_PageErase(uint32_t PageAddress) |
Line 1047... | Line 1126... | ||
1047 | 1126 | ||
1048 | /** |
1127 | /** |
1049 | * @} |
1128 | * @} |
1050 | */ |
1129 | */ |
1051 | 1130 | ||
1052 | /** |
- | |
1053 | * @} |
- | |
1054 | */ |
- | |
1055 | - | ||
1056 | /** |
1131 | /** |
1057 | * @} |
1132 | * @} |
1058 | */ |
1133 | */ |
1059 | 1134 | ||
1060 | #endif /* HAL_FLASH_MODULE_ENABLED */ |
1135 | #endif /* HAL_FLASH_MODULE_ENABLED */ |