2024-10-15 06:40 AM - edited 2024-10-15 07:10 AM
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
Solved! Go to Solution.
2024-10-15 07:10 AM
2024-10-15 07:10 AM
Because that's the same SRAM2, accessible at two addresses.
JW