Use of WKUP input after Power.Shutdown

Hello,
I am doing some experiments with shutdown and restart using the WKUP input.
The device I am using is a FEZ Feather with firmware V 2.1.0.2000.

To shut down, the device calls
Power.Shutdown(true, DateTime.MaxValue);

It appears that sometimes the device restarts on a raising edge and sometimes it works on a falling edge. I don’t see the logic in how this exactly works…

Previously the same pin was used with a button like this:
button = gpio.OpenPin(SC20100.GpioPin.PA0);
button.SetDriveMode(GpioPinDriveMode.InputPullDown);
Can this have something to do with the behavior?

When do shutdown, I believe the gpio configuration has no effect. It uses special pin PA0 directly. So no need open PA0 and set pulldown.

And I think change the PA0 state will trigger a reset.

Thanks for that reply.
The problem seemed to be that since the internal pulldown cannot be used, the pin was floating. That explains the strange behavior.
Now I added an external pulldown resistor and it works fine!

2 Likes

This should be documented, i ran into the same scenario just now. I was 90% sure it needed a pull resistor anyway, but this confirms it.

GitHub issues is our friend here

Where does

Power.Shutdown(true, DateTime.MaxValue);

work from? only from main thread main method?
because everywhere else I get a System.InvalidOperation

We have only tested it with a working RTC. I know your code shouldn’t need RTC but can you please try to enable RTC first?

Did you use PA0 anywhere before calling Shutdown?

Yes, im trying to use PA0 as an ON/OFF button. Once the code runs PA0 should run Shutdown and once its shutdown it should by design Wakeup (restart).

This works with LDR button but not when i use PA0.
Btw i don’t have any more interrupts available. All 16 are used as buttons.

This is not a big issue atm, i can just shutdown every 5 minutes of inactivity (not pressing any of the buttons) and PA0 will then work as expected.
But i need to know if the button will be labeled ON/OFF on the membrane keyboard or just ON.

class Program
    {
        static GpioController gpio;
        static GpioPin led;
        static GpioPin ldr;
        static Thread wkupThread;
        static void Main()
        {
            gpio = GpioController.GetDefault();

            led = gpio.OpenPin(SC20100.GpioPin.PA6);
            led.SetDriveMode(GpioPinDriveMode.Output);

            ldr = gpio.OpenPin(SC20100.GpioPin.PE3);
            ldr.SetDriveMode(GpioPinDriveMode.InputPullUp);

            wkupThread = new Thread(PollWkup);
            wkupThread.Start();

            while (true)
            {
                for (int i = 0; i < 10; i++)
                {
                    led.Write(GpioPinValue.High);
                    Thread.Sleep(500);
                    led.Write(GpioPinValue.Low);
                    Thread.Sleep(500);
                }
            }
        }

        static void PollWkup()
        {
            while (true)
            {
                Debug.WriteLine("poll wkup");
                if (ldr.Read() == GpioPinValue.Low)
                {
                    Debug.WriteLine("ldr low");
                    Power.Shutdown(true, DateTime.MaxValue);
                }
                else {
                    Debug.WriteLine("ldr high");
                }
                Thread.Sleep(100);
            }
        }
    }

Because we check PA0 before switch this pin to different function (shutdown mode), that is reason get the exception, not related to thread.

We added an issue to see if we need to check or not.

For now, you can not call shutdown gpio if PA0 is used.

Easy, just Dispose the pin before calling Shutdown. You don’t need this pin because wakeup from shutdown is similar to reset.

Ha :laughing:, works, but at the same time it doesn’t because when the button is pressed it goes to sleep and as soon as i release it it wakes up :stuck_out_tongue:
This would work if the button was toggle button

1 Like

That is expected. You need a pull up or pull down on the pin.

Yeah i have it, that’s not the issue. You cannot un-press it with your finger fast enough so that it doesn’t trigger a second change therefore waking up the system.

I’m not sure if I’m fully following this thread, so forgive me if my answer is something completely unrelated.

You cannot un-press it with your finger fast enough so that it doesn’t trigger a second change therefore waking up the system.

This sounds like a bouncing problem. Can you try adding a 100nf capacitor between the pin and gnd?
For anyone wondering why, here is described how that works.

2 Likes

Maybe you should add a small delay, or wait untill you see a raising edge before you call the shutdown function.

1 Like

Two heads are better then one. :smiley: Never would’ve thought of that. Works perfectly.