2025-07-16 8:30 AM - last edited on 2025-07-16 8:59 AM by Andrew Neil
I have an STM32CubeIDE project using HAL for a STM32G071RBT6
I have Port D bits 0 to 6 set up for GPIO Input, with pull-up enabled.
In hardware these are connected to an 8-WAY dip switch, which when each switch is "on" connects the respective pin to GND. (PB3[STOPBITS] is connected to the 8th switch)
The issue is that when I read the port using
id = (GPIOD->IDR & 0x7F); /* Lowest 7-bits are from PORT D0-D6 */
Bits 0 and 2 are always stuck at 0.
With the board powerd off I have tested the board connctions to the chip and the dip switch, all seems OK. There is no short to GND on bits 0 and 2.
I checked the resistance on all the bits of port D and bits 0 and 2 have about 500KΩ to ground, whereas the rest of port D has about 7 MΩ
I have checked through the rest of my code and it's not doing anything else to PORT D, and the alternate-function registers (PORTD->AFR) read all zero immediately before reading from the IDR.
I have five of these boards, all made by JLCPCB (including assembly) and they all do the same thing.
What's causing the bits 0 and 2 to be stuck at 0? Does PULL UP not work on those bits? I could try hand-soldering some stronger pullups on, but it works for the other bits in port d, and it's the same on all boards!
Solved! Go to Solution.
2025-07-16 9:32 AM
@Andrew Neil Thank you!
The STOBE Bit was the issue.
I set the appropriate bit in SYSCFG1 and now it all works as expected.
You have saved me a lot of grief! Who would have thought the Pull-Downs would be enabled when the UCPD Device is disabled?
2025-07-16 9:56 AM
@KMill wrote:The STOBE Bit was the issue.
Great - please mark the solution.
@KMill wrote:Who would have thought the Pull-Downs would be enabled when the UCPD Device is disabled?
Always good to check those little footnotes on the the pinout table - there's a few gotchas!