Volatile variables causes issues with Coocox
hello,
I know that I should post this in Coocox forum, but I what to know if one of STM32 users faced this issue before:I have a strange issue with Coocox (COIDE V1.7.6), it may be a bug:
- Optimization is set to -O0,here is part of my code that causes the issue : Inside a function, I have declared a local variabes as volatile :
*****************************************************************************
volatile uint32_t tmpcounter = 0x00, indexoffset = 0x00;
volatile uint32_t counterread = 0x00;/* Read flash memory */
while ((indexoffset != USER_FLASH_SIZE) && (HCD_IsDeviceConnected(&USB_OTG_Core) == 1)) { for (counterread = 0; counterread < BUFFER_SIZE; counterread++) { /* Check the read bytes versus the end of flash */ if (indexoffset + counterread != USER_FLASH_SIZE) { tmpcounter = counterread; RAM_Buf[tmpcounter] = (*(uint8_t*)(address++)); } /* In this case all flash was read */ else { break; } } /* Write buffer to file */ f_write (&file, RAM_Buf, BUFFER_SIZE, (void *)&bytesWritten); /* Number of byte written */ indexoffset = indexoffset + counterread;*****************************************************************
When reaching the last line and before executing it : ''indexoffset = indexoffset + counterread;'' I see that counterread is equal to 0 which is wrong (it should be equal to BUFFER_SIZE )
If I declared ''indexoffse'' and ''counterread'' without being volatile the issue is solved.
If I declared ''indexoffse'' and ''counterread'' as volatile but global variables , the issue is also solved.
I can't understand it ? it may be a bug is COIDE ?
Thanks,
franco
#volatile #stm32f4 #coide #coocox #fwupgrade-volatile-stack-fault