Skip to main content
LVara.1
Associate III
March 26, 2022
Question

Externai interupts for I/O pin in OUTPUT

  • March 26, 2022
  • 7 replies
  • 1918 views

I'm using a board Nucleo Stm32F401RE on Stm32Cube 1.8.

A simple question : I have cofigured, in MX, I/O pin PC5 as GPIO_EXT_INT5

with interrupt in falling edge , pull_up enabled and NVIC[9:5] enabled

Remember: in Nucleo board PA5 pin control in OUTPUT a green led on board

Genereting the configuration code I have:

/*Configure GPIO pin : PtPin */

 GPIO_InitStruct.Pin = LD2_Pin;

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

 HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);

 /*Configure GPIO pin : PC5 */

 GPIO_InitStruct.Pin = GPIO_PIN_5;

 GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;

 GPIO_InitStruct.Pull = GPIO_PULLUP;

 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

OK.

In stm32f4xxit.c I have:

void EXTI9_5_IRQHandler(void)

{

 HAL_GPIO_EXTI_IRQHandler(LD2_Pin);

}

WHY LD2_PIN ??? I asked interrupt for GPIO_PIN5 in GPIOC in Falling edge!

many thanks ...

This topic has been closed for replies.

7 replies

KnarfB
Super User
March 26, 2022

The EXTI interrupts don't care about the GPIO port, only about the pin number. LD2_Pin == GPIO_PIN_5 in you case, so the code is not wrong, maybe not plausible.

hth

KnarfB

Tesla DeLorean
Guru
March 27, 2022

Did you create the "PtPin" name?

There have been complaints about the tools muddling up pin names/designations.

But what PC5 gets configured with doesn't look problematic for working as an EXTI, the "Output" mode isn't carrying over between individual pin configurations here.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Pavel A.
March 27, 2022

The "PtPin" and inappropriate use of user defined pin names are artifacts of Cube generator.

Already reported several times. Can only hope they fix it soon.

S.Ma
Principal
March 27, 2022

Manually configure the pin as non exti, then hack the EXTI hw register to enbale the inrerrupt. I guess it is similar to people who need EXTI on alternare function pins.

LVara.1
LVara.1Author
Associate III
March 27, 2022

The correct PtPin was

 /*Configure GPIO pin : PtPin */

 GPIO_InitStruct.Pin = tasto_Pin;

 GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;

 GPIO_InitStruct.Pull = GPIO_PULLUP;

 HAL_GPIO_Init(tasto_GPIO_Port, &GPIO_InitStruct);

Nothing useful in the stm32f4xx_it.c file. This was an example....

Obviously in the real application I had at least 4 output pins which conflicted with EXTI pins. I changed the names in the stm32f4xx_it.c file by hand. But all this wastes a lot of time, especially if you are a teacher, with 20 young people who have some difficulty understanding how interrupts work ..... If you use two EXTI on two pins of the same number, MX obviously reports the conflict . In this case I did not understand which name is chosen. Thanks and good job!!

Pavel A.
March 27, 2022

For the original question (can an output pin be used as EXTI) - no, EXTI pins of course should be input.

Using pins soldered to LEDs does not look as good idea.

LVara.1
LVara.1Author
Associate III
March 27, 2022

The pins of a micro can control a signaling LED (not a lighting led), obviously through a resistance of discrete value. All STM Nucleo boards (and also boards from other manufacturers) control one to two LEDs. From data-sheet DocID024738 Rev 10 ,page 92 ".. The GPIOs (general purpose input/outputs) can sink or source up to ±8 mA...."