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

Problem with installing DMX on UART2 #150

Open
k-dedman opened this issue Mar 27, 2024 · 7 comments
Open

Problem with installing DMX on UART2 #150

k-dedman opened this issue Mar 27, 2024 · 7 comments

Comments

@k-dedman
Copy link

k-dedman commented Mar 27, 2024

Any time I try to set up UART2 with dmx_driver_install the program crashes. I am trying to setup all 3 UART ports with a DMX output, I do not need RX or the enable pin. I have tried setting up UART2 on an ESP32-WROOM-32D and a WT32-ETH01 module, both modules crash when trying to setup UART2. UART0 & UART1 are working as intended. I have stripped my project to only setup UART2 and it still crashes. I am using Arduino IDE with esp_dmx 4.1.0


dmx_port_t dmxPort0 = DMX_NUM_0;
dmx_port_t dmxPort1 = DMX_NUM_1;
dmx_port_t dmxPort2 = DMX_NUM_2;

uint8_t dmx0_tx_pin = 1;
uint8_t dmx1_tx_pin = 18;
uint8_t dmx2_tx_pin = 21;

void dmx_setup(void)
{
    dmx_config_t config0 = DMX_CONFIG_DEFAULT;
    dmx_config_t config1 = DMX_CONFIG_DEFAULT;
    dmx_config_t config2 = DMX_CONFIG_DEFAULT;
    dmx_personality_t personalities0[] = {};
    dmx_personality_t personalities1[] = {};
    dmx_personality_t personalities2[] = {};
    int personality_count0 = 0;
    int personality_count1 = 0;
    int personality_count2 = 0;
    dmx_driver_install(dmxPort0, &config0, personalities0, personality_count0);
    dmx_set_pin(dmxPort0, dmx0_tx_pin, -1, -1);
    dmx_driver_install(dmxPort1, &config1, personalities1, personality_count1);
    dmx_set_pin(dmxPort1, dmx1_tx_pin, -1, -1);
    dmx_driver_install(dmxPort2, &config2, personalities2, personality_count2); // Crashes here
    dmx_set_pin(dmxPort2, dmx2_tx_pin, -1, -1);

}
@riwalker
Copy link

riwalker commented Mar 27, 2024

assume you checked the pins, some UARTS have non moveable UART functions (i.e the C6 UART2 has to be on 5 & 4)
I submitted some changes which were included in 4.1.0 for UART2 specifically for the LP (Low-Power) UART which is UART2 on the C6 family. it may be these changes which are now jarring with the older (none LP) UARTS.
look at uart.c (see dmx_art_init(), line ~341) , we may need some additional changes to check for non LP uarts, or only apply the recent changes ONLY for the C6

@k-dedman
Copy link
Author

Thanks for the reply.

The problem is the code never gets to the point where it can set the pins for UART2, if i comment everything out but the dmx_driver_install for UART2, it still crashes.

I looked into the CONFIG_IDF_TARGET_ESP32C6 #ifdef's and commented out the code just to make sure it was initialising UART2 normally and it still crashes. The pins for UART2 should be remappable for the WT32-ETH01 dev board.

I have also made sure that I can setup a serial output on UART2 and that works, so the port can definitely be used.

I have got DMX output working for UART0 (tx pin 1), UART1 (tx pin 17 or 14), but I cannot get it to work on UART2

@k-dedman
Copy link
Author

Ok I got it working.

Not sure whats going wrong but heres how I fixed it.

The program was failing whenever it hit uart_ll_set_sclk due to a null pointer at uart->dev
I removed the check for including UART2 in the dmx_uart_t struct initialisation and the dmx port constant enum. I also explicitly defined &UART2 instead of using the UART_LL_GET_HW function.

static struct dmx_uart_t {
  const int num;
  uart_dev_t *const dev;
  intr_handle_t isr_handle;
} dmx_uart_context[DMX_NUM_MAX] = {
    {.num = 0, .dev = UART_LL_GET_HW(0)},
    {.num = 1, .dev = UART_LL_GET_HW(1)},
// #if DMX_NUM_MAX > 2
    {.num = 2, .dev = &UART2},
// #endif
};
/** @brief DMX port constants.*/
enum {
  DMX_NUM_0, /** @brief DMX port 0.*/
  DMX_NUM_1, /** @brief DMX port 1.*/
// #if SOC_UART_NUM > 2
  DMX_NUM_2, /** @brief DMX port 2.*/
// #endif
  DMX_NUM_MAX /** @brief DMX port max. Used for error checking.*/
};

I now have 3 seperate DMX TX outputs tested and working. Im not sure why this fix works as the ESP32 core should have 3 UARTS available and I had tested this with HardwareSerial.

@riwalker
Copy link

Agree, I also in past versions had to code out the same struct #if test for UART2 and force it, although the latest code works for the LP UART on the C6.
its been a nightmare for the latest esp-idf code rolls, they are making huge code changes around the LP UART, hence why I provided the new routines for UART2 init, its changed every time for the last 3 or 4 esp-idf library release (5.0 to 5.2+)

@GIPdA
Copy link

GIPdA commented Apr 11, 2024

Hello!
Got the same issue today with ESP-IDF and the v4.1.0 release, for an ESP32-C3.
I fixed it with a small change in uart.c, line 32:

#if SOC_UART_NUM > 2

Currently DMX_NUM_MAX is used, but it's an enum and cannot be used in pre-processor.

@bensuffolk
Copy link

This sounds like a problem I have having as well. I have just tried to upgrade from 3.0.3-beta that I have been successfully using on esp-idf 4.4.5 with DMX_NUM_1 and DMX_NUM_2 as the 2 UARTS.

I am using an original ESP32-WROVER

Now I have 4.1.0 it crashes when trying to install the dmx driver for UART2. I have not changed the version of esp-idf.

Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

...

#0  0x400fb617:0x3ffb8240 in uart_ll_set_sclk at /Users/suffo_b/.platformio/packages/framework-espidf/components/hal/esp32/include/hal/uart_ll.h:76
      (inlined by) dmx_uart_init at components/esp_dmx-4.1.0/src/dmx/hal/uart.c:357
#1  0x400f779d:0x3ffb8260 in dmx_driver_install at components/esp_dmx-4.1.0/src/dmx/driver.c:226

@riwalker
Copy link

riwalker commented Jun 11, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants