5 Replies Latest reply on Jun 2, 2015 10:38 PM by userc_17272

    Program gets stuck in wiced_rtos_delay_microseconds(...) upon reset

      I am trying to generate  PWM for IR transmission. In order to get this functionality, I am required to switch on the PWM for some x time and then switch off the pwm for again some y time. This sequence continues till all the IR codes are transmitted. I am facing a unique problem here. I am using :

      • WICED_SDK version 3.1.2, Broadcom module (part no: BCM943362WCD4) used on Broadcom EVM (part no: BCM9WCD1EVAL1_P400),
      • Using FreeRTOS+LWIP stack for generation of PWM using platform_PWM functions implemented in wiced sdk.

       

      • Issue faced:

      Test Code snippet where problem is observed.

      while(loopCnt <dataLength)

      {

            onTime_inuS = AC_TMP_UP[loopCnt]*10; //AC_TMP_UP is an array with pronto codes

            offTime_inuS = AC_TMP_UP[loopCnt+1]*10;

            loopCnt+=2;

            irTX_Start(); 

            wiced_rtos_delay_microseconds(onTime_inuS);  // there is no problem in                                                    //delaycalculation. it gets stuck here                                                    //upon reset.

            irTX_Stop();

            wiced_rtos_delay_microseconds(offTime_inuS); // there is no problem in delay                                                    //calculation.

        }

       

      1. In the above code snippet,  after the first time programming, the PWM start and stop works via wrappers : irTX_Start() & irTX_Stop() and does not get stuck in delay routine wiced_rtos_delay_microseconds for either start or stop cases.

       

      2. However upon restarting the EVM board (power down and power up again) , the program gets stuck up in wiced_rtos_delay_microseconds(onTime_inuS) line.

       

      3.  Upon debugging Inside wiced_rtos_delay_microseconds(onTime_inuS), we find the code gets stuck inside a while(current_time < end_time) loop implemented in this wiced_rtos function.  Since this while loop condition never becomes false upon a reset, the program is stuck on this delay function and is unable to proceed ahead. The only way to recover the system to normal is to reprogram/reflash and again it works fine till we again reset the EVM.

      (while loop snippet):

      while ( current_time < end_time )

      {

      current_time = host_platform_get_cycle_count( );

      }

       

      Any help here or if anyone has encountered such a situation and has found a fix or workaround please share.

        • 1. Re: Program gets stuck in wiced_rtos_delay_microseconds(...) upon reset

          In addition I made one more observation: This has nothing to do in specific with PWM. Even if use a normal gpio toggling instead of pwm start and pwm stop even then the same problem persists. If I use a gpio to toggle Like below:

           

          while(loopCnt <dataLength)

          {

               loopCnt+=2;

                gpio_on();

                wiced_rtos_delay_microseconds(4500);  //it gets stuck here upon reset.

                gpio_off();

                wiced_rtos_delay_microseconds(4500);

          }

          Here too gpio stays on because the program gets stuck inside wiced_rtos_delay_microseconds(...) hence it never executes the next gpio_off() function. The remaining situation is same as above - the code is stuck in that while loop inside wiced_rtos_delay_microseconds(...).


          Regards,

          Rohit

          • 2. Re: Program gets stuck in wiced_rtos_delay_microseconds(...) upon reset
            JaeyoungY_71

            Hi Rohit,

             

            I've tried the wiced_rtos_delay_microseconds() inside the scan app, put it inside the while(1) loop and the code runs fine before and after resetting the board.

             

            void application_start( )

            {

                wiced_init( );

             

                while(1)

                {

                     wiced_rtos_delay_microseconds(4500);

                    record_count = 0;

                    WPRINT_APP_INFO( ( "Waiting for scan results...\n" ) );

                    WPRINT_APP_INFO( ("  # Type  BSSID             RSSI  Rate Chan  Security    SSID\n" ) );

                    WPRINT_APP_INFO( ("----------------------------------------------------------------------------------------------\n" ) );

                    wiced_time_get_time(&scan_start_time);

                    wiced_wifi_scan_networks(scan_result_handler, NULL );

                    wiced_rtos_delay_milliseconds(DELAY_BETWEEN_SCANS);

                }

            }

             

            Could you let me know how you got to this conclusion?

            >>Since this while loop condition never becomes false upon a reset,

             

            The variables current_time and end_time get reset every time the wiced_rtos_delay_microseconds() function is called. You can add a print statement inside the while loop in wiced_rtos_delay_microseconds to check the values current_time and end_time and see what's happening. For the parameter 4500 microseconds used, I'm getting three prints before the condition while ( current_time < end_time ) becomes false and goes through.

            rtos_delay.PNG

             

            Thanks,

            Jaeyoung

            • 3. Re: Program gets stuck in wiced_rtos_delay_microseconds(...) upon reset

              Hi Jaeyoung,

               

              I tried to run your code on our platform. We tried both BCM9WCDPLUS114 and BCM943362WCD4 and in both platforms even your code gets stuck up on the  wiced_rtos_delay_microseconds(4500).

               

              When you flash the program the first time and run it and even if you press the reset switch on the EVM still everything works fine. Now physically switch off the main power supply to the EVM board and switch it on and then monitor, it gets stuck up. Can you try this step and confirm? We are using WICED_SDK 3.1.2. We see your code too gets stuck up on physically removing power and then plugging the power back in.

               

              Please try and share if such an occurrence happens.

               

              Regards,
              Rohit

              • 4. Re: Program gets stuck in wiced_rtos_delay_microseconds(...) upon reset
                JaeyoungY_71

                Hi Rohit,

                 

                We've looked into it and indeed the cycle count stops when the board is power cycled in SDK 3.1.2. It turns out the cycle count enable register bit was not getting set after the board gets power cycled. You can do the following to get it working properly.

                 

                1. In your application code, insert the following line into application_start() after wiced_init().

                     platform_init_nanosecond_clock();

                     app_start.PNG

                2. If you are using STM32F2xx as the host MCU (BCM9WCDPLUS114 and BCM943362WCD4) you will have to copy the file platform_nsclock.c from

                     <copy source>: <SDK>/WICED/platform/MCU/STM32F4xx/peripherals/

                     <copy destination>: <SDK>/WICED/platform/MCU/STM32F2xx/peripherals/

                 

                3. Also change the peripherals.mk in

                     <SDK>/WICED/platform/MCU/STM32F2xx/peripherals/

                     to add the platform_nsclock.c to the source file list.

                 

                Thank you for your patience and do let us know if you have any other problems.


                Thanks,

                Jaeyoung


                nano_clock.PNG

                1 of 1 people found this helpful
                • 5. Re: Program gets stuck in wiced_rtos_delay_microseconds(...) upon reset

                  Hi Jaeyoung,

                   

                  Thanks for sharing the work-around.

                  I have done something similar instead of adding platform_init_nanosecond_clock();  adding after wiced_init.

                  In the work-around patch that I have added and which works, I have added in wwd_platform_common.c (found in location: Wiced-SDK/WICED/platform/MCU/) inside the function named “wwd_result_t host_platform_init( void )” :

                   

                  wwd_result_t host_platform_init( void )

                  {

                  host_platform_deinit_wlan_powersave_clock( );

                   

                      //patch added to resolve the microseconds delay hang issue.

                     do

                     {

                       // enable DWT hardware and cycle counting

                       CoreDebug->DEMCR = CoreDebug->DEMCR | CoreDebug_DEMCR_TRCENA_Msk;

                       // reset a counter

                       DWT->CYCCNT = 0;

                       // enable the counter

                       DWT->CTRL = (DWT->CTRL | DWT_CTRL_CYCCNTENA_Msk) ;

                      }

                      while(0);

                   

                  #if defined ( WICED_USE_WIFI_RESET_PIN )

                  platform_gpio_init( &wifi_control_pins[WWD_PIN_RESET], OUTPUT_PUSH_PULL );

                  host_platform_reset_wifi( WICED_TRUE );  /* Start wifi chip in reset */

                  #endif

                   

                  #if defined ( WICED_USE_WIFI_POWER_PIN )

                  platform_gpio_init( &wifi_control_pins[WWD_PIN_POWER], OUTPUT_PUSH_PULL );

                  host_platform_power_wifi( WICED_FALSE ); /* Start wifi chip with regulators off */

                  #endif

                        return WWD_SUCCESS;

                  }

                   

                  Hope this too should be fine as we are able to get it working with the above patch code. This patch is the same that gets called when calling platform_init_nanosecond_clock().

                   

                  Regards,

                  Rohit