Page 1 of 2

[Not a] Bugette in UART examples

Posted: Thu Feb 07, 2019 11:42 am
by RobMeades
Hi there. I've just been programming the UART and found a bugette in the UART examples.

When the examples fill in the uart_config_t structure they all miss out the last two fields, rx_flow_ctrl_thresh and use_ref_tick. Since the structure is on the stack these fields will generally be left containing garbage resulting, in my case, in strange errors, e.g. "uart: uart_set_hw_flow_ctrl(257): rx flow thresh error" (since I had HW flow control disabled, as the example does).

It would be worth you modifying the examples to fill in all of the fields.

Re: Bugette in UART examples

Posted: Sat Feb 09, 2019 11:05 am
by ESP_Sprite
Erm, which example specifically does this? I opened a few, and they all use the C90-style designated initializers:

Code: Select all

uart_config_t uart_config = {
    .baud_rate = 115200,
    //...
}
Because initializers like that make all fields that are not mentioned 0/NULL, I don't think there is an issue.

Re: Bugette in UART examples

Posted: Sun Feb 10, 2019 9:58 am
by Ritesh
RobMeades wrote:
Thu Feb 07, 2019 11:42 am
Hi there. I've just been programming the UART and found a bugette in the UART examples.

When the examples fill in the uart_config_t structure they all miss out the last two fields, rx_flow_ctrl_thresh and use_ref_tick. Since the structure is on the stack these fields will generally be left containing garbage resulting, in my case, in strange errors, e.g. "uart: uart_set_hw_flow_ctrl(257): rx flow thresh error" (since I had HW flow control disabled, as the example does).

It would be worth you modifying the examples to fill in all of the fields.
Hi,

We are using all UARTs into our project and didn't find any issue like you have faced. So, Would you please check that did you miss anything into UART configuration or not?

Re: Bugette in UART examples

Posted: Mon Feb 11, 2019 10:26 am
by RobMeades
Ah, I had not understood that the newfangled C90 initialiser pattern (not something I've ever seen used in an embedded system before) guarantees zeroes in the uninitialised portions. That's all fine then.

Re: Bugette in UART examples

Posted: Tue Feb 12, 2019 10:35 am
by Ritesh
RobMeades wrote:
Mon Feb 11, 2019 10:26 am
Ah, I had not understood that the newfangled C90 initialiser pattern (not something I've ever seen used in an embedded system before) guarantees zeroes in the uninitialised portions. That's all fine then.
Hi,

So, Issue has been resolved which you have posted here or still facing?

Re: [Not a] Bugette in UART examples

Posted: Tue Feb 12, 2019 10:41 am
by RobMeades
Yes, though I won't use C90-style initialisers myself just yet (afraid that people reading my code will not realise what's going on in such scarily modern constructions), I now know what you intend and so can initialise all the structure elements appropriately myself.

Re: [Not a] Bugette in UART examples

Posted: Tue Feb 12, 2019 11:48 am
by ESP_Sprite
No offense, you're free to write your code in whichever way you want, but you do know the '90' in 'c90' stands for the year the standard was introduced, right? That means by now it's almost 30 years old; there are people on this very forum, doing productive things with ESP32s, that never lived during a time where designated initializers weren't valid. Just idly wondering: If 30 years is not enough for these constructs not to be scary, how long do you intend to wait to use them?

Re: [Not a] Bugette in UART examples

Posted: Tue Feb 12, 2019 11:53 am
by RobMeades
:-) I thought you might say that. Just to give you an idea how conservative the embedded world is, I've been coding embedded systems in C all my working life (which started after C90) and have never seen this construction before. And I'm not alone: I asked a colleague 10 years younger than me and he also hadn't seen the construction before (in fact he said "what does it do with strings?").

Just sayin'...

Re: [Not a] Bugette in UART examples

Posted: Tue Feb 12, 2019 11:58 am
by ESP_Sprite
Kinda makes you wonder if 100 years in the future, people are still writing in the classic Ansi C because no one decided to ever look up any advances after the first one...

Also curious: do you guys also only use /* */ style comments? Because // came even later than C90.

Re: [Not a] Bugette in UART examples

Posted: Tue Feb 12, 2019 12:02 pm
by RobMeades
Newest coding standard (which I wrote) allows "//" comments but some still fear them from the days when compilers with previous ANSI compliance and strict checking would throw an error.

Next you'll be saying that the ESP32 API's should have been written in C++ like mbed-os ;-).