AnsweredAssumed Answered

Does flashx manage the writing of data to the flash in phrase-sized chunks?

Question asked by gorakk on Feb 26, 2015
Latest reply on Mar 16, 2015 by gorakk

If I want to perform multiple writes to a flashx file - that could each be less than a phrase - does the flashx driver accumulate bytes until it has a phrase and then write that to flash?  Or do I need to manage that myself?  The phrase size for the processor I am using appears to be 8 bytes.

 

From some experimentation it seems that I have to manage it myself but maybe I am missing a setting?

 

My experiments are based on the flashx example, flash_demo.c

 

This works - but obviously leaves gaps in the file:

   fseek(flash_file, 0, IO_SEEK_SET);  
   buffer[0] = 'a';  
   write(flash_file, buffer, 1);  
    
   fseek(flash_file, 8, IO_SEEK_SET); // move to the next phrase    
   buffer[0] = 'b';  
   write(flash_file, buffer, 1);  
  
   fseek(flash_file, 16, IO_SEEK_SET); // move to the next phrase  
   buffer[0] = 'c';  
   write(flash_file, buffer, 1);  

 

This doesn't work - the second and third write() give a write error:

   fseek(flash_file, 0, IO_SEEK_SET);  
   buffer[0] = 'a';  
   write(flash_file, buffer, 1);  
    
   fseek(flash_file, 1, IO_SEEK_SET);  
   buffer[0] = 'b';  
   write(flash_file, buffer, 1);  
  
   fseek(flash_file, 2, IO_SEEK_SET);  
   buffer[0] = 'c';  
   write(flash_file, buffer, 1);    

 

TWR-K60F120M, CodeWarrior 10.5, MQX 4.0

Outcomes