如何在代码本身中找到闪存的大小?

Ale*_*aev 3 hal stm32

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

我在文件中只找到了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 */
Run Code Online (Sandbox Code Playgroud)

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

Tom*_*m V 5

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

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

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

uint16_t flash_size_kb = *(const uint16_t*)FLASHSIZE_BASE;
Run Code Online (Sandbox Code Playgroud)