Can0.IFLAG1(Address 0x4002 4030) is 0x0000 0002 in EmbSys Registers view.
Then u32flagReg reads from 0x4002 4030,the value is 0.Why are they different?Whether it is related to the optimization level?
I don't know what the macro does, can you replace is with something like this:
u32flagReg = *((uint32_t*)0x40024030);
You can try using lower optimization level, I guess.
It does not seems to be an issue with the optimization, please use the default one.
The screenshots that you sent shows the variable before the register is read by the core.
Can you step the whole function without a breakpoint there? Do you see a difference when you step the code and run the code?
I see the project is complex, can you reproduce the behavior with a simple test project?
If so, please send to the project so that we can test it on our side.