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

Implement gpio:init/1 on esp32 #1234

Merged
merged 1 commit into from
Jul 26, 2024
Merged

Conversation

pguyot
Copy link
Collaborator

@pguyot pguyot commented Jul 21, 2024

Some GPIO pins require initialization as gpio pins to work, for example GPIO 4 on ESP32C3. This is achieved by calling esp-idf gpio_config. Implement this within gpio:init/1 which is used on rp2040.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@UncleGrumpy
Copy link
Collaborator

Is there any documentation in ESP-IDF about which pins require this special use case? This is new to me, and I can’t find any reference to this being needed for certain pins. We definitely need clear documentation about which pins this is required for to enable them.

@UncleGrumpy
Copy link
Collaborator

This definitely hammers home the need to re-write our GPIO APIs so that they are unified across platforms (and now chipsets within platforms).

@pguyot
Copy link
Collaborator Author

pguyot commented Jul 22, 2024

Is there any documentation in ESP-IDF about which pins require this special use case? This is new to me, and I can’t find any reference to this being needed for certain pins. We definitely need clear documentation about which pins this is required for to enable them.

The documentation says:

Do not rely on the default configurations values in the Technical Reference Manual, because it may be changed in the bootloader or application startup code before app_main.

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html

Because we didn't call gpio_config, we did rely on previous configuration.

Explicitely, the technical reference manual of esp32c3 (page 169) says that pin 9 of esp32-c3 has function 0 MTMS and function 1 GPIO4, so I'm not surprised I had to call gpio_config. There also are functions to select pin functions, but the API changed between esp idf versions, so I favored gpio_config in gpio:init/1.

https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf

The table seems to document that gpios 4-7, 12-17 and 20-21 would need this. Not all are exposed on popular esp32c3 boards though.

Copy link
Collaborator

@bettio bettio left a comment

Choose a reason for hiding this comment

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

Can we mention this change in our changelog?
Let's place this under v0.6.4 section (that I added just before).

Some GPIO pins require initialization as gpio pins to work, for example GPIO 4
on ESP32C3. This is achieved by calling esp-idf `gpio_config`. Implement
this within `gpio:init/1` which is used on rp2040.

Signed-off-by: Paul Guyot <pguyot@kallisys.net>
@bettio bettio merged commit 1f06efc into atomvm:release-0.6 Jul 26, 2024
81 of 87 checks passed
@pguyot pguyot deleted the w29/gpio-init-esp32 branch July 27, 2024 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants