We are currently using various variants of the STM32 microcontroller family. I would like to know the following:

  1. What are the recommended default settings for pins of the microcontrollers in general if you have the option to select both pull ups or pull downs? What are the pros and cons of going with one or the other? (Assuming you will set them up by default as inputs)

  2. In particular I would like to know what to do with unused pins for the STM32 microcontroller family. It is obvious to me that we should not leave the pins floating, (which is all that the datasheet says, :( ), but should I should set them to input with pull ups or inputs with pull downs? In particular, I would like to choose a setting that is least susceptible to ESD and also if possible, consumes the least amount of power.

  3. For critical pins, should we rely on the firmware to correctly set up the pins to the correct default state or should this responsibility lie with the external hardware (connecting external pull ups or pull downs)? If the values chosen for the external resistors is greater than the internal pull ups or pull downs, the setting in firmware does not matter.

The pro that I can see for doing the above, is that if the micro does not initialise properly for whatever reason (faulty hardware or the likes), we are not relying on the firmware to set up the pin correctly.

The con I see is that it costs more to do this is hardware.

Any light that you can shed on the above will be really appreciated.


  • \$\begingroup\$ Why not set unused pins as outputs? That would eliminate the pull-up vs pull-down issue. \$\endgroup\$ Commented Oct 18, 2011 at 7:50
  • \$\begingroup\$ Of note: "Upon any reset event all GPIOs are floating inputs. This prevents any accidental damage to GPIOs in the event of emergency." embedded-lab.com/blog/stm32-gpio-ports-insights \$\endgroup\$
    – cp.engr
    Commented Nov 4, 2016 at 18:37

3 Answers 3


This answer is not STM32 specific but is based on experience and many such discussions over many (many) years. Others can add to this - it covers the main points (I think) but may not be complete.

It's encouraging to see someone asking these simple but fundamental questions and showing an awareness how such "little things" can 'gang aglae' in real life.

ie "If the micro does not initialise properly ..." really reads " ... when the micro does not initialise properly ..." :-) - and it's obvious that you realise this.


  • Use of external pullup or pulldown is essential for those really keen on getting a well defined result. This is the single biggest must-do here. All the rest is a bonus. ie Setting to inputs with internal pullxxx is a compromise which will almost always work.
    BUT if "almost always" is not good enough for your design then you need external pull xxxs.

  • Pullup or down does not seem to have an overwhelming better result. It may vary between ICs but can be determined from the data sheet. All things being equal (as they may be) I'd favour pull-down as there is a potential for lower leakage currents to device external circuitry - but this is liable to be minimal in a conformally coated PCB and/or a benign environment.

  • You may wish to look at startup action if you really care. eg a pulled up pin will start low and transit high at some stage. A pulled down pin will probably stay low throughout. This is probably not important but is mentioned for completeness.

  • ESD susceptibility will be device specific, quite likely symmetric and on average over many processors probably favours pull down as drivers tend to sink better than source if asymmetric. If you care a lot about ESD then you may wish to use low outputs with pull downs - as a a low impedance path will (probably) offer better ESD protection. But if you care a lot about ESD you will want to design for it in other ways and not rely on in-IC protection as your main protection.

  • Re question 3 - external pullxxxs is desirable but it seems safe to use values which are at the limiting high end of proper design and then use internal xxx's in parallel if desired. However, as internal pull xxxs often have a 2:1 Reffective you can get largest R and smallest current by using external only. What you of course want to avoid is external pull ups and internal pull downs or vice bersa - but that's unlikely to be an issue.

  • When I say " ... limiting high end of proper design ... " I mean just that and not "past the limiting ...". ie the pin will have a specified value of resistance which allows the worst case Vin spec to be met. A larger resistor may take less current in the resistor but may start to very slightly turn on the internal switch. ie it may be that there is an Rpulldown_current versus lowest overall current tradeoff as the internal driver starts to see leakage current (which will be extremely small) increasing the current to the dirver and whispering it on very slightly.

  • If you use eg pulldown you may then find it lower power to set the pin to output and drive it low, but this is an option that can be decided on in due course.

  • Almost an aside - NEVER allow protection diodes to handle "any significant currents" at any stage during operation. Allowing them to do so can lead to totally inexplicable processor action. The less the current the lower the chance of things gong wrong - and the harder to find it when they do.

  • 1
    \$\begingroup\$ Very insightful answer. Thank you very much. Can you elaborate a bit more on this - "If you care a lot about ESD then you may wish to use low outputs with pull downs - as a a low impedance path will (probably) offer better ESD protection" ? If setting to an output - would you go open drain or push pull (high/low) by default? \$\endgroup\$ Commented Oct 18, 2011 at 20:26
  • \$\begingroup\$ @IntelliChick The whole point of setting it is an output is to drive it to a known state at low impedance which means you would most definitely NOT set it to open drain, especially open drain with a HI output since that's just high impedance. \$\endgroup\$
    – DKNguyen
    Commented Feb 24, 2020 at 2:32
  • \$\begingroup\$ @DKNguyen 8+ years on ... :-). And Intellichick has not been seen these 8+ years - BUT still worth adding your comment. \$\endgroup\$
    – Russell McMahon
    Commented Feb 24, 2020 at 8:44
  • \$\begingroup\$ @RussellMcMahon Release yourself from the prison that is the conventional perception of time. \$\endgroup\$
    – DKNguyen
    Commented Feb 24, 2020 at 8:51
  • \$\begingroup\$ @DKNguyen I long ago made fiends with photons. We live in the eternal now. I still don't, however, manage to achieve what they do. ALL photons live in a timeless, "spaceless" togetherness. A photon that leaves Sol and a photon that leaves alpha centauri proxima are together at all times, never know the meaning of arrive first or last or time between. When I ask them how to achieve that they just smile. || A steady trickle of people comment on my posts many years after they are posted. Or even edit them. Yours as well, no doubt. \$\endgroup\$
    – Russell McMahon
    Commented Feb 24, 2020 at 10:06

I just configure unused pins as outputs and set them low.

  • \$\begingroup\$ would you normally set them to push-pull or open drain? And in both cases would you set them to low? Can you tell me why you would choose one over the other. \$\endgroup\$ Commented Oct 18, 2011 at 20:22
  • \$\begingroup\$ @Leon Heller - that meets the "works usually" test, but fails "when the micrprocessor does not initialise properlY, or when Murphy flips a bit semi randomly, as he occasionally does. Your 'pin set to output & set low' PLUS pulldowns, works . \$\endgroup\$
    – Russell McMahon
    Commented Oct 19, 2011 at 6:46

What are you optimizing for? Cost optimization dictates that you set unused pins to outputs. Reliability optimization dictates that all pin levels are defined, even in the short period before the firmware has the chance to set unused pins to what it deems appropriate.

I once had to check the reliability calculations of a processor board. It was well designed, with decoupling caps all over the place and pull-to-whatever resistors on all I/O pins. The reliability engineer took out his handbook, added the failure rates of all components involved, and ended up with a figure that was dominated by the failure rates of the passive components. That figure was higher than the requirement, so we had a problem. Remove those resistors, and the figure would be OK. But at that proposal the electrical engineers started to shout in anger (rightly so, IMO). I don't recall how the story ended; I think we went to the client and asked dispensation for omitting the failure rates of the resistors from the calculation, on the grounds that they carried no significant current.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.