Closed Xylopyrographer closed 4 months ago
Does it also happen if you use this: https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-rgb-led.h#L14
Short answer is yes, using neopixelWrite()
works with USB CDC On Boot either Enabled or Disabled.
Real question is why does Enabling USB CDC On Boot crash the legacy RMT driver at runtime while Disabling USB CDC On Boot does not?
Agree on the real question. @SuGlider will have a look
@Xylopyrographer - I see that your project does #include "driver/rmt.h"
, which is the legacy driver of IDF 5.1
https://github.com/espressif/esp-idf/blob/release/v5.1/components/driver/deprecated/driver/rmt.h
It is deprecated, as said in the folder name.
Arduino Core 3.0.x (IDF 5.1) uses new drivers from driver/rmt_tx.h
and driver/rmt_rx.h
instead.
I think that there is a mix of many thing here that have a conflict, exactly as reported in the issue:
E (91) rmt(legacy): CONFLICT! driver_ng is not allowed to be used with the legacy driver
That sounds like the application is trying to use both, legacy and the new one at the same time... which seems to be forbiden.
Regarding CDC On Boot, I only can guess that it may lead to initialize the new Arduino RMT driver, somehow.
I could not find any call to rmtInit()
or neopixelWrite()
that would cause the issue...
@SuGlider, thanks for the reply.
Couple of points: The RMT driver, though legacy, is included in ESP-IDF v5.x and as well in arduino-esp32 core 3.0.x. Given that any RMT code moving from IDF 4.x to 5.x has to be rewritten from the ground up to use the new API's, inclusion of the legacy driver in the IDF 5.x and core 3.0.x releases is the wise and correct thing to do.
So the issue is, the example above (which uses only the legacy ESP-IDF driver) runs 100% on targets where USB-CDC On Boot is Disabled (or where USB CDC is not available on the target SOC) but fails as noted when USB-CDC On Boot is Enabled.
As the S3 has a complete and separate USB OTG peripheral (in addition to the USB Serial/JTAG peripheral), why would Enabling USB CDC on Boot do anything with the RMT peripheral?
Were you able find from where driver_ng
is invoked?
@Xylopyrographer both drivers should never be used/compiled together. We have moved to the new driver and so should you :) Maybe start using the Arduino layer for it from now on?
@me-no-dev Agree that at some point, moving to the new world order is the thing to to.
In the mean time, the legacy driver is included in core 3.0.x and does work, except when USB-CDC On Boot is Enabled.
The sample sketch uses calls only to the legacy ESP-IDF v4.4.x driver.
Neither the new ESP-IDF v5.x.y RMT drivers nor the new arduino-esp32 core 3.0.x RMT drivers are included or called.
The issue is, why would enabling USB-CDC On Boot cause an RMT conflict?
The issue is, why would enabling USB-CDC On Boot cause an RMT conflict?
I'll investigate this odd relation.
This is the IDF place where it causes the error (rmt_legacy.c
):
/**
* @brief This function will be called during start up, to check that this legacy RMT driver is not running along with the new driver
*/
__attribute__((constructor))
static void check_rmt_legacy_driver_conflict(void)
{
// This function was declared as weak here. The new RMT driver has one implementation.
// So if the new RMT driver is not linked in, then `rmt_acquire_group_handle()` should be NULL at runtime.
extern __attribute__((weak)) void *rmt_acquire_group_handle(int group_id);
if ((void *)rmt_acquire_group_handle != NULL) {
ESP_EARLY_LOGE(TAG, "CONFLICT! driver_ng is not allowed to be used with the legacy driver");
abort();
}
ESP_EARLY_LOGW(TAG, "legacy driver is deprecated, please migrate to `driver/rmt_tx.h` and/or `driver/rmt_rx.h`");
}
I have tested the LiteLED sketch and it fails only when USB CDC On Boot
is enabled.
It doesn't matter if the CDC Driver is the OTG TinyUSB or Hardware CDC and JTAG.
Based on the IDF code, it looks like a linking issue...
For example, this code with USB CDC On Boot
disabled, also causes the issue:
It just adds a simple digitalWrite()
to the code...
static const uint8_t currBright = 20; // change this to set the brightness level of the matrix
static const crgb_t BLINK_COL = 0x00002f;
LiteLED myDisplay( LED_TYPE, LED_TYPE_IS_RGBW ); // create the LiteLED object
void setup() {
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
delay( 2000 );
printf( "printf: Sketch in setup()" );
Serial.begin( 115200 );
delay( 2000 );
Serial.println( "Sketch in setup()" );
myDisplay.begin( LED_GPIO, 1, 0 ); // initialze the myDisplay object.
myDisplay.brightness( currBright );
myDisplay.setPixel( 0, BLINK_COL, 1 );
}
void loop() {
// blink a pixel
myDisplay.brightness( 0, 1 );
delay( 1000 );
myDisplay.brightness( currBright, 1 );
delay( 1000 );
}
just the pinMode(2)
causes the issue also...
The reason for that is because in esp32-hal-gpio.c
there is a possible call to neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val);
, which in turn llinks RMT HAL into the final firmware.
The code that has it in HAL GPIO is:
extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
#ifdef RGB_BUILTIN
if (pin == RGB_BUILTIN) {
//use RMT to set all channels on/off
RGB_BUILTIN_storage = val;
const uint8_t comm_val = val != 0 ? RGB_BRIGHTNESS : 0;
neopixelWrite(RGB_BUILTIN, comm_val, comm_val, comm_val);
return;
}
#endif
if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) {
gpio_set_level((gpio_num_t)pin, val);
} else {
log_e("IO %i is not set as GPIO.", pin);
}
}
@Xylopyrographer - If the board used has no RGB_BUILTIN definition in its variants/BOARD_NAME/pins_arduino.h
file, the LiteLED sketch works fine.
An example of S3 board that has no RGB_BUILTIN
definition is the u-blox NORA-W10 series (ESP32-S3)
board.
When selecting it, I can set the USB CDC On Boot
enabled and it runs with no issues.
@Xylopyrographer - Therefore, the solution to this puzzle is the call to any GPIO function, in a board that has RGB_BUILTIN
definition, which activates in the code a possible call to neopixelWrite()
that forces the binary to have the linked new RMT driver into it.
Both CDC drivers call digitalWrite()
to set the USB pins... but this is just a coincidence, because any other call to a Arduino GPIO function will also trigger the issue.
Short answer is yes, using
neopixelWrite()
works with USB CDC On Boot either Enabled or Disabled.Real question is why does Enabling USB CDC On Boot crash the legacy RMT driver at runtime while Disabling USB CDC On Boot does not?
This is not correct... if the sketch uses LiteLED.h
and also calls neopixelWrite()
, it will fail in the same way.
@SuGlider Very much appreciate the in-depth analysis. Dealing with a death in the family at this time, will then need some time to absorb it all and get back to you.
@Xylopyrographer @softhack007
Please check the PR #9941 - It creates a way to completely disable the New RMT Driver within Arduino Core 3.0.x. It may be useful for your projects.
Please check the PR #9941 - It creates a way to completely disable the New RMT Driver within Arduino Core 3.0.x. It may be useful for your projects.
I can confirm the fix works for me on -C6, when using arduino 3.0.3. No more crashes at startup 🥇 Thanks @SuGlider thanks for the good help. 👍
@me-no-dev I have written some code to control WS2812 from ESP32-S3 based on esp32-hal-rgb-led.cpp Everything works well with latest Arduino core V3.03. Works with CDC enabled too. Seem like this code works directly with the Arduino Espressif core board libraries and presumably therefore using the latest RMT driver?
@Rich968 yes. they use the new RMT driver
Thanks. All works well.
Board
ESP32S3 Dev Module
Device Description
ESP32S3 Dev Module with an on-board WS2812 RGB LED on GPIO48.
Hardware Configuration
No
Version
v3.0.1
IDE Name
Arduino IDE 2.3.2
Operating System
Debian 12
Flash frequency
Flash Mode: "QIO 80MHZ"
PSRAM enabled
yes
Upload speed
921600
Description
When using the legacy RMT driver as per: https://docs.espressif.com/projects/esp-idf/en/v5.1.4/esp32/migration-guides/release-5.x/5.0/peripherals.html#rmt-driver and when USB CDC On Boot is set to "Disabled" the sketch below runs.
If however USB CDC On Boot is set to "Enabled" the sketch crashes into a boot loop. Crash log is below.
The LiteLED library uses only ESP-IDF calls.
To test, must use the LiteLED v3 development branch at: https://github.com/Xylopyrographer/LiteLED/tree/v1.3
Sketch
Debug Message
Other Steps to Reproduce
Crash occurs whenever USB CDC On Boot is enabled, regardless of other USB settings and whether PSRAM is enabled or not.
Serial monitor output with Core Debug Level: "Debug" and USB DFU On Boot: "Disabled":
I have checked existing issues, online documentation and the Troubleshooting Guide