16

I am working with STM32 micro-controllers. These micro-controllers have the option to set the input pin as pull up or pull down:

enter image description here

Earlier I used to give external pull up or pull down resistor wherever required but now I am wondering whether I can do away with external components and use the pull down feature of the micro-controller itself.

Will that be a good thing to do?

Is there some use case where I should take extra precaution or not use this feature at all?

Bence Kaulics
  • 6,353
  • 12
  • 33
  • 60
Whiskeyjack
  • 7,946
  • 8
  • 53
  • 91
  • 2
    I use the internal pu/pd whenever I can and had no problems sofar. So unless you have a valid reason **not** to use the build-in pull up/down you can just use them. A reason not to rely on the internal pu/pd could be that the input has a long wire connected to it which might couple to other lines causing unexpected behavior. The internal pu/pd is quite weak (to save current) and is more easily disturbed than for example a 10 kohm resistor. – Bimpelrekkie Nov 22 '16 at 09:46
  • @Fake - Thanks. Looks like I can use it without any worries. My input is opto-isolated. – Whiskeyjack Nov 22 '16 at 10:05
  • 25
    A little note: it may not function as a pullup while the microcontroller is resetting. So if there's external circuitry depending on it being pulled down all the time, you may have a problem at startup. If it's just being read by the micro, this is not a problem. – pjc50 Nov 22 '16 at 10:18
  • 1
    @pjc50 you should have posted that as an answer, I didn't notice your comment until after I posted my answer. – Jason S Nov 22 '16 at 13:48
  • 1
    If you can't trust the pull up resistor in a microcontroller, you can't trust anything in that controller. What you want to know is if it's useful though – Passerby Nov 22 '16 at 18:23
  • @Passerby - Yeah you are right. Wrong choice of words on my part. – Whiskeyjack Nov 22 '16 at 20:29
  • 1
    @Whiskeyjack: You should consider changing the questions title. Maybe "Considerations when using internal pull-up/down resistors" or something like that. – Rev Nov 23 '16 at 19:15
  • @rev - Yeah that is a much better title that you suggested. Thanks. – Whiskeyjack Nov 23 '16 at 19:26

5 Answers5

18

In general, it is perfectly fine to use the internal pull-up or pull-down resistors.

Disadvantage is that you can forget to enable it from software, that can cause a little headache. The external pull-ups will always be there. So do not forget to enable the internal ones and save a lot of PCB area by reducing component number.

The STM32's internal pull-up and pull-down resistors usually have a value between \$ 30\small~k\Omega \$ and \$ 50\small~k\Omega \$.

enter image description here

You should always check if your application needs a certain pull-up or pull-down resistor value before using the internal resistors. For example do not use them with I2C, as these values will be too high for that.

Bence Kaulics
  • 6,353
  • 12
  • 33
  • 60
17

Yes... You can... It's a proven feature. If you see pin structure in STM32 Reference manual, you can see that it has required components --

STM32 Pin structure

If this satisfies your requirements, then, you can do away with external components.

Edit Remember that at Power up, Pins will be tristated. If it does not hamper your application, it is good! That's why it's good practise to init IO section first and then go ahead with other peripherals.

Swanand
  • 3,245
  • 5
  • 28
  • 45
14

Unless the pullup and pulldown resistors are active during reset (I suspect they aren't, but I'm not familiar with STM32 devices), there is an undefined pin state at reset. This is one major reason to use external pullup or pulldown resistors.

Jason S
  • 13,950
  • 3
  • 41
  • 68
10

As others have said, internal pull-ups and pull-downs are fine as long as:

  • you remember to configure them,
  • they are strong enough,
  • you do not end up fighting them with an external pull, and
  • the voltage at start-up and reset is unimportant.

On the last point, remember that CMOS inputs at mid-voltage level can cause significant shoot-through current on their input pair. This can cause a problem in a low power system during start-up.

In general, external pull resistors will yeild a more conservative design.

Richard
  • 399
  • 1
  • 4
  • 1
    With regard to shoot-through currents, it might be helpful to put things in perspective by noting that for most microcontrollers the levels are generally far below anything that would cause damage to a device, but they may be orders of magnitude above a device's best-case sleep currents. In some cases, such currents don't matter; in others they're an absolute killer. – supercat Nov 22 '16 at 15:41
  • 1
    +1 for "the voltage at startup and reset is unimportant". You need to guarantee that the rest of your circuit is in a safe and quiescent state while the micro is starting up. This is harder than it looks, when you consider that a reset or fast power-cycle may leave the rest of your circuit in an indeterminate state, or leave it powered up and running without the micro keeping an eye on it. – Graham Nov 23 '16 at 12:09
5

In addition to the other fine exceptions listed in all the answers, the internal pull-up resistors are too weak for I²C in many cases.

Peter Mortensen
  • 1,676
  • 3
  • 17
  • 23
Scott Seidman
  • 29,274
  • 4
  • 44
  • 109
  • 2
    ... case in point: [What happens if I omit the pullup resistors on I2C lines?](http://electronics.stackexchange.com/questions/102611/what-happens-if-i-omit-the-pullup-resistors-on-i2c-lines) – Nick Alexeev Nov 22 '16 at 21:19
  • Of course, some (many?) microcontrollers have open-drain pins specifically for I2C that you can configure – Thomas Nov 23 '16 at 08:02
  • 2
    I haven't seen anything but weak pull ups/downs, @Thomas – Scott Seidman Nov 23 '16 at 11:33