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
Can't use early, shared resource in init in 0.6.0-alpha.0
#429
Comments
Hi, More or less this support is in limbo in What you did encounter is a bug though. :) |
Ok. If this isn't yet supported, it would be nice to add an error message indicating that's the case. Most of the macro error messages have been helpful, so I'm surprised that isn't the case here. |
0.6.0-alpha.0
Hi, it was supported but it in the major rewrite of the resource handling module, it broke. |
Sorry, I must still be misunderstanding something then. In chat you said
What would happen in 0.5 if I tried to use an early resource in both
For now, I'm using the static mut transform and sharing references to the buffers as resources. It works, but it seems like it should be possible to use early resources in |
Something like (not tested) #![no_std]
#![no_main]
use panic_halt as _;
#[rtic::app(device = atsamd51n)]
mod app {
#[resources]
struct Resources {
ping_buf: &'static mut [i16; 8],
pong_buf: &'static mut [i16; 8],
}
#[init]
fn init(mut ctx: init::Context) -> init::LateResources {
static mut PING_BUF: [i16; 8] = [0; 8];
static mut PONG_BUF: [i16; 8] = [0; 8];
init::LateResources{
ping_buf: &mut PING_BUF,
pong_buf: &mut PONG_BUF,
}
}
} Edit: Mmm, it must be what you mean by "the static mut transform"? |
@TeXitoi, yes, as I said this is precisely what I'm doing now. I'm just trying to understand why the limitation is there and how the previous version of RTIC would have handled my code. I would try 0.5 myself, but I'm not in front of my computer right now. |
This static mut transform is working on 0.5 |
Yes, I understand. I used the static mut transform before I ever migrated to 0.6. My question is about the resources struct. If you tried to create an early shared resource and use it in both init and some other task, what would have happened? Would there have been an error? Would it have silently failed? |
@bradleyharden The thing that changes is how lifetimes are generated. I hope this helps :) To directly answer the 2 questions:
Not from RTIC, the rust compiler might give you lifetime errors though.
No, it would not. If it compiles, it is fine. |
@korken89, ok, so it's just a question of lifetimes. This sort of ties into my question in #417. It sounds like you'll give a In this case, I don't want to put the reference inside a structure. I need to access the buffers from two different normal tasks, so it needs to be shared; and I need access in For now, the static mut transform is fine. |
This is correct, only |
Thanks for the tip. I took a look at your implementation. I think my case is even simpler. For my situation, everything is a fixed size at a known frequency, so I don't need anything fancy. Two static buffers that I switch between is all I really need. That's why I was hoping to do it with RTIC resources. Hopefully the bug will be fixed soon and I can use an |
Hi, that sounds fine. |
I don't believe this was fixed in I guess I can just make them late resources for now, but what is the proposed solution to this? |
Hi, unfortunately not. |
Hi, the recommended approach is now:
Then you will get the old functionality with minimal overhead. |
The following example gives
cannot find value priority in this scope
.It looks like the generated code is trying to assign a priority for the lock, but there is no priority.
That leads to another question. Why are locks necessary for early resources in
init
in the first place?In the meantime, do you have any suggested workarounds? I need the static address of the buffers in
init
. I guess I could do it myself, outside of theResources
struct, but I'd rather not have to go that far.The text was updated successfully, but these errors were encountered: