Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@TrekMax
Copy link
Contributor

@TrekMax TrekMax commented Sep 24, 2024

Summary

The is esp32c2 officially supported in IDF v5.2 but requires a number of changes to work...
Pulling together changes and generic board support needed here.

Testing

Functions verified by actual hardware include:

  • machine.pin
  • machine.i2c
  • machine.adc
  • machine.pwm
  • machine.timer
  • bluetooth

@agatti
Copy link
Contributor

agatti commented Sep 24, 2024

Isn't this already covered by #11869?

@sanderjo
Copy link

Isn't this already covered by #11869?

That is about esp32c6

This PR has subject esp32c2.

So c6 versus c2?

@andrewleech
Copy link
Contributor

Nice one @sanderjo there's a bunch of new chips getting added to IDF these days!

It still needs testing but this commit on the top of my C6 branch is intended to make it easier to bring in new chips like this one if you want to take a look: #15862

@agatti
Copy link
Contributor

agatti commented Sep 24, 2024

@sanderjo I saw the ESP32C2 definition in mpconfigport.h in @andrewleech's branch so I thought it had basic C2 integration too, along with IDF 5.2 - my bad.

@agatti
Copy link
Contributor

agatti commented Sep 24, 2024

@TrekMax MICROPY_EMIT_RV32 being enabled should work on ESP32C2 too, it has the same RV32 core as C3 after all. Same for MICROPY_NLR_SETJMP being disabled.

Edit: forgot to mention that MICROPY_EMIT_RV32 used with MICROPY_NLR_SETJMP will crash native tests unless N_NLR_SETJMP is enabled in py/emitnrv32.c. So just follow C3's definitions set in ports/esp32/mpconfigport.h.

@andrewleech
Copy link
Contributor

@agatti the latest changes on C6 (about to push) should enable the emitter on all risk chips based on the soc defines, rather than listing individual chips.

I suggest this PR would be well placed to rebase on top of the C6 work once it's merged as lots of people have contributed to that PR to help it fill gaps / support that will then naturally apply to many of the newer chips.

@agatti
Copy link
Contributor

agatti commented Sep 24, 2024

@andrewleech oh, that's nice to hear. Hopefully that would make support for the C5 easier to add once that chip shows up in production :)

@projectgus
Copy link
Contributor

Thanks @TrekMax for updating your PR! (Note for housekeeping: this is replacing earlier PR #15440).

Similar to discussions above, suggest we tackle in this order:

  1. Merge esp32c6 support (IDF v5.2) #11869
  2. Damien will do the upcoming 1.24 MicroPython release.
  3. Merge ports/esp32: Use capability defines to configure features. #15862 - this should make adding future SoCs much simpler, but has some risk of bugs in other SoCs.
  4. Rebase this branch, then review and merge ESP32-C2 support.

@TrekMax Let us know if we can help with any part of this process. It should be possible to update this PR with totally new commits without needing to close and open a new PR. There is a guide to doing this online at https://github.com/jimmo/git-and-micropython#README

@TrekMax
Copy link
Contributor Author

TrekMax commented Sep 27, 2024

@projectgus Thanks. I will wait for esp32c6 support (IDF v5.2) #11869 to be merged, then rebase this branch, and then review and commit ESP32-C2 support.

@TrekMax TrekMax force-pushed the port/esp32c2 branch 5 times, most recently from c7d3a2b to 67dec7c Compare October 14, 2024 13:34
@TrekMax
Copy link
Contributor Author

TrekMax commented Oct 14, 2024

@projectgus Hey , the commit has been rebased to the latest master, please review it. Thanks!

@andrewleech
Copy link
Contributor

Hi @TrekMax could you also take a look at this which is intended to make it much easier to bring in new chips: #15862

@TrekMax
Copy link
Contributor Author

TrekMax commented Oct 16, 2024

@andrewleech Of course. I have ESP32C3, ESP32C2 and ESP32S3 to verify it.

@dpgeorge
Copy link
Member

@TrekMax please can you rebase this PR on the latest master, because there have been a lot of changes to the esp32 port, in particular support for IDF v5.3.

@projectgus
Copy link
Contributor

@TrekMax Further to damien's request: now that #15862 is merged a lot of the C2 specific #ifdefs are probably not needed, so the PR will hopefully become very simple. 😁

@TrekMax TrekMax force-pushed the port/esp32c2 branch 2 times, most recently from 0c8abf5 to 642eb25 Compare December 11, 2024 13:39
@TrekMax TrekMax changed the title esp32c2 support (IDF v5.2.2) esp32c2 support (IDF v5.3) Dec 12, 2024
Copy link
Contributor

@projectgus projectgus left a comment

Choose a reason for hiding this comment

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

Thanks for your patience and for the quick update of this PR, @TrekMax ! I have some comments below, mostly minor.

@projectgus
Copy link
Contributor

@TrekMax Thanks for updating the PR in response to the review! It's looking pretty tidy.

There are a couple of unresolved questions above, do you know the answer to them?

@AmirHmZz
Copy link
Contributor

AmirHmZz commented Mar 7, 2025

@TrekMax Any updates on this PR?

@dpgeorge dpgeorge added this to the release-1.26.0 milestone Mar 13, 2025
@dpgeorge
Copy link
Member

Current status of this PR: it needs rebasing on latest master, and resolving the few questions above left by @projectgus .

@projectgus

This comment was marked as outdated.

@projectgus

This comment was marked as outdated.

@projectgus projectgus force-pushed the port/esp32c2 branch 2 times, most recently from abb5131 to 777183b Compare July 25, 2025 04:54
@projectgus
Copy link
Contributor

miracle fix for the Wi-Fi & Bluetooth problems

Turns out this was possible! By tweaking various config settings it was possible to free up 40KB of static RAM (went from 60KB free static RAM to 100KB) and also reduce the runtime memory usage from Wi-Fi and TCP/IP. These tweaks are added in their own sdkconfig.free_ram file, as they're potentially useful for other chips as well.

With the free RAM increases implemented, tests pass:

  • multi_net - passing [*][^]
  • net_inet - passing
  • multi_bluetooth - passing [*]
  • unit tests - defaults, extmod_hardware & ports/esp32 - passing

[*] I had to tweak the run-multitests.py script for ESP32C2 as (like ESP8266) the ESP8684 prints its early boot log at 74880bps which is interpreted as line noise by the script and can trigger encoding errors. Will submit another PR for this.

[^] Except DTLS tests, it seems DTLS support has been disabled on ESP-IDF v5.4.2 (on all targets). Will investigate and submit a fix separately.

@projectgus projectgus requested a review from dpgeorge July 25, 2025 04:55
@codecov
Copy link

codecov bot commented Jul 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.38%. Comparing base (88cb6bc) to head (d4399b3).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #15906   +/-   ##
=======================================
  Coverage   98.38%   98.38%           
=======================================
  Files         171      171           
  Lines       22257    22257           
=======================================
  Hits        21898    21898           
  Misses        359      359           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dpgeorge
Copy link
Member

Thanks @projectgus for getting this working, and tweaking the RAM for WiFi/BLE. That's really good, and this PR is relatively simple.

Just a few minor comments above, but otherwise I think this is good to go in.

Copilot AI review requested due to automatic review settings July 29, 2025 00:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@projectgus
Copy link
Contributor

@dpgeorge Thanks for the detailed review, have updated!

@projectgus
Copy link
Contributor

With these RAM tweaks there's almost as much free RAM on the C2 as the original ESP32 (without SPIRAM) - 142KiB vs 125KiB:

Original:

>>> micropython.mem_info()
stack: 704 out of 15360
GC: total: 56000, used: 3200, free: 52800, max new split: 90112
 No. of 1-blocks: 59, 2-blocks: 10, max blk sz: 19, max free sz: 3287

C2:

>>> import micropython
>>> micropython.mem_info()
stack: 500 out of 15360
GC: total: 35968, used: 1232, free: 34736, max new split: 92160
 No. of 1-blocks: 22, 2-blocks: 7, max blk sz: 19, max free sz: 2158

Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

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

A few more minor comments.

TrekMax and others added 3 commits July 30, 2025 10:51
Includes:
esp32/esp32c2: Adapt to target chip ESP32C2.
esp32/esp32c2: Fix heap size is too small to enable Bluetooth.

Signed-off-by: TianShuangKe <[email protected]>
Signed-off-by: Angus Gratton <[email protected]>
This is necessary for ESP32-C2 Wi-Fi & BT to work reliably (and for TLS to
work at all). On IDF 5.4.2 the free static RAM goes from 60KB to 100KB, and
there will also be a reduction in lwIP & Wi-Fi memory use at runtime.

The performance trade-off seems low for most use cases, although it will
probably be significant for certain combinations of load (i.e. heavy
TCP/IP, heavy BT throughput, and some peripheral driver functions).

Added as a set of config flags because this is potentially useful on other
SoCs where the goal is to maximise RAM available for MicroPython.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
ESP32-C2 ROM prints at 74880bps (same as ESP8266), so need a newline
before first MicroPython output to avoid it being appended on end of
a line of noise.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
@projectgus
Copy link
Contributor

@dpgeorge Updated!

Copy link
Member

@dpgeorge dpgeorge 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 now, thanks!

@dpgeorge dpgeorge merged commit d4399b3 into micropython:master Jul 30, 2025
34 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants