0
\$\begingroup\$

I have a problem, I use an InterruptIn in a class to generate interruption when a button is pressed. In this class I just have constructor, destructor and callback for the rise and the fall. When I use this class in my main, if I do something like a printf or call some functions my Nucleo freeze. Nothing is written on my terminal and I can't do anything. But if I comment just one line the script work fine. I don't have any idea of what is the problem.

Does anyone can help me for this?

My class look like this

//*********************************************************************************//
//                                                                                 //
//                                    GLOBAL VARIABLES                             //
//                                                                                 //
//*********************************************************************************//
int nbRise;
int nbFall;

//*********************************************************************************//
//                                                                                 //
//                                  UART        Debug                              //
//                                                                                 //
//*********************************************************************************//
#ifdef DEBUG
Serial pcTOR(USBTX, USBRX);  // TX ( D8 ), RX ( D2 )
#endif


//*********************************************************************************//
//                                                                                 //
//                                        FLAG                                     //
//                                                                                 //
//*********************************************************************************//
bool FlagBTN = false;


//*********************************************************************************//
//                                                                                 //
//                                  PUBLIC FONCTIONS                               //
//                                                                                 //
//*********************************************************************************//

/***************************************************************************//**
 * @fn Snef_TOR(PinName Pin): _interruptin(Pin)
 * @brief Constructor of the TOR object
 * @param PIN ex: PA_1
 * @return void
 * @author Simon NOWAK
 *
 ******************************************************************************/
Snef_TOR::Snef_TOR(PinName Pin): _interruptin(Pin){
    //Evite la section critique (Taches parallèles)
    _interruptin.disable_irq();
#ifdef DEBUG
    pcTOR.printf("TOR: Initialisation\r\n");
    wait(0.1);
#endif
    _interruptin.mode(PullUp);
    nbRise = 0;
    nbFall = 0;
    _interruptin.rise(this, &Snef_TOR::Snef_TOR_IncrementRise);
    //Desactivation de ce qui evite la section critique (Taches parallèles)
    _interruptin.enable_irq();
}

/***************************************************************************//**
 * @fn Snef_TOR(PinName Pin): _interruptin(Pin)
 * @brief Constructor of the TOR object
 * @param PIN ex: PA_1
 * @param Front ex: Snef_ENUM_RISE
 * @return void
 * @author Simon NOWAK
 *
 ******************************************************************************/
Snef_TOR::Snef_TOR(PinName Pin, uint32_t Front): _interruptin(Pin){
    //Evite la section critique (Taches parallèles)
#ifdef DEBUG
    pcTOR.printf("TOR: Initialisation\r\n");
    wait(0.1);
#endif
    _interruptin.mode(PullUp);
    nbRise = 0;
    nbFall = 0;
    if((Front&Snef_ENUM_RISE) == Snef_ENUM_RISE){
        _interruptin.rise(this, &Snef_TOR::Snef_TOR_IncrementRise);
    }
    else if((Front&Snef_ENUM_FALL) == Snef_ENUM_FALL){
        _interruptin.fall(this, &Snef_TOR::Snef_TOR_IncrementFall);
    }
    //Desactivation de ce qui evite la section critique (Taches parallèles)
}


/***************************************************************************//**
 * @fn Snef_TOR_IncrementRise(void)
 * @brief Increment the rise value
 * @param void
 * @return void
 * @author Simon NOWAK
 *
 ******************************************************************************/
void Snef_TOR::Snef_TOR_IncrementRise(void){
    nbRise++;
    //Change the flag to true. This allow to know if the wakeUp come from RTC or this sensor
    FlagBTN = true;
}


/***************************************************************************//**
 * @fn Snef_TOR_IncrementFall(void)
 * @brief Increment the fall value
 * @param void
 * @return void
 * @author Simon NOWAK
 *
 ******************************************************************************/
void Snef_TOR::Snef_TOR_IncrementFall(void){
    nbFall++;
    //Change the flag to true. This allow to know if the wakeUp come from RTC or this sensor
    FlagBTN = true;
}


/***************************************************************************//**
 * @fn Snef_TOR_GetRise(void)
 * @brief Return the rise value
 * @param void
 * @return int
 * @author Simon NOWAK
 *
 ******************************************************************************/
int Snef_TOR::Snef_TOR_GetRise(void){
    return nbRise;
}


/***************************************************************************//**
 * @fn Snef_TOR_GetFall(void)
 * @brief Return the fall value
 * @param void
 * @return int
 * @author Simon NOWAK
 *
 ******************************************************************************/
int Snef_TOR::Snef_TOR_GetFall(void){
    return nbFall;
}


/***************************************************************************//**
 * @fn Snef_TOR_ClearFlagBtn(void)
 * @brief Clear the flag associate with the ZCMD21 button
 * @param void
 * @return void
 * @author Simon NOWAK
 *
 ******************************************************************************/
void Snef_TOR::Snef_TOR_ClearFlagBtn(void){
    FlagBTN = false;
}


/***************************************************************************//**
 * @fn Snef_TOR_GetFlagBtn(void)
 * @brief Allow to get the Flag associate with the ZCMD21 button
 * @param void
 * @return bool
 * @author Simon NOWAK
 *
 ******************************************************************************/
bool Snef_TOR::Snef_TOR_GetFlagBtn(void){
    return FlagBTN;
}

Thank you very much for your time.

\$\endgroup\$
  • 1
    \$\begingroup\$ It would help if you write which line you comment out to get it working. \$\endgroup\$ – staringlizard Feb 2 '17 at 13:21
  • \$\begingroup\$ @Tut My ISR is not declared in extern, I should ? \$\endgroup\$ – Simon NOWAK Feb 2 '17 at 13:34
  • \$\begingroup\$ @staringlizard for example "pc.printf("Hello");" OR "HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);" This is two examples of the multiple lines who can freeze my script. It's depend \$\endgroup\$ – Simon NOWAK Feb 2 '17 at 13:34
  • \$\begingroup\$ @Tut So in this case I should put extern "c" on the constructor of my class ? \$\endgroup\$ – Simon NOWAK Feb 2 '17 at 13:40
  • 1
    \$\begingroup\$ Any chance that you run the printf call in an ISR? printf() is wrapped in a mutex in the ARM C standard library, and mutex calls are not allowed in an ISR. See for some background developer.mbed.org/blog/entry/… \$\endgroup\$ – Jan Jongboom Feb 2 '17 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.