Skip to content
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

Wrapper for RTC Slow memory #300

Closed
weiying-chen opened this issue Apr 14, 2024 · 2 comments
Closed

Wrapper for RTC Slow memory #300

weiying-chen opened this issue Apr 14, 2024 · 2 comments

Comments

@weiying-chen
Copy link

weiying-chen commented Apr 14, 2024

Is there a wrapper for this?

RTC Slow Memory

Global and static variables used by code which runs from RTC memory must be placed into RTC Slow memory. For example deep sleep variables can be placed here instead of RTC FAST memory, or code and variables accessed by the ULP Coprocessor Programming.

The attribute macro named RTC_NOINIT_ATTR can be used to place data into this type of memory. The values placed into this section keep their value after waking from deep sleep.

I searched all over Github, but I couldn't find anything.

@Vollbrecht
Copy link
Collaborator

You don't need any wrapper for it since you can directly specify where you want stuff to be linked.

Here is a small example

#[no_mangle]
#[link_section = ".rtc.data"]
static mut RTC_VARIABLE: u32 = 0;

fn main() {
    // It is necessary to call this function once. Otherwise some patches to the runtime
    // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
    esp_idf_svc::sys::link_patches();

    // Bind the log crate to the ESP Logging facilities
    esp_idf_svc::log::EspLogger::initialize_default();

    log::info!("Current RTC Value!: {}", unsafe { RTC_VARIABLE });
    unsafe { RTC_VARIABLE += 1 };

    FreeRtos::delay_ms(2_000);
    unsafe {
        esp_deep_sleep(2_000_000);
    }
}

Keep in mind that this example only illustrate the point. Please use something more appropriate that a static mut raw pointer here as its an easy footgun

@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Apr 14, 2024
@weiying-chen
Copy link
Author

Thanks for the reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants