This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Writing to Flash on C8051f350

Hello,

I have some problem when I try to write to Flash memory.

I read AN201 "WRITING TO FLASH FROM FIRMWARE" and I use write functions for F350 (page 100).

There is no problem with a light program.
But now I try to integrate these functions on a large program. When I look at memory, any data has been written.

In AN20 (page 3), I found this : "Be cautious when using the 'Large' and 'Compact' memory models, which target xdata and pdata spaces for user variables, both of which generate MOVX write opcodes."
Indeed, my first program use small memory model (no pb) and my last program use large one.

Is there a solution to write to flash memory with a large program ?

  • Is there a solution to write to flash memory with a large program ?
    what does program size have to do with it?. The memory model choses has nothing to do with program size.

    Erik

  • "Is there a solution to write to flash memory with a large program ?"

    I'm not familiar with your particular derivative, but I'm assuming that the procedure to write to the flash is something like:

    1) Map the flash into xdata space
    2) Write to flash
    3) Map the flash back out of xdata space

    If an interrupt occurs during this sequence and the associated ISR accesses the xdata memory space you are in trouble. One solution is to disable interrupts before step (1) and reenable them after step (3).

  • "what does program size have to do with it?"

    He would seem to be referring to the large memory model.

    "The memory model choses has nothing to do with program size."

    Although the program size will probably increase if the large model is used.

  • yes, interrupts MUSt, of course be disabled, the trouble the OP is seing is the compiler wiring/reading XDATA (with large memory model) after the SFR (whatever the name, whatever the bit) is cahnged to redirect XDATA operations/writes to flash.

    an illustration from my codes where I use the high part of a f126 flash as permanent data storage

    U8 ReadFlashChar (U8 code *  RFSaddr)
    {
    U8 RFCintsav;
    U8 RFCdata;
    
      RFCintsav = SG_IE;
      SG_IE = 0;
      SG_SFRPAGE = 0;
      if (RFSaddr > 0x7fff)
      {
        SG_PSBANK = 0x30;
      }
      else
      {
        SG_PSBANK = 0x20;
        RFSaddr   += 0x8000   ;
      }
      RFCdata = *RFSaddr;
      SG_PSBANK = 0x10      ;
      SG_IE = RFCintsav;
      return (RFCdata) ;
    }
    
    If RFCdata were mapped to XDATA, it would be written to flash.
    
    
    Erik
    

  • "The memory model choses has nothing to do with program size."
    What I tried to say was "if you have a large program, you do not HAVE TO choose the large model"

    Erik

  • Thank you for your help,

    Finally, I just forgot a word (very important).

    In my write function, i declared the write pointer like this :

    char xdata * pwrite;

    The space where this pointer is stored isn't defined.
    In small memory model, the compiler put it in data, no problem. But with compact or large model, the compiler put it in xdata, doesn't work.

    I just wrote :
    char xdata * data pwrite;
    and it works.