You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

735 lines
22 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32wbxx_hal_flash.c
  4. * @author MCD Application Team
  5. * @brief FLASH HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the internal FLASH memory:
  8. * + Program operations functions
  9. * + Memory Control functions
  10. * + Peripheral Errors functions
  11. *
  12. @verbatim
  13. ==============================================================================
  14. ##### FLASH peripheral features #####
  15. ==============================================================================
  16. [..] The Flash memory interface manages CPU AHB I-Code and D-Code accesses
  17. to the Flash memory. It implements the erase and program Flash memory operations
  18. and the read and write protection mechanisms.
  19. [..] The Flash memory interface accelerates code execution with a system of instruction
  20. prefetch and cache lines.
  21. [..] The FLASH main features are:
  22. (+) Flash memory read operations
  23. (+) Flash memory program/erase operations
  24. (+) Program and Erase suspension
  25. (+) Read / write protections (2 areas per features)
  26. (+) CPU2 Security area
  27. (+) Option bytes programming
  28. (+) Prefetch on CPU1 I-Code and CPU2 S-bus
  29. (+) 32 instruction cache lines of 4*64 bits on I-Code for CPU1
  30. (+) 8 data cache lines of 4*64 bits on D-Code for CPU1
  31. (+) 4 instruction cache lines of 1*64 bits on S-bus for CPU2
  32. (+) 4 data cache lines of 1*64 bits on S-Bus for CPU2
  33. (+) Error code correction (ECC) : Data in flash are 72-bits word
  34. (8 bits added per double word)
  35. ##### How to use this driver #####
  36. ==============================================================================
  37. [..]
  38. This driver provides functions and macros to configure and program the FLASH
  39. memory of all STM32WBxx devices.
  40. (#) Flash Memory IO Programming functions:
  41. (++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and
  42. HAL_FLASH_Lock() functions
  43. (++) Program functions: double word and fast program (full row programming)
  44. (++) There are two modes of programming:
  45. (+++) Polling mode using HAL_FLASH_Program() function
  46. (+++) Interrupt mode using HAL_FLASH_Program_IT() function
  47. (#) Interrupts and flags management functions:
  48. (++) Handle FLASH interrupts by calling HAL_FLASH_IRQHandler()
  49. (++) Callback functions are called when the flash operations are finished :
  50. HAL_FLASH_EndOfOperationCallback() when everything is ok, otherwise
  51. HAL_FLASH_OperationErrorCallback()
  52. (++) Get error flag status by calling HAL_GetError()
  53. (#) Option bytes management functions :
  54. (++) Lock and Unlock the option bytes using HAL_FLASH_OB_Unlock() and
  55. HAL_FLASH_OB_Lock() functions
  56. (++) Launch the reload of the option bytes using HAL_FLASH_OB_Launch() function.
  57. In this case, a reset is generated
  58. [..]
  59. In addition to these functions, this driver includes a set of macros allowing
  60. to handle the following operations:
  61. (+) Set the latency
  62. (+) Enable/Disable the prefetch buffer
  63. (+) Enable/Disable the suspend program or erase request
  64. (+) Enable/Disable the Instruction cache and the Data cache
  65. (+) Reset the Instruction cache and the Data cache
  66. (+) Enable/Disable the Flash interrupts
  67. (+) Monitor the Flash flags status
  68. @endverbatim
  69. ******************************************************************************
  70. * @attention
  71. *
  72. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  73. * All rights reserved.</center></h2>
  74. *
  75. * This software component is licensed by ST under BSD 3-Clause license,
  76. * the "License"; You may not use this file except in compliance with the
  77. * License. You may obtain a copy of the License at:
  78. * opensource.org/licenses/BSD-3-Clause
  79. *
  80. ******************************************************************************
  81. */
  82. /* Includes ------------------------------------------------------------------*/
  83. #include "stm32wbxx_hal.h"
  84. /** @addtogroup STM32WBxx_HAL_Driver
  85. * @{
  86. */
  87. /** @defgroup FLASH FLASH
  88. * @brief FLASH HAL module driver
  89. * @{
  90. */
  91. #ifdef HAL_FLASH_MODULE_ENABLED
  92. /* Private typedef -----------------------------------------------------------*/
  93. /* Private defines -----------------------------------------------------------*/
  94. /** @addtogroup FLASH_Private_Constants
  95. * @{
  96. */
  97. #define FLASH_NB_DOUBLE_WORDS_IN_ROW 64
  98. /**
  99. * @}
  100. */
  101. /* Private macros ------------------------------------------------------------*/
  102. /* Private variables ---------------------------------------------------------*/
  103. /** @defgroup FLASH_Private_Variables FLASH Private Variables
  104. * @{
  105. */
  106. /**
  107. * @brief Variable used for Program/Erase sectors under interruption
  108. */
  109. FLASH_ProcessTypeDef pFlash = {.Lock = HAL_UNLOCKED, \
  110. .ErrorCode = HAL_FLASH_ERROR_NONE, \
  111. .ProcedureOnGoing = 0U, \
  112. .Address = 0U, \
  113. .Page = 0U, \
  114. .NbPagesToErase = 0U
  115. };
  116. /**
  117. * @}
  118. */
  119. /* Private function prototypes -----------------------------------------------*/
  120. /** @defgroup FLASH_Private_Functions FLASH Private Functions
  121. * @{
  122. */
  123. static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data);
  124. static void FLASH_Program_Fast(uint32_t Address, uint32_t DataAddress);
  125. /**
  126. * @}
  127. */
  128. /* Exported functions --------------------------------------------------------*/
  129. /** @defgroup FLASH_Exported_Functions FLASH Exported Functions
  130. * @{
  131. */
  132. /** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions
  133. * @brief Programming operation functions
  134. *
  135. @verbatim
  136. ===============================================================================
  137. ##### Programming operation functions #####
  138. ===============================================================================
  139. [..]
  140. This subsection provides a set of functions allowing to manage the FLASH
  141. program operations.
  142. @endverbatim
  143. * @{
  144. */
  145. /**
  146. * @brief Program double word or fast program of a row at a specified address.
  147. * @note Before any operation, it is possible to check there is no operation suspended
  148. * by call HAL_FLASHEx_IsOperationSuspended()
  149. * @param TypeProgram Indicate the way to program at a specified address
  150. * This parameter can be a value of @ref FLASH_TYPE_PROGRAM
  151. * @param Address Specifies the address to be programmed.
  152. * @param Data Specifies the data to be programmed
  153. * This parameter is the data for the double word program and the address where
  154. * are stored the data for the row fast program.
  155. *
  156. * @retval HAL_StatusTypeDef HAL Status
  157. */
  158. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
  159. {
  160. HAL_StatusTypeDef status;
  161. /* Check the parameters */
  162. assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
  163. assert_param(IS_ADDR_ALIGNED_64BITS(Address));
  164. assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
  165. /* Process Locked */
  166. __HAL_LOCK(&pFlash);
  167. /* Reset error code */
  168. pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
  169. /* Verify that next operation can be proceed */
  170. status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
  171. if (status == HAL_OK)
  172. {
  173. if (TypeProgram == FLASH_TYPEPROGRAM_DOUBLEWORD)
  174. {
  175. /* Check the parameters */
  176. assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
  177. /* Program double-word (64-bit) at a specified address */
  178. FLASH_Program_DoubleWord(Address, Data);
  179. }
  180. else
  181. {
  182. /* Check the parameters */
  183. assert_param(IS_FLASH_FAST_PROGRAM_ADDRESS(Address));
  184. /* Fast program a 64 row double-word (64-bit) at a specified address */
  185. FLASH_Program_Fast(Address, (uint32_t)Data);
  186. }
  187. /* Wait for last operation to be completed */
  188. status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
  189. /* If the program operation is completed, disable the PG or FSTPG Bit */
  190. CLEAR_BIT(FLASH->CR, TypeProgram);
  191. }
  192. /* Process Unlocked */
  193. __HAL_UNLOCK(&pFlash);
  194. /* return status */
  195. return status;
  196. }
  197. /**
  198. * @brief Program double word or fast program of a row at a specified address with interrupt enabled.
  199. * @note Before any operation, it is possible to check there is no operation suspended
  200. * by call HAL_FLASHEx_IsOperationSuspended()
  201. * @param TypeProgram Indicate the way to program at a specified address.
  202. * This parameter can be a value of @ref FLASH_TYPE_PROGRAM
  203. * @param Address Specifies the address to be programmed.
  204. * @param Data Specifies the data to be programmed
  205. * This parameter is the data for the double word program and the address where
  206. * are stored the data for the row fast program.
  207. *
  208. * @retval HAL Status
  209. */
  210. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
  211. {
  212. HAL_StatusTypeDef status;
  213. /* Check the parameters */
  214. assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
  215. assert_param(IS_ADDR_ALIGNED_64BITS(Address));
  216. assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
  217. /* Process Locked */
  218. __HAL_LOCK(&pFlash);
  219. /* Reset error code */
  220. pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
  221. /* Verify that next operation can be proceed */
  222. status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
  223. if (status != HAL_OK)
  224. {
  225. /* Process Unlocked */
  226. __HAL_UNLOCK(&pFlash);
  227. }
  228. else
  229. {
  230. /* Set internal variables used by the IRQ handler */
  231. pFlash.ProcedureOnGoing = TypeProgram;
  232. pFlash.Address = Address;
  233. /* Enable End of Operation and Error interrupts */
  234. __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_OPERR);
  235. if (TypeProgram == FLASH_TYPEPROGRAM_DOUBLEWORD)
  236. {
  237. /* Check the parameters */
  238. assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
  239. /* Program double-word (64-bit) at a specified address */
  240. FLASH_Program_DoubleWord(Address, Data);
  241. }
  242. else
  243. {
  244. /* Check the parameters */
  245. assert_param(IS_FLASH_FAST_PROGRAM_ADDRESS(Address));
  246. /* Fast program a 64 row double-word (64-bit) at a specified address */
  247. FLASH_Program_Fast(Address, (uint32_t)Data);
  248. }
  249. }
  250. /* return status */
  251. return status;
  252. }
  253. /**
  254. * @brief Handle FLASH interrupt request.
  255. * @retval None
  256. */
  257. void HAL_FLASH_IRQHandler(void)
  258. {
  259. uint32_t param = 0xFFFFFFFFU;
  260. uint32_t error;
  261. /* Check FLASH operation error flags */
  262. error = (FLASH->SR & FLASH_FLAG_SR_ERRORS);
  263. /* Clear Current operation */
  264. CLEAR_BIT(FLASH->CR, pFlash.ProcedureOnGoing);
  265. /* A] Set parameter for user or error callbacks */
  266. /* check operation was a program or erase */
  267. if ((pFlash.ProcedureOnGoing & (FLASH_TYPEPROGRAM_DOUBLEWORD | FLASH_TYPEPROGRAM_FAST)) != 0U)
  268. {
  269. /* return adress being programmed */
  270. param = pFlash.Address;
  271. }
  272. else if ((pFlash.ProcedureOnGoing & (FLASH_TYPEERASE_PAGES)) != 0U)
  273. {
  274. /* return page number being erased */
  275. param = pFlash.Page;
  276. }
  277. else
  278. {
  279. /* No Procedure on-going */
  280. /* Nothing to do, but check error if any */
  281. }
  282. /* B] Check errors */
  283. if (error != 0U)
  284. {
  285. /*Save the error code*/
  286. pFlash.ErrorCode |= error;
  287. /* clear error flags */
  288. __HAL_FLASH_CLEAR_FLAG(error);
  289. /*Stop the procedure ongoing*/
  290. pFlash.ProcedureOnGoing = FLASH_TYPENONE;
  291. /* Error callback */
  292. HAL_FLASH_OperationErrorCallback(param);
  293. }
  294. /* C] Check FLASH End of Operation flag */
  295. if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
  296. {
  297. /* Clear FLASH End of Operation pending bit */
  298. __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
  299. if (pFlash.ProcedureOnGoing == FLASH_TYPEERASE_PAGES)
  300. {
  301. /* Nb of pages to erased can be decreased */
  302. pFlash.NbPagesToErase--;
  303. /* Check if there are still pages to erase*/
  304. if (pFlash.NbPagesToErase != 0U)
  305. {
  306. /* Increment page number */
  307. pFlash.Page++;
  308. FLASH_PageErase(pFlash.Page);
  309. }
  310. else
  311. {
  312. /* No more pages to erase: stop erase pages procedure */
  313. pFlash.ProcedureOnGoing = FLASH_TYPENONE;
  314. }
  315. }
  316. else
  317. {
  318. /*Stop the ongoing procedure */
  319. pFlash.ProcedureOnGoing = FLASH_TYPENONE;
  320. }
  321. /* User callback */
  322. HAL_FLASH_EndOfOperationCallback(param);
  323. }
  324. if (pFlash.ProcedureOnGoing == FLASH_TYPENONE)
  325. {
  326. /* Disable End of Operation and Error interrupts */
  327. __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP | FLASH_IT_OPERR);
  328. /* Process Unlocked */
  329. __HAL_UNLOCK(&pFlash);
  330. }
  331. }
  332. /**
  333. * @brief FLASH end of operation interrupt callback.
  334. * @param ReturnValue The value saved in this parameter depends on the ongoing procedure
  335. * Page Erase: Page which has been erased
  336. * Program: Address which was selected for data program
  337. * @retval None
  338. */
  339. __weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
  340. {
  341. /* Prevent unused argument(s) compilation warning */
  342. UNUSED(ReturnValue);
  343. /* NOTE : This function should not be modified, when the callback is needed,
  344. the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
  345. */
  346. }
  347. /**
  348. * @brief FLASH operation error interrupt callback.
  349. * @param ReturnValue The value saved in this parameter depends on the ongoing procedure
  350. * Page Erase: Page number which returned an error
  351. * Program: Address which was selected for data program
  352. * @retval None
  353. */
  354. __weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
  355. {
  356. /* Prevent unused argument(s) compilation warning */
  357. UNUSED(ReturnValue);
  358. /* NOTE : This function should not be modified, when the callback is needed,
  359. the HAL_FLASH_OperationErrorCallback could be implemented in the user file
  360. */
  361. }
  362. /**
  363. * @}
  364. */
  365. /** @defgroup FLASH_Exported_Functions_Group2 Peripheral Control functions
  366. * @brief Management functions
  367. *
  368. @verbatim
  369. ===============================================================================
  370. ##### Peripheral Control functions #####
  371. ===============================================================================
  372. [..]
  373. This subsection provides a set of functions allowing to control the FLASH
  374. memory operations.
  375. @endverbatim
  376. * @{
  377. */
  378. /**
  379. * @brief Unlock the FLASH control register access.
  380. * @retval HAL Status
  381. */
  382. HAL_StatusTypeDef HAL_FLASH_Unlock(void)
  383. {
  384. HAL_StatusTypeDef status = HAL_OK;
  385. if (READ_BIT(FLASH->CR, FLASH_CR_LOCK) != 0U)
  386. {
  387. /* Authorize the FLASH Registers access */
  388. WRITE_REG(FLASH->KEYR, FLASH_KEY1);
  389. WRITE_REG(FLASH->KEYR, FLASH_KEY2);
  390. /* verify Flash is unlock */
  391. if (READ_BIT(FLASH->CR, FLASH_CR_LOCK) != 0U)
  392. {
  393. status = HAL_ERROR;
  394. }
  395. }
  396. return status;
  397. }
  398. /**
  399. * @brief Lock the FLASH control register access.
  400. * @retval HAL Status
  401. */
  402. HAL_StatusTypeDef HAL_FLASH_Lock(void)
  403. {
  404. HAL_StatusTypeDef status = HAL_OK;
  405. /* Set the LOCK Bit to lock the FLASH Registers access */
  406. /* @Note The lock and unlock procedure is done only using CR registers even from CPU2 */
  407. SET_BIT(FLASH->CR, FLASH_CR_LOCK);
  408. /* verify Flash is locked */
  409. if (READ_BIT(FLASH->CR, FLASH_CR_LOCK) == 0U)
  410. {
  411. status = HAL_ERROR;
  412. }
  413. return status;
  414. }
  415. /**
  416. * @brief Unlock the FLASH Option Bytes Registers access.
  417. * @retval HAL Status
  418. */
  419. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
  420. {
  421. HAL_StatusTypeDef status = HAL_ERROR;
  422. /* @Note The lock and unlock procedure is done only using CR registers even from CPU2 */
  423. if (READ_BIT(FLASH->CR, FLASH_CR_OPTLOCK) != 0U)
  424. {
  425. /* Authorizes the Option Byte register programming */
  426. WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
  427. WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);
  428. /* verify option bytes are unlocked */
  429. if (READ_BIT(FLASH->CR, FLASH_CR_OPTLOCK) == 0U)
  430. {
  431. status = HAL_OK;
  432. }
  433. }
  434. return status;
  435. }
  436. /**
  437. * @brief Lock the FLASH Option Bytes Registers access.
  438. * @retval HAL Status
  439. */
  440. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
  441. {
  442. HAL_StatusTypeDef status = HAL_OK;
  443. /* Set the OPTLOCK Bit to lock the FLASH Option Byte Registers access */
  444. /* @Note The lock and unlock procedure is done only using CR registers even from CPU2 */
  445. SET_BIT(FLASH->CR, FLASH_CR_OPTLOCK);
  446. /* verify option bytes are lock */
  447. if (READ_BIT(FLASH->CR, FLASH_CR_OPTLOCK) == 0U)
  448. {
  449. status = HAL_ERROR;
  450. }
  451. return status;
  452. }
  453. /**
  454. * @brief Launch the option byte loading.
  455. * @retval HAL Status
  456. */
  457. HAL_StatusTypeDef HAL_FLASH_OB_Launch(void)
  458. {
  459. /* Set the bit to force the option byte reloading */
  460. /* The OB launch is done from the same register either from CPU1 or CPU2 */
  461. SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH);
  462. /* We should not reach here : Option byte launch generates Option byte reset
  463. so return error */
  464. return HAL_ERROR;
  465. }
  466. /**
  467. * @}
  468. */
  469. /** @defgroup FLASH_Exported_Functions_Group3 Peripheral State and Errors functions
  470. * @brief Peripheral Errors functions
  471. *
  472. @verbatim
  473. ===============================================================================
  474. ##### Peripheral Errors functions #####
  475. ===============================================================================
  476. [..]
  477. This subsection permits to get in run-time Errors of the FLASH peripheral.
  478. @endverbatim
  479. * @{
  480. */
  481. /**
  482. * @brief Get the specific FLASH error flag.
  483. * @retval FLASH_ErrorCode The returned value can be
  484. * @arg @ref HAL_FLASH_ERROR_NONE No error set
  485. * @arg @ref HAL_FLASH_ERROR_OP FLASH Operation error
  486. * @arg @ref HAL_FLASH_ERROR_PROG FLASH Programming error
  487. * @arg @ref HAL_FLASH_ERROR_WRP FLASH Write protection error
  488. * @arg @ref HAL_FLASH_ERROR_PGA FLASH Programming alignment error
  489. * @arg @ref HAL_FLASH_ERROR_SIZ FLASH Size error
  490. * @arg @ref HAL_FLASH_ERROR_PGS FLASH Programming sequence error
  491. * @arg @ref HAL_FLASH_ERROR_MIS FLASH Fast programming data miss error
  492. * @arg @ref HAL_FLASH_ERROR_FAST FLASH Fast programming error
  493. * @arg @ref HAL_FLASH_ERROR_RD FLASH Read Protection error (PCROP)
  494. * @arg @ref HAL_FLASH_ERROR_OPTV FLASH Option validity error
  495. */
  496. uint32_t HAL_FLASH_GetError(void)
  497. {
  498. return pFlash.ErrorCode;
  499. }
  500. /**
  501. * @}
  502. */
  503. /**
  504. * @}
  505. */
  506. /* Private functions ---------------------------------------------------------*/
  507. /** @addtogroup FLASH_Private_Functions
  508. * @{
  509. */
  510. /**
  511. * @brief Wait for a FLASH operation to complete.
  512. * @param Timeout Maximum flash operation timeout
  513. * @retval HAL_StatusTypeDef HAL Status
  514. */
  515. HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
  516. {
  517. uint32_t error;
  518. uint32_t tickstart = HAL_GetTick();
  519. /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
  520. Even if the FLASH operation fails, the BUSY flag will be reset and an error
  521. flag will be set */
  522. while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY))
  523. {
  524. if ((HAL_GetTick() - tickstart) >= Timeout)
  525. {
  526. return HAL_TIMEOUT;
  527. }
  528. }
  529. /* Check FLASH operation error flags */
  530. error = FLASH->SR;
  531. /* Check FLASH End of Operation flag */
  532. if ((error & FLASH_FLAG_EOP) != 0U)
  533. {
  534. /* Clear FLASH End of Operation pending bit */
  535. __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
  536. }
  537. /* Now update error variable to only error value */
  538. error &= FLASH_FLAG_SR_ERRORS;
  539. /* clear error flags */
  540. __HAL_FLASH_CLEAR_FLAG(error);
  541. if (error != 0U)
  542. {
  543. /*Save the error code*/
  544. pFlash.ErrorCode = error;
  545. return HAL_ERROR;
  546. }
  547. /* Wait for control register to be written */
  548. while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_CFGBSY))
  549. {
  550. if ((HAL_GetTick() - tickstart) >= Timeout)
  551. {
  552. return HAL_TIMEOUT;
  553. }
  554. }
  555. return HAL_OK;
  556. }
  557. /**
  558. * @brief Program double-word (64-bit) at a specified address.
  559. * @param Address Specifies the address to be programmed.
  560. * @param Data Specifies the data to be programmed.
  561. * @retval None
  562. */
  563. static void FLASH_Program_DoubleWord(uint32_t Address, uint64_t Data)
  564. {
  565. /* Set PG bit */
  566. SET_BIT(FLASH->CR, FLASH_CR_PG);
  567. /* Program first word */
  568. *(uint32_t *)Address = (uint32_t)Data;
  569. /* Barrier to ensure programming is performed in 2 steps, in right order
  570. (independently of compiler optimization behavior) */
  571. __ISB();
  572. /* Program second word */
  573. *(uint32_t *)(Address + 4U) = (uint32_t)(Data >> 32U);
  574. }
  575. /**
  576. * @brief Fast program a 32 row double-word (64-bit) at a specified address.
  577. * @param Address Specifies the address to be programmed.
  578. * @param DataAddress Specifies the address where the data are stored.
  579. * @retval None
  580. */
  581. static __RAM_FUNC void FLASH_Program_Fast(uint32_t Address, uint32_t DataAddress)
  582. {
  583. uint8_t row_index = (2 * FLASH_NB_DOUBLE_WORDS_IN_ROW);
  584. __IO uint32_t *dest_addr = (__IO uint32_t *)Address;
  585. __IO uint32_t *src_addr = (__IO uint32_t *)DataAddress;
  586. uint32_t primask_bit;
  587. /* Set FSTPG bit */
  588. SET_BIT(FLASH->CR, FLASH_CR_FSTPG);
  589. /* Enter critical section: row programming should not be longer than 7 ms */
  590. primask_bit = __get_PRIMASK();
  591. __disable_irq();
  592. /* Program the double word of the row */
  593. do
  594. {
  595. *dest_addr = *src_addr;
  596. dest_addr++;
  597. src_addr++;
  598. row_index--;
  599. }
  600. while (row_index != 0U);
  601. /* wait for BSY in order to be sure that flash operation is ended before
  602. allowing prefetch in flash. Timeout does not return status, as it will
  603. be anyway done later */
  604. while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != 0U)
  605. {
  606. }
  607. /* Exit critical section: restore previous priority mask */
  608. __set_PRIMASK(primask_bit);
  609. }
  610. /**
  611. * @}
  612. */
  613. #endif /* HAL_FLASH_MODULE_ENABLED */
  614. /**
  615. * @}
  616. */
  617. /**
  618. * @}
  619. */
  620. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/