Interact with a STM32 chip's memory in C [clos

2019-07-31 16:24发布

I would like to interact with a STM32 chip's memory, 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.
I am quite good in C but really beginning embedded programming so I chose Atollic Studio IDE because it seemed quite complete and was based on Eclipse which I had already used prior.

My problem is that I can't find some sort of documentation listing the functions, variables etc. I could use to interact with the chip. I have searched in nearly all the PDFs given on the ST site, read ST's GitHub, but since I am a beginner I could have missed those information for I did not know what what I am searching for looks like.

The code below is irrevelant and completely imagined, but it could help understanding what I am trying to do, which I picture somehow like this :

#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

}

Thus, in this case and even more generally :

1) Where should I look for such documentation ?

2) Does those functions and variables change depending on what STM32 chip I am dealing with ?

3) Where could I have found the answers to 1) and 2) if not on StackExchange ?

2条回答
Root(大扎)
2楼-- · 2019-07-31 16:48

STM publishes several types of documents for each MCU and it's difficult for me to guess which document will contain the piece of information that I'm looking for. So I search within the documents for related key words until I narrow in on the information. The two most important documents are the Datasheet and the Reference Manual so I always start with them.

In this case I started searching the 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 for "unique ID" and found the base address for the register in section 49.1 on page 1808.

Yes, details like this can change from one STM MCU to the next so you need to ensure you're using the correct Datasheet and Reference Manual. However, STM provides a Hardware Abstraction Layer (HAL) called STM32Cube, which abstracts away MCU specific details like this and allows you to call more generic functions which are MCU independent.

Edit: I may have pointed you to the wrong ID register. Clifford points out in the comments that there is an MCU device ID register at address 0xE0042000. This MCU device ID register is different from the Unique device ID register and it's described in section 48.6.1 on page 1782 of the Reference Manual.

查看更多
趁早两清
3楼-- · 2019-07-31 16:51

You may want to have a look here: http://www.openstm32.org

This part may give you a hint: char in_ccram_buffer[1024] __attribute__((section("ccmram")));

I have something similar in my AVR code:

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

works a charm.

查看更多
登录 后发表回答