cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO Pin Assignment

KMew
Senior III

I am trying to understand how to configure a custom GPIO pin via the CubeMX/CubeIDE. I am using the STM32H7B3I-EVAL. Through the CubeMX, I am trying to assign PA13 to a GPIO (in output mode). I enabled PA13 via the CubeMX without issue.

0693W00000WHdlhQAD.png 

Now I want to configure the GPIO in the CubeIDE and use it. In the GPIO Example for my STM32H7B3I-EVAl board, they configure it as follows:

  /* Configure IO in output push-pull mode to drive external LEDs */
  gpio_init_structure.Mode  = GPIO_MODE_OUTPUT_PP;
  gpio_init_structure.Pull  = GPIO_PULLUP;
  gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  gpio_init_structure.Pin   = GPIO_PIN_13;
  HAL_GPIO_Init(GPIOG, &gpio_init_structure);

What I don't understand is how they knew that gpio_init_structure.Pin = GPIO_PIN_13.

How did the example know to use PIN_13? How do I know which pin PA15 should be?

1 ACCEPTED SOLUTION

Accepted Solutions
gbm
Lead III

Read The Fine Manual (and the Datasheet) (and the board's manual). PA13 & PA14 are SWDIO pins, used for programming and debugging. Other than that, you may use any pin you want as long as its use does not conflict with its connection on the board you have..

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

View solution in original post

8 REPLIES 8
gbm
Lead III

Believe me, you don't want to assign PA13 as g.p. output - it's the debug interface pin.

And GPIO_PIN_13 is simply the bit mask of any port's line no. 13. It has nothing to do with physical pin numbering. So PA15 will be GPIO_PIN_15

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

Hello gbm,

Thank you for the warning. This leads to two follow-up questions:

1) What pins should I use for GP outputs?

2) Once I select the pin, how do I configure and use that pin? There's a command to toggle the pin (Example: HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);). How do I know which GPIOx and GPIO_PIN to use?

>>1) What pins should I use for GP outputs?

Ones that are NOT used or connected to other things in the design. Perhaps use the Schematic as a guide, but expect the EVAL board to be using most already, the design is dense, supporting a lot of functionality. Schematic for the board can be found under the "CAD Resources" of the product's landing page.

The code snip configures PG13 not PA13, perhaps PG13 is already associated with a LED, again there's the schematic. If in doubt refer to the manuals or documentation.

PA13 is part of the debug interface, you reconfigure that, and you likely lose the ability to download/debug.

NUCLEO boards would have many more available pins, and a Shield connection

DISCO boards also typically have a Shield connection, but many other pins are already utilized.

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

Read The Fine Manual (and the Datasheet) (and the board's manual). PA13 & PA14 are SWDIO pins, used for programming and debugging. Other than that, you may use any pin you want as long as its use does not conflict with its connection on the board you have..

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

Hello gbm,

In the CubeMX view, it has many of hte pins greyed out. That would mean they're not being used, correct? So if I use one of those greyed out pins, it should not affect any other functionality, correct?

I think it means they are not in use by the peripherals you have currently enabled in the project.

I don't think it means they are not physically committed to some other functionality via the wiring on the board.

Expect close to 98% commitment of all pins to other functionality on the EVAL board.

How egregious those conflicts are depends on what/how those pins are connected too. Have your HW engineer review the board level design.

The EVAL boards are NOT good break-out boards. They are KITCHEN SINK boards where ST has built about every piece of functionality it can demonstrate into a single board. So Screens, SDRAM, Parallel NOR Flash, Serial NOR Flash, Ethernet, Serial, CAN, CAMERA, etc.

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

Hello Tesla,

Yes, I am certainly starting to realize this. It was the board my company gave to me for doing testing of a new board since it had a bunch of functionalities. For sending out custom GPIO signals, it does seem to be quite the headache...

Thank you for the help though! I will have to figure out what pins I can use.

@gbm​ , i agree with you, i just got handled a board in which the designer decided to use the SW pins as gpio outputs , everything is so much harder now

we dont need to firmware by ourselves, lets talk