Global variables used across the main function and a CY_ISR are not working. Why?
At higher levels of optimization, global variables can get optimized out by the compiler. This happens when the variable is modified only by functions like CY_ISR. Use the volatile keyword to inform the compiler not to optimize out similar variables, as shown in the following code snippet from a Cypress Developer Community member, Bob Marlowe.
uint8 FlagToCheck = FALSE;
FlagToCheck = TRUE;
CyGlobalIntEnable; /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
In this example, if optimization in the compiler is set to higher levels, LED_Write(LEDON) will never get executed; however, with the volatile keyword added, LED_Write(LEDON) will get executed.