esp-idf: RMT with TX loop enabled results in crash. Does not loop for 64 items.

EDIT: apologies - this may actually be two issues - if someone can advise perhaps I should split it into two?

When using RMT to generate a simple square wave, the application will crash if the rmt_config_t.tx_config.loop_en field is set to true and rmt_write_items() is called. If set to false it does not crash.

void rmt_task(void * pvParameter)
{
    rmt_config_t rmt_tx = {
        .rmt_mode = RMT_MODE_TX,
        .channel = RMT_CHANNEL_0,
        .gpio_num = GPIO_NUM_4,
        .mem_block_num = 1,
        .clk_div = 80,
        .tx_config.loop_en = true,  // <-- set this to 'true' for crash
        .tx_config.carrier_en = false,
        .tx_config.idle_level = RMT_IDLE_LEVEL_LOW,
        .tx_config.idle_output_en = true,
    };
    rmt_config(&rmt_tx);
    rmt_driver_install(rmt_tx.channel, 0, 0);

    // simple sequence of high for one clock, low for one clock
    rmt_item32_t items[2] = {0};
    items[0].level0 = 1;
    items[0].duration0 = 1;
    items[0].level1 = 0;
    items[0].duration1 = 1;

    // terminate sequence with a zero-duration item
    items[1].level0 = 0;
    items[1].duration0 = 0;

    // Note: I've also tried this with a single item - same result
    rmt_write_items(RMT_CHANNEL_0, items, 2, false);

    while(1)
        ;
}

void app_main()
{
    xTaskCreate(&rmt_task, "rmt_task", 2048, NULL, 5, NULL);
}

Sometimes when it crashes I see log messages such as:

W (90) boot: PRO CPU has been reset by WDT.

or

***ERROR*** A stack overflow in task ???D??@(?? has been detected.

Other times it just restarts with no error.

100% reproducible with my setup. I’m using ESP-IDF 27574a31e7c41f6e22e10e9b9d7713c6d49f795d

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

It appears that the driver does not support continuous mode for signals that don’t fit in the channel’s reserved memory block(s). So you can try to increase the number of blocks for that channel.