-
Notifications
You must be signed in to change notification settings - Fork 235
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
Using sram4/5 #843
Comments
I don't see a reason why there should be a difference between STM32 and RP2040 in this regard.
For the linker script, instead of replacing
You'd need to add code to actually initialize RAM4 contents before jumping to functions located there, and that code probably needs some linker symbols so it can find the data to be copied in flash. I don't have a ready-made example, and the details depend on what you are actually trying to achieve. But if you have working code for STM32, you can probably copy most of what you need from there. |
You can also just put functions in |
@jannic with your linker file the resulting elf still reports that region at address 0, which will not work:
@thejpster I do care where it is, the idea is that the second core will only run within sram4+5 to improve performance. |
You should benchmark carefully to ensure it actually does improve performance, as SRAM0-3 are striped so each successive word comes from a different bank. jannic suggested a section and a segment called |
sorry, I did just put the two together:
it's currently a very basic routine just to test that all works as expected
build.rs: use std::io::Error;
fn main() -> Result<(), Error> {
println!("cargo:rerun-if-changed=c64/basic.S");
cc::Build::new()
.file("c64/basic.S")
.warnings(true)
.warnings_into_errors(true)
.debug(true)
.compile("c64");
Ok(())
} |
Please try References: |
That looks way better.
but it does not run, probably I have to copy the code? I'll continue this evening but wanted you to know now. |
Yes, that's what I meant when I wrote "some code which copies the code to RAM". |
I did got it to work with:
unsafe {
extern "C" {
static mut _srelocate: u8;
static mut _erelocate: u8;
static mut _xrelocate: u8;
}
let srelocate: *mut u8 = addr_of_mut!(_srelocate);
let erelocate: *const u8 = addr_of!(_erelocate);
let xrelocate: *const u8 = addr_of!(_xrelocate);
let size = erelocate.offset_from(srelocate) as usize;
from_raw_parts_mut(srelocate, size).copy_from_slice(from_raw_parts(xrelocate, size));
}
let _test = core1.spawn(
unsafe {
&mut *(slice_from_raw_parts_mut((0x20040000 + 8 * 1024 - 4 * 100) as *mut usize, 100))
},
move || unsafe { basic() },
); probably not the nicest but it's working. the first core uses the "normal" way and the second only this. btw. the rp2040 datasheet says that if a ram 0-5 is accessed by more than one cpu/other than they have to wait, since sram4+5 is exclusively used by the second core no waiting should happen. thanks for all you help! |
Glad that it finally worked! |
I won't measure it, but just believe them that there is no wait states if not used elsewhere. And as already said: Thanks! |
In my previous project with rust on a STM32 I managed to place assembly code in ram. The code is compiled with gcc via build.rs and cc. And is more or less this:
and
I'd like to use sram4 and 5 for the assembly code, I tried several things and it does compile but the elf says:
Any tips on how to do that?
Otherwise I'll try compile the assembly program with gcc into an elf, convert that to bin and include it in the rust code and copy it there myself - in the hope that I can get that to work.
The text was updated successfully, but these errors were encountered: