[Not a] Bugette in UART examples

RobMeades
Posts: 85
Joined: Thu Nov 29, 2018 1:12 pm

[Not a] Bugette in UART examples

Postby RobMeades » 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.
Last edited by RobMeades on Mon Feb 11, 2019 12:44 pm, edited 1 time in total.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Bugette in UART examples

Postby ESP_Sprite » Sat Feb 09, 2019 11:05 am

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.

Ritesh
Posts: 1365
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Bugette in UART examples

Postby Ritesh » Sun Feb 10, 2019 9:58 am

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?
Regards,
Ritesh Prajapati

RobMeades
Posts: 85
Joined: Thu Nov 29, 2018 1:12 pm

Re: Bugette in UART examples

Postby RobMeades » 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.

Ritesh
Posts: 1365
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Bugette in UART examples

Postby Ritesh » Tue Feb 12, 2019 10:35 am

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?
Regards,
Ritesh Prajapati

RobMeades
Posts: 85
Joined: Thu Nov 29, 2018 1:12 pm

Re: [Not a] Bugette in UART examples

Postby RobMeades » Tue Feb 12, 2019 10:41 am

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.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: [Not a] Bugette in UART examples

Postby ESP_Sprite » Tue Feb 12, 2019 11:48 am

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?

RobMeades
Posts: 85
Joined: Thu Nov 29, 2018 1:12 pm

Re: [Not a] Bugette in UART examples

Postby RobMeades » Tue Feb 12, 2019 11:53 am

:-) 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'...

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: [Not a] Bugette in UART examples

Postby ESP_Sprite » Tue Feb 12, 2019 11:58 am

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.

RobMeades
Posts: 85
Joined: Thu Nov 29, 2018 1:12 pm

Re: [Not a] Bugette in UART examples

Postby RobMeades » Tue Feb 12, 2019 12:02 pm

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 ;-).

Who is online

Users browsing this forum: hp_song, leschge and 123 guests