在 C 中与 STM32 芯片的内存交互

Interact with a STM32 chip's memory in C

我想和STM32芯片的内存交互,STM32L476, first to read and store its electronic signature (MCU_ID) and then to write data in its memory. I am using a STM32QFP64 socket linked to a JTAG ST-LINK.
我在 C 方面相当不错,但真正开始嵌入式编程所以我选择了 Atollic Studio IDE 因为它看起来很完整并且基于我之前已经使用过的 Eclipse。

我的问题是 我找不到某种列出函数、变量 等的文档。我可以用来与芯片交互。我几乎搜索了 ST 站点上提供的所有 PDF,阅读了 ST 的 GitHub,但由于我是初学者,我可能会错过这些信息,因为我不知道我要搜索的内容是什么样的。

下面的代码是无关紧要的,完全是想象出来的,但它可以帮助理解我正在尝试做的事情,我在某种程度上是这样的:

#define MEMORY_ADRESS_MCU_ID FFFFF // A memory adress ( I should be able to find it in STM32L476 documentation)
#define MEMORY_ADRESS_TO_WRITE FFFF // Same

unsigned extractMCUID() {

   return READ_IN_MEMORY(MEMORY_ADRESS_MCU_ID); // Returns the ID stored in a particular memory adress

}

void writeData(char* d) {

   WRITE_IN_MEMORY(MEMORY_ADRESS_TO_WRITE, d); // Writes data in specified memory adress

}

因此,在这种情况下,更普遍

1) 我应该去哪里找这样的文档?

2) 这些函数和变量会根据我处理的 STM32 芯片而改变吗?

3) 如果不在 StackExchange 上,我在哪里可以找到 1)2) 的答案?

你可能想看看这里: http://www.openstm32.org

这部分可能会给你一个提示: char in_ccram_buffer[1024] __attribute__((section("ccmram")));

我的 AVR 代码中有类似的东西:

 const uint16_t tempTable[42] __attribute__((section(".eeprom"))) = ...

很有魅力。

STM 为每个 MCU 发布了几种类型的文档,我很难猜测哪个文档将包含我要查找的信息。所以我在文档中搜索相关的关键词,直到我缩小信息范围。两个最重要的文档是数据表和参考手册,所以我总是从它们开始。

在这种情况下,我开始在 Datasheet for "MCU_ID" and found nothing so I searched for the more generic "ID" and found it associated with the more specific keyword "unique". I searched the Datasheet for "unique" but didn't find the register address information. So then I searched the Reference Manual 中搜索 "unique ID",并在第 1808 页的第 49.1 节中找到了寄存器的基地址。

是的,像这样的详细信息可能会从一个 STM MCU 到另一个 STM MCU,因此您需要确保您使用的是正确的数据表和参考手册。但是,STM 提供了一个名为 STM32Cube 的硬件抽象层 (HAL),它像这样抽象出 MCU 特定的细节,并允许您调用更多独立于 MCU 的通用函数。

编辑: 我可能向您指出了错误的 ID 寄存器。 Clifford 在评论中指出,在地址 0xE0042000 处有一个 MCU 设备 ID 寄存器。此 MCU 设备 ID 寄存器不同于唯一设备 ID 寄存器,在参考手册第 1782 页的第 48.6.1 节中有描述。