mciantyre / teensy4-rs

Rust support for the Teensy 4
Apache License 2.0
271 stars 31 forks source link

Allocate the heap in OCRAM2 #110

Closed mciantyre closed 2 years ago

mciantyre commented 2 years ago

The heap starting address is in DTCM, right after .uninit. Observed using

cargo build --target=thumbv7em-none-eabihf --release --no-default-features --features=rt --example=led
rust-objdump -t target/thumbv7em-none-eabihf/release/examples/led | rg heap

The approach is OK, and consistent with how other systems might separate their stack and heap. However, it's inconsistent with the official Teensy 4 runtime, which allocates the heap in OCRAM2.

This PR moves the heap into OCRAM2. It's maximum possible size is 512KB (all of OCRAM2). In practice, there may be DMA buffers allocated in the memory region, so not all of the space is available. Use heap_len() to compute the actual amount for a given program.

mciantyre commented 2 years ago

bors r+

Backported to 0.2 release. This should have been in OCRAM2 since the beginning, but I overlooked it when integrating the runtime.

bors[bot] commented 2 years ago

Build succeeded: