Skip to main content
warm38
Associate III
December 28, 2020
Solved

STM32L4xx board has GPIO pin 5 on two different ports (GPIOA and GPIOB) that need to interrupt at different phases of processing. How to initialize PA5 to interrupt initially and the switch to PB5 until done and switch back?

  • December 28, 2020
  • 4 replies
  • 1130 views

EE designed the board with both pins in use and both needing to wake up from STOP2. At start PA5 must be used to awake. Once awake, switch interrupt to PB5 for normal processing. When normal processing is done, switch back to PA5 and enter STOP2. Is there some sample code out there that I can use? Or do I need to reinvent the wheel?

This topic has been closed for replies.
Best answer by warm38

In HAL_GPIO_Init() it initializes PA5 to use the interrupt. When I switch to run mode, I call a function to reinitialize PA5 to be GPIO_Input and PB5 (and others) to be interrupted. When it is time to go to STOP2, I call another function to make PB5 (and others) to be GPIO_Input and PA5 to be interrupted.

4 replies

TDK
Super User
December 28, 2020

You can change which pin is connected via HAL_GPIO_Init. Just switch when you wake up, and again when you go back to sleep.

"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
December 28, 2020

Are you talking about EXTI? Then simply change the setting of respective SYSCFG_EXTICRx field.

JW

warm38
warm38Author
Associate III
December 29, 2020

I was getting the coding ready for the HAL_GPIO_Init(), but I like the SYSCFG_EXTICR2 idea even better. It is a simple CLEAR and OR. I don't believe that I will need to do anything with the NVIC. The ISR will have to change to accommodate the different ports.

Thanks for the quick and good responses!

warm38
warm38AuthorBest answer
Associate III
January 8, 2021

In HAL_GPIO_Init() it initializes PA5 to use the interrupt. When I switch to run mode, I call a function to reinitialize PA5 to be GPIO_Input and PB5 (and others) to be interrupted. When it is time to go to STOP2, I call another function to make PB5 (and others) to be GPIO_Input and PA5 to be interrupted.