-
Notifications
You must be signed in to change notification settings - Fork 212
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
Common neorv32 uart functions #509
Common neorv32 uart functions #509
Conversation
…hieve backward compatibility with c macros
-> recommended by @emb4fun
This looks good! I think it would be cleaner to move all "legacy function wrappers" to What about the |
I have closed my PR because some of the tests was negative and I do not know why, and could not find the problem.
Yes both functions should also be generalized I think. If you need help, give me a sign. I would also change two other points. First: I would like to change the definition for the NEORV32_UART0. At the moment the define looks like:
I would like to change to:
This has the disadvantage that you cannot set the CTRL variable as follows, for example:
But you have to use the following variant with the "pointer character":
But this reflects what it really is, a pointer and not a "variable". Yes, that's a bit more work at first, but the changes should only be in the neorv32_uart.c file. Of course, with this change, the macro must also look slightly different:
Here the "&" character in front of NEORV32_UART0 has now been removed. Second: I would like to change the new parameter "self" to "UARTx":
Will be changed to:
And now inside the functions it will look like:
That somehow shows better what it is than using "self" here. |
@emb4fun : let us work together on this PR. As next I introduce Stephans recommendation to move the c macros to the legacy.h function. |
done in f22bafe |
@emb4fun : now i work on this. |
…hieve backward compatibility with c macros
-> recommended by @emb4fun
…aeba/neorv32 into common_neorv32_uart_functions
@embfun: i did also a rebase, now the branch should be on main. Therefore the changes of neorv32.h should possible. |
Hello akaeba, the changes are looking good so far. But I am missing the first point.
I would like to change to:
Or do you not want to take over this? It looks that the following functions was not "translated": neorv32_uart0_available Should I send you an example for these? Best regards, |
Yes please. |
For neorv32_uart_available the source could look like:
|
What is your problem with the setup functions? |
Your setup functions proposal looks good! 👍
I agree here.
If we change the way of accessing low-level register to the "pointer style" then the only the UARTs would requires this style while all remaining modules would still require "variable style". I think we should keep this identical across all modules. However, I like the pointer concept. Maybe we can change that for all modules in a future PR?! 😉 |
we should discuss about the use of "volatile" too. I think the keyword volatile is used here wrong in this project.
If I have understood that correctly, only the pointer is volatile here, but not the structure to which the pointer points.
And now the prototype and function can be used without the volatile keyword:
Or you can also make every single register volatile via __IO. That was the suggestion I had made before #499.
Be careful with your wishes 😉 |
added in 269cc45 |
Looks good so far! 👍 Only the setup function is still missing, right? Seems like we have some merge conflicts here... @akaeba can you resolve those after completing your updates? 😉 |
Yes, try to use same approach, like in the available functions? What about the volatile, should I try to implement this approach: #define __IO volatile
typedef struct
{
__IO uint32_t CTRL;
__IO uint32_t DATA;
} UART_TypeDef; but only for UART for start, the rest comes with every single change and the sw framework.
Yes i can try. |
I do not think an if-else is required as you can use the passed pointer for configuring the according control register.
Right now we all structs are of type
We can discuss this in a new issue (let's not change too much within a single PR 😉).
👍 |
Perfect, let's bring this PR to main :) |
the issue is with the UART0_SIM_MODE and UART1_SIM_MODE. In the legacy variant would it be easy. but here i need to distinguish between UART0/1: #ifdef UART_SIM_MODE
#warning <UART_SIM_MODE> is obsolete (but still supported for compatibility). Please consider using the new flag <UART0_SIM_MODE>.
#endif
#if defined UART0_SIM_MODE || defined UART_SIM_MODE
#warning UART0_SIM_MODE (primary UART) enabled! Sending all UART0.TX data to text.io simulation output instead of real UART0 transmitter. Use this for simulations only!
uint32_t sim_mode = 1 << UART_CTRL_SIM_MODE;
#else
uint32_t sim_mode = 0;
#endif |
I made a proposal for this in #499 (reply in thread): // setup UART0
// ...
uint32_t sim_mode = 0;
#ifdef UART0_SIM_MODE
#warning UART0_SIM_MODE (primary UART) enabled! Sending all UART0.TX data to text.io simulation output instead of real UART0 transmitter. Use this for simulations only!
if ((uint32_t(&self) == NEORV32_UART0_BASE) then {
sim_mode = 1 << UART_CTRL_SIM_MODE;
}
#endif
// ... |
oh, i don't had in mind. |
…v32_uart_functions
…mon register definitions
@stnolting : I think it's mostly done. |
Hello akaeba, please take a look at the definitions too. The UART definitions looks like:
Here I think the volatile was missing:
At the same time, the definition of the UART_POINTER can be changed like:
And in case of the prototypes in legacy.h, the
can be defined in
Best regards, |
@stnolting : now fails the checks. Could you please check where is the issue, probably a timing issue? 6094755000000 fs - UART1.RX - ERROR - Equality check failed - Got cr. Expected 0. |
I'll have a look. |
Simulation mode of UART0 is never enabled, which leads to a simulation fail. I think there is a problem with the code I have posted and the actual definition of the UART structs as @emb4fun has already converted the type of all "hardware handle structs" to |
from "variable style" to "pointer style"
@stnolting great work! Now i think is this branch ready to merge. |
Use common UART functions, see #499 for details.