Skip to main content
AKrup
Associate III
March 20, 2019
Question

Can running code find out the part number it's running on?

  • March 20, 2019
  • 4 replies
  • 1050 views

I'm writing code for STM32F042. If I'm running on the TSSOP20 package, I need to remap PA11 and PA12 to PA9 and PA10. For all other packages, I need to leave them alone.

I can have a compile-time switch and generate different binaries for different packages. Ideally, I'd like to have a single binary. It's only a small difference in code, and I'd like to avoid the potential for confusion about flushing the wrong binary.

This topic has been closed for replies.

4 replies

Tesla DeLorean
Guru
March 20, 2019

There might be some bits in unique id. Otherwise look if there are bits in OTP you can utilize.

Diff the ROM/OTP and see if anything drops out.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
AKrup
AKrupAuthor
Associate III
March 22, 2019

Sadly, I don't have any of the TSSOP parts or boards to solder them to. The next version of the board may use that package, and I need to decide what, if anything I need to put on the LQFP board to accommodate this future change.

Geoffrey1
Associate III
March 22, 2019

Interesting question. The stm32l4 has a package register defined that can be used to determine the package type, but it doesn't look like the stm32f0 does. However, there are some user definable bytes in the option registers part of flash -- these don't get erased by ordinary flash options. You could "label" the boards with the TSSOP versions by writing something in one of these bytes that your firmware could read. An extra manufacturing step for sure, but might solve your problem

AKrup
AKrupAuthor
Associate III
March 22, 2019

I can also put a version ID resistor on an ADC pin or pull some GPIOs up or down to indicate board version. I was hoping to avoid relying on such out-of-band information :=)

In a way, I prefer encoding the version in the physical board layout. This way hardware features (package type) is encoded in a medium that can only change with hardware changes.

Thank you for the info about the larger chips. I have no experience with them, and it's valuable knowledge that this feature is available on the larger parts.