Skip to content

drivers: serial: rpi_pico: added functions for runtime uart configuration #49883

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

Merged
merged 1 commit into from
Nov 15, 2022
Merged

drivers: serial: rpi_pico: added functions for runtime uart configuration #49883

merged 1 commit into from
Nov 15, 2022

Conversation

WebmasterTD
Copy link
Contributor

Added functions to raspberry pico uart to enable runtime configuration. Necessary when using Modbus RTU.

Signed-off-by: Akos Melczer [email protected]

@WebmasterTD WebmasterTD requested a review from yonsch as a code owner September 3, 2022 20:51
@zephyrbot zephyrbot added the area: UART Universal Asynchronous Receiver-Transmitter label Sep 3, 2022
@zephyrbot zephyrbot requested a review from dcpleung September 3, 2022 20:51
uart_inst_t * const uart_inst = config->uart_dev;
struct uart_rpi_data *data = dev->data;

int baudrate = uart_set_baudrate(uart_inst, cfg->baudrate);\
Copy link
Collaborator

Choose a reason for hiding this comment

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

Strary \

uart_inst_t * const uart_inst = config->uart_dev;
struct uart_rpi_data *data = dev->data;

int baudrate = uart_set_baudrate(uart_inst, cfg->baudrate);\
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should also validate all parameters before making any configuration changes, if one setting is not valid, no UART configuration change should occur

Copy link
Contributor Author

@WebmasterTD WebmasterTD left a comment

Choose a reason for hiding this comment

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

Fixed the mentioned typo and added validation before changing configuration parameters.

@yonsch
Copy link
Collaborator

yonsch commented Sep 4, 2022

@WebmasterTD Thanks. Please fix according to the compliance checks, and rebase to squash your commits.

@WebmasterTD WebmasterTD changed the title Added functions for runtime uart configuartion for raspberry pico drivers: serial: rpi_pico: added functions for runtime uart configuartion Sep 4, 2022
@WebmasterTD WebmasterTD changed the title drivers: serial: rpi_pico: added functions for runtime uart configuartion drivers: serial: rpi_pico: added functions for runtime uart configuration Sep 4, 2022
return -EINVAL;
}

uint stop_bits = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to be a 32-bit variable?

return -EINVAL;
}

int baudrate = uart_set_baudrate(uart_inst, cfg->baudrate);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to be signed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The function returns uint, so the assigned type should also be unsigned. This also means that the assertion below should be ==, not <=

Copy link
Collaborator

@yonsch yonsch left a comment

Choose a reason for hiding this comment

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

Looking good overall, added a few comments

return -EINVAL;
}

int baudrate = uart_set_baudrate(uart_inst, cfg->baudrate);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The function returns uint, so the assigned type should also be unsigned. This also means that the assertion below should be ==, not <=

@yonsch yonsch added the platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico) label Sep 5, 2022
@WebmasterTD
Copy link
Contributor Author

changed baudrate to uint
changed assignment to memcpy
initialized uart_conf in init function to hw reset values

*/
data->uart_config = (struct uart_config){
.baudrate = baudrate,
.data_bits = UART_CFG_DATA_BITS_5,
Copy link
Collaborator

Choose a reason for hiding this comment

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

5 data bits? Might be the default for the silicon but that would be very non-standard

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does seem non standard to me as well.
However according the documentation:

UARTLCR_H

Bits Name Description Type Reset
6:5 WLEN Word length. These bits indicate the number of data bits transmitted or received in a frame as follows: b11 = 8 bits b10 = 7 bits b01 = 6 bits b00 = 5 bits. RW 0x0

https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf#tab-registerlist_uart page:431

Copy link
Member

Choose a reason for hiding this comment

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

Hm... I think we should set this to 8-bit as default. UARTs are used for console/log output (most of the time). So setting to 5-bit is not going to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the default to 8 bits

@WebmasterTD WebmasterTD requested review from yonsch and removed request for dcpleung September 8, 2022 17:44
Copy link
Collaborator

@yonsch yonsch left a comment

Choose a reason for hiding this comment

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

Looking better, added one nitpick. Also, please remove the commit messages of the commits making up your final commits, such as "fixed typo", "fixed compliance checks" etc.

Please note that Zephyr entered a feature freeze yesterday, as we are approaching the v3.2.0 release, meaning that new features can't be merged. I recommend that you finish this now anyway, because sometimes exceptions are made (although this changes existing code, so I doubt it) and because it's fresh in your, and the reviewers' memory. Once 3.2 is released, this can then be merged.

@zephyrbot zephyrbot requested a review from dcpleung September 10, 2022 10:47
dcpleung
dcpleung previously approved these changes Sep 12, 2022
yonsch
yonsch previously approved these changes Sep 13, 2022
@yonsch
Copy link
Collaborator

yonsch commented Oct 2, 2022

@WebmasterTD please rebase on a fresh main

@DaAwesomeP
Copy link

@WebmasterTD any updates?

@WebmasterTD
Copy link
Contributor Author

Sorry for the inactivity. I just updated the default to 8 bits as discussed above and synchronised the branch to the current main

.flow_ctrl = UART_CFG_FLOW_CTRL_NONE,
.parity = UART_CFG_PARITY_NONE,
.stop_bits = UART_CFG_STOP_BITS_1
};
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to call uart_set_format() here, since the hardware defaults to 5-bit at reset? Also might be a good idea to document that the data bit setting is different than hardware reset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an extra comment the deviation from hw default.
Added a call for uart_set_format()

@yonsch
Copy link
Collaborator

yonsch commented Nov 13, 2022

@WebmasterTD Could you rebase and address all issues?

yonsch
yonsch previously approved these changes Nov 13, 2022
Copy link
Collaborator

@yonsch yonsch left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@DaAwesomeP
Copy link

@dcpleung
Copy link
Member

Please fix the compliance check errors.

…tion

Added functions for runtime uart configuartion for raspberry pico

Signed-off-by: Akos Melczer <[email protected]>
@fabiobaltieri fabiobaltieri merged commit d7d6a84 into zephyrproject-rtos:main Nov 15, 2022
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 platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants