Skip to content

esp32: IDF v5.4(v5.5-dev) compile. #16565

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

Merged
merged 2 commits into from
Jan 24, 2025

Conversation

IhorNehrutsa
Copy link
Contributor

@IhorNehrutsa IhorNehrutsa commented Jan 10, 2025

Summary
This PR attempts to fix the esp32 compilation with IDF v5.4 (v5.5-dev)

Testing
ESP32 generic, ESP32-S3 boards tested with esp32/machine_pin: Add mode and pull in machine_pin_print() as repr() function. #12293.

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.58%. Comparing base (c69f0e4) to head (a4ab847).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #16565   +/-   ##
=======================================
  Coverage   98.58%   98.58%           
=======================================
  Files         167      167           
  Lines       21596    21596           
=======================================
  Hits        21291    21291           
  Misses        305      305           

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

Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Copy link
Contributor

@DvdGiessen DvdGiessen left a comment

Choose a reason for hiding this comment

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

I made the same changes locally to compile against IDF v5.4; found this PR so adding a few comments here instead of opening a new one.

I think this commit/PR should probably be referring to v5.4 instead of v5.5, since the latter is not out yet.

@@ -145,7 +145,7 @@ static mp_obj_t ppp_active(size_t n_args, const mp_obj_t *args) {
return mp_const_true;
}

self->pcb = pppapi_pppos_create(&self->pppif, ppp_output_callback, ppp_status_cb, self);
self->pcb = pppapi_pppos_create(&self->pppif, (void *)ppp_output_callback, ppp_status_cb, self);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of erasing the callback type, since the function is IDF-specific anyway wouldn't it be better to update its signature? That way we'll still get compiler errors if there's potentially incompatible changes in the future.

diff --git a/ports/esp32/network_ppp.c b/ports/esp32/network_ppp.c
index c739264b9..a6e3b152f 100644
--- a/ports/esp32/network_ppp.c
+++ b/ports/esp32/network_ppp.c
@@ -101,7 +101,7 @@ static mp_obj_t ppp_make_new(mp_obj_t stream) {
 }
 MP_DEFINE_CONST_FUN_OBJ_1(esp_network_ppp_make_new_obj, ppp_make_new);
 
-static u32_t ppp_output_callback(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx) {
+static u32_t ppp_output_callback(ppp_pcb *pcb, const void *data, u32_t len, void *ctx) {
     ppp_if_obj_t *self = ctx;
 
     mp_obj_t stream = self->stream;
@@ -110,7 +110,7 @@ static u32_t ppp_output_callback(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx)
     }
 
     int err;
-    return mp_stream_rw(stream, data, len, &err, MP_STREAM_RW_WRITE);
+    return mp_stream_rw(stream, (void *)data, len, &err, MP_STREAM_RW_WRITE);
 }
 
 static void pppos_client_task(void *self_in) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

@@ -770,7 +770,9 @@ static const mp_rom_map_elem_t wlan_if_locals_dict_table[] = {
};
static MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table);

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
_Static_assert(WIFI_AUTH_MAX == 16, "Synchronize WIFI_AUTH_XXX constants with the ESP-IDF. Look at esp-idf/components/esp_wifi/include/esp_wifi_types_generic.h");

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

@@ -402,7 +402,7 @@ static mp_raw_code_t *load_raw_code(mp_reader_t *reader, mp_module_context_t *co

#if MICROPY_EMIT_MACHINE_CODE
} else {
const uint8_t *prelude_ptr;
const uint8_t *prelude_ptr = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

This change is unrelated to this PR, and shouldn't be needed.

Copy link
Contributor

@DvdGiessen DvdGiessen Jan 12, 2025

Choose a reason for hiding this comment

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

I discovered independently this change is required to prevent an error while building against IDFv5.4 with a compiler error; perhaps a change in the compiler version included used by the IDF caused this issue to be exposed?

Without this change:

-- The C compiler identification is GNU 14.2.0
(...)
[1325/1467] Building C object esp-idf/main_esp32s3/CMakeFiles/__idf_main_esp32s3.dir/build/micropython/py/persistentcode.c.obj
FAILED: esp-idf/main_esp32s3/CMakeFiles/__idf_main_esp32s3.dir/build/micropython/py/persistentcode.c.obj (...)
/build/micropython/py/persistentcode.c: In function 'load_raw_code':
/build/micropython/py/persistentcode.c:439:38: error: 'prelude_ptr' may be used uninitialized [-Werror=maybe-uninitialized]
  439 |                 children[n_children] = (void *)prelude_ptr;
      |                 ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/build/micropython/py/persistentcode.c:405:24: note: 'prelude_ptr' was declared here
  405 |         const uint8_t *prelude_ptr; // = NULL;
      |                        ^~~~~~~~~~~
cc1: some warnings being treated as errors
(...)
ninja failed with exit code 1

EDIT: Although I agree it shouldn't be needed; reading it myself it appears correct regardless of which ifdef block is used. Not sure why the compiler disagrees.

Copy link
Member

Choose a reason for hiding this comment

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

Although I agree it shouldn't be needed; reading it myself it appears correct regardless of which ifdef block is used. Not sure why the compiler disagrees.

Yeah, it looks like a compiler optimisation bug here.

I'm using gcc 14.2.1 and arm-none-eabi-gcc 14.2.0 here, and neither of them complain (with MICROPY_EMIT_NATIVE_PRELUDE_SEPARATE_FROM_MACHINE_CODE enabled).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the end, are we forced to leave this fix as is?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we can leave this change in. It doesn't affect any other ports (the code size diff is zero for them all).

@dpgeorge
Copy link
Member

@IhorNehrutsa when you open a pull request, can you please make sure you fill in the GitHub PR template, with a summary, testing that you did, and a list of trade-offs/alternatives. Otherwise we may just close the PR.

@IhorNehrutsa IhorNehrutsa changed the title esp32: IDF v.5.5 compile. esp32: IDF v5.4(v5.5) compile. Jan 13, 2025
@IhorNehrutsa
Copy link
Contributor Author

IhorNehrutsa commented Jan 13, 2025

@dpgeorge

@IhorNehrutsa when you open a pull request, can you please make sure you fill in the GitHub PR template, with a summary, testing that you did, and a list of trade-offs/alternatives. Otherwise we may just close the PR.

The latest line in the template is

Delete this heading if not relevant (i.e. small fixes) -->

It seems that these small fixes are described in the PR/commit title.

Thanks.

@dpgeorge
Copy link
Member

The latest line in the template is

Delete this heading if not relevant (i.e. small fixes) -->

That line is only referring to the Trade-offs and Alternatives heading, not the entire template.

Please can you update the top post of this PR with the following template filled out:

### Summary

<!-- Explain the reason for making this change. What problem does the pull request
     solve, or what improvement does it add? Add links if relevant. -->


### Testing

<!-- Explain what testing you did, and on which boards/ports. If there are
     boards or ports that you couldn't test, please mention this here as well.

     If you leave this empty then your Pull Request may be closed. -->

@IhorNehrutsa IhorNehrutsa force-pushed the esp32_idf_5_5 branch 2 times, most recently from 1212006 to 70ffd8e Compare January 20, 2025 07:56
Copy link
Contributor

@DvdGiessen DvdGiessen left a comment

Choose a reason for hiding this comment

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

Combined changes seem correct to me, but the commits can perhaps be organized to provide a bit more context to future readers.

  • The first commit message still mentions this is for IDFv5.5 which isn't out yet; I think it should only mention v5.4?
  • The other two commits could probably be squashed into the first one; they belong together after all.
  • It might make sense to split out the change to py/persistentcode.c into a separate commit and add a short comment that this is to work around a compiler optimization bug in the compiler used by ESP-IDFv5.4. That way it'll be clear why that change is there, instead of being grouped in with the ESP32 port-specific changes. The change itself seems harmless enough to me; and with a clear separate commit documenting the reason for it I think it should be alright.

@IhorNehrutsa IhorNehrutsa changed the title esp32: IDF v5.4(v5.5) compile. esp32: IDF v5.4(v5.5-dev) compile. Jan 21, 2025
@IhorNehrutsa IhorNehrutsa force-pushed the esp32_idf_5_5 branch 3 times, most recently from 2dcdcaa to 46ee241 Compare January 21, 2025 08:20
@IhorNehrutsa
Copy link
Contributor Author

@DvdGiessen
Thanks for the detailed review.

@@ -100,7 +100,7 @@ static mp_obj_t ppp_make_new(mp_obj_t stream) {
}
MP_DEFINE_CONST_FUN_OBJ_1(esp_network_ppp_make_new_obj, ppp_make_new);

static u32_t ppp_output_callback(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx) {
static u32_t ppp_output_callback(ppp_pcb *pcb, const void *data, u32_t len, void *ctx) {
Copy link
Member

Choose a reason for hiding this comment

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

This change now gives a compiler warning for IDF 5.2.2 (at least, probably also 5.3). So I suggest having something like:

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
static u32_t ppp_output_callback(ppp_pcb *pcb, const void *data, u32_t len, void *ctx)
#else
static u32_t ppp_output_callback(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx)
#endif
{
    ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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.

Thanks for updating, this looks good now.

@dpgeorge dpgeorge added this to the release-1.25.0 milestone Jan 23, 2025
IhorNehrutsa and others added 2 commits January 24, 2025 23:17
Add WIFI_AUTH_WPA3_ENTERPRISE and WIFI_AUTH_WPA2_WPA3_ENTERPRISE, and
update PPP callback signature for latest lwIP.

Co-authored-by: Daniel van de Giessen <daniel@dvdgiessen.nl>
Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
The esp32 IDF toolchain can give a "may be used uninitialized" warning, at
least for ESP32-S3 with gcc 14.2.0.  Silence that warning by initializing
the variable with NULL.

Co-authored-by: Daniel van de Giessen <daniel@dvdgiessen.nl>
Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
@dpgeorge dpgeorge merged commit a4ab847 into micropython:master Jan 24, 2025
64 checks passed
@dpgeorge
Copy link
Member

I updated the esp32 README to note that IDF v5.4 is now supported.

@IhorNehrutsa
Copy link
Contributor Author

Thanks, Daniel.
Thanks, Damien.

@dpgeorge dpgeorge mentioned this pull request Feb 28, 2025
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.

3 participants