Skip to content

Conversation

@ExtremeGTX
Copy link
Contributor

@ExtremeGTX ExtremeGTX commented Oct 10, 2019

  • Updates gpio driver and device tree files to the new GPIO Config flags
  • Implements the new port_* APIs
  • Fixes GPIO Bank1 config
  • Add esp32.overlay to gpio_basic_api test

Tests:

  • samples/basic/blinky
  • samples/basic/button
  • tests/drivers/gpio/gpio_basic_api
  • tests/drivers/gpio/gpio_api_1pin

Board:

  • esp32 DevKitC V4

Known issues:
part of callback_variants tests are failing

GPIO_INT_LEVEL_HIGH/LOW,
GPIO_INT_LEVEL_ACTIVE/INACTIVE
GPIO_INT_EDGE_BOTH

will continue working on it and update this PR

Signed-off-by: Mohamed ElShahawi [email protected]

@ExtremeGTX ExtremeGTX requested a review from ydamigos as a code owner October 10, 2019 14:55
@zephyrbot zephyrbot added area: PWM Pulse Width Modulation area: I2C area: Boards area: Tests Issues related to a particular existing or missing test labels Oct 10, 2019
@ydamigos
Copy link
Contributor

ydamigos commented Oct 10, 2019

@ExtremeGTX I quickly tested the following samples/test on odroid_go:

samples/basic/blinky -> works
samples/basic/button -> doesn't work (blue_led turns on!!!)
tests/drivers/gpio/gpio_basic_api -> fails (gpio_basic_api.log)

@zephyrbot
Copy link

zephyrbot commented Oct 18, 2019

All checks passed.

Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages.

@ExtremeGTX
Copy link
Contributor Author

tests/drivers/gpio/gpio_basic_api

The following tests still fails:

GPIO_INT_LEVEL_HIGH/LOW,
GPIO_INT_LEVEL_ACTIVE/INACTIVE
GPIO_INT_EDGE_BOTH

GPIO_INT_EDGE_BOTH is working in application code but test case is not working, i tested it on DevKit V4 and M5-Stack using GPIOs and using Buttons.

The problem with LEVEL interrupts is clearing the interrupt, dunno why clearing status register is not working.
it is only working in esp-idf test suite

Copy link
Member

@mnkp mnkp left a comment

Choose a reason for hiding this comment

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

When the issues are fixed, could you also try to run tests/drivers/gpio/gpio_api_1pin/ testcase. It will use the pin where LED0 is connected to perform the test. The test requires pin to work in simultaneous input/output mode. According to the documentation and comments in the pinmux_esp32.c file this is supported.

@pabigot
Copy link
Contributor

pabigot commented Oct 19, 2019

I think I've resolved the core problem; at least in a way that makes sense to me: you can't support both edge and level interrupts simultaneously on this hardware.

CONFIG_GPIO_ESP32_IRQ defaults to 10, which is an edge-triggered interrupt. The test currently fails on the level-triggered tests.

If I set CONFIG_GPIO_ESP32_IRQ=12 in prj.conf then the level tests pass and the edge-triggered ones fail.

There are no CPU interrupts that are listed as both edge and level triggered.

Now it's possible all that is wrong, and in fact you can use any CPU interrupt line for both edge and level interrupts, but it doesn't look that way to me.

So in https://github.com/pabigot/zephyr/commits/pr/19753 I've added a commit that detects the supported trigger type of the configured GPIO interrupt line and rejects attempts to configure for unsupported interrupt types. I also tweaked some macros/comments, and moved the interrupt acknowledge before the callback. I have verified that this does in fact clear the status register, so the fact that it didn't may be because the level configuration conflicted with the interrupt support.

@ExtremeGTX you are welcome to cherry-pick and squash that into your work. This passes the two-pin test with line 10 (edge) and line 12 (level) (or will once #19784 gets merged).

However: I cannot make the both-edge case work, so I've just disabled support for that.

@mnkp
Copy link
Member

mnkp commented Oct 20, 2019

I think I've resolved the core problem; at least in a way that makes sense to me: you can't support both edge and level interrupts simultaneously on this hardware.

There are no CPU interrupts that are listed as both edge and level triggered.

Well spotted, that indeed seems to be the culprit. It is possible to attach more than one "Peripheral Interrupt Source" to the same CPU IRQ, e.g. we can have SPI and I2C modules trigger interrupt on the same IRQ line, however it doesn't seem possible to attach the same "Peripheral Interrupt Source" to two different CPU IRQ lines. In this case, the GPIO module can indeed respond either to edge or level interrupts but not both since any given IRQ line is predefined as either edge or level.

That complicates the driver. One clean way to handle this situation would be to add a function which would take IRQ line number as a parameter and return the type of the interrupt this line supports: edge, level or invalid (since some IRQs are internal to the CPU). Then the driver would need to return -ENOTSUP for the type of the interrupt which is not supported.

@pabigot
Copy link
Contributor

pabigot commented Oct 20, 2019

One clean way to handle this situation would be to add a function which would take IRQ line number as a parameter and return the type of the interrupt this line supports: edge, level or invalid (since some IRQs are internal to the CPU). Then the driver would need to return -ENOTSUP for the type of the interrupt which is not supported.

Like this, perhaps.

@mnkp
Copy link
Member

mnkp commented Oct 20, 2019

Like this, perhaps.

Looks good. But maybe we should put switch (trig) { in the else branch. The macro verifying the supported interrupt type gets resolved at the compilation stage. With the else the switch (trig) { would only get compiled in if supported.

@ExtremeGTX
Copy link
Contributor Author

@pabigot Good Catch 👍
Thanks for this, but dunno why you disabled BOTH_EDGE interrupts, it works in application (i know testcase is not passing), but i tested it with an ACTIVE LOW Button and i got 2 interrupts.
One on button press and the other on button release.
did i miss anything here ?

@pabigot
Copy link
Contributor

pabigot commented Oct 21, 2019

Looks good. But maybe we should put switch (trig) { in the else branch. The macro verifying the supported interrupt type gets resolved at the compilation stage. With the else the switch (trig) { would only get compiled in if supported.

Without the else the compiler will discard the unreachable code that would follow the unconditional return.

Thanks for this, but dunno why you disabled BOTH_EDGE interrupts, it works in application (i know testcase is not passing),

That'd be why. There may be circumstances where it works, but it's not reliable.

@carlescufi
Copy link
Member

@ExtremeGTX can you cherry-pick @pabigot's commit and squash it into yours and then the PR will be ready for merging.

@ExtremeGTX
Copy link
Contributor Author

@carlescufi sure, will do it tomorrow morning.
But, am still want to leave EDGE_BOTH mode enabled, since it works with normal applications.

In the end, it is up to you

@pabigot
Copy link
Contributor

pabigot commented Oct 22, 2019

@ExtremeGTX The general position when discussed today was that if the test doesn't pass we can't enable it, because something's clearly not right. We can continue to investigate and enable it later if we can figure out what's going on. I may find some time for that, or you can look at it, but we'd really like to get the basic driver in ASAP.

@ExtremeGTX
Copy link
Contributor Author

ok, i will update this PR tomorrow morning

@mnkp
Copy link
Member

mnkp commented Oct 22, 2019

GPIO_INT_EDGE_BOTH is working in application code but test case is not working, i tested it on DevKit V4 and M5-Stack using GPIOs and using Buttons.

I don't know the evaluation board in question. However - unless there is some extra circuitry - signal from the button will bounce / won't be clean. It's not a reliable way to verify edge interrupts. Having passing testcase would be preferable.

@ExtremeGTX
Copy link
Contributor Author

ExtremeGTX commented Oct 23, 2019

The new push includes all changes requested by @mnkp and changes done by @pabigot
dunno if i should add something in commit msg to give credits for @pabigot work.

Both tests PASS:

  • tests/drivers/gpio/gpio_basic_api
  • tests/drivers/gpio/gpio_api_1pin

Copy link
Contributor

@pabigot pabigot left a comment

Choose a reason for hiding this comment

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

Code looks good. No need for acknowledgment for such a small change.

The commit message is a little unusual, but except for the subject line including [TOPIC-GPIO] I don't think it violates any standards. There are existing merged PRs that have that same prefix though, so it can be fixed in a cleanup pass over the branch after it's merged.

@ExtremeGTX
Copy link
Contributor Author

@mnkp if you are interested, here is the code i use for testing
https://gist.github.com/ExtremeGTX/fb5a3a35696eee48ec27541b282dfb76

Pins 16,17 gpio0 (Connect both pins using a jumper) - no external circuitry required
Espressif DevkitC V4 board

@mnkp mnkp self-requested a review October 24, 2019 00:33
Copy link
Member

@mnkp mnkp left a comment

Choose a reason for hiding this comment

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

LGTM with minor comment.

- Updates gpio driver and device tree files to the new GPIO Config flags
- Implements the new port_* APIs
- Update I2C and PWM Drivers to use new GPIO config
- Add esp32.overlay to gpio_basic_api test
- refactor convert_int_type, regs struct
- remove config_polarity
- add kConfig notes

Tests:
- samples/basic/blinky
- samples/basic/button
- tests/drivers/gpio/gpio_basic_api
- tests/drivers/gpio/gpio_api_1pin

Board:
- esp32 DevKitC V4

Note about interrupts:
The ESP32 requires specifying a CPU interrupt to be used for GPIO
interrupt signals.  CPU interrupts can be either level or edge (or
special) triggered, but not both.
Please check gpio/Kconfig.esp32 for more info.

Signed-off-by: Mohamed ElShahawi <[email protected]>
@galak galak merged commit 68c1256 into zephyrproject-rtos:topic-gpio Oct 24, 2019
@ExtremeGTX ExtremeGTX deleted the topic-gpio_esp32 branch December 5, 2019 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Boards area: GPIO area: I2C area: PWM Pulse Width Modulation area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants