Unable to Shutdown

I’m working on a SCM20260 development board with 2.1.0-preview4 firmware to better understand the power management functionality. I have an external pushbutton switch with pullup connected to PA0 (WKUP pin).

Functionally, my goal is to be able to:

  • Put the SCM20260 into Sleep state.
  • At switch press, wake from Sleep and do some work.
  • Shutdown the SCM20260.
  • At switch press, reset the SCM20260.

In my setup, I can put the SCM20260 to Sleep, wake upon switch press, and perform some work in the event handler. However, I receive a System.InvalidOperationException when I call Shutdown() and the processor remains active.

Below is an example which I’ve tried running. Is there anything that needs to be setup or handled differently to get the SCM20260 to shutdown?

        static void Main()
        {

            var LED = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PB0);
            LED.SetDriveMode(GpioPinDriveMode.Output);

            // --- Test Sleep ---

            var wakePin = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PA0);
            wakePin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            wakePin.ValueChangedEdge = GpioPinEdge.FallingEdge;
            wakePin.ValueChanged += WakePin_ValueChanged;

            Debug.WriteLine("Doing some work before I sleep...");
            for (int i = 0; i < 3; i++)
            {
                LED.Write(GpioPinValue.High);
                Thread.Sleep(250);

                LED.Write(GpioPinValue.Low);
                Thread.Sleep(250);
            }

            Power.Sleep();      // External switch with pullup awakens.

            Debug.WriteLine("Doing some work after I wake...");
            for (int i = 0; i < 3; i++)
            {
                LED.Write(GpioPinValue.High);
                Thread.Sleep(250);

                LED.Write(GpioPinValue.Low);
                Thread.Sleep(250);
            }


            // --- Test Shutdown ---

            try
            {
                // Throws 'System.InvalidOperationException' in GHIElectronics.TinyCLR.Native.dll
                // for each of the following.
                //Power.Shutdown(true, DateTime.MaxValue);
                //Power.Shutdown(true, DateTime.Now.AddSeconds(5));
                Power.Shutdown(false, DateTime.Now.AddSeconds(5));
            }
            catch { }

            Debug.WriteLine("If I get here, the SCM20600 did not shutdown!");
            LED.Write(GpioPinValue.High);

        }


        private static void WakePin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            Debug.WriteLine("Wakeup Pin Interrupt!");
        }

I think there is a bug now where you have to dispose PA0. This pin must be free to become wakeup

And do not forget to add external pull resistor. There is no internal pull when you shut down!

Use of WKUP input after Power.Shutdown - TinyCLR OS - GHI Electronics’ Forums

1 Like

You are using DateTime.Now.AddSeconds(5), this needs RTC setup.

Thank you. By adding RTC initialization and disposing the WKUP pin before calling Shutdown(), I can now sleep, wake from switch press, shutdown, and restart on switch press.

3 Likes