Skip to content
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

serial: stm32: Implement configure and config_get api calls #12366

Merged
merged 1 commit into from
Jan 17, 2019

Conversation

psidhu
Copy link
Contributor

@psidhu psidhu commented Jan 7, 2019

Implement these two new api calls. Allows on-the-fly configuration
adjustment of uarts.

Signed-off-by: Pushpal Sidhu [email protected]

@codecov-io
Copy link

codecov-io commented Jan 7, 2019

Codecov Report

Merging #12366 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #12366   +/-   ##
=======================================
  Coverage   48.27%   48.27%           
=======================================
  Files         295      295           
  Lines       44283    44283           
  Branches    10601    10601           
=======================================
  Hits        21377    21377           
  Misses      18637    18637           
  Partials     4269     4269

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4426bfd...200775f. Read the comment docs.

@galak galak added platform: STM32 ST Micro STM32 area: UART Universal Asynchronous Receiver-Transmitter Enhancement Changes/Updates/Additions to existing features labels Jan 8, 2019
@erwango
Copy link
Member

erwango commented Jan 10, 2019

@qianfan-Zhao

}; \
\
static struct uart_stm32_data uart_stm32_data_##name = { \
.conf = { \
.baudrate = DT_UART_STM32_##name##_BAUD_RATE, \
.parity = UART_CFG_PARITY_NONE, \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need these fields?
Why wouldn't we be able to use registers for storage and save some RAM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I'll push something new shortly.

@psidhu psidhu force-pushed the pr-stm32-uart-update-api branch 3 times, most recently from 466b88b to 5ba966d Compare January 10, 2019 21:44
@psidhu
Copy link
Contributor Author

psidhu commented Jan 10, 2019

@erwango recheck.

Copy link
Collaborator

@qianfan-Zhao qianfan-Zhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use a variable to save the baudrate, not reading from the register every times.


static int uart_stm32_config_get(struct device *dev, struct uart_config *cfg)
{
cfg->baudrate = uart_stm32_get_baudrate(dev);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a discussion with @erwango long days ago, here is the link: #8306
(don't know why can't copy the link now, so I copied them)

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.
the baud_rate we read using LL_USART_GetBaudRate maybe not equal the baud_rate setted using LL_USART_SetBaudRate because the BRR is inaccurate for some specify baud rate.

eg: I had set uart's baud rate to 115200, but the baudrate readed is 115107.

332 baud_rate = LL_USART_GetBaudRate(UartInstance, clock_rate, LL_USART_OVERSAMPLING_16);

(gdb) p baud_rate
$1 = 115107

So in my options, we should use a variable to save the baud rate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, my comment was for other fields (parity and so on), I guess you agree for those ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes😊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize that could occur. I've pushed new code, please recheck.

Implement these two new api calls. Allows on-the-fly configuration
adjustment of uarts.

Signed-off-by: Pushpal Sidhu <[email protected]>
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.
One proposal to optimize further additional code footprint.

{
struct uart_stm32_data *data = DEV_DATA(dev);
USART_TypeDef *UartInstance = UART_STRUCT(dev);
const u32_t parity = uart_stm32_cfg2ll_parity(cfg->parity);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check if we can save some code footprint by getting uart_stm32_cfg2ll_xxx functions to return and error code if requested valued is not supported and remove the checks below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick and dirty test with hello world on the nucleo_l4r5zi:

;; as is code
Memory region         Used Size  Region Size  %age Used
           FLASH:       13304 B         2 MB      0.63%
            SRAM:        4372 B       640 KB      0.67%
        IDT_LIST:         120 B         2 KB      5.86%

;; With cfg2ll functions returning error codes
Memory region         Used Size  Region Size  %age Used
           FLASH:       13320 B         2 MB      0.64%
            SRAM:        4372 B       640 KB      0.67%
        IDT_LIST:         120 B         2 KB      5.86%

I think the increase in codesize is due to error checks still needing to occur (to check the error of the cfg2ll functions), but now having more return codes out of those functions.

@nashif nashif merged commit acd0e25 into zephyrproject-rtos:master Jan 17, 2019
@psidhu psidhu deleted the pr-stm32-uart-update-api branch January 17, 2019 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: UART Universal Asynchronous Receiver-Transmitter Enhancement Changes/Updates/Additions to existing features platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants