Based on the documentation I'm pretty sure the answer to this question is "You can't.", but it's worth asking anyway. On STM32 processors is there any way to determine the specific CPU type in software? (ie, I'd like to be able to tell if my code is running on an STM32F407x, an STM32F417x or an STM32F437x)
Asked
Active
Viewed 2,776 times
1
-
here https://stackoverflow.com/questions/48327625#48353946 is description how to read this with JTAG, but same way you can read CPU type with accessing registers, but as mentioned problem is to make difference between 407 and 417, you need to check of existence of some peripherals like crypto. – vlk Feb 27 '18 at 15:41
2 Answers
1
The information you're after is in the DBGMCU_IDCODE
register. You can tell if you're a 407 or 437 from there, but I don't think you can tell whether you're a 407 or 417.
You could try writing to the crypto unit, and see if it works to tell the difference between a 407 and a 417, I don't know that it would be reliable though.

Colin
- 3,394
- 1
- 21
- 29
-
1I have several thoughts: 1) If you are planning to use the Crypto features, you need a 417. It should be acceptable to crash if the code is used on the wrong chip. 2) If you are not planning to use crypto, does it matter if you are on a 407 or 417? 3) Sometimes chips are made with the same die, and "downgraded" to keep yield if there are flaws. It's possible that a chip was made with a 417 die but the crypto unit is flawed, so it is marked and sold as a 407. Writing to the registers could reveal the presence of the crypto unit but it cannot be relied upon. – mbmcavoy Mar 01 '18 at 17:22
-
I can imagine you might want to fall back to a software implementation of crypto on a 407, (or other chip-dependent features) but making a common image with chip/feature detection seems risky. You could have common source code with a compile-time flag, and use an image built for the specific chip as stated in the answer from @PeterJ_01. – mbmcavoy Mar 01 '18 at 17:32
1
There's a HAL library for getting pretty far along:
- https://stm32f4-discovery.net/2015/09/hal-library-27-identification-for-stm32fxxx/
- http://stm32f4-discovery.net/hal_api/group___t_m___i_d.html
You may be able to extend these if your specific devices aren't covered. It probably uses the same register as Colin's answer as its starting point.

Dave Newton
- 158,873
- 26
- 254
- 302
-
Indeed it does use that register, in fact that's pretty much all it does. – teryret Feb 27 '18 at 15:31
-
@teryret Yeah, I was afraid of that--oh well! I don't know the difference between a 407/417 off the top of my head, but there's almost always a register or behavior or two that can be used to narrow things down. It looks like Colin's Crypto Hash processor approach would work to differentiate the two, though. – Dave Newton Feb 27 '18 at 15:32
-
@DaveNewton I believe the only difference is the 417 has the crypto processor – Colin Feb 27 '18 at 15:36