Repository navigation
esp32: Fix unitialized flags field in init of the RMT driver - #1308
Conversation
|
Verified this issue on Wokwi: this sketch works well with Arduino Core 1.0.6, but is flakey with the latest Arduino Core (2.0.0). I tracked it down to the flags not being initialized, causing the wrong clock source to be selected occasionally. |
|
@samguyer any thoughts on what's left to be done before merging this? |
My guess is that all memory was always initialized to 0x00 in 1.0.6 after reboot (Which would be the correct flag) and not anymore in 2.0.0, so state was random after reboot. My code works flawless since I applied that patch with 2.0.0 and I have a large sketch (1.5MB) with lots of background tasks. |
|
Nice work. This fix works for me using esp core 2.0.0 |
|
@alorbach Thank you so much for identifying this problem. One issue: the rmt_tx.flags part doesn't seem to compile in our commit checks. Does it compile under the old ESP core? |
|
@samguyer note that there's an alternative way to achieve a similar effect, without depending on the existence of the rmt_config_t rmt_tx = {}:As far as I can tell, this initializes all the fields to 0 (including flags). |
|
@urish OK, great, thanks! I figured there was some way to do this in a newer version of C++. Do you know if this syntax works on older versions of the Arduino IDE? |
Both In Or, if you don't trust the compilers conform to the standards, then you'd need to manually review the output of the initialization.... |
|
The definition of rmt_config_t: /**
* @brief Data struct of RMT configure parameters
*/
typedef struct {
rmt_mode_t rmt_mode; /*!< RMT mode: transmitter or receiver */
rmt_channel_t channel; /*!< RMT channel */
gpio_num_t gpio_num; /*!< RMT GPIO number */
uint8_t clk_div; /*!< RMT channel counter divider */
uint8_t mem_block_num; /*!< RMT memory block number */
uint32_t flags; /*!< RMT channel extra configurations, OR'd with RMT_CHANNEL_FLAGS_[*] */
union {
rmt_tx_config_t tx_config; /*!< RMT TX parameter */
rmt_rx_config_t rx_config; /*!< RMT RX parameter */
};
} rmt_config_t;And with older SDK, 3.0 (link): /**
* @brief Data struct of RMT configure parameters
*/
typedef struct {
rmt_mode_t rmt_mode; /*!< RMT mode: transmitter or receiver */
rmt_channel_t channel; /*!< RMT channel */
uint8_t clk_div; /*!< RMT channel counter divider */
gpio_num_t gpio_num; /*!< RMT GPIO number */
uint8_t mem_block_num; /*!< RMT memory block number */
union{
rmt_tx_config_t tx_config; /*!< RMT TX parameter */
rmt_rx_config_t rx_config; /*!< RMT RX parameter */
};
} rmt_config_t; |
|
@henrygab Ah ok, thank you. It's been a while since I thought about initializers. I would probably have gone old-school -- with memset. @urish Yeah, I saw that they added that flags field. I haven't lookup much (yet) at what those flags can do. @alorbach Would you mind modifying your code to use the = {} initialization? Then we can run the commit checks and get this code in the repo. |
|
That's definitely aggregate initialization. For the union, only the first listed item ( Thus, if Thus, I'd recommend proper initialization to zero via |
Sure no problem, I will amend my commit |
32d0363 to
d9a4c2e
Compare
|
@alorbach these are the flags that are currently available: Quoting the docs, which explain why setting the
|
Actually, using brace-init is not guaranteed to initialize the entirety of the structure. Depending on which symbols are defined, Thus, I actually recommended the use of |
d9a4c2e to
f99bc76
Compare
|
@henrygab: I have changed the initialization tp 0 with memset as recommended. |
f99bc76 to
0cd2d10
Compare
|
I have fixed the merge conflicts, can this now be merged? |
The flags field was not initialized to 0 (No flags) which caused random failures of the esp32 RMT driver (Depending on what was in the unitialized memory) on newer esp-idf versions. Also added support for debugging output in ESP32 RMT Driver (Disabled by default). related: FastLED#1300
0cd2d10 to
ebdfea0
Compare
|
When will this be delivered? |
The flags field was not initialized to 0 (No flags) which caused
random failures of the esp32 RMT driver (Depending on what
was in the unitialized memory).
Also added support for debugging output in ESP32 RMT Driver
(Disabled by default).
related: #1300