My custom nRF52840 board uses the STmicro STM6601 push-button controller. To keep the nRF powered, the PSHOLD line must be kept high. I have a GPIO set as an output for that.
I am trying to incorporate the Open bootloader in my code.
Obviously using a reset (hard or soft) will change that GPIO to an input, causing the PSHOLD line to go low.
I can successfully call the boot loader directly without a reset, but it seems to reset the GPIO pin to an input anyway.
I would like a suggestion on how to keep that GPIO set through the bootloader initialization.
Where in the Open bootloader process does it reset the GPIOs?
Could you tell which GPIO pin you use ?
Note that after a soft reset, a pin will be configured as input with input buffer disconnected. The level of the pin will be high impedance (floating). It's not driven low. You can have an external pull up for the pin.
Note that if you implement the GPIO configuration inside the bootloader, there would be a very short period when the pin is float. And because it's very short (microseconds) you can add a capacitor to keep the pin high during the period if pull up is not an option.
The GPIO is P0.12
When I step through the process using the debugger (from when the app calls the bootloader to when the bootloader enters its main loop), the GPIO stays high.
But when I run it "stand-alone", the output goes low long enough for the system power to go off.
Could you capture an oscilloscope / logic analyzer of the pin ? I want to see how long the pin goes low. Have you tried to put a capacitor / a pull up resistor?
Please make sure there is no code in the bootloader that pull the pin low.
Here the signal from the scope.
Note that the nRF52840 is here powered by the Dev Kit debugger (i.e. SB47 is joined.)
This is necessary so you can see that the signal does indeed go high after the restart.
If I step through the code in the debugger, I don't see anywhere where the output is set low.
Sorry for a late response, I was on vacation.
When the pin set to input (the default state after reset), it's floating so it can be low. Have you tried to connect it to a pull up resistor or a capacitor ?
The reset pin is not bidirectional. You can check if which reset reason was the last reset by reading RESETREAS register. Please refer to chapter 18 in the nRF52832 product spec.
I can't use a pull up resistor, because one function of the STM6601 is to switch the power off after a start up if the MCU doesn't set PSHOLD within a few seconds. A pull up resistor would defeat that purpose.
I managed to find a work-around using the "Wake from System OFF mode", which performs a reset without changing the GPIO state. See this question.
This actually a good trick. I didn't think of this. Thanks for sharing Damon.