I am writing a custom BLE profile library and when I add new characteristics that are read write parameters and initialize the value with 0 the code seems to lose context and whenever there is a BLE update the value goes to 0xff. When i initialize it with any other value it maintains its value. I have tried the volatile keyword and that has no effect. If it is read only then the value is also maintained. Also if I initialize it to 0 and use a function to updated it at boot the value is updated with the read but if any other BLE event happens the value goes to 0xff. This seems very strange like some inappropriate compiler optimization.
I am using 3.0.2 version of the sdk. I have also tried using the _user_data field with a pointer to my variable and that does not work either. It does not matter if the variable is marked static.

