硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3668|回复: 0
收起左侧

STM32G4库搞的一个快速内部Flash编程函数FLASH_Program_Fast

[复制链接]

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117545
QQ
发表于 2020-7-26 11:14:30 | 显示全部楼层 |阅读模式


代码如下,在文件stm32g4xx_hal_flash.c里面。
  1. /**
  2.   * @brief  Fast program a row double-word (64-bit) at a specified address.
  3.   * @param  Address specifies the address to be programmed.
  4.   * @param  DataAddress specifies the address where the data are stored.
  5.   * @retval None
  6.   */
  7. static void FLASH_Program_Fast(uint32_t Address, uint32_t DataAddress)
  8. {
  9.   uint8_t row_index = (2 * FLASH_NB_DOUBLE_WORDS_IN_ROW);
  10.   uint32_t *dest_addr = (uint32_t *)Address;
  11.   uint32_t *src_addr = (uint32_t *)DataAddress;
  12.   uint32_t primask_bit;

  13.   /* Check the parameters */
  14.   assert_param(IS_FLASH_MAIN_MEM_ADDRESS(Address));

  15.   /* Set FSTPG bit */
  16.   SET_BIT(FLASH->CR, FLASH_CR_FSTPG);

  17.   /* Enter critical section: Disable interrupts to avoid any interruption during the loop */
  18.   primask_bit = __get_PRIMASK();
  19.   __disable_irq();

  20.   /* Program the double words of the row */
  21.   do
  22.   {
  23.     *dest_addr = *src_addr;
  24.     dest_addr++;
  25.     src_addr++;
  26.     row_index--;
  27.   }
  28.   while (row_index != 0U);

  29.   /* Exit critical section: restore previous priority mask */
  30.   __set_PRIMASK(primask_bit);
  31. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-8-14 00:24 , Processed in 0.037480 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表