In this lesson, you will learn how to selectively power down SRAM banks during deep sleep while maintaining critical data retention to minimize leakage current.
Understanding Memory Retention
In modern microcontrollers, the SRAM is often divided into independent physical banks or "partitions." While SRAM is volatile and requires a constant power supply to maintain its state, the leakage current—which dominates power consumption during sleep—is proportional to the amount of memory being energized. By disabling power to unused SRAM banks while keeping only essential variables (like stack pointers or state variables) in a retained bank, we can significantly reduce the overall current draw.
Implementing Selective Retention
To configure retention, the system controller typically provides a set of registers that govern the bias voltage of specific SRAM blocks. When transitioning to a deep sleep state, your firmware must ensure that all critical data is moved into the "retained" section, while the remaining banks are gated off.
Consider a system where SRAM is split into four 8KB banks. If our application state only requires 4KB of data, we can disable the other three banks:
// Example: Configuring SRAM retention banks before entering deep sleep
void prepare_for_sleep(void) {
// 1. Move critical data to the base bank (e.g., Bank 0)
// 2. Disable power supply to Banks 1, 2, and 3
SRAM_RETENTION_CTRL |= (BIT_BANK1_OFF | BIT_BANK2_OFF | BIT_BANK3_OFF);
// 3. Ensure the retention bias is set for Bank 0
SRAM_RETENTION_CTRL |= BIT_BANK0_RETENTION_ENABLE;
// 4. Enter low-power mode
enter_deep_sleep();
}
Considerations for Safety
When implementing this, you must account for the integrity of the data. If the voltage drops too low due to improper bias configuration, you risk "bit-flipping" or data corruption, which could violate the safety requirements discussed in our earlier modules on lifecycle phases. Always verify that your memory retention settings are mapped to your specific hardware diagnostic requirements, ensuring that the state remains valid upon wake-up.
Key Takeaway: By partitioning SRAM and selectively gating power to unused banks, you effectively isolate leakage paths and reduce the static power footprint of your system during deep sleep.