This is my code:
volatile uint32_t value = *((volatile uint32_t *) 0xA0000000); // here `value` is 12498
value *= 2; // here `value` is still 12498
value |= 0x0000001; // still 12498
When analysing the variable value in my debugger, it holds the same value on all lines. What am I doing wrong?
Maybe your debugger isn’t actually that good. When one of my tools doesn’t seem to behave, I always check it against another tool.
Try to debug the old-fashioned way, with:
or some other output method if
printfis unavailable (it looks like you may be working in the embedded space).See what you get with that – I’d be more inclined to trust
printf-debugging than debuggers.If your problem is not with
valuebut instead with the memory at location0xA0000000, then it’s working as expected.You’re manipulating the local variable, not the memory location. You need to write the value back, with something like:
However, given your use of volatile, it’s entirely possible you just wanted a variable pointer to that location so that changes would reflect immediately.
If that’s the case, you would need something along the lines of:
In that case, the memory location would be changed at each instruction without having to explicitly write the value.