-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
renesas-ra: Support changing baudrate for UART. #11680
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
Conversation
When I tested this before I had to disable/re-enable uart before changing the baudrate, this makes it work if UART is already initialized. if (R_SCI_UART_BaudCalculate(baud, 1, 5000, &baud_setting) == FSP_SUCCESS) {
// Disable transmitter and receiver.
uint8_t scr = sci_reg->SCR;
sci_reg->SCR = scr & ~(0xF0);
// Change baudrate
//...
// Restore SCR
sci_reg->SCR = scr;
} |
Thank you for your review, @iabdalkader -san. When UART is already initialized, it is re-initialized in
|
But you don't need to re-initialize it just to change the baudrate. For example, I initialize uart, then later want to switch to a higher baudrate, I can just call this:
But this only works if you disable/restore the SCR register. |
Yes, right. In case of when UART(id, baudrate) and UART.init(baudrate, ....) are executed, ra_sci_init_with_flow() is called internally. Therefore it is re-initialized currently. |
If you need to use ra_sci_set_baud(uart_id, baudrate) internally, disable/restore the SCR register might be needed in ra_sci_set_baud() as you mentioned. If you need it, I will try it. |
Yes I use machine_uart and ra_sci.c internally for bluetooth, at some point the baudrate is switched to higher one, so I call I understand that in this change you made it possible to re-initialize the uart, which would allow changing the baudrate, but I still think it's more efficient to just switch the baudrate when needed if uart is already initialized. |
Understood. Your code below would be able to support both use-cases. I will try it and test tomorrow.
|
db31163
to
eb0a738
Compare
Updated and tested so that ra_sci_set_baud() can be used internally. |
@TakeoTakahashi2020 I tested this and it seems to be working fine, thank you! However, the flags you disable in the diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile
index 51fdfb12d..b554d8bd7 100644
--- a/ports/renesas-ra/Makefile
+++ b/ports/renesas-ra/Makefile
@@ -375,6 +375,9 @@ HAL_SRC_C += $(addprefix $(HAL_DIR)/ra/fsp/src/,\
r_sci_uart/r_sci_uart.c \
)
+CFLAGS_FSP = -DSCI_UART_CFG_TX_ENABLE=0 -DSCI_UART_CFG_RX_ENABLE=0 -Wno-unused-variable -Wno-unused-function
+$(BUILD)/lib/fsp/ra/fsp/src/r_sci_uart/r_sci_uart.o: CFLAGS += $(CFLAGS_FSP) |
eb0a738
to
e2e2ac3
Compare
@iabdalkader -san, Thank you very much for testing this and proposal of Makefile. I agree that your proposal is better way. I have done applying it and test. |
Looks great, thank you! |
@TakeoTakahashi2020 Unrelated, but would you happen to know if there's a simple way to just read the TRNG ? Any example code, documentation etc.. ? |
Sorry for the delay in responding. I am not familier but could you refer to the following document? |
@TakeoTakahashi2020 Thank you, I did see those before and tried to enable and use the SCE, through that function, but it didn't work, something about missing definition of TRNG, even though the series should have one. I will try again this week. |
@iabdalkader-san, If you could use e2 studio, you would be able to confirm the function works as the first step. You need to add the component and need to call Open function before calling it. |
It's now working thank you, but there's no simple way to just get a random number from micropython, I have to link at least the following files
|
Thank you @iabdalkader-san . Good to hear that it's working. It's only way because the spec is not disclosed. Hope removing unused .text by compiler & linker optimization. |
ports/renesas-ra/Makefile
Outdated
) | ||
|
||
CFLAGS_FSP = -DSCI_UART_CFG_TX_ENABLE=0 -DSCI_UART_CFG_RX_ENABLE=0 -Wno-unused-variable -Wno-unused-function |
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 did not see the previous version of this PR, so I'm not certain of the discussion around these settings, but why can't they go in r_sci_uart_cfg.h
? That config file is included by r_sci_uart.c
which is the only place that uses these config variables.
Eg at the top of r_sci_uart_cfg.h
add:
#define SCI_UART_CFG_TX_ENABLE 0
#define SCI_UART_CFG_RX_ENABLE 0
@iabdalkader is there a problem doing it that way, putting the configs in the header file?
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.
There were unconditional #pragma
s before to disable warnings, if the file is included anywhere else it will disable warnings there, but even if it's only included in one place (for now) this patch has to be re-added by hand if the config is regenerated (it's not autogenerated by e2studio).
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.
The -Wno...
's can be kept here in the Makefile as they are, but the two CFG options would fit better in r_scr_uart_cfg.h
(and there only needs to be one of those for the whole port, not one per board).
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.
(and there only needs to be one of those for the whole port, not one per board).
If the headers can be shared, then yes those defines can be moved.
@@ -0,0 +1,16 @@ | |||
#ifndef R_SCI_UART_CFG_H_ |
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.
These config files look exactly the same for all boards. In the interest of trying to reduce the number of files, and to make it easier to add new boards, can this config file be removed from each board and added either in ports/renesas-ra
, or ports/renesas-ra/ra
, or maybe in a new subdirectory called ports/renesas-ra/fsp_cfg
?
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.
See #11846 for my proposal to simplify this configuration.
@TakeoTakahashi2020 -san, if you could please rebase this PR on the latest master commit, have just a single fsp_cfg header file for all boards, and move the |
@dpgeorge -san, Okay I will update. |
e2e2ac3
to
a856220
Compare
@dpgeorge -san, Rebase and test has been done. I would appreciate it if you could check it. |
ports/renesas-ra/ra/ra_sci.c
Outdated
@@ -1097,23 +1098,28 @@ static void ra_sci_fifo_init(uint32_t ch) { | |||
ra_sci_rxfifo_set(ch, (uint8_t *)&rx_buf[idx][0], SCI_RX_BUF_SIZE); | |||
} | |||
|
|||
|
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 remove this extra blank line.
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.
Oh, sorry. Removed it.
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.
Thank you.
* Use R_SCI_UART_BaudCalculate() of fsp/src/r_sci_uart/r_sci_uart.c * Support UART.init(baudrate) Signed-off-by: Takeo Takahashi <[email protected]>
a856220
to
ab8c080
Compare
This PR enables changing baudrate for UART such as UART.init(baudrate) and available other than 115200 baudrate.
(except EK-RA4M1 & EK-RA4W1 does not work with 2000000)
This request and issue was reported by @iabdalkader -san and @mbedNoobNinja -san in #10943.
This change affects #10943 and #11405.