Skip to main content
Explorer
October 15, 2024
Solved

Strange Behavior with SRAM and RAM Addresses on STM32L431?

  • October 15, 2024
  • 1 reply
  • 743 views

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 

    This topic has been closed for replies.
    Best answer by waclawek.jan

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

    waclawekjan_0-1729001393409.png

    JW

    1 reply

    Super User
    October 15, 2024

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

    waclawekjan_0-1729001393409.png

    JW