首页 > 解决方案 > 如何在代码本身中找出闪存的大小?

问题描述

我想在代码本身中获取闪存的限制地址,或者至少是这个闪存的大小。

我在文件中只找到了flash的起始地址,stm32f302xc.h没有找到结束地址。

/** @addtogroup Peripheral_memory_map
  * @{
  */

#define FLASH_BASE            0x08000000UL /*!< FLASH base address in the alias region */
#define SRAM_BASE             0x20000000UL /*!< SRAM base address in the alias region */
#define PERIPH_BASE           0x40000000UL /*!< Peripheral base address in the alias region */
#define SRAM_BB_BASE          0x22000000UL /*!< SRAM base address in the bit-band region */
#define PERIPH_BB_BASE        0x42000000UL /*!< Peripheral base address in the bit-band region */

什么定义对此负责,谢谢。

标签: stm32hal

解决方案


参考手册RM0366的第29.2 节内存大小数据寄存器中描述了您想要的内容。

ST 提供了这种功能,但由于某种原因,它们并不总是提供一种在标题中访问它的简单方法。

这个寄存器的地址是FLASHSIZE_BASE。您必须在运行时阅读它,例如:

uint16_t flash_size_kb = *(const uint16_t*)FLASHSIZE_BASE;

推荐阅读