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)

谢谢

相关推荐
小李不想当小白2 小时前
SPI通信外设与W25Q64 (硬件SPI)(STM32标准库学习笔记)
笔记·stm32·单片机·嵌入式硬件·学习·嵌入式
LCG米2 小时前
STM32驱动W5500以太网模块实测:TCP吞吐瓶颈定位、TX指针回绕陷阱与断线重连保活落地
stm32·单片机·嵌入式硬件·tcp/ip
创界工坊工作室4 小时前
63-基于STC89C52霍尔传感器的智能化电能表设计
stm32·单片机·嵌入式硬件·51单片机·proteus
意法半导体STM327 小时前
【官方原创】LAT6048 如何扩大MP2的A35核和M33核共享内存
stm32·单片机·嵌入式硬件·内存映射·stm32mp2
en.en..7 小时前
STM32(F429)启动模式与两种烧录方式
stm32·单片机·嵌入式硬件
Zw-awa7 小时前
从 printf 到曲线:把数据送上 VOFA+
stm32
【 STM32开发 】9 小时前
【CubeMX+STM32】SD卡 文件系统读写 FatFs+SDIO+DMA (F103版本)
stm32·单片机·嵌入式硬件·1024程序员节
‎ദ്ദിᵔ.˛.ᵔ₎10 小时前
STM32 USART 串口
stm32·单片机·嵌入式硬件
LCG米1 天前
STM32 ADC多通道DMA定时器触发实测:TRGO触发链、采样率精确控制与乒乓缓冲落地
stm32·单片机·嵌入式·adc
youcans_1 天前
【嵌入式软件AI编程】22. STM32 基础实验:GPIO外部中断
stm32·单片机·嵌入式硬件·ai编程·claude