cancel
Showing results for 
Search instead for 
Did you mean: 

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?

warm38
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions
warm38
Associate III

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.

View solution in original post

4 REPLIES 4
TDK
Guru

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".

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

JW

warm38
Associate III

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
Associate III

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.