Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Rust and Arduino part 3 #4
Rust and Arduino part 3 #4
Changes from 2 commits
21861c2
b01ea0e
5560d6e
e54ef2a
d53f258
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
That last sentence is my understanding of the distinction. Feel free to edit if I made a mistake there (my computer architecture knowledge is a bit rusty :P )
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'm really not sure. It might be wrong. I will ask
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.
Can you ship the raw files separately and load them at runtime?
By calling
include_bytes!
you are embedding them into your program binary. When you invoke your program the OS will load all of it into memory, because it doesn't know where your various instructions are located inside of it.The advantage is that you only have to ship one thing, the assets are literally part of the binary.
I suppose if you can put the assets somewhere on disk as separate files, and then load them one by one, you can avoid corrupting the stack (making sure they go out of scope so rust cleans them up and frees the memory).
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 guess I need to work more on my wording XD
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.
(Don't forget that there is no OS here: I have to use assembly if I want to access the flash memory)
There are only 2 memories: flash and RAM. The program is actually in flash so the include_bytes are fine it the compiler wouldn't put code that loads them on startup.
But even if I make a binary without it and add the assets at a specific address after the binary itself (but still inside the flash), then I would still need assembly code to actually load the data.
There are ways but they are all complicated and out-of-scope imo.
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.
Ah, the fact that it is the compiler that loads the entire program somehow escaped me.
Loading the data without an OS would be more complicated for sure, having to rely on the raw chipset instructions / assembly.
Would you be able to get a raw pointer to the data if you used unsafe rust here (since you can control at which offset / memory location the frames are located)?
I guess this is still out of scope for the blog post, but the problem interests me :-)
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.
This is fine! ^_^ It gives me ideas on how to improve this section which is the most important part of the post.
No using unsafe won't work. You can make pointer only to the SRAM, not to the flash memory (there are 2 address spaces). To read from the flash memory I would need to use asm!. But also building the binary would be a bit more complicated because I would need to add the image data somehow at the end of the code so it won't be loaded on startup