rtic
rtic copied to clipboard
Cfg blocks in Shared Resource fields
Code to replicate:
#[shared]
struct Shared {
#[cfg(feature = "h7")]
uart_elrs: Usart<USART7>,
#[cfg(feature = "g4")]
uart_elrs: Usart<USART3>
}
Error:
error: this resource is listed more than once
--> src\main.rs:310:9
|
310 | uart_elrs: Usart<USART3>,
| ^^^^^^^^^
For normal struct fields, the syntax I posted is valid. I suspect this has to do with RTIC being macro-based.
For the specific code I mentioned, you could workaround it by feature-gating an alias for USARTx, but ideally, the RTIC macros wouldn't inhibit the above behavior.
Indeed, it's a long standing issue to have cfg support.
In a nutshell the issue is that we can't analyze if the cfg is active or not, so we need to generate code assuming both are active.
This causes clashes in many cases, as you have noticed.
So the general recommendation for now is, don't use cfg in RTIC.
Instead, move the cfg to a user type wrapping the thing you want to have in RTIC.
Closing, feel free to reopen if you have more questions.
Why is it closed / 'closed as completed'? Is this a won't-fix?