From 8af7f377078ab5049a01817dec79d523b25a2352 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 11 Jul 2025 21:18:21 +0300 Subject: [PATCH 1/5] Revert "espressif: port_malloc() shoud not use SPIRAM when dma_capable=true" This reverts commit f999afd2c8d53ca3a3525fdf4fc3d9f592d114eb. --- ports/espressif/supervisor/port.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ports/espressif/supervisor/port.c b/ports/espressif/supervisor/port.c index 48ae29ab4f927..ba25747476c5e 100644 --- a/ports/espressif/supervisor/port.c +++ b/ports/espressif/supervisor/port.c @@ -308,18 +308,18 @@ void port_heap_init(void) { } void *port_malloc(size_t size, bool dma_capable) { + size_t caps = MALLOC_CAP_8BIT; if (dma_capable) { - // SPIRAM is not DMA-capable, so don't bother to ask for it. - return heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA); + caps |= MALLOC_CAP_DMA; } void *ptr = NULL; - // Try SPIRAM first if available. + // Try SPIRAM first when available. #ifdef CONFIG_SPIRAM - ptr = heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + ptr = heap_caps_malloc(size, caps | MALLOC_CAP_SPIRAM); #endif if (ptr == NULL) { - ptr = heap_caps_malloc(size, MALLOC_CAP_8BIT); + ptr = heap_caps_malloc(size, caps); } return ptr; } From 1d3e6e35fab5127ab3b33683dab9fd2291be80b0 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 11 Jul 2025 21:18:53 +0300 Subject: [PATCH 2/5] Revert "Apply suggestions from code review" This reverts commit a2ad339de06745f9cc894bbbea938e32cc6dd63b. --- ports/espressif/common-hal/pulseio/PulseIn.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/espressif/common-hal/pulseio/PulseIn.c b/ports/espressif/common-hal/pulseio/PulseIn.c index a90f9796ab8c5..d76542b07c5ac 100644 --- a/ports/espressif/common-hal/pulseio/PulseIn.c +++ b/ports/espressif/common-hal/pulseio/PulseIn.c @@ -82,7 +82,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu // captured because we may skip the first portion of a symbol. self->raw_symbols_size = (maxlen / 2 + 1) * sizeof(rmt_symbol_word_t); // RMT DMA mode cannot access PSRAM -> ensure raw_symbols is in internal ram - self->raw_symbols = (rmt_symbol_word_t *)port_malloc(self->raw_symbols_size, true); + self->raw_symbols = (rmt_symbol_word_t *)heap_caps_malloc(self->raw_symbols_size, MALLOC_CAP_INTERNAL); if (self->raw_symbols == NULL) { m_free(self->buffer); m_malloc_fail(self->raw_symbols_size); @@ -116,7 +116,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu // If we fail here, the self->buffer will be garbage collected. esp_err_t result = rmt_new_rx_channel(&config, &self->channel); if (result != ESP_OK) { - port_free(self->raw_symbols); + heap_caps_free(self->raw_symbols); raise_esp_error(result); } @@ -127,7 +127,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu rmt_enable(self->channel); result = rmt_receive(self->channel, self->raw_symbols, self->raw_symbols_size, &rx_config); if (result != ESP_OK) { - port_free(self->raw_symbols); + heap_caps_free(self->raw_symbols); raise_esp_error(result); } } From 25edea87e234ca5c0282f7ae72c60ec41de6c149 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 11 Jul 2025 21:19:01 +0300 Subject: [PATCH 3/5] Revert "fix whitespaces" This reverts commit dde4a40c594783f037c927546a11eef51f0352f6. --- ports/espressif/common-hal/pulseio/PulseIn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/espressif/common-hal/pulseio/PulseIn.c b/ports/espressif/common-hal/pulseio/PulseIn.c index d76542b07c5ac..e292761d3bbf2 100644 --- a/ports/espressif/common-hal/pulseio/PulseIn.c +++ b/ports/espressif/common-hal/pulseio/PulseIn.c @@ -115,7 +115,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu }; // If we fail here, the self->buffer will be garbage collected. esp_err_t result = rmt_new_rx_channel(&config, &self->channel); - if (result != ESP_OK) { + if (result != ESP_OK){ heap_caps_free(self->raw_symbols); raise_esp_error(result); } @@ -126,7 +126,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu rmt_rx_register_event_callbacks(self->channel, &rx_callback, self); rmt_enable(self->channel); result = rmt_receive(self->channel, self->raw_symbols, self->raw_symbols_size, &rx_config); - if (result != ESP_OK) { + if (result != ESP_OK){ heap_caps_free(self->raw_symbols); raise_esp_error(result); } From 1e77ad2c205891729317d686ad111a8b4a1e84df Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 11 Jul 2025 21:19:02 +0300 Subject: [PATCH 4/5] Revert "espressif: use dma for pulseio" This reverts commit 85db016b8c6464ba256f155000a5946b78109ad6. --- ports/espressif/common-hal/pulseio/PulseIn.c | 22 ++++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/ports/espressif/common-hal/pulseio/PulseIn.c b/ports/espressif/common-hal/pulseio/PulseIn.c index e292761d3bbf2..f7e500790562a 100644 --- a/ports/espressif/common-hal/pulseio/PulseIn.c +++ b/ports/espressif/common-hal/pulseio/PulseIn.c @@ -80,9 +80,8 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu } // We add one to the maxlen version to ensure that two symbols at lease are // captured because we may skip the first portion of a symbol. - self->raw_symbols_size = (maxlen / 2 + 1) * sizeof(rmt_symbol_word_t); - // RMT DMA mode cannot access PSRAM -> ensure raw_symbols is in internal ram - self->raw_symbols = (rmt_symbol_word_t *)heap_caps_malloc(self->raw_symbols_size, MALLOC_CAP_INTERNAL); + self->raw_symbols_size = MIN(64, maxlen / 2 + 1) * sizeof(rmt_symbol_word_t); + self->raw_symbols = (rmt_symbol_word_t *)m_malloc_without_collect(self->raw_symbols_size); if (self->raw_symbols == NULL) { m_free(self->buffer); m_malloc_fail(self->raw_symbols_size); @@ -110,26 +109,17 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, const mcu .clk_src = RMT_CLK_SRC_DEFAULT, // 2 us resolution so we can capture 65ms pulses. The RMT period is only 15 bits. .resolution_hz = 1000000 / 2, - .mem_block_symbols = self->raw_symbols_size, - .flags.with_dma = 1 + .mem_block_symbols = SOC_RMT_MEM_WORDS_PER_CHANNEL, }; - // If we fail here, the self->buffer will be garbage collected. - esp_err_t result = rmt_new_rx_channel(&config, &self->channel); - if (result != ESP_OK){ - heap_caps_free(self->raw_symbols); - raise_esp_error(result); - } + // If we fail here, the buffers allocated above will be garbage collected. + CHECK_ESP_RESULT(rmt_new_rx_channel(&config, &self->channel)); rmt_rx_event_callbacks_t rx_callback = { .on_recv_done = _done_callback }; rmt_rx_register_event_callbacks(self->channel, &rx_callback, self); rmt_enable(self->channel); - result = rmt_receive(self->channel, self->raw_symbols, self->raw_symbols_size, &rx_config); - if (result != ESP_OK){ - heap_caps_free(self->raw_symbols); - raise_esp_error(result); - } + rmt_receive(self->channel, self->raw_symbols, self->raw_symbols_size, &rx_config); } bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) { From 8f54e3343703303a802a603c62f2f281950ad673 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 11 Jul 2025 21:55:05 +0300 Subject: [PATCH 5/5] Reapply "espressif: port_malloc() shoud not use SPIRAM when dma_capable=true" This reverts commit 8af7f377078ab5049a01817dec79d523b25a2352. --- ports/espressif/supervisor/port.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ports/espressif/supervisor/port.c b/ports/espressif/supervisor/port.c index ba25747476c5e..48ae29ab4f927 100644 --- a/ports/espressif/supervisor/port.c +++ b/ports/espressif/supervisor/port.c @@ -308,18 +308,18 @@ void port_heap_init(void) { } void *port_malloc(size_t size, bool dma_capable) { - size_t caps = MALLOC_CAP_8BIT; if (dma_capable) { - caps |= MALLOC_CAP_DMA; + // SPIRAM is not DMA-capable, so don't bother to ask for it. + return heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA); } void *ptr = NULL; - // Try SPIRAM first when available. + // Try SPIRAM first if available. #ifdef CONFIG_SPIRAM - ptr = heap_caps_malloc(size, caps | MALLOC_CAP_SPIRAM); + ptr = heap_caps_malloc(size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); #endif if (ptr == NULL) { - ptr = heap_caps_malloc(size, caps); + ptr = heap_caps_malloc(size, MALLOC_CAP_8BIT); } return ptr; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy