Skip to content

Commit f160701

Browse files
committed
Merge branch 'fix/rmt_tx_loop_mode' into 'master'
fix(rmt): correct the condition for warnings in loop mode See merge request espressif/esp-idf!41060
2 parents 14f2d9e + 6c3d275 commit f160701

File tree

3 files changed

+11
-8
lines changed
  • components/esp_driver_rmt/src
  • docs
    • en/api-reference/peripherals
    • zh_CN/api-reference/peripherals

3 files changed

+11
-8
lines changed

components/esp_driver_rmt/src/rmt_tx.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ esp_err_t rmt_transmit(rmt_channel_handle_t channel, rmt_encoder_t *encoder, con
521521
ESP_RETURN_ON_FALSE(channel && encoder && payload && payload_bytes && config, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
522522
ESP_RETURN_ON_FALSE(channel->direction == RMT_CHANNEL_DIRECTION_TX, ESP_ERR_INVALID_ARG, TAG, "invalid channel direction");
523523
#if !SOC_RMT_SUPPORT_TX_LOOP_COUNT
524-
ESP_RETURN_ON_FALSE(config->loop_count <= 0, ESP_ERR_NOT_SUPPORTED, TAG, "loop count is not supported");
524+
ESP_RETURN_ON_FALSE(config->loop_count <= 1, ESP_ERR_NOT_SUPPORTED, TAG, "loop count is not supported");
525525
#endif // !SOC_RMT_SUPPORT_TX_LOOP_COUNT
526526
#if CONFIG_RMT_TX_ISR_CACHE_SAFE
527527
// payload is retrieved by the encoder, we should make sure it's still accessible even when the cache is disabled
@@ -546,7 +546,8 @@ esp_err_t rmt_transmit(rmt_channel_handle_t channel, rmt_encoder_t *encoder, con
546546
t->encoder = encoder;
547547
t->payload = payload;
548548
t->payload_bytes = payload_bytes;
549-
t->loop_count = config->loop_count;
549+
// treat loop_count == 1 as no loop
550+
t->loop_count = config->loop_count == 1 ? 0 : config->loop_count;
550551
t->remain_loop_count = t->loop_count;
551552
t->flags.eot_level = config->flags.eot_level;
552553

@@ -648,20 +649,22 @@ size_t rmt_encode_check_result(rmt_tx_channel_t *tx_chan, rmt_tx_trans_desc_t *t
648649
rmt_encode_state_t encode_state = RMT_ENCODING_RESET;
649650
rmt_encoder_handle_t encoder = t->encoder;
650651
size_t encoded_symbols = encoder->encode(encoder, &tx_chan->base, t->payload, t->payload_bytes, &encode_state);
652+
bool is_mem_full = encode_state & RMT_ENCODING_MEM_FULL;
653+
bool need_eof_mark = (encode_state & RMT_ENCODING_WITH_EOF) == 0;
651654

652655
if (encode_state & RMT_ENCODING_COMPLETE) {
653-
bool need_eof_mark = (encode_state & RMT_ENCODING_WITH_EOF) == 0;
654656
// inserting EOF symbol if there's extra space
655-
if (!(encode_state & RMT_ENCODING_MEM_FULL)) {
657+
if (!is_mem_full) {
656658
encoded_symbols += rmt_tx_mark_eof(tx_chan, need_eof_mark);
657659
}
658660
t->flags.encoding_done = true;
659661
t->flags.need_eof_mark = need_eof_mark;
660662
}
661663

662-
// for loop transaction, the memory block should accommodate all encoded RMT symbols
664+
// for loop transaction, the memory block should accommodate all encoded RMT symbols and an extra EOF symbol
663665
if (t->loop_count != 0) {
664-
if (unlikely(encoded_symbols > tx_chan->base.mem_block_num * SOC_RMT_MEM_WORDS_PER_CHANNEL)) {
666+
size_t limit_symbols = tx_chan->base.mem_block_num * SOC_RMT_MEM_WORDS_PER_CHANNEL;
667+
if (unlikely(encoded_symbols > limit_symbols || (encoded_symbols == limit_symbols && is_mem_full && need_eof_mark))) {
665668
ESP_DRAM_LOGE(TAG, "encoding artifacts can't exceed hw memory block for loop transmission");
666669
}
667670
}

docs/en/api-reference/peripherals/rmt.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ Once you created an encoder, you can initiate a TX transaction by calling :cpp:f
256256

257257
.. note::
258258

259-
There is a limitation in the transmission size if the :cpp:member:`rmt_transmit_config_t::loop_count` is set to non-zero, i.e., to enable the loop feature. The encoded RMT symbols should not exceed the capacity of the RMT hardware memory block size, or you might see an error message like ``encoding artifacts can't exceed hw memory block for loop transmission``. If you have to start a large transaction by loop, you can try either of the following methods.
259+
There is a limitation in the transmission size if the :cpp:member:`rmt_transmit_config_t::loop_count` is set to non-zero, i.e., to enable the loop feature. The total amount of symbols returned by the encoder should not exceed the capacity of :c:macro:`SOC_RMT_MEM_WORDS_PER_CHANNEL`, or you might see an error message like ``encoding artifacts can't exceed hw memory block for loop transmission``. If you have to start a large transaction by loop, you can try either of the following methods.
260260

261261
- Increase the :cpp:member:`rmt_tx_channel_config_t::mem_block_symbols`. This approach does not work if the DMA backend is also enabled.
262262
- Customize an encoder and construct an infinite loop in the encoding function. See also :ref:`rmt-rmt-encoder`.

docs/zh_CN/api-reference/peripherals/rmt.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ RMT 是一种特殊的通信外设,无法像 SPI 和 I2C 那样发送原始字
256256

257257
.. note::
258258

259-
如果将 :cpp:member:`rmt_transmit_config_t::loop_count` 设置为非零值,即启用循环功能,则传输的大小将受到限制。编码的 RMT 符号不应超过 RMT 硬件内存块容量,否则会出现类似 ``encoding artifacts can't exceed hw memory block for loop transmission`` 的报错信息。如需通过循环启动大型事务,请尝试以下任一方法:
259+
如果将 :cpp:member:`rmt_transmit_config_t::loop_count` 设置为非零值,即启用循环功能,则传输的大小将受到限制。编码器返回的符号总量不能超过 :c:macro:`SOC_RMT_MEM_WORDS_PER_CHANNEL`,否则会出现类似 ``encoding artifacts can't exceed hw memory block for loop transmission`` 的报错信息。如需通过循环启动大型事务,请尝试以下任一方法:
260260

261261
- 增加 :cpp:member:`rmt_tx_channel_config_t::mem_block_symbols`。若此时启用了 DMA 后端,该方法将失效。
262262
- 自定义编码器,并在编码函数中构造一个无限循环,详情请参阅 :ref:`rmt-rmt-encoder`。

0 commit comments

Comments
 (0)