Skip to content
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

arch/risc-v/espressif: Add full GPIO support #9586

Merged
merged 4 commits into from Jun 24, 2023

Conversation

lucasssvaz
Copy link
Contributor

Summary

Add full GPIO and Buttons support for ESP32-C3/C6/H2 using the Espressif HAL.

Impact

None on existing code. Support for new peripherals when using the Espressif HAL.

Testing

Tested on ESP32-C3-DevKitC.

@gustavonihei
Copy link
Contributor

GPIO interrupts used to be enabled by a specific Kconfig option, disabled by default:

config ESP32_GPIO_IRQ
bool "GPIO pin interrupts"
default n
---help---
Enable support for interrupting GPIO pins

This PR seems to change this behavior. Please confirm whether this is indeed an intended move.

@lucasssvaz
Copy link
Contributor Author

GPIO interrupts used to be enabled by a specific Kconfig option, disabled by default:

config ESP32_GPIO_IRQ
bool "GPIO pin interrupts"
default n
---help---
Enable support for interrupting GPIO pins

This PR seems to change this behavior. Please confirm whether this is indeed an intended move.

Yes, it is. From now on we will follow the same approach as the other chips/boards.

@gustavonihei
Copy link
Contributor

GPIO interrupts used to be enabled by a specific Kconfig option, disabled by default:

config ESP32_GPIO_IRQ
bool "GPIO pin interrupts"
default n
---help---
Enable support for interrupting GPIO pins

This PR seems to change this behavior. Please confirm whether this is indeed an intended move.

Yes, it is. From now on we will follow the same approach as the other chips/boards.

Ok, but besides that is there any stronger reason for doing so?
I believe the initial motivation for having it disabled by default is to avoid the unnecessary memory overhead if GPIO interrupts are not required.
Enabling GPIO interrupts directly affects NR_IRQS, which is used as the size of the NuttX interrupt vector table:

struct irq_info_s g_irqvector[NR_IRQS];

nuttx/sched/irq/irq.h

Lines 57 to 71 in 5e7ce13

struct irq_info_s
{
xcpt_t handler; /* Address of the interrupt handler */
FAR void *arg; /* The argument provided to the interrupt handler. */
#ifdef CONFIG_SCHED_IRQMONITOR
clock_t start; /* Time interrupt attached */
#ifdef CONFIG_HAVE_LONG_LONG
uint64_t count; /* Number of interrupts on this IRQ */
#else
uint32_t mscount; /* Number of interrupts on this IRQ (MS) */
uint32_t lscount; /* Number of interrupts on this IRQ (LS) */
#endif
uint32_t time; /* Maximum execution time on this IRQ */
#endif
};

So, considering that ESP32-C3 contains 22 IRQ-capable pins, this move may increase RAM usage by at least 176 bytes.

@mu578
Copy link

mu578 commented Jun 22, 2023

besides the RAM overhead (2023).

// that's true overhead for nothing ->  (should be chased everywhere)
- gpioinfo("Attach %p\n", irqhandler);
- gpioinfo("Enabling the interrupt\n");

+ gpioinfo(
+     "Attach %p\n"
+     "Enabling the interrupt\n"
+   , irqhandler
+ );

@lucasssvaz
Copy link
Contributor Author

@gustavonihei Me, @tmedicci and @acassis debated about this and decided that there weren't many applications where disabling the GPIO IRQs would be beneficial. So, for the sake of simplicity and consistency, we decided to remove it.

@tmedicci
Copy link
Contributor

@gustavonihei Me, @tmedicci and @acassis debated about this and decided that there weren't many applications where disabling the GPIO IRQs would be beneficial. So, for the sake of simplicity and consistency, we decided to remove it.

Is there any application on NuttX that use GPIO by polling? Particularly, I don't see any benefits of keeping GPIO support without IRQs.

@acassis
Copy link
Contributor

acassis commented Jun 22, 2023

@gustavonihei I think the "overhead" is too small and normally people will need to use GPIO with interrupt. Another alternative could be to keep the Kconfig entry but enable it by default because normally it will be needed 99% of the time when people are using GPIO.

@gustavonihei
Copy link
Contributor

there weren't many applications where disabling the GPIO IRQs would be beneficial

Is there any application on NuttX that use GPIO by polling? Particularly, I don't see any benefits of keeping GPIO support without IRQs.

normally people will need to use GPIO with interrupt

There is one trivial scenario that you (@tmedicci @lucasssvaz @acassis) seem to ignore is that there are many applications that don't work with the processor pins in general-purpose function at all. Take a look at how many defconfigs define CONFIG_ESP32_GPIO_IRQ=y, just a fraction. A practical example is a gateway device, like the newly release Espressif Thread Border Router board, which most probably won't need any externally generated GPIO interrupts at the simplest form.

I think the "overhead" is too small

At the driver level any overhead should be minimized. It is up to the application developer to quantify the size of the overhead and decide whether the price is worth paying.

@tmedicci
Copy link
Contributor

there weren't many applications where disabling the GPIO IRQs would be beneficial

Is there any application on NuttX that use GPIO by polling? Particularly, I don't see any benefits of keeping GPIO support without IRQs.

normally people will need to use GPIO with interrupt

There is one trivial scenario that you (@tmedicci @lucasssvaz @acassis) seem to ignore is that there are many applications that don't work with the processor pins in general-purpose function at all. Take a look at how many defconfigs define CONFIG_ESP32_GPIO_IRQ=y, just a fraction. A practical example is a gateway device, like the newly release Espressif Thread Border Router board, which most probably won't need any externally generated GPIO interrupts at the simplest form.

I think the "overhead" is too small

At the driver level any overhead should be minimized. It is up to the application developer to quantify the size of the overhead and decide whether the price is worth paying.

You're right about the applications that don't use GPIOs at all... So, let's re-think the problem: considering GPIO is being used, should we provide an option to not use the GPIO with IRQs just for the sake of saving a couple of bytes? Are there any practical applications that could be built relying on that?

I agree that this PR doesn't consider this and should be fixed.

@lucasssvaz lucasssvaz force-pushed the feature/esp_gpio branch 2 times, most recently from e7bc50c to 6696896 Compare June 22, 2023 21:38
@lucasssvaz
Copy link
Contributor Author

lucasssvaz commented Jun 22, 2023

I've added the toggle back.

Copy link
Contributor

@pkarashchenko pkarashchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general

arch/risc-v/src/espressif/esp_gpio.c Outdated Show resolved Hide resolved
arch/risc-v/src/espressif/esp_gpio.c Outdated Show resolved Hide resolved
arch/risc-v/src/espressif/esp_gpio.c Outdated Show resolved Hide resolved
arch/risc-v/src/espressif/esp_gpio.c Outdated Show resolved Hide resolved
@xiaoxiang781216 xiaoxiang781216 merged commit 09dcf50 into apache:master Jun 24, 2023
26 checks passed
@jerpelea jerpelea added this to To-Add in Release Notes - 12.2.0 Jun 26, 2023
@jerpelea jerpelea moved this from To-Add to In Progress in Release Notes - 12.2.0 Jun 26, 2023
@lucasssvaz lucasssvaz deleted the feature/esp_gpio branch June 26, 2023 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

7 participants