There are two points during the boot process where you have control over a pin:
1st When the defined pin properties are written and the pin comes out of High-Z state a LED can be lit.
2nd When main() starts execution you can read the button state and turn on the LED.
From the description it is not clear how a momentary button switch turns on power to PSoC. Is there any other external latching circuit like relay, etc.?
Alternative way would be to power PSoC permanently, while putting it in deep sleep, and having it to wake up on the button press. This way PSoC can live on a battery for months.
Hey Bob, thank you for the response.
Control over the pin when it comes out of high Z, by that do you mean having a direct connection between the pin and the LED? To read the pin from main() is a bit tricky because, I checked that the bootloader currently takes 700msec to complete and by the time it enters main(), the button press pulse is already over (considering typical button press of 200 - 300 msec).
Is it normal for the bootloader to take that long in PSoC4? Is there any way I can shorten that?
Hi Odissey, thank you for your response.
Yes, the button press does enable power to the PSoC via external latching circuit. Once powered the PSoC does go into deepsleep when not in use and I use the global interrupt to wake up (and turn the LED ON), which works fine.
I'm facing this issue only when the system is booting for the first time.
Control over the pin when it comes out of high Z, by that do you mean having a direct connection between the pin and the LED
Yes, the LED must be connected to any output pin. You may set the initial state in the configurator. This will be applied when the pin comes out of Hi-Z.
If your project has reached main(), then power has been activated, and if power has been activated, then there must have been a button push to trigger the power activation. Can't you just use the initialization in main() before running the application's while/for loop to turn the LED on?
Unless there is another case where you will reinitialize the project with, say, a CySysSoftwareReset(), then it should be simple to do.
As @user_1377889 mentioned, you can also set the default mode of the LED to be high and it will be set when leaving the bootup sequence.
You could also read the reset reason at powerup to determine if the unit was reset or first time turning on, and change the LED based on that, but it is a little more tricky.