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

[NeoPixel] Fix issue running addressable LEDs on ESP32S3 with OPI PSRAM #5254

Open
wants to merge 3 commits into
base: mega
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,17 @@ docs/source/Plugin/_plugin_sets_overview.repl

.platformio/
.pio/

managed_components/

CMakeLists.txt

sdkconfig.max_ESP32s3_16M8M_LittleFS_OPI_PSRAM_CDC_ETH

sdkconfig.defaults

dependencies.lock

.dummy/

.cache/
2 changes: 1 addition & 1 deletion lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "../internal/NeoEsp32RmtMethod_idf5.h"


size_t rmt_encode_led_strip(rmt_encoder_t *encoder, rmt_channel_handle_t channel, const void *primary_data, size_t data_size, rmt_encode_state_t *ret_state)
size_t IRAM_ATTR rmt_encode_led_strip(rmt_encoder_t *encoder, rmt_channel_handle_t channel, const void *primary_data, size_t data_size, rmt_encode_state_t *ret_state)
{
rmt_led_strip_encoder_t *led_encoder = __containerof(encoder, rmt_led_strip_encoder_t, base);
rmt_encoder_handle_t bytes_encoder = led_encoder->bytes_encoder;
Expand Down
20 changes: 15 additions & 5 deletions lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,10 @@ template<typename T_SPEED, typename T_CHANNEL> class NeoEsp32RmtMethodBase
config.gpio_num = static_cast<gpio_num_t>(_pin);
config.mem_block_symbols = NEOESP32_RMT_MEM_BLOCK_SYMBOLS; // memory block size, 64 * 4 = 256 Bytes
config.resolution_hz = RMT_LED_STRIP_RESOLUTION_HZ; // 1 MHz tick resolution, i.e., 1 tick = 1 µs
config.trans_queue_depth = 4; // set the number of transactions that can pend in the background
config.trans_queue_depth = 2; // set the number of transactions that can pend in the background
config.intr_priority = 0;
config.flags.io_loop_back = 0;
config.flags.io_od_mode = 0;
config.flags.invert_out = false; // do not invert output signal
config.flags.with_dma = NEOESP32_RMT_FLAGS_WITH_DMA;

Expand All @@ -464,6 +467,8 @@ template<typename T_SPEED, typename T_CHANNEL> class NeoEsp32RmtMethodBase
encoder_config.resolution = RMT_LED_STRIP_RESOLUTION_HZ;

_tx_config.loop_count = 0; //no loop
_tx_config.flags.eot_level = 0; // Low level for end-of-transaction
_tx_config.flags.queue_nonblocking = 1; // May block

ret += rmt_new_led_strip_encoder(&encoder_config, &_led_encoder, T_SPEED::RmtBit0, T_SPEED::RmtBit1);

Expand All @@ -476,10 +481,10 @@ template<typename T_SPEED, typename T_CHANNEL> class NeoEsp32RmtMethodBase
{
// AddLog(2,"..");
// wait for not actively sending data
// this will time out at 10 seconds, an arbitrarily long period of time
// this will time out at 100 ms, an arbitrarily long period of time
// and do nothing if this happens

if (ESP_OK == ESP_ERROR_CHECK_WITHOUT_ABORT(rmt_tx_wait_all_done(_channel.RmtChannelNumber, 10000 / portTICK_PERIOD_MS)))
if (ESP_OK == ESP_ERROR_CHECK_WITHOUT_ABORT(rmt_tx_wait_all_done(_channel.RmtChannelNumber, 100 / portTICK_PERIOD_MS)))
{
// AddLog(2,"__ %u", _sizeData);
// now start the RMT transmit with the editing buffer before we swap
Expand Down Expand Up @@ -530,10 +535,15 @@ template<typename T_SPEED, typename T_CHANNEL> class NeoEsp32RmtMethodBase
void construct()
{
// AddLog(2,"RMT:construct");
_dataEditing = static_cast<uint8_t*>(malloc(_sizeData));
// _dataEditing = static_cast<uint8_t*>(malloc(_sizeData));
_dataEditing = static_cast<uint8_t*>(
heap_caps_malloc(_sizeData, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA)
);
// data cleared later in Begin()

_dataSending = static_cast<uint8_t*>(malloc(_sizeData));
_dataSending = static_cast<uint8_t*>(
heap_caps_malloc(_sizeData, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA)
);
// no need to initialize it, it gets overwritten on every send
}
};
Expand Down
13 changes: 7 additions & 6 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
; *********************************************************************;

[platformio]
core_dir = .platformio
description = Firmware for ESP82xx/ESP32/ESP32-S2/ESP32-S3/ESP32-C3 for easy IoT deployment of sensors.
boards_dir = boards
lib_dir = lib
extra_configs =
core_dir = .platformio
description = Firmware for ESP82xx/ESP32/ESP32-S2/ESP32-S3/ESP32-C3 for easy IoT deployment of sensors.
boards_dir = boards
lib_dir = lib
build_cache_dir = .cache
extra_configs =
platformio_core_defs.ini
platformio_esp82xx_base.ini
platformio_esp82xx_envs.ini
Expand Down Expand Up @@ -100,7 +101,7 @@ upload_speed = 115200
monitor_speed = 115200
;targets = size, checkprogsize
targets =
src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<*/Commands_tmp/> -<*/ControllerQueue_tmp/> -<*/DataStructs_tmp/> -<*/DataTypes_tmp/> -<*/ESPEasyCore_tmp/> -<*/Globals_tmp/> -<*/Helpers_tmp/> -<*/PluginStructs_tmp/> -<*/WebServer_tmp/>
;src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<*/Commands_tmp/> -<*/ControllerQueue_tmp/> -<*/DataStructs_tmp/> -<*/DataTypes_tmp/> -<*/ESPEasyCore_tmp/> -<*/Globals_tmp/> -<*/Helpers_tmp/> -<*/PluginStructs_tmp/> -<*/WebServer_tmp/>

; Backwards compatibility: https://github.com/platformio/platformio-core/issues/4270
;build_src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<*/Commands/> -<*/ControllerQueue/> -<*/DataStructs/> -<*/DataTypes/> -<*/Globals/> -<*/Helpers/> -<*/PluginStructs/> -<*/WebServer/>
Expand Down
6 changes: 3 additions & 3 deletions platformio_core_defs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ build_flags = -DESP32_STAGE
-DESP_IDF_VERSION_MAJOR=5
-DLIBRARIES_NO_LOG=1
-DDISABLE_SC16IS752_SPI
-DCONFIG_PM_ENABLE
-DCONFIG_PM_ENABLE=0
-DESP_IDF_STILL_NEEDS_SPI_REGISTERS_FIXED
-DPR_9453_FLUSH_TO_CLEAR=clear

Expand Down Expand Up @@ -203,7 +203,7 @@ build_flags = -DESP32_STAGE
-DESP_IDF_VERSION_MAJOR=5
-DLIBRARIES_NO_LOG=1
-DDISABLE_SC16IS752_SPI
-DCONFIG_PM_ENABLE
; -DCONFIG_PM_ENABLE=0
-DETH_TYPE_JL1101_SUPPORTED
; PR_9453_FLUSH_TO_CLEAR_REVERTED
-DPR_9453_FLUSH_TO_CLEAR=clear
Expand All @@ -217,7 +217,7 @@ build_flags = -DESP32_STAGE
-include "sdkconfig.h"
-include "ESPEasy_config.h"
-include "esp32x_fixes.h"
-Wnull-dereference
; -Wnull-dereference
lib_ignore =
lib_extra_dirs =
lib/lib_ssl
Expand Down
6 changes: 4 additions & 2 deletions platformio_esp32_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ extends = common, core_esp32_IDF5_1_4__3_1_0_SPIFFS
upload_speed = 460800
upload_before_reset = default_reset
upload_after_reset = hard_reset
extra_scripts = post:tools/pio/post_esp32.py
extra_scripts = pre:tools/pio/pre_esp32.py
post:tools/pio/post_esp32.py
${extra_scripts_default.extra_scripts}
; you can disable debug linker flag to reduce binary size (comment out line below), but the backtraces will become less readable
; tools/pio/extra_linker_flags.py
Expand Down Expand Up @@ -38,7 +39,8 @@ extends = common, core_esp32_IDF5_3_2__3_1_0_LittleFS
upload_speed = 460800
upload_before_reset = default_reset
upload_after_reset = hard_reset
extra_scripts = post:tools/pio/post_esp32.py
extra_scripts = pre:tools/pio/pre_esp32.py
post:tools/pio/post_esp32.py
${extra_scripts_default.extra_scripts}
; you can disable debug linker flag to reduce binary size (comment out line below), but the backtraces will become less readable
; tools/pio/extra_linker_flags.py
Expand Down
5 changes: 5 additions & 0 deletions platformio_esp32s3_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ build_flags = ${esp32s3_common_LittleFS.build_flags}
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_BUILD_MAX_ESP32
-DPLUGIN_BUILD_IR_EXTENDED
-DCONFIG_PM_LIGHTSLEEP_RTC_OSC_CAL_INTERVAL=1
extra_scripts = ${esp32s3_common_LittleFS.extra_scripts}
custom_sdkconfig =
CONFIG_RMT_ISR_CACHE_SAFE=y
CONFIG_PM_LIGHTSLEEP_RTC_OSC_CAL_INTERVAL=1



39 changes: 39 additions & 0 deletions tools/pio/pre_esp32.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Part of ESPEasy build toolchain.
#
# ESP8266 builds need to concatenate the files to a single .cpp file.
# However for ESP32 we should ignore this file.
# So when building for ESP32, we simply delete this temporary file.

Import("env")

platform = env.PioPlatform()

import os
import glob
import filecmp


def delete_concat_cpp_files(paths_to_concat):
cpp_files = []

cpp_path = paths_to_concat[0]

cpp_path_out = '{}_tmp'.format(cpp_path)

tmp_cpp_file = os.path.join(cpp_path_out, '__tmpfile.cpp')
tmp2_cpp_file = os.path.join(cpp_path_out, '__tmpfile.cpp.test')
if os.path.exists(tmp_cpp_file):
os.remove(tmp_cpp_file)
if os.path.exists(tmp2_cpp_file):
os.remove(tmp2_cpp_file)


delete_concat_cpp_files(['./src/src/Commands',
'./src/src/ControllerQueue',
'./src/src/DataStructs',
'./src/src/DataTypes',
'./src/src/ESPEasyCore',
'./src/src/Globals',
'./src/src/Helpers',
'./src/src/PluginStructs',
'./src/src/WebServer'])
Loading