1
\$\begingroup\$

I'm looking to programmatically read the serial number out of a device which uses an STM32 (L07x / L08x / L010). I can read the serial using the STM32 St-Link Utility GUI by reading addresses 0x1FF80050, 0x1FF80054, 0x1FF80064 (using size: 0x4, data width: 32 bits).

I now need to do this programmatically. I'm using st-tools to flash firmware, so thought I could use this to read the addresses out.

I've tried to do it as follows:

st-flash --format ihex read part1.hex 0x1FF80050 32
st-flash --format ihex read part1.hex 0x1FF80054 32
st-flash --format ihex read part1.hex 0x1FF80064 32

It produces an output which I'm finding difficult to parse to extract the serial I need. E.g. part1.hex produces this:

:020000041FF8E3
:100050003139510E363135341100000000FFFFFFF9
:1000600011008C6715002E00000000111100001116
:00000001FF

...where the St-Link utility gives me 0E513931.

I'm not hugely familiar with STM32 kit - can anyone advise if there's a more concise way to retrieve the serial number?

asked Mar 8, 2021 at 16:29
\$\endgroup\$
2
  • 2
    \$\begingroup\$ This is the standard Intel-HEX format. But I am under the impression that it reads 32 bytes and not 32 bits what you expect it to do, so maybe change the 32 to 4 and have a look at it then. Intel-HEX records aren't all that hard to parse. \$\endgroup\$ Commented Mar 8, 2021 at 16:40
  • \$\begingroup\$ Thanks. I've opened the files with Okteta to try and understand how to break them up into the format I need (see response to Justme below). I'll try changing the 32 to 4 as well. \$\endgroup\$ Commented Mar 9, 2021 at 13:16

1 Answer 1

2
\$\begingroup\$

You have already read serial number, and far beyond it. You are not reading 32 bits, but 32 bytes from the starting offset.

You just need to understand how the Intel Hex format encodes data.

For instance, the serial number 0E513931 said by the ST-Link utility is the first 32 bits in the first dump file, it just reads 3139510E because that is how it is stored in the memory and then it goes on for the rest of the serial number bytes and the unused area is FF bytes.

answered Mar 8, 2021 at 16:45
\$\endgroup\$
3
  • \$\begingroup\$ Thanks, I'll try to do some reading up on the Intel Hex format. I'm more familiar with programming web technologies, so there's a bit of a learning curve. Is there a way to convert the 3139510E to 0E513931 format? The latter is the format my web app is used to seeing. Any pointers would be appreciated \$\endgroup\$ Commented Mar 9, 2021 at 13:15
  • \$\begingroup\$ Convert? Bytes stored in memory as 31 39 51 0E means exactly the same thing as printing that as an integer (in hex) to get 0x0e513931. If the Intel Hex format is hard, simply read as binary then. \$\endgroup\$ Commented Mar 9, 2021 at 14:12
  • \$\begingroup\$ Sorry, my lack of knowledge. A combination of Linux utilities, and I can successfully cut out the data I need. This URL was handy: dlwrr.com/electronics/tools/hexview/hexview.html \$\endgroup\$ Commented Mar 9, 2021 at 17:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.