-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support for inverting reset and boot pins (ESF-177) #120
base: master
Are you sure you want to change the base?
Conversation
I do not understand how the esp32_spi_port |
Thanks @shiona, nice work! Please remove the reset inverting from SPI port and mention in the documentation and Kconfig that the feature is UART only. I do not see reason to implement it to 'esp32_usb_cdc_acm_port' and if we'll agree to add this feature to 'esp32_spi_port' I will do that. Thanks. |
I installed python kconfiglib and used its menuconfig to check that:
|
README.md
Outdated
* `SERIAL_FLASHER_RESET_INVERT` | ||
|
||
This inverts the output of the reset gpio pin. Useful if the hardware has inverting connection | ||
between the host and the target reset pin. Works only on UART interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nitpick.
between the host and the target reset pin. Works only on UART interface. | |
between the host and the target reset pin. Implemented only for UART interface. |
README.md
Outdated
|
||
* `SERIAL_FLASHER_BOOT_INVERT` | ||
This inverts the output of the boot (IO0) gpio pin. Useful if the hardware has inverting connection | ||
between the host and the target boot pin. Works only on UART interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
between the host and the target boot pin. Works only on UART interface. | |
between the host and the target boot pin. Implemented only for UART interface.. |
Please squash the second commit to the first one. I proposed just a little nitpick. Did a quick test and I like it, thanks for finding out the Thank you for contribution. I will test it properly and merge it as soon as possible. |
Add two new config variables SERIAL_FLASHER_RESET_INVERT and SERIAL_FLASHER_BOOT_INVERT that invert the output of their respective pins when resetting the target device. Only implemented for UART interface.
8de5511
to
848a0ab
Compare
I would have squashed them earlier, but the PR template specifically requests not force pushing after review has started. |
Okay, thanks for letting me know. |
I tried to build it and found few problems unfortunately. Main problem is that bool type option is not present in sdkconfig.h when set to |
config SERIAL_FLASHER_RESET_INVERT | ||
bool "Invert reset signal" | ||
default n | ||
depends on SERIAL_FLASHER_INTERFACE_UART | ||
help | ||
Enable this option if there is an inverting connection between | ||
the output of the serial-flasher and the reset pin of the ESP chip. | ||
|
||
config SERIAL_FLASHER_BOOT_INVERT | ||
bool "Invert boot signal" | ||
default n | ||
depends on SERIAL_FLASHER_INTERFACE_UART | ||
help | ||
Enable this option if there is an inverting connection between | ||
the output of the serial-flasher and the boot pin of the ESP chip. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config SERIAL_FLASHER_RESET_INVERT | |
bool "Invert reset signal" | |
default n | |
depends on SERIAL_FLASHER_INTERFACE_UART | |
help | |
Enable this option if there is an inverting connection between | |
the output of the serial-flasher and the reset pin of the ESP chip. | |
config SERIAL_FLASHER_BOOT_INVERT | |
bool "Invert boot signal" | |
default n | |
depends on SERIAL_FLASHER_INTERFACE_UART | |
help | |
Enable this option if there is an inverting connection between | |
the output of the serial-flasher and the boot pin of the ESP chip. | |
config SERIAL_FLASHER_RESET_ACTIVE_LEVEL | |
int "Set the active level of the reset pin" | |
range 0 1 | |
default 0 | |
depends on SERIAL_FLASHER_INTERFACE_UART | |
help | |
Set the active level of the reset pin. 0 for low active, 1 for high active. | |
config SERIAL_FLASHER_BOOT_ACTIVE_LEVEL | |
int "Set the active level of the boot pin" | |
range 0 1 | |
default 0 | |
depends on SERIAL_FLASHER_INTERFACE_UART | |
help | |
Set the active level of the boot pin. 0 for low active, 1 for high active. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't see a problem with the current naming, but this is fine as well.
* `SERIAL_FLASHER_RESET_INVERT` | ||
|
||
This inverts the output of the reset gpio pin. Useful if the hardware has inverting connection | ||
between the host and the target reset pin. Implemented only for UART interface. | ||
|
||
Default: n | ||
|
||
* `SERIAL_FLASHER_BOOT_INVERT` | ||
This inverts the output of the boot (IO0) gpio pin. Useful if the hardware has inverting connection | ||
between the host and the target boot pin. Implemented only for UART interface. | ||
|
||
Default: n | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite appropriately.
@@ -142,18 +142,18 @@ esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeo | |||
// assert reset pin for 50 milliseconds. | |||
void loader_port_enter_bootloader(void) | |||
{ | |||
gpio_set_level(s_gpio0_trigger_pin, 0); | |||
gpio_set_level(s_gpio0_trigger_pin, SERIAL_FLASHER_BOOT_INVERT ? 1 : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gpio_set_level(s_gpio0_trigger_pin, SERIAL_FLASHER_BOOT_INVERT ? 1 : 0); | |
gpio_set_level(s_gpio0_trigger_pin, CONFIG_SERIAL_FLASHER_BOOT_ACTIVE_LEVEL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esp32_port.c refers to SERIAL_FLASHER_RESET_HOLD_TIME_MS
as such without CONFIG_
prefix.
Is there something I don't understand why this new option would behave differently?
This same question goes for the other comments too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @shiona, this is due to the fact that KConfig options do not get simply passed as defines to the build in ESP-IDF. KConfig options are processed and then CMake variables are created from them, which have to be handled in the build system.
These CMake variables will have the CONFIG
prefix, unlike CMake variables for non-esp ports.
You can see that we have created a convenience macro for adding options which handles those differences and also the n
and y
booleans from KConfig, please use this to add the option.
loader_port_reset_target(); | ||
loader_port_delay_ms(SERIAL_FLASHER_BOOT_HOLD_TIME_MS); | ||
gpio_set_level(s_gpio0_trigger_pin, 1); | ||
gpio_set_level(s_gpio0_trigger_pin, SERIAL_FLASHER_BOOT_INVERT ? 0 : 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gpio_set_level(s_gpio0_trigger_pin, SERIAL_FLASHER_BOOT_INVERT ? 0 : 1); | |
gpio_set_level(s_gpio0_trigger_pin, !CONFIG_SERIAL_FLASHER_BOOT_ACTIVE_LEVEL); |
} | ||
|
||
|
||
void loader_port_reset_target(void) | ||
{ | ||
gpio_set_level(s_reset_trigger_pin, 0); | ||
gpio_set_level(s_reset_trigger_pin, SERIAL_FLASHER_RESET_INVERT ? 1 : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gpio_set_level(s_reset_trigger_pin, SERIAL_FLASHER_RESET_INVERT ? 1 : 0); | |
gpio_set_level(s_reset_trigger_pin, CONFIG_SERIAL_FLASHER_RESET_ACTIVE_LEVEL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually believe the initial approach is more readable and future-proof, as well as being consistent with the rest of the ports.
loader_port_delay_ms(SERIAL_FLASHER_RESET_HOLD_TIME_MS); | ||
gpio_set_level(s_reset_trigger_pin, 1); | ||
gpio_set_level(s_reset_trigger_pin, SERIAL_FLASHER_RESET_INVERT ? 0 : 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gpio_set_level(s_reset_trigger_pin, !CONFIG_SERIAL_FLASHER_RESET_ACTIVE_LEVEL);
You can use logic inversion in ports where the pin status is set using |
Hi @shiona, sorry for confusion. I did not know about the macro so thanks @DNedic for help. As @DNedic proposed, it should be enough to keep changes you already did and use the macro in |
Add two new config variables SERIAL_FLASHER_RESET_INVERT and SERIAL_FLASHER_BOOT_INVERT that invert the output of their respective pins when resetting the target device.
Description
Some hardware have inverting connection between the host running the esp-serial-flasher code, and the target device boot (io0) and/or reset pin. Before this change such hardware could not be supported.
Related
Implements the feature request in #119
Testing
Minimal testing was done.
One STM32 device flashing an ESP32. Build system is custom and depends completely on Makefiles, so the Kconfig part was not tested at all. No other hardware has been tested.
Checklist
Before submitting a Pull Request, please ensure the following: