-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
driver: uart-stm32: add line_ctrl_set/get support #8306
driver: uart-stm32: add line_ctrl_set/get support #8306
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8306 +/- ##
======================================
Coverage 53.1% 53.1%
======================================
Files 218 218
Lines 26883 26883
Branches 5952 5952
======================================
Hits 14277 14277
Misses 10172 10172
Partials 2434 2434 Continue to review full report at Codecov.
|
45ffb37
to
d27d8c8
Compare
drivers/serial/uart_stm32.h
Outdated
@@ -19,6 +19,8 @@ struct uart_stm32_config { | |||
struct stm32_pclken pclken; | |||
/* Baud rate */ | |||
u32_t baud_rate; | |||
/* HW flow control */ | |||
u32_t rts_cts:1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"config" struct is device startup configuration.
You should not use it to store information that will be modified at run time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it's my mistake and actually 'config' is const and can't changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want move baud_rate from uart_stm32_config to uart_stm32_data. Because uart_stm32_data can be changed at runtime. what's your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be ok to do that.
But what about setting/reading directly in registers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change baud rate need disable usart first and then calc clock rate and then set registers. thats was almost did in stm32_init.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had updated this pr setting directly in registers now. please review again
} while (0) | ||
|
||
switch (ctrl) { | ||
case LINE_CTRL_BAUD_RATE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not store information in baud_rate which is used to hold start-up configuration.
I propose you update registers directly.
drivers/serial/uart_stm32.c
Outdated
@@ -314,6 +293,15 @@ static int uart_stm32_init(struct device *dev) | |||
LL_USART_PARITY_NONE, | |||
LL_USART_STOPBITS_1); | |||
|
|||
/* HW flow control */ | |||
if (config->rts_cts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should provide a start up configuration otherwise behavior is undefined here.
d27d8c8
to
f9ae244
Compare
2493699
to
e40efad
Compare
drivers/serial/uart_stm32.c
Outdated
|
||
switch (ctrl) { | ||
case LINE_CTRL_BAUD_RATE: | ||
change_if_not_equal(baud_rate, val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're able to update directly registers, why do you need to store information in driver data?
Using registers, you can save some memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we need to use data fields to store information, since we can use device registers.
No, you should not do that. We must using an variable to store the baud_rate setted before. eg: I had set uart's baud rate to 115200, but the baudrate readed is 115107.
|
drivers/serial/uart_stm32.c
Outdated
return -ENOTSUP; | ||
} | ||
|
||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line could not be accessed, code coverage tools will complain.
I propose to remove default and return -ENOSUP here.
drivers/serial/uart_stm32.c
Outdated
}; \ | ||
\ | ||
static struct uart_stm32_data uart_stm32_data_##name = { \ | ||
.baud_rate = CONFIG_UART_STM32_##name##_BAUD_RATE, \ | ||
.rts_cts = 0, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide a constant here so one can known what default value is actually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry can you explain more clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace 0 with something like RTS_HW_FC_DISABLED
drivers/serial/uart_stm32.c
Outdated
static inline void uart_stm32_set_baud_rate(struct device *dev, | ||
u32_t clock_rate, u32_t baud_rate) | ||
{ | ||
#if defined(CONFIG_SOC_SERIES_STM32L0X) || defined(CONFIG_SOC_SERIES_STM32L4X) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take care to rework this if #8359 is merged first
Ok, let's keep it that way then |
e40efad
to
2bd1367
Compare
@erwango Done |
recheck |
@qianfan-Zhao , can you fix CI issue, so we can continue the review?
|
@erwango But I think the best way is no space, there shouldn't add a space between '*' and point. eg: int p; / good / Can we ignore this error? |
I don't think so. It is strange that this "error" has not been detected before. |
This is the lastly commit for checkpatch.pl, seems that scripts haven't changed this days.
|
This is really strange since CAN driver introduction also introduced some |
2bd1367
to
55ec6ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that mandatory to store RTS_CTS in uart_stm32_data_XXX?
Can't we set and get info directly in registers?
drivers/serial/uart_stm32.h
Outdated
#ifdef CONFIG_UART_INTERRUPT_DRIVEN | ||
uart_irq_callback_t user_cb; | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this extra line
55ec6ad
to
a87b08e
Compare
@erwango I had updated this pr based on your requested. Get RTS_CTS informations direct from register. And has another issue fix:
Please review this section carefully. I don't know if return -EINVAL if an uart instance doesn't support hardware flow control is OK. |
a87b08e
to
64e9541
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments, otherwise looks good
drivers/serial/uart_stm32.c
Outdated
#else | ||
uart_stm32_usart_set_baud_rate(dev, clock_rate, baud_rate); | ||
#endif | ||
uart_stm32_set_baud_rate(dev, data->clock_rate, baud_rate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using "data->baud_rate" directly there as well?
drivers/serial/uart_stm32.c
Outdated
break; | ||
case LINE_CTRL_RTS: | ||
if (!IS_UART_HWFLOW_INSTANCE(UartInstance)) { | ||
result = -EINVAL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe ENOTSUP would fit better here
drivers/serial/uart_stm32.c
Outdated
} | ||
break; | ||
default: | ||
result = -ENOTSUP; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EINVAL at this point?
64e9541
to
70485d4
Compare
@erwango recheck |
Can you fix CI and we're good: -:41: ERROR:SPACING: need consistent spacing around '*' (ctx:WxV)
|
70485d4
to
2b69d05
Compare
Well, I'm unsure what is the issue here. |
@erwango Or just fix this issue to let Shippable happy? |
Sure, if you manage to |
support change bandrate and hardware flow control at runtime Signed-off-by: qianfan Zhao <[email protected]>
2b69d05
to
b6ecfc7
Compare
@qianfan-Zhao , this PR will now conflicts with #11185 Do you plan to rebase this PR on top of #11185 when merged? |
@erwango sure, i will |
#11185 merged |
@qianfan-Zhao , closing this as #11185 merged. |
support change bandrate and hardware flow control at runtime
Signed-off-by: qianfan Zhao [email protected]