-
Notifications
You must be signed in to change notification settings - Fork 225
How to allocate opaque resources in init
#217
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
Comments
Maybe this issue can help you? https://github.com/japaric/cortex-m-rtfm/issues/164 We use existentials in our rtfm app (see, for example, https://github.com/copterust/fcfs-rtfm/blob/master/src/main.rs#L44) |
@little-arhat Thanks for the reply, I did see that issue before and it is what prompted me to try out the existential type approach, unfortunately in my case it results in a EDIT: actually now that I copied your approach exactly it works, but only because the existential type is in a separate module... as soon as I move it into the main.rs next to the #[app] it dies. This is the ICE I'm getting, it appears to be known: rust-lang/rust#60407. Iffy... I'll see if I can make progress with this and let you know though. |
Closing because this has been addressed to my satisfaction. It's still a bit iffy but that's not on RTFM. |
Uh oh!
There was an error while loading. Please reload this page.
Hi, I'm trying out this framework, looks pretty neat but I have a problem. I have an opaque type (it's a compiler-generated generator struct). I'd like to initialize it on startup in the
init
method and then be able to access it in another interrupt as a normal resource. The problem is I can't put it in astatic mut
because I cannot name its type.In my previous code without RTFM I got it working by simply allocating it on the stack (so just in a normal
let
with inference) in the reset handler. And since the reset handler is never exited from but just goes into a WFI loop (or intoidle
which never returns), it's perfectly safe to transmute the resulting&'_ mut
into a&'static mut
. I tried the same thing in RTFM but unfortunately it does drop theinit
block scope, so this approach does not work.Currently I am using a boxed trait object as a workaround, but it's very sad that I need to pull in the
alloc
heap machinery when (1) the compiler knows the object's size and (2) there is a perfectly good place for it in either BSS (if I could name its type) or the reset handler's stack frame (if I can't).I tried hard to get it working with existential types, unfortunately the resulting code is very obtuse and triggers an ICE on nightly anyway.
Any way to get this working? It feels like there could be a provision added to
init
to allow preserving at least some part of the stack frame as "effective statics" implemented aslet
... e.g. couldn't the leadingstatic mut
s at the top ofinit
be implemented as justlet
statements that exist in a global stack frame rather than restricting them to being actual statics? (this would be optimal for my case if this were possible and it doesn't seem like it would break anything.. maybe there's some cases where it's unsafe though? any thoughts?)Thanks
The text was updated successfully, but these errors were encountered: