cancel
Showing results for 
Search instead for 
Did you mean: 

Strange Behavior with SRAM and RAM Addresses on STM32L431?

oguzkagan
Associate II

Hello everyone,

I'm working on an STM32L431-based custom board, and I’ve encountered some very strange behavior that I can’t seem to explain. I have two variables pointing to different memory regions (SRAM and RAM), but when I modify one variable, both variables change as if they are somehow linked. To recreate the problem that I am having, I wrote a simplified version of the code below.

Here's a simplified version of my code:

 

volatile uint32_t *ram_var = (uint32_t *) 0x2000C004;   // Points to RAM region
volatile uint32_t *sram_var = (uint32_t *) 0x10000004;  // Points to SRAM region

int main() {
    *sram_var = 10;   // Expected: ram_var = 0, sram_var = 10, but both are 10!
    *ram_var = 15;    // Expected: ram_var = 15, sram_var = 10, but both are 15!
    (*sram_var) += 5; // Expected: ram_var = 15, sram_var = 15, but both are 20!
    (*ram_var) += 5;  // Expected: ram_var = 20, sram_var = 15, but both are 25!
    (*sram_var) += 5; // Expected: ram_var = 20, sram_var = 20, but both are 30!
}

 

This suggests that these addresses are somehow being aliased or mirrored, but I’m not sure why this is happening.

Why is this happening?

 

I attached the test project 

1 ACCEPTED SOLUTION

Accepted Solutions

Because that's the same SRAM2, accessible at two addresses.

waclawekjan_0-1729001393409.png

JW

View solution in original post

1 REPLY 1

Because that's the same SRAM2, accessible at two addresses.

waclawekjan_0-1729001393409.png

JW