From bf73aaf2af426cb57540f75d165a240b641b3bf3 Mon Sep 17 00:00:00 2001 From: Artem Lytkin Date: Tue, 8 Sep 2026 22:28:45 +0300 Subject: [PATCH 1/2] unix: fix the coverage build on arm64 Clang rejects the forward typedefs the bindings headers share with shared-module under C99, so use -std=gnu11 like every other port. Return the MP3 RMS level as mp_float_t so it no longer promotes to double, and define MP3DEC_GENERIC so lib/mp3 accepts aarch64, as espressif already does. --- ports/unix/Makefile | 4 ++-- ports/unix/variants/coverage/mpconfigvariant.mk | 4 ++++ shared-bindings/audiomp3/MP3Decoder.h | 2 +- shared-module/audiomp3/MP3Decoder.c | 8 ++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ports/unix/Makefile b/ports/unix/Makefile index 32e3b44b227..13cae392648 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -51,7 +51,7 @@ INC += -I$(BUILD) CWARN = -Wall -Werror // CIRCUITPY-CHANGE: add -Wno-missing-field-initializers CWARN += -Wextra -Wno-unused-parameter -Wpointer-arith -Wdouble-promotion -Wfloat-conversion -Wno-missing-field-initializers -CFLAGS += $(INC) $(CWARN) -std=gnu99 -DUNIX $(COPT) -I$(VARIANT_DIR) $(CFLAGS_EXTRA) +CFLAGS += $(INC) $(CWARN) -std=gnu11 -DUNIX $(COPT) -I$(VARIANT_DIR) $(CFLAGS_EXTRA) # Force the use of 64-bits for file sizes in C library functions on 32-bit platforms. # This option has no effect on 64-bit builds. @@ -262,7 +262,7 @@ CFLAGS += -DMPZ_DIG_SIZE=16 # force 16 bits to work on both 32 and 64 bit archs CFLAGS += -DMICROPY_MODULE_FROZEN_STR endif -CXXFLAGS += $(filter-out -Wmissing-prototypes -Wold-style-definition -std=gnu99,$(CFLAGS) $(CXXFLAGS_MOD)) +CXXFLAGS += $(filter-out -Wmissing-prototypes -Wold-style-definition -std=gnu11,$(CFLAGS) $(CXXFLAGS_MOD)) ifeq ($(MICROPY_FORCE_32BIT),1) RUN_TESTS_MPY_CROSS_FLAGS = --mpy-cross-flags='-march=x86' diff --git a/ports/unix/variants/coverage/mpconfigvariant.mk b/ports/unix/variants/coverage/mpconfigvariant.mk index 0dd93b25cf4..2ef5b0a1bdb 100644 --- a/ports/unix/variants/coverage/mpconfigvariant.mk +++ b/ports/unix/variants/coverage/mpconfigvariant.mk @@ -150,6 +150,10 @@ SRC_C += $(addprefix lib/mp3/src/, \ $(BUILD)/lib/mp3/src/buffers.o: CFLAGS += -include "shared-module/audiomp3/__init__.h" -D'MPDEC_ALLOCATOR(x)=malloc(x)' -D'MPDEC_FREE(x)=free(x)' -fwrapv +# mp3dec.h only recognizes a fixed list of platforms and errors out on anything +# else, including aarch64. Ask for the portable C code path, like espressif does. +CFLAGS += -DMP3DEC_GENERIC + CFLAGS += \ -DCIRCUITPY_AESIO=1 \ -DCIRCUITPY_AUDIOCORE=1 \ diff --git a/shared-bindings/audiomp3/MP3Decoder.h b/shared-bindings/audiomp3/MP3Decoder.h index 0b485b4bca1..e316b061248 100644 --- a/shared-bindings/audiomp3/MP3Decoder.h +++ b/shared-bindings/audiomp3/MP3Decoder.h @@ -19,5 +19,5 @@ void common_hal_audiomp3_mp3file_construct(audiomp3_mp3file_obj_t *self, void common_hal_audiomp3_mp3file_set_file(audiomp3_mp3file_obj_t *self, mp_obj_t stream); void common_hal_audiomp3_mp3file_deinit(audiomp3_mp3file_obj_t *self); -float common_hal_audiomp3_mp3file_get_rms_level(audiomp3_mp3file_obj_t *self); +mp_float_t common_hal_audiomp3_mp3file_get_rms_level(audiomp3_mp3file_obj_t *self); uint32_t common_hal_audiomp3_mp3file_get_samples_decoded(audiomp3_mp3file_obj_t *self); diff --git a/shared-module/audiomp3/MP3Decoder.c b/shared-module/audiomp3/MP3Decoder.c index 6f0b5d4723f..463fccf9708 100644 --- a/shared-module/audiomp3/MP3Decoder.c +++ b/shared-module/audiomp3/MP3Decoder.c @@ -517,14 +517,14 @@ audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t * return result; } -float common_hal_audiomp3_mp3file_get_rms_level(audiomp3_mp3file_obj_t *self) { - float sumsq = 0.f; +mp_float_t common_hal_audiomp3_mp3file_get_rms_level(audiomp3_mp3file_obj_t *self) { + mp_float_t sumsq = MICROPY_FLOAT_CONST(0.0); // Assumes no DC component to the audio. Is that a safe assumption? int16_t *buffer = (int16_t *)(void *)self->pcm_buffer[self->buffer_index]; for (size_t i = 0; i < self->base.max_buffer_length / sizeof(int16_t); i++) { - sumsq += (float)buffer[i] * buffer[i]; + sumsq += (mp_float_t)buffer[i] * buffer[i]; } - return sqrtf(sumsq) / (self->base.max_buffer_length / sizeof(int16_t)); + return MICROPY_FLOAT_C_FUN(sqrt)(sumsq) / (self->base.max_buffer_length / sizeof(int16_t)); } uint32_t common_hal_audiomp3_mp3file_get_samples_decoded(audiomp3_mp3file_obj_t *self) { From ae50cb8a35c9e0ea32c8cc20bc637e04c58cf7cd Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 8 Sep 2026 19:53:02 -0400 Subject: [PATCH 2/2] ports/unix/Makefile: add CIRCUITPY-CHANGE --- ports/unix/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ports/unix/Makefile b/ports/unix/Makefile index 13cae392648..def45e2a405 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -49,8 +49,9 @@ INC += -I$(BUILD) # compiler settings CWARN = -Wall -Werror -// CIRCUITPY-CHANGE: add -Wno-missing-field-initializers +# CIRCUITPY-CHANGE: add -Wno-missing-field-initializers CWARN += -Wextra -Wno-unused-parameter -Wpointer-arith -Wdouble-promotion -Wfloat-conversion -Wno-missing-field-initializers +# CIRCUITPY-CHANGE: use gnu11 instead of gnu99 CFLAGS += $(INC) $(CWARN) -std=gnu11 -DUNIX $(COPT) -I$(VARIANT_DIR) $(CFLAGS_EXTRA) # Force the use of 64-bits for file sizes in C library functions on 32-bit platforms. @@ -262,6 +263,7 @@ CFLAGS += -DMPZ_DIG_SIZE=16 # force 16 bits to work on both 32 and 64 bit archs CFLAGS += -DMICROPY_MODULE_FROZEN_STR endif +# CIRCUITPY-CHANGE: use gnu11 instead of gnu99 CXXFLAGS += $(filter-out -Wmissing-prototypes -Wold-style-definition -std=gnu11,$(CFLAGS) $(CXXFLAGS_MOD)) ifeq ($(MICROPY_FORCE_32BIT),1)