Dual role pin configuration
Hello there,
I am using STM32L4 family MCU. I was wondering either it is possible to configure a pin to act as 2 configurations. In my situation, I am trying to make the pin PA0 to act as UART2 CTS line and External interrupt 0. From what I am reading in the datasheet and by checking the way HAL code for initialization is written it should be possible. The problem I am facing however is that my MCU keeps reseting after this config so maybe I am doing something wrong after all. Here is the code generated by MxCube, it configures the pin as uart2 CTS:
/**USART2 GPIO Configuration
PA0 ------> USART2_CTS PA2 ------> USART2_TX PA3 ------> USART2_RX */ GPIO_InitStruct.Pin = GSM_UART2_CTS_Pin|GSM_UART2_TX_Pin|GSM_UART2_RX_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF7_USART2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);...
HAL_NVIC_SetPriority(USART2_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn);// My added code to also enable EXTI:
// Add external interrupt config to UART2 CTS line
GPIO_InitStruct.Pin = GSM_UART2_CTS_Pin; GPIO_InitStruct.Mode |= GPIO_MODE_IT_RISING_FALLING; HAL_GPIO_Init(GSM_UART2_CTS_GPIO_Port, &GPIO_InitStruct); // set IRQ for EXTI0 priority but disable it for now HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0); HAL_NVIC_EnableIRQ(EXTI0_IRQn);Is there any error in my understanding of this? Is this config a possible one, or do I need to turn CTS off before turning EXTI0 on? I would appreciate all help.
#interrput #uart