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)

谢谢

相关推荐
无敌贵点大王12 小时前
从寄存器层面重学STM32(11)——ADC理论
stm32·单片机·嵌入式硬件
Zw-awa13 小时前
卡尔曼到底在算什么:从一维到它的变式以及工程版卡尔曼滤波算法C语言实现
stm32
希和202717 小时前
代码讲解:STM32F103C8T6 驱动 HC-SR04 超声波测距
stm32·单片机·嵌入式硬件
编程小白菜12318 小时前
STM32L0 ADC串扰揭秘:充电电压如何“伪造”压力数据
stm32·单片机·嵌入式硬件
Zw-awa1 天前
两路信号,两种滤波:角速度走低通滤波,加速度走卡尔曼滤波
stm32
橘为己有4411 天前
STM32:USART 串口(2)
stm32·单片机·嵌入式硬件
Zw-awa3 天前
滤波是什么:限幅、滑动平均、中位值、一阶低通怎么选?嵌入式传感器滤波算法原理与C源码
stm32
Zw-awa4 天前
陀螺仪数据为什么看起来总在动:零偏、噪声和零漂
stm32
Zw-awa4 天前
什么是IMU:两颗传感器、一件别人替代不了的事,MPU6050、IMU660RA、JY901S等模块有何区别
stm32
Zw-awa6 天前
MPU6050:从原始加速度到姿态变化
stm32