Electronic – Recommendation for default settings for unused pins on an STM32 (ARM Cortex M3) – pull up/pull down

best practicemicrocontrollerpulldownpullupstm32

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.


Best Answer

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.