Portenta H7 GPIOs

I'd like to share my experience and code for using the unused pins on Portenta H7 MCU module as digital GPIO pins (input, output, open-drain, not as EXTI yet).

You will see (as I did) signals called PA0_C, PA1_C, PC2_C and PC3_C (on MCU module header J2).
How to configure such PA0_C. And what does it mean, this _C?

OK, I got it, based on this:
STM32H7xx GPIOs

There are pins for PA0 as well as PA0_C. If available depends on the chip (e.g. BGA package). We have it this way on Portenta H7 (the biggest package used with all the pins).

But just using PA0 (instead of PA0_C, which is physically a different ball/pin) will not work.
_C is a direct analog input pin. It can be switched (internal analog switch) in order to be connected with the other pins (here PA0_C can be analog switched with PA0, and you configure and drive PA0 but it comes out on PA0_C).

So, you had to do something like this:

HAL_SYSCFG_AnalogSwitchConfig(SYSCFG_SWITCH_PA0, SYSCFG_SWITCH_PA0_CLOSE);

OK, it works. Attached my GPIO_usr files:
GPIO_usr.h (1.1 KB)
GPIO_usr.cpp (4.8 KB)

Strange is just PA1_C:
it shows me a low voltage of approx. 326mv (much higher as the others when set to low) and 3.08V (lower as the others with 3.1V as driving high).
Is this signal connected to something else on the board?
I use the breakout board. Maybe, it is intended to monitor battery voltage, it is connected to battery charger... Why the voltage there is different as the other GPIOs? (still to TODO a schematics check if signal goes to something else)

Dear community, potentially you can teach me:
mbed uses actually different methods to configure GPIOs. I see pins as numbers, e.g. 166 for green LED (instead of GPIOx, GPIO_PIN_y, as I use via STM HAL).

  • Where could I find the GPIO pin definition (pin numbering) for mbed and this board?

  • Is the name in schematics for Portenta H7 MCU module, e.g. as J2-75 (as for PA1_C), a hint that it is pin number 75 in mbed software?

  • When it comes to PA1_C pin - can I configure as GPIO input and output and does it do this analog switch configuration for me?
    (Otherwise it would not come out when just PA1 is configured, as I understand it has to be "cross-connected" with other ball/pin PA1_C via analog switch.)

BTW: VDD_IO is just 3.1V - not 3.3V
When you see schematics or you measure voltage on pull-ups, GPIOs driven high - the voltage on board is just 3.1V, not 3.3V. So, all the IO voltages are just 3.1V.

OK, just a smaller noise margin for digital signals. But potentially you had to be careful when you connect Portenta H7 to another external HW which is running with 3.3V. Pins should be 5V tolerant when used as input. But if you have a higher load on GPIO output pins - the high voltage level on external HW can be seen a bit lower, resulting in a threshold issue to realize a high level.

(why board runs just with 3.1V? For power saving reasons? OK, the PMIC involved: does it need this drop for a stable voltage out?)

Even though you didn't ask, I'll start with the Arduino pin number. These are defined in the core variant:

https://github.com/arduino/ArduinoCore-mbed/blob/3.1.1/variants/PORTENTA_H7_M7/pins_arduino.h#L31

#define LEDG        (24u)

So the LEDG macro is a convenient name for Arduino pin 24. Arduino pin numbers are the index of g_APinDescription[]:

https://github.com/arduino/ArduinoCore-mbed/blob/3.1.1/variants/PORTENTA_H7_M7/variant.cpp#L49

  { PK_6,         NULL, NULL, NULL },    // LEDG

And now the definition of PK_6 for this Mbed OS target in the core:

https://github.com/arduino/ArduinoCore-mbed/blob/3.1.1/cores/arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_PORTENTA_H7/PinNames.h#L311

    PK_6       = 0xA6,

Cool, thank you.
But still confused:

You say: green LED, LEDG is (24u) (as I can see in this file mentioned).
But if I use in myProject this code (which works):

pinMode(LEDG, OUTPUT);

it shows me LEDG as value 166. Going to the definition it ends up in file .myProject.vsarduiono.h .
And there is this code:

enum {
	// LED_RED
	LEDR = 165,
	// LED_GREEN
	**LEDG = 166**,
	// LED_BLUE
	LEDB = 167
};

OK, I see also PIN_A0 in other file and a static const A0 initialized with PIN_A0.
Just: based on this LEDG "number confusion" - I do not trust the numbers in this file.

There is also this:

#define NUM_DIGITAL_PINS     (22u)
...
#define D0  (0u)
...
#define LEDB        (25u)

So: 22 total pins but numbering seen from 0..25. It confuses me even more (less pins as defined).

Plus: when I want to use PA0_C as GPIO - am I sure that it will do the analog switch as well?
File gives me a PIN_A0 and static const uint8_t A0 = PIN_A0. But it would just configure PA0 (instead of PA0_C) - it would not work.

I think I miss the functions to use in combination with this pins_arduino.h. Obviously, my LEDG is defined differently. (What does generate this .MyProject.vsarduiono.h? I have not created.)

Do you have an example where the values in pins_arduiono.h are "really" used?
(esp. for PA0 as GPIO)
Thank you.

I guess it must be something specific to Visual Studio or Visual Micro. It is nothing to do with the official Arduino build system. The information I shared is correct for the Arduino build system. I assumed they used the core in the same manner, but I see now that was not a safe assumption.

I don't have any knowledge of those tools other than that I tried them out years ago and found they were not at all to my liking.

No. 22 "digital" pins. It is not necessarily the same thing. For example, note this:

I could give you one if you were using the official Arduino build system, but I can't help you with Visual Micro. I'm sure one of the other forum users is familiar with that system though.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.