Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Intersting observation regarding flash...

hello i wrote:

     
      
//Write to flash
int var_2 = FLASH_getIndex();   
////////////////////////////////////////////////////////////////////////////////////
LCD_clear();    
fprintf(fp_LCD, "%d %d %d\r\n", regions.offset, regions.block_size, var_2);
            
ret_code = alt_write_flash_block(fd_FLASH, 0, regions.offset + (regions.block_size* var_2), FLASH_buffer, BUFF_SIZE);                  
fprintf(fp_LCD, "%d %d %d\r\n", regions.offset, regions.block_size, var_2);                                                                                                                                                                                                
while(1)
////////////////////////////////////////////////////////////////////////////////////
.
the output is:

65536 65536 0 <-- correct

65536 65536 100663112 <--wrong!!!

why does the var_2 value changes after the alt_write_flash_block function call????

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    i tested without the function the value of var_2 does not change without the function....

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    memory corruption and stack overflows are the most difficult bugs to track down... If you are using pointers in your code, doublecheck that they are always pointing to what they are supposed to point to.

    Also check that you don't use big structures as local variables in your functions (such as big tables) as it can generate a stack overflow.