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

Support for ESP32-C2 & ESP32-C6 #4377

Merged
merged 3 commits into from
Aug 20, 2023
Merged

Support for ESP32-C2 & ESP32-C6 #4377

merged 3 commits into from
Aug 20, 2023

Conversation

vidplace7
Copy link
Contributor

@vidplace7 vidplace7 commented Feb 2, 2023

What does this implement/fix?

Add initial support for GPIO validation on ESP32-C2 and ESP32-C6
These variants require ESP-IDF 5.x support added via #4364

This PR simply seeks to add variant-specific modifications for GPIO Validation, ADC, Deep Sleep wakeup, SPI, and logging based on espressif's datasheets.

Some additional work still needs to be done in logger.cpp and logger.h, marking this as a Draft PR until this is completed.

Docs I referenced:

ESP32-C2:
https://www.espressif.com/sites/default/files/documentation/esp8684_datasheet_en.pdf

ESP32-C6:
https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): fixes

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040

Example entry for config.yaml:

N/A

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@@ -29,7 +29,6 @@
KEY_ESP32,
KEY_SDKCONFIG_OPTIONS,
KEY_VARIANT,
VARIANT_ESP32C3,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was un-used, removed it while I was in here.

@@ -76,7 +76,7 @@ void SPIComponent::setup() {
if (spi_bus_num == 0) {
this->hw_spi_ = &SPI;
} else {
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32C2) || defined(USE_ESP32_VARIANT_ESP32C6)
Copy link
Contributor Author

@vidplace7 vidplace7 Feb 2, 2023

Choose a reason for hiding this comment

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

Confirmed ESP32-C2 and ESP32-C6 use FSPI. This line may have grown too long...

Copy link

@na4ma4 na4ma4 Feb 17, 2023

Choose a reason for hiding this comment

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

Yeah, the clang-format test baulked on it.

Suggested change
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32C2) || defined(USE_ESP32_VARIANT_ESP32C6)
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) || \
defined(USE_ESP32_VARIANT_ESP32C2) || defined(USE_ESP32_VARIANT_ESP32C6)

@Hedda
Copy link

Hedda commented Mar 20, 2023

@vidplace7 Any chance you would also be willing to look at adding support for ESP32-H2 (ESP32-H2-MINI-1 / ESP32-H2-DevKitM-1) as well?

At least on paper, the ESP32-H2 looks to need the same config ESP32-C6 but the ESP32-H2 SoC is without Wi-Fi radio support:

https://www.espressif.com/en/products/socs/esp32-h2

https://www.espressif.com/en/news/ESP32_H2

https://media.digikey.com/pdf/Data%20Sheets/Espressif%20PDFs/ESP32-H2_MINI_1_Prelim_v0.2_EN.pdf

https://github.com/espressif/esp-idf/search?q=esp32h2

@github-actions
Copy link
Contributor

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jun 19, 2023
@Hedda
Copy link

Hedda commented Jun 19, 2023

@vidplace7 any updates on this?

@github-actions github-actions bot removed the stale label Jun 20, 2023
@HarvsG
Copy link

HarvsG commented Jul 1, 2023

These variants are still pending ESP-IDF 5.x support in ESPHome. See: #4364

As per @Hedda in esphome/feature-requests#1397 (comment)

Espressif ESP-IDF v5.1 with ESP32-C6 and ESP32-H2 has now been released

https://github.com/espressif/esp-idf/releases/tag/v5.1

@HeMan
Copy link
Contributor

HeMan commented Jul 3, 2023

Does my debug+logger-pr #5036 work with this?

@stintel
Copy link
Contributor

stintel commented Aug 8, 2023

@vidplace7 would you mind updating this PR with stintel/esphome@ec1c4b4 and unmarking it as draft? Alternatively, you could give me access to your repo/branch and let me do it, or close this PR and I open a new one including your commit? I'll be travelling from 12/08 until at least 31/08, and I'd like to open a PR for ESP32-C6 support before that, and this PR is a dependency of my work.

Thanks!

@stintel stintel force-pushed the esp32-c6 branch 2 times, most recently from 03054ab to f751fb5 Compare August 8, 2023 13:46
@stintel
Copy link
Contributor

stintel commented Aug 8, 2023

I've been testing this for months on multiple ESP32-C6 devices. Have a few of them in production for a few months, and they've been doing great. I'd say it's time to merge this PR.

@vidplace7 vidplace7 marked this pull request as ready for review August 8, 2023 14:10
@probot-esphome
Copy link

probot-esphome bot commented Aug 8, 2023

Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration (adc) you are listed as a code owner for? Thanks!
Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration (logger) you are listed as a code owner for? Thanks!
Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration (spi) you are listed as a code owner for? Thanks!
Hey there @esphome/core, mind taking a look at this pull request as it has been labeled with an integration (esp32) you are listed as a code owner for? Thanks!
Hey there @jesserockz, mind taking a look at this pull request as it has been labeled with an integration (esp32_rmt_led_strip) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@vidplace7
Copy link
Contributor Author

Un-marked as draft thanks to @stintel's amazing work finishing this off.

@vidplace7 vidplace7 changed the title Initial Support for ESP32-C2 & ESP32-C6 Support for ESP32-C2 & ESP32-C6 Aug 8, 2023
@slimcdk
Copy link

slimcdk commented Aug 8, 2023

Not really contributing with anything but an apprecation for the implementation and a verfication! No issues flashing my C6 modules with the following config:

esp32:
  board: esp32-c6-devkitc-1
  variant: esp32c6
  framework:
    type: esp-idf
    version: 5.1.0
    platform_version: https://github.com/stintel/platform-espressif32#esp32-c6-test

@HemmiBZ
Copy link

HemmiBZ commented Aug 17, 2023

I am a newcomer with home assistant but I would like to built some projects with the new esp32-c6 using zigbee or thread. If I understood right there is a chance that within a few months this chip can be used in esphome of home assistant? Or I am wrong? I am not so experienced and I would like to use the simple way selecting esp32-c6 as device. Or should I use the esphome beta integration/add on? Thank you.
@slimcdk If I anderstood right you selected esp32 adding the new device and then you added with yaml the other lines? Did you use esphome or esphome beta? Does it work with zigbee and/or thread?

@slimcdk
Copy link

slimcdk commented Aug 17, 2023

@HemmiBZ Please join the Discord server and let's chat there https://discord.com/invite/KhAMKrd

@Hedda
Copy link

Hedda commented Aug 17, 2023

I am a newcomer with home assistant but I would like to built some projects with the new esp32-c6 using zigbee or thread.

...

Does it work with zigbee and/or thread?

@HemmiBZ I think that Zigbee and Thread implementations would be completely new features so really separate from ESP32-C6.

Neither Zigbee or Thread support exist today in ESPHome and I expect either require quite a lot of work and time to implement.

If you are not a developer then recommend checking out the existing feature request like this -> esphome/feature-requests#1397

Anyway, both Zigbee and Thread and really off-topic for this specific pull request.

@slimcdk
Copy link

slimcdk commented Aug 20, 2023

The UART component won't compile with the current used clock source (UART_SCLK_APB). Adding a check to use a different source should fix it, unless switching entirely to the new source is fine. I've tested one of my projects with an S3 and UART_SCLK_RTC source and it worked fine, but I'm not sure if it will break something else.

https://github.com/esphome/esphome/blob/f16a24ddf460c48176391b06078a70bdedd974b1/esphome/components/uart/uart_component_esp_idf.cpp#L51C34-L51C34

  uart_config_t uart_config;
  uart_config.baud_rate = this->baud_rate_;
  uart_config.data_bits = data_bits;
  uart_config.parity = parity;
  uart_config.stop_bits = this->stop_bits_ == 1 ? UART_STOP_BITS_1 : UART_STOP_BITS_2;
  uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
#if USE_ESP32_VARIANT_ESP32C6
  uart_config.source_clk = UART_SCLK_RTC;
#else
  uart_config.source_clk = UART_SCLK_APB;
#endif
  uart_config.rx_flow_ctrl_thresh = 122;

Copy link
Member

@jesserockz jesserockz left a comment

Choose a reason for hiding this comment

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

Changes look good. Thanks

@jesserockz jesserockz merged commit fe7893d into esphome:dev Aug 20, 2023
25 checks passed
@stintel
Copy link
Contributor

stintel commented Aug 21, 2023

Technically this is enough to close esphome/feature-requests#2176 but merging #5289 would auto-close that. Up to you :-)

@stintel stintel deleted the esp32-c6 branch August 21, 2023 10:57
@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants