cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 GPIO mode and pull

Dick Lin
Senior

Hi,

How to setup gpio pull? If I have INPUT, should I setup to PULLUP or NOPULL or PULLDOWN?

How about OUTPUT?

Thx

GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

GPIO_InitStruct.Pull = GPIO_PULLUP;

9 REPLIES 9

I'm confused as to who you are, and you've not answered previous questions. Are you a student? Do you work for a company? In what capacity? Trying to gauge how to answer your questions, if you're a high school student it would be useful to know.

Depends on specific application. Is the pin wired to some source that might be disconnected, or is naturally open.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Dick Lin
Senior

I work for a company doing battery management board using STM32L4A6VG. I am investigating a issue with STM32L4A6VG consume too much power both running (80 mA) and standby mode (10 mA).

Here is an example for the CAN bus init, the upper comment out code is the code running on Nucleo-144 board but consume 40 mA more than the code down below. I am in the stage can't verify if the code running on our board. Why those setting make so much difference in terms of power consumption?

//  GPIO_InitStruct.Pin = GPIO_PIN_0;

//  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

//  GPIO_InitStruct.Pull = GPIO_PULLUP;

//  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

//  GPIO_InitStruct.Alternate = GPIO_AF9_CAN1;

//  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

//

//  GPIO_InitStruct.Pin = GPIO_PIN_9;

//  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /**CAN1 GPIO Configuration

  PD0   ------> CAN1_RX

  PB9   ------> CAN1_TX

  */

  GPIO_InitStruct.Pin = GPIO_PIN_0;

  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

  GPIO_InitStruct.Alternate = GPIO_AF9_CAN1;

  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = GPIO_PIN_9;

  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

Another thing I am looking into is the GPIO pin setting. Before going standby, should I set all of GPIO to high impedance (my test so far doesn't help at all.)? We are thinking we might need do something before going standby mode than just call HAL_PWR_EnterSTANDBYMode() function.

Is there anything I need to do before calling HAL_PWR_EnterSTANDBYMode()?

GPIO_InitStruct.Pin = GPIO_PIN_12;

GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

GPIO_InitStruct.Pull = GPIO_NOPULL;

Thanks

For PP outputs I would not use pull up/down, I would also pick a slew rate that reflects the load being driven, and the wire lengths.

For OD outputs you want a pull-up internal or external. How strong that is depends on the capacitive load and how rapidly you want the pin to go high once released.

For input from a PP source that's alway present, no pull up/down require.

For an input from an OD source, circuit needs a pull-up at one end or the other, ideally close to the input.

For an input from a switch or removal connector, probably want a pull up/down to bring a known state in the open-circuit case.

For an unused input, probably want a pull-down to prevent chance of oscillation.

Use analogue input more when you want to turn off the schmitt-trigger on the input going to the IDR

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

Overkill for a pin that might transition at 1 MHz and is connected to a transceiver.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Dick Lin
Senior

My focus is on the standby mode power consumption for now. I am trying to disable all buses, set one of its GPIO pins at high impedance. So far, doesn't help much.

I am still getting 9 mA in standby mode.

Does seem a bit high, not an experiment I can replicate.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Dick Lin
Senior

It's way too high. See the number below. Maybe I should try stop 2 mode.

– 25 nA Shutdown mode (5 wakeup pins)

– 108 nA Standby mode (5 wakeup pins)

– 426 nA Standby mode with RTC

– 2.57 µA Stop 2 mode, 2.86 µA Stop 2 with RTC – 91 µA/MHz run mode (LDO Mode) – 37 μA/MHz run mode (@3.3 V SMPS Mode)

Dick Lin
Senior

I did try the STOP2 mode, doesn't seems to have any difference with standby mode.

// HAL_PWR_EnterSTANDBYMode();

LL_PWR_SetPowerMode(LL_PWR_MODE_STOP2);

Dick Lin
Senior

I did try the shutdown mode, still same about 9 mA. Basically low power mode is not working at all.

LL_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);