This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP432P401R: Program hangs waiting for changes even after the change occurs

Part Number: MSP432P401R

Tool/software: Code Composer Studio

I have had this happen waiting for an input bit to change and also waiting for a variable to change that is changed in an interrupt routine. If I Pause the program and Run again immediately, it works fine.

The part waiting for a bit to change is a very short while loop and is identical to another while loop waiting for a different bit to change on a different port. I have checked the port direction register and it is correct.

The part waiting for a variable to change is a null loop waiting for the test variable to change. It works fine for the first change, but not later. Again, pausing and running again gets it through.

  • Hello Steven

    Can you please attach a simplified version of your code? Also please let us know which SimpleLink SDK version you are using, whether your application is using TI Drivers or DriverLib function calls.
  • This hangs until I Pause and then Resume:

         uint32_t chargeCount = 0;

         while(chargeCount == 0){

              if ((P6->IN & BIT6) == BIT6) {

                   chargeCount++;

              }

         }

    This works fine:

    uint32_t risingEdgeCount = 0;

               // waiting for current to exceed upper threshold

              while(risingEdgeCount != 1){

                   if ((P2->IN & BIT6) == BIT6){

                         risingEdgeCount++;

                   }

              }

    The first piece of code works the second time through the function.

  • I forgot to mention that the pins being read have been verified through the debugger to be defined as inputs, and the input bits are high.
  • Hello Steven,

    Are the variables declared as global? Also did you try to put a break point at the increment statement to see if the condition is being executed?
  • As shown in the code, the variables are declared immediately before they are used.

    I put a statement to write to the Red LED on the LaunchPad just before the "if statement" and it does not execute.

    The second time I go through this function, it usually works.

    It is like the processor is going to sleep and not waking up. I have a T32 timer interrupt handler that should wake it up. The user interface interrupt routine continues to work.

  • Are you using SleepOnIsrExit? That could produce symptoms similar to this.
  • See if change this makes any difference.

    volatile uint32_t chargeCount = 0;

  • Hello Steven,

    In addition to the inputs from the forum member, could you specify if the loop is run in main or inside an interrupt handler. Inside an interrupt handler you do not need to create a while loop as the interrupt should wake up the CPU and the status should be set for the bit.
  • This loop is in main.

  • Where else is the value of chargeCount changed? Please show all code that touches this variable.
  • That is the only place. It was set up to allow some filtering. I reduced the test value to make sure that it worked.
  • In the first loop, if you change P6 with P2, does the code stop hanging? If yes, check that P6 bit6 is initialized correctly, it should be like P2.
  • 8561.gpio_input_interrupt.c
    /* --COPYRIGHT--,BSD
     * Copyright (c) 2017, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    /*******************************************************************************
     * MSP432 GPIO - Input Interrupt
     *
     * Description: This example demonstrates a very simple use case of the
     * DriverLib GPIO APIs. P1.1 (which has a switch connected to it) is configured
     * as an input with interrupts enabled and P1.0 (which has an LED connected)
     * is configured as an output. When the switch is pressed, the LED output
     * is toggled.
     *
     *                MSP432P401
     *             ------------------
     *         /|\|                  |
     *          | |                  |
     *          --|RST         P1.0  |---> P1.0 LED
     *            |                  |
     *            |            P1.1  |<--Toggle Switch
     *            |                  |
     *            |                  |
     *
     ******************************************************************************/
    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>
    
    /* Standard Includes */
    #include <stdint.h>
    #include <stdbool.h>
    
    int main(void)
    {
        /* Halting the Watchdog */
        MAP_WDT_A_holdTimer();
    
        /* Configuring P1.0 as output and P1.1 (switch) as input */
        MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
        MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
    
        /* Configuring P1.1 as an input and enabling interrupts */
        MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
        MAP_GPIO_setAsInputPinWithPullDownResistor(GPIO_PORT_P6, GPIO_PIN6);
        MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1);
        MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1);
        MAP_Interrupt_enableInterrupt(INT_PORT1);
    
        /* Enabling SRAM Bank Retention */
        MAP_SysCtl_enableSRAMBankRetention(SYSCTL_SRAM_BANK1);
        
        /* Enabling MASTER interrupts */
        MAP_Interrupt_enableMaster();   
    
        /* Going to LPM3 */
        while (1)
        {
            MAP_PCM_gotoLPM3();
        }
    }
    
    /* GPIO ISR */
    void PORT1_IRQHandler(void)
    {
        uint32_t status;
        uint32_t chargeCount = 0;
    
        status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P1);
        MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, status);
    
        /* Toggling the output on the LED */
        if(status & GPIO_PIN1)
        {
            while(chargeCount == 0)
            {
                if ((P6->IN & BIT6) == BIT6)
                {
                    chargeCount++;
                }
            }
    
            MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
        }
    
    }
    
    Hello Steven

    I modified the gpio_input_interrupt example from the latest MSP432P4 SDK (see attached main code). The code that you mentioned works fine w/o the need to halt and resume. I ran the code in CCS with ARM Compiler.

  • My code is in main, not in an interrupt routine.

    I am not familiar with the MAP_GPIO functions that you used. Are those standard? Where can I find info on them?
  • This did not help. I also tried moving the declaration to the beginning of main, but that did not help.
  • Hello Steven

    From you very first post "I have had this happen waiting for an input bit to change and also waiting for a variable to change that is changed in an interrupt routine." and the subsequent post that it is in Interrupt routine, I deduced the example.

    Secondly, the MAP_GPIO functions are available as part of the driverlib examples in the SDK. Can you please modify the example code that I provided to replicate the issue?
  • Try not using it (i.e. SleepOnIsrExit), since it can cause symptoms like this.

    [Edit: Added antecedent.]

  • I put in breakpoints to try to debug code, but when I single step, it jumps around all over. It jumps several lines up or down and then back again.
  • This sounds like the optimizer at work. You can try -O0 or (what I do) just live with it.

    Did this start happening when you stopped using SleepOnIsrExit? It may actually indicate that your program is operating (more) properly.
  • It single steps properly now.
    It still stops in the main routine. It really looks like it is going to sleep, but hitting Pause and Run gets it going.
  • You haven't given us much context, so we're all really just guessing. How big is your program? Is it something you can post? Even just main()?
  • I masked off the SleepOnExit bit and now it works!!!!
    I don't know why it worked before with SleepOnExit enabled, but I don't care.
    Thank you for all of your time. I really appreciate the help that all of you gave me.
  • SleepOnIsrExit is hazardous unless your (entire) program is architected to use it.

    In general, once you enter that mode you shouldn't count on main() to accomplish anything -- maybe it will, maybe it won't, depending on when interrupts go off.

    I'm glad you're running again.
  • Thanks for the advice. I was considering trying to get SleepOnIsrExit working again in my UART handler so that it wouldn't interfere with a function that delays for a certain amount of time based on a Timer32 interrupt. Now, I will just check a flag set in the Timer32 interrupt handler. If it woke from sleep for some other reason, back to sleep until the Timer32 interrupt. No more SleepOnIsrExit for me.

**Attention** This is a public forum