stm32 15-2 flash 闪存:代码部分二

(101)继续老师的库函数的讲解 :

++ 写入字:

c 复制代码
/**
  * @brief  Programs a word at a specified address.
  * @note   This function can be used for all STM32F10x devices.
  * @param  Address: specifies the address to be programmed.
  * @param  Data: specifies the data to be programmed.
  * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG,
  *         FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. 
  */
FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
{
  FLASH_Status status = FLASH_COMPLETE;
  __IO uint32_t tmp = 0;

  /* Check the parameters */
  assert_param(IS_FLASH_ADDRESS(Address));

#ifdef STM32F10X_XL
  //................
#else
  /* Wait for last operation to be completed */
  status = FLASH_WaitForLastOperation(ProgramTimeout);
  
  if(status == FLASH_COMPLETE)
  {
    /* if the previous operation is completed, proceed to program the new first half word */
    FLASH->CR |= CR_PG_Set;
  
    *(__IO uint16_t*)Address = (uint16_t)Data;
    /* Wait for last operation to be completed */
    status = FLASH_WaitForLastOperation(ProgramTimeout);
 
    if(status == FLASH_COMPLETE)
    {
      /* if the previous operation is completed, proceed to program the new second half word */
      tmp = Address + 2;  // 这里也可以看出, stm323 是小端法 CPU 

      *(__IO uint16_t*) tmp = Data >> 16;  // 把一个字拆分成两个半字,分两次写入 flash 
    
      /* Wait for last operation to be completed */
      status = FLASH_WaitForLastOperation(ProgramTimeout);
        
      /* Disable the PG Bit */
      FLASH->CR &= CR_PG_Reset;
    }
    else
    {
      /* Disable the PG Bit */
      FLASH->CR &= CR_PG_Reset;
    }
  }         
#endif /* STM32F10X_XL */
   
  /* Return the Program Status */
  return status;
}

(102)例题 1 ,读写内部 flash :

++ 上面没有写入字节的函数,因为太麻烦,改用缓冲区了 。

++

(103) 两个项目工程配置 :

++

(104) 看懂编译信息 :

++

++

++

++

++

(105)例题2 , 读取芯片 ID :

++ 这里也可以查看与验证程序的执行结果,但上面的截图,是截图老师的视频里的 :

(106)

(107)

谢谢

相关推荐
硅基手札4 小时前
【串口技术系列文档 07】UART控制器寄存器详解
驱动开发·stm32·单片机·嵌入式硬件·mcu·计算机外设
硅基手札4 小时前
【串口技术系列文档 09】FIFO管理与流控
驱动开发·stm32·单片机·嵌入式硬件·mcu·计算机外设
硅基手札4 小时前
【串口技术系列文档 08】中断驱动vs轮询vs DMA
驱动开发·stm32·单片机·嵌入式硬件·mcu·计算机外设
Zw-awa5 小时前
把 AO 接回来:黑线和白底之间到底差了多少
stm32
桀人5 小时前
USART帧格式
网络·stm32·单片机·嵌入式硬件
深圳老胡5 小时前
STM32F4 OTA 升级双 App 方案设计与实现
笔记·stm32·单片机·代码规范
2401_888859717 小时前
STM32H733 MPU、AXI、FMC学习
java·开发语言·stm32·spring
深圳老胡7 小时前
STM32F4 OTA升级:单App与双App方案优缺点对比
笔记·stm32·单片机·代码规范
BSD_CGQ18 小时前
FSR传感器STM32 DMA高速采样工程实现(高精度、低CPU占用)
stm32·单片机·嵌入式硬件·压力传感器·源头工厂·柔性薄膜压力传感器·可变电阻压力传感器