AnsweredAssumed Answered

Dual role pin configuration

Question asked by Lukasz Przenioslo on Apr 24, 2018
Latest reply on Apr 24, 2018 by Lukasz Przenioslo

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.Alternate = GPIO_AF7_USART2;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);




    HAL_NVIC_SetPriority(USART2_IRQn, 5, 0);


// My added code to also enable EXTI:

    // Add external interrupt config to UART2  CTS line
    GPIO_InitStruct.Pin = GSM_UART2_CTS_Pin;
    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);

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.