6 Replies Latest reply on Jan 17, 2019 10:00 PM by PY_21

    PSOC4 BLE stuck in main loop inside CyBle_ProcessEvents

    sapc_3956266

      I have modified cypress project "Day041_PSoC_4_BLE_Low_Power_Modes" from "100_Projects_in_100_Days".
      It is low power implementation of BLE. In this code, I have added the BLE always on in fast advertising mode & CPU is put in DEEP_SLEEP_MODE.
      So, now BLE-Subsystem wakes up at regular interval & keep advertising all the time & CPU is in DEEP_SLEEP.

      CPU can be wake up using external interrupts like switch.

       

      After this I have added following component

      1. Timer based on Watchdog_Timer_Counter_1 :  triggers periodically every 1 second, when CPU active.
      2. Watchdog_Timer_Counter_0 : To reset the device if any hang state occurs in code.

      ###################################################################

      Now, main function is as below
      main.c

       

      TimerCallBack()

      {

          uart_dbg_print("##");

      }

       

      main()
      {

             uart_dbg_print(" Enter_main ");
              timer_init(TimerCallBack);  // every one second peroidic
             watchdog_init(); // To reset
      while(1)

      {

       

                Watchdog_isr_clear();

          process_application_events();

      uart_dbg_print(" 1 ");     CyBle_ProcessEvents();

      uart_dbg_print(" 2 ");
           Enter_low_power_mode();

      }

      }

      ###########################################################################

       

      Observaton:

      If Watchdog Timer Counter 1 interrupt occurs while processing CyBle_ProcessEvents(). The device hangs and resets because of watchdog.

       

      How to resolve this stuck issue.

        • 1. Re: PSOC4 BLE stuck in main loop inside CyBle_ProcessEvents
          PY_21

          Hello,

           

          • Please ensure that the BLE subsystem (BLESS) interrupt has the highest priority i.e., the priority should be 0.
          • Make sure that CyBle_ProcessEvents is called at regular intervals in the firmware. If any custom function consumes more time for execution, call CyBle_ProcessEvents inside it.

           

          Thanks,

          P Yugandhar.

          • 2. Re: PSOC4 BLE stuck in main loop inside CyBle_ProcessEvents
            sapc_3956266

            Thanks P Yugandhar, for the inputs. I have checked with interrupt priority to Zero i.e. Highest. Still the issue is there.

            ble_priority.JPG

            I am calling CyBle_ProcessEvents, this in while loop continuously, with some other functions serially. I have observed that, this issue is not because, other functions taking longer time for execution. I have used debug prints and verified that.

            But the stuck condition occurs, when timer interrupts comes while processing CyBle_ProcessEvents.

            Whenever there is the exact match of this condition, cpu is stuck inside this function CyBle_ProcessEvents forever. And this stuck creates watchdog reset.

             

            I mean to say if  CyBle_ProcessEvents is taking some time to process & another timer isr comes while processing BLE, then it is getting stuck.

             

            Should I disable timer interrupts while processing CyBle_ProcessEvents ?
            Should I use CyEnterCriticalSection ?

            • 3. Re: PSOC4 BLE stuck in main loop inside CyBle_ProcessEvents
              PY_21

              Hello,

               

              Please attach your project (if possible) so that we can reproduce the issue and find out the root cause. (If not complete project please share a simplified project where the issue is getting).

               

              Thanks,

              P Yugandhar.

              • 4. Re: PSOC4 BLE stuck in main loop inside CyBle_ProcessEvents
                sapc_3956266

                Please share your email id, so that I can share the project.

                • 5. Re: PSOC4 BLE stuck in main loop inside CyBle_ProcessEvents
                  sapc_3956266

                  Ok. So, the scenario is that, If Watchdog Timer Counter 1 or RING_BUTTON interrupt occurs while processing CyBle_ProcessEvents(). The device hangs and resets because of watchdog.

                   

                  To create that scenario, for that you can decrease timer period, so it will increase the no. of interrupts & may help recreating the issue. 

                  Timer_Set_Period(32768);// make this 327 or 100 or something little...

                   

                  You can also use the RING_BUTTON continuously to generate the interrupts simultaneously.

                   

                  If it is stuck you can see "UART_DBG_PutString(".");" the dot printing in main() has stopped, if it is in wake-up condition.

                  You can also check that in this stuck condition CPU is still processing timer ISR, you can observer prints " UART_DBG_PutString("##");".

                  • 6. Re: PSOC4 BLE stuck in main loop inside CyBle_ProcessEvents
                    PY_21

                    Hello,


                    Please refer the below points.
                    1. Don't write big code inside any ISR. Instead, set a variable inside ISR and check the variable status and call the function in main loop.
                    2. Always keep Bless interrupt to highest priority i.e., bless interrupt priority to 0.
                    3. Please clear the WDT interrupt after completion using CySysWdtClearInterrupt(), this function will Clears all the WDT counter interrupts set in the mask.
                    4. It is not recommended to use the delays inside any ISR and also it is not recommended to disable the global interrupts inside the ISR (using CyGlobalIntDisable). This will block the other interrupts to execute.
                    5. Use the upgraded components in the project (Goto Project -> Update_components ).

                     

                    Thanks,

                    P Yugandhar.