cancel
Showing results for 
Search instead for 
Did you mean: 

PORT D Read errors.

KMill
Senior

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.

Screenshot 2025-07-16 at 16.20.46.png

Screenshot 2025-07-16 at 16.20.13.png

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!

1 ACCEPTED SOLUTION

Accepted Solutions

@KMill did you see my PS?

 

AndrewNeil_0-1752682338541.png

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

View solution in original post

11 REPLIES 11
Andrew Neil
Super User

If you measure the voltage at the STM32 pins, are they going high?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Thanks @Andrew Neil 

The 2 stuck pins are reading 0.24v and the rest are reading 3.26v with the swicthes open.

So the port is actually reading correctly - those bits really are at zero.

The question becomes: why are they not being pulled-up.

As a test, can they be pulled-up with an external resistor?

 

PS:

AndrewNeil_0-1752681760567.png

https://www.st.com/resource/en/datasheet/stm32g071rb.pdf#page=48

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
KMill
Senior

With a 4K7 pull up they are reading as expected (1 when switchopen, 2 when closed) but the voltage on the pins is only getting pulled up to 1.65 V (VCC is 3.3 V)

 

So yip, I agree, the quesion is what has happened to the pull ups?

Let me go read the PUDR register...

mfgkw
Associate III

Which board do you use?

In DS12232 section Pinouts... PD0 and PD2 are said to have an IO structure of "FT_c" where the _c means "USB Type-C PD capable" and they have an additional function of UCPD2_CC1 resp. UCPD2_CC2.

Does your board have an USB port connected to them?

@KMill did you see my PS?

 

AndrewNeil_0-1752682338541.png

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

It's a self-designed custom PCB with nothing else connected to those pins.

This is the schematic for that part:

Screenshot 2025-07-16 171105.png

 

And the PCB (top view)

Screenshot 2025-07-16 171135.png

 

Keep in mind that I have measured the PCB Traces and resistance/conductance when powered off is all as expected.

So now I'm wondering if there's something USBish going on... maybe my USB perohperal is enabled... I'll check.

AHA! A smoking gun!

Thank you - that sounds like exactly the sort of thing that would cause this. I'll try strobing that bit and see what happens.

(never mind)

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.