1
votes

I am trying to read the MCU_ID (device electronic signature) from STM32L476 chip using a JTAG ST-Link/V2 on Windows 7. No code has to be uploaded inside the chip, the program shall just be launched on my cumputer and read this information from the flash memory.

I have managed to find and extract the following screenshot from the Reference Manuel given on ST website :

Device Electronic Signature Registre

So I have to read the value stored in the flash memory at the adess 0x1FFF7590 by using a C program. I am using the Atollic TrueStudio IDE which is recommended by ST itself, but it seems to me that it includes the "stm32l476xx.h"library which does not even contain any function which could help me.

What I have done so far

After spending days and days looking for some functions or examples to do something as simple as read flash memory, I have asked on this very site How to interact with a STM32 chip memory, which helped me understand a couple of things about what I had to do; nevertheless, I haven't been able to find what I was looking for even after days reading all the links and docs advised in the comments.

I have asked a couple of professionals who told me that I should search for a JTAG driver to interact with the flash memory, but it seems a bit complicated and I haven't been able to found any. Someone on this site told me that simply using pointer should be enough; the lack of C example and internet tutorials couldn't help me figure out how to do so.

Finally, I started recently digging around STM32Cube and HAL, even since I wanted to avoid using those because I thought that a simple read could be done without having to include those layers. Asking this question is my final hope before trying to use them.

In Conclusion :

I can't show any code since the only thing I have so far is a #include "stm32l476xx.h"and an empty main.
A hint or solution on How to read a STM32L476's flash memory in C would be just perfect. Every example of C (or any programming language which would be as low or higher level) program or instructions interacting with a STM32 chip's memory could help me a lot since it is very hard to find on internet.

3
Why do you want to write your own program rather than using an existing tool such as OpenOCDBrian Sidebotham
I don't understand the actual point. If you have know address where device signature is then you can do this: uint16_t sign = *(uint16_t *)0x1FFF7590; and you have signature of device.tilz0R
The production-friendly way would probably be to 1) either have the MCU program spit out the data on your favourite flavour of serial bus, or 2) download a dummy program which does nothing but spitting out the data, then overwrite it with the actual firmware later.Lundin
It is common practice to load a test firmware out of factory (pre-flashed MCU) and then overwrite it with the actual application later. But since you are not looking for firmware or programming advise, it means that the question is nothing but a tool recommendation, which is explicitly off-topic for this site.Lundin
The debugger/programmer in Atollic Studio is a program running on your PC that communicates with the JTAG interface; so of course you can write your own program to do that; however you have to know how to talk to the JTAG, and I suggested OpenOCD as a generic means to do that with a wide variety of JTAG devices. Your JTAG vendor may provide their own API; there may even be a command line interface to the Atollic software that you could use (I am not familiar with it so I cannot advise).Clifford

3 Answers

2
votes

Reading MCU ID using ST-Link (graphical interface)

You can use ST-Link Utility (can be downloaded from ST.com here: http://www.st.com/en/embedded-software/stsw-link004.html). After you do Target->Connect you can specify the address and number of bytes you want to read on top of the Window. This also works for the memory area where MCU ID is defined.

For STM32L476 MCU that you use it's going to be memory address 0x1FFF7590, size 0xC (96 bits). Pressing enter should allow you to see the unique ID read from the MCU you're connected to, in form of 3x32 bit values.

Reading MCU ID using ST-Link (command line interface)

ST-Link Utility provides CLI (command line interface) to do the most common operations. This is done using ST-LINK_CLI.exe located in your ST-Link Utility installation directory.

Reading Unique ID as 32-bit values (STM32L476 MCU from the example):

ST-LINK_CLI.exe -r32 0x1FFF7590 0xC

Reading as 8-bit values:

ST-LINK_CLI.exe -r8 0x1FFF7590 0xC

You can also read it to file using -Dump parameter:

ST-LINK_CLI.exe -Dump 0x1FFF7590 0xC D:\temp\out.bin

Keep in mind that you must have the priviledges to write to the destination directory. If you don't run the command prompt with administrative priviledges, in most common cases this means that you won't be able to create the file in locations such as root drive directory (C:\out.bin) or inside "Program Files", where most likely your program is installed (for example by specifying a relative path, such as giving an output file name only out.bin). The program sadly doesn't inform about failed attempts to write the file, however it does say when it succeeds to create the file. The program execution should end with a green line saying Dumping memory to D:\temp\out.bin succeded. In addition, keep in mind that only the following file extensions are supported: *.bin *.hex *.srec *.s19. It cannot be anything because the extension determines the format in which the data will be written to the file.

You can find more information about CLI parameters in User Manual UM0892.

Reading MCU ID using C code

The same can be done using a program loaded into the MCU. You read it by simply accessing the memory directly. Sample code:

#define STM32_UNIQUEID_ADDR 0x1FFF7590
uint32_t id[3];
id[0] = *(STM32_UNIQUEID_ADDR + 0);
id[1] = *(STM32_UNIQUEID_ADDR + 1);
id[2] = *(STM32_UNIQUEID_ADDR + 2);

After this operation id array should contain the same 3x32bit values you've previously read using ST-Link Utility. You may of course choose to read it as uint8_t byte array of size 12, you may even choose to read it into a struct, in case you're interested in the details (lot number, wafer number etc.). This example should however give you a general idea of how to access this value.

0
votes

There is Texane stlink, that does what you want. It's written in C, interacts with STM32 chips through an ST-Link adapter, and it can read from chip memory.

0
votes

What you are looking for is not a feature of ST but a feature of ARM.
Remember, ST simply uses an ARM core. I know most programmers load some code in RAM and use that to access flash. You can find these simple programs in the install directory or Keil for example.

I think this is the manual you will need. But I don't know if there is more information behind the login-wall.