2
\$\begingroup\$

While trying to configure the GPIOs using CMSIS on a NUCLEO-F103RB board, I couldn't seem to find in the reference manual how one is supposed to choose between internal pull-up and pull-down resistors.

Page 160 shows the configuration of the CNF and MODE bits and shows that the bits are the same for pull-up and pull-down. Searching the entire PDF file for "pull-up" and "pull-down" yields no results. The errata also has no mention of this.

Did ST seriously forget to put this information in the manual? If so, how come no one has noticed this? Or am I just being blind?

Anyway, looking at their standard peripheral library, it seems that writing a 1 to the corresponding bit in the GPIO BRR register activates the pull-down resistor, while writing a 1 to the BSRR actives the pull-up resistor:

    /* Reset the corresponding ODR bit */
    if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
    {
      GPIOx->BRR = (((uint32_t)0x01) << pinpos);
    }
    else
    {
      /* Set the corresponding ODR bit */
      if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
      {
        GPIOx->BSRR = (((uint32_t)0x01) << pinpos);
      }
    }

This code can be found in the stm32f10x_gpio.c file.

\$\endgroup\$
9
\$\begingroup\$

The information you are looking for is in the manual, but not as obvious as it could be. The table you mentioned on page 160 contains more info:

gpio

As you can see, assuming the pin is configured as an input, the value in the ODR registers is the deciding factor as to whether the pin is pull-up or pull-down.

You can set and/or clear all these bits at once by writing a 16-bit value to the appropriate GPIOx_ODR register, or you can set/reset them individually by using the GPIOx_BRR and/or GPIOx_BSRR registers.

Interestingly, the same ODR register controls the pin state (high or low) when the pin is configured as an output.

I've found that I can sometimes learn more about the workings of the STM ARM controllers by reading through their Standard Peripheral Libraries than their reference manuals!

\$\endgroup\$
  • \$\begingroup\$ I like how it was right in front of my eyes and even though I looked at that table so many times I still couldn't see it. facepalm. Thank you. \$\endgroup\$ – Chi Jan 17 '17 at 9:01
  • 1
    \$\begingroup\$ @Chi Ha! That happens to me more than I like to admit :) \$\endgroup\$ – bitsmack Jan 17 '17 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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