Esp32S3 : Is it possible to activate an output of the chip before app_main() is executed ?

ThomasESP32
Posts: 206
Joined: Thu Jul 14, 2022 5:15 am

Esp32S3 : Is it possible to activate an output of the chip before app_main() is executed ?

Postby ThomasESP32 » Fri Jan 19, 2024 7:48 am

Good morning,

I am working with an Esp32S3, and I would like to activate an output of the chip
as soon as possible (After the Power has been turned ON) in order to activate a relay.

At the moment, I configures the pin as an output and I activates the pin as soon as the app_main()
is executed but when I measure the time between the 3V3 ramps up and the moment the relay is
activated, I get 882ms.

I wish I could decrease this amount of time.
Do you think it is possible to activate the output of the chip before the app_main() is executed ?
Is there a way to do it please ?

The goal would be to activate the pin as soon as possible.

Thank you for your help,
Best regards,

Thomas TRUILHE

DrMickeyLauer
Posts: 160
Joined: Sun May 22, 2022 2:42 pm

Re: Esp32S3 : Is it possible to activate an output of the chip before app_main() is executed ?

Postby DrMickeyLauer » Fri Jan 19, 2024 9:15 am

Perhaps muting the bootloader output makes it fast enough for you. If not, you're in for hacking the bootloader itself.

boarchuz
Posts: 575
Joined: Tue Aug 21, 2018 5:28 am

Re: Esp32S3 : Is it possible to activate an output of the chip before app_main() is executed ?

Postby boarchuz » Fri Jan 19, 2024 9:31 am

Use a "bootloader_before_init()" hook as in the example here: https://github.com/espressif/esp-idf/tr ... ader_hooks

Since this is executed in the bootloader you'll need to be conscious of the limitations, in particular you'll need to use ROM functions where possible or gpio_hal_x or gpio_ll_x, rather than the usual GPIO driver API.

If a hardware revision is possible, use a pin that has a pullup enabled by default.

ThomasESP32
Posts: 206
Joined: Thu Jul 14, 2022 5:15 am

Re: Esp32S3 : Is it possible to activate an output of the chip before app_main() is executed ?

Postby ThomasESP32 » Fri Jan 19, 2024 9:57 am

Good morning,

thank you for your answer.
Could you please tell me more about that ?

1) Your speak about using a pin which has a PullUp by default.
Do you know if there is this kind of Pin on the Esp32S3-WROOM1 module please ?
If the answer is yes, do you know if we have the possibility to change the default PullUp value (PullUP ON by default or PullUPOFF by default) ?

2) You speak about the bootloader_before_init() hook function.
Do you know what are the ROM functions that can be executed from this hook ?
Is there a list somewhere or is there an example that I can use in order to turn ON/OFF a pin output ?

Best regards,
Thomas TRUILHE

boarchuz
Posts: 575
Joined: Tue Aug 21, 2018 5:28 am

Re: Esp32S3 : Is it possible to activate an output of the chip before app_main() is executed ?

Postby boarchuz » Fri Jan 19, 2024 11:16 am

1. Check the datasheet, "Appendix A – ESP32-S3 Consolidated Pin Overview": https://www.espressif.com/sites/default ... eet_en.pdf
In the "At Reset" column, find a pin that is initialised in the desired state, taking care of strapping pins. Also check the S3 WROOM datasheet to ensure you avoid pins connected to flash, and take note of external pullx resistors added in the WROOM module, if any.

2. Stick to lower level HAL stuff and you'll be fine. Any higher level APIs, especially those that use FreeRTOS internally, will not be available. There's some GPIO interaction in the bootloader already, so you can use that as a reference, eg. https://github.com/espressif/esp-idf/bl ... .c#L37-L54

ThomasESP32
Posts: 206
Joined: Thu Jul 14, 2022 5:15 am

Re: Esp32S3 : Is it possible to activate an output of the chip before app_main() is executed ?

Postby ThomasESP32 » Fri Jan 19, 2024 11:33 am

Thank you,

Concerning the PullUp/Down value at reset, the thing is that I need a pin on which I could change
the Pull Value (Sometime the pin should have a PullUp at reset and sometime the pin should have a pulldown at reset).
And this on the same pin. You see what I mean ? I don't know if it is possible.


However, using your example I manage to pilot the output value of my pin on the bootloader_hook.
This is perfect !

Now, I need to know in this hook function how to pilot the output value of the pin at reset.
Sometime, I will have to set the output value high and sometime low...

Do you know if is is possible to access flash part or something where I could put a value
which could be read in the hook function at reset ??
I know that I can use NVS to do thins kind of thing but I think NVS is not accessible in the hook function.
Thank you for your help

boarchuz
Posts: 575
Joined: Tue Aug 21, 2018 5:28 am

Re: Esp32S3 : Is it possible to activate an output of the chip before app_main() is executed ?

Postby boarchuz » Fri Jan 19, 2024 12:25 pm

The NVS component would be quite heavy for this imo, not to mention the significant effort of porting it to the bootloader.

I would assign a single-sector (0x1000 bytes) partition for this purpose, and use basic flash operations to read and alter the setting: to get the current setting, read and count the number of leading 0 bits % 2; to change the setting, write the next bit to 0, or erase the partition if all 0s.
You should use the bootloader_*after*_init() hook to ensure this happens after flash is initialised.

djixon
Posts: 105
Joined: Sun Oct 01, 2023 7:48 pm

Re: Esp32S3 : Is it possible to activate an output of the chip before app_main() is executed ?

Postby djixon » Sat Jan 20, 2024 8:33 pm

You are at the wrong track and that usually happens when you want to "re-solve" hardware responsibility by software.

Look, there is dead time in between powering-up controller (until voltage and clock become stable enough, reading boot strapping pins for proper voltage establishment on flash peripherals etc.) and calling the main() routine. If it is too long for your circuit then I must say your hardware design is wrong. In your specific case, if you need activation of relay at power-up and default pin-output on that pad which triggers circuit of your relay is LOW, then simply, re-design the hardware to invert the logic of TURNING-ON relay by low voltage level. So instead to activate relay by HIGH voltage level you will activate it by LOW level. End of story 1.

If PAD is floating (open collector or open drain) or does not have determined state on power up, then you can add an external pull-up or pull-down resistor to define its state which will establish proper voltage of that pad until main() where you configure that pad is called. Do not use too low resistance for that to avoid high permanent current consumption through that resistor. 10K should be ok in most designs but it depends on input impedance of your relay circuit. End of story 2.

Who is online

Users browsing this forum: No registered users and 130 guests