Skip to main content
Visitor II
March 26, 2025
Question

HAL_GPIO_EXTI_Callback - using rising edge and falling edge

  • March 26, 2025
  • 3 replies
  • 894 views

I use it to see if R S T is present in 3-phase systems with F072 c8t6 processor. I have defined only R pin as interrupt, the other two are defined as input. When I write the code as below, I cannot check the status of R. I guess it is because of the version or the processor I cannot use HAL_GPIO_EXTI_Rising_Callback

CODE:

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{



 sPhase_t *rstPhase = &taskPeripheralUnits.phase;

 if(GPIO_Pin == ioR_Pin)

 {

 if (HAL_GPIO_ReadPin(ioR_GPIO_Port, ioR_Pin))

 {

 rstPhase->ucRawPhaseData[ZERO][rstFACTOR_R_PHASE] = ACTIVE;

 rstPhase->ucRawPhaseData[ZERO][rstFACTOR_S_PHASE] = HAL_GPIO_ReadPin(ioS_GPIO_Port, ioS_Pin);

 rstPhase->ucRawPhaseData[ZERO][rstFACTOR_T_PHASE] = HAL_GPIO_ReadPin(ioT_GPIO_Port, ioT_Pin);

 }

 else

 {

 rstPhase->ucRawPhaseData[1u][rstFACTOR_R_PHASE] = PASSIVE;

 stPhase->ucRawPhaseData[1u][rstFACTOR_S_PHASE] = HAL_GPIO_ReadPin(ioS_GPIO_Port, ioS_Pin);

 rstPhase->ucRawPhaseData[1u][rstFACTOR_T_PHASE] = HAL_GPIO_ReadPin(ioT_GPIO_Port, ioT_Pin);

 }

 }

}

 

    This topic has been closed for replies.

    3 replies

    Super User
    March 26, 2025

    The hardware is capable to select raising or falling external interrupt edge or both. This is reflected in STM32CubeMX as well.  

    I cannot check the status of R

    You are reading the pin level with HAL_GPIO_ReadPin.

    So, what unexpected behaviour exactly are you observing? 

    hth

    KnarF

    Visitor II
    March 26, 2025

     I check whether there are 3 phases according to the states of the RS and T pins, but here the value of R always comes as 0 1 0 1. In my code, when R is 0, I write a voltage error, but even though R = 0, the error is not entered.

    Super User
    March 26, 2025

    > the value of R always comes as 0 1 0 1

    That's what I would expect from a periodic signal.

    KnarfB

    Technical Moderator
    March 26, 2025

    Hello,

    The question is not clear. Could you please elaborate/reword?

    Regarding HAL_GPIO_EXTI_Rising_Callback() it's not available on STM32F0 CubeHAL. HAL_GPIO_EXTI_Rising_Callback() is available on STM32F0 CubeHAL like what you shared in your post.

    Visitor II
    March 27, 2025
    What I mean is this I have a code that controls 3 phases on the stm32u073 processor. There are HAL_GPIO_EXTI_Rising_Callback and HAL_GPIO_EXTI_Falling_Callback functions on that processor and I posted the code as in the example and it works properly. However, I only changed HAL_GPIO_EXTI_Callback on the stm32F072C8T6 and it does not work. Could there be a problem due to these functions?

    /*Code with U073*/
    void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
    {
     sPhase_t *rstPhase = &taskPeripheralUnits.phase;
     if (GPIO_Pin == ioINPEXT_R_Pin)
     {
     rstPhase->ucRawPhaseData[1u][rstFACTOR_R_PHASE] = PASSIVE;
     rstPhase->ucRawPhaseData[1u][rstFACTOR_S_PHASE] = HAL_GPIO_ReadPin(ioINP_S_GPIO_Port, ioINP_S_Pin);
     rstPhase->ucRawPhaseData[1u][rstFACTOR_T_PHASE] = HAL_GPIO_ReadPin(ioINP_T_GPIO_Port, ioINP_T_Pin);
     }
    }
    /*---------------------------------------------------------------------------------------------------------------------------*/
    void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
    {
     sPhase_t *rstPhase = &taskPeripheralUnits.phase;
     if (GPIO_Pin == ioINPEXT_R_Pin)
     {
     rstPhase->ucRawPhaseData[ZERO][rstFACTOR_R_PHASE] = ACTIVE;
     rstPhase->ucRawPhaseData[ZERO][rstFACTOR_S_PHASE] = HAL_GPIO_ReadPin(ioINP_S_GPIO_Port, ioINP_S_Pin);
     rstPhase->ucRawPhaseData[ZERO][rstFACTOR_T_PHASE] = HAL_GPIO_ReadPin(ioINP_T_GPIO_Port, ioINP_T_Pin);
     }
    }
    /*---------------------------------------------------------------------------------------------------------------------------*/
    static void prvRstPhaseExistanceCtrl(void)
    {
     sPhase_t *rstPhase = &taskPeripheralUnits.phase;
     static TickType_t xTickTimer;
     uint8_t Rdetected, Sdetected, Tdetected;
     uint8_t *ucPhases[rstPHASE_COUNT_TOTAL] = {&Rdetected, &Sdetected, &Tdetected};
    
     for (int Idx = ZERO; Idx < rstPHASE_COUNT_TOTAL; Idx++)
     {
     if (!(rstPhase->ucRawPhaseData[0][Idx] & rstPhase->ucRawPhaseData[1][Idx]) )
     {
     *(ucPhases[Idx]) = ACTIVE;
     }
     else
     {
     *(ucPhases[Idx]) = PASSIVE;
     }
     }
    
     if((Rdetected & Sdetected & Tdetected) == ACTIVE)
     {
     xTickTimer = xTaskCurrentTick;
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_ALL_DETECTED;
     }
     else
     {
     taskPeripheralUnits.phase.sequenceStatus.ucSequence = rstPHASE_SEQUENCE_WRONG;
    
     if (xTaskCurrentTick - xTickTimer > timeDELAY_RST_CONTROL)
     {
     if((Rdetected & Sdetected) == ACTIVE)
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_RS_DETECTED;
     }
     else if((Sdetected & Tdetected) == ACTIVE)
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_ST_DETECTED;
     }
     else if((Tdetected & Rdetected) == ACTIVE)
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_RT_DETECTED;
     }
     else if(Rdetected == ACTIVE)
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_R_DETECTED;
     }
     else if(Sdetected == ACTIVE)
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_S_DETECTED;
     }
     else if(Tdetected == ACTIVE)
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_T_DETECTED;
     }
     else /* None of them Active */
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_ALL_NOT_DETECTED;
     }
     }
     else
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_ALL_DETECTED;
     }
     }
    }
    
    /* Code with F072 */ 
    
    void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
    {
    
     sPhase_t *rstPhase = &taskPeripheralUnits.phase;
     if(GPIO_Pin == ioR_Pin)
     {
     if (HAL_GPIO_ReadPin(ioR_GPIO_Port, ioR_Pin) == GPIO_PIN_RESET)
     {
     rstPhase->ucRawPhaseData[ZERO][rstFACTOR_R_PHASE] = ACTIVE;
     rstPhase->ucRawPhaseData[ZERO][rstFACTOR_S_PHASE] = HAL_GPIO_ReadPin(ioS_GPIO_Port, ioS_Pin);
     rstPhase->ucRawPhaseData[ZERO][rstFACTOR_T_PHASE] = HAL_GPIO_ReadPin(ioT_GPIO_Port, ioT_Pin);
     }
     else
     {
     rstPhase->ucRawPhaseData[1u][rstFACTOR_R_PHASE] = PASSIVE;
     rstPhase->ucRawPhaseData[1u][rstFACTOR_S_PHASE] = HAL_GPIO_ReadPin(ioS_GPIO_Port, ioS_Pin);
     rstPhase->ucRawPhaseData[1u][rstFACTOR_T_PHASE] = HAL_GPIO_ReadPin(ioT_GPIO_Port, ioT_Pin);
     }
    
     }
    }
    /*---------------------------------------------------------------------------------------------------------------------------*/
    static void prvRstPhaseExistanceCtrl(void)
    {
     sPhase_t *rstPhase = &taskPeripheralUnits.phase;
     static TickType_t xTickTimer;
     uint8_t Rdetected, Sdetected, Tdetected;
     uint8_t *ucPhases[rstPHASE_COUNT_TOTAL] = {&Rdetected, &Sdetected, &Tdetected};
     for (int Idx = ZERO; Idx < rstPHASE_COUNT_TOTAL; Idx++)
     {
     if (!(rstPhase->ucRawPhaseData[0][Idx] & rstPhase->ucRawPhaseData[1][Idx]) )
     {
     *(ucPhases[Idx]) = ACTIVE;
     }
     else
     {
     *(ucPhases[Idx]) = PASSIVE;
     }
     }
    
     if((Rdetected & Sdetected & Tdetected) == ACTIVE)
     {
     xTickTimer = xTaskCurrentTick;
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_ALL_DETECTED;
     vSciPrintf((uint8_t *) "1\n");
     }
     else
     {
     taskPeripheralUnits.phase.sequenceStatus.ucSequence = rstPHASE_SEQUENCE_WRONG;
    
     if (xTaskCurrentTick - xTickTimer > timeDELAY_RST_CONTROL)
     {
     if((Rdetected & Sdetected) == ACTIVE)
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_RS_DETECTED;
     vSciPrintf((uint8_t *) "2\n");
     }
     else if((Sdetected & Tdetected) == ACTIVE)
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_ST_DETECTED;
     vSciPrintf((uint8_t *) "3\n");
     }
     else if((Tdetected & Rdetected) == ACTIVE)
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_RT_DETECTED;
     vSciPrintf((uint8_t *) "4\n");
     }
     else if(Rdetected == ACTIVE)
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_R_DETECTED;
     vSciPrintf((uint8_t *) "5\n");
     }
     else if(Sdetected == ACTIVE)
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_S_DETECTED;
     vSciPrintf((uint8_t *) "6\n");
     }
     else if(Tdetected == ACTIVE)
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_T_DETECTED;
     vSciPrintf((uint8_t *) "7\n");
     }
     else /* None of them Active */
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_ALL_NOT_DETECTED;
     vSciPrintf((uint8_t *) "8\n");
     }
     }
     else
     {
     rstPhase->sequenceStatus.ucStatus = rstPHASE_STATUS_ALL_DETECTED;
     }
     }
    }
    Technical Moderator
    March 27, 2025

    Hello,

    Please use </> to share your code. I'm editing your post.

    You can refer to this link on how to do it.

    Thank you for your understanding.