RL78/G14 Data flash memory rewrite problem


I am using R5F104BC microcontroller of RL78/G14 family.

software is CS+ for CC.

I have generated files of pfdl from code generator and also added pfdl.h, pfdl.inc, pfdl_types.h and pfdl.lib files from "RL78 Data Flash Access Library Type T04" to program.

My program read and write operation works well when I write value to data flash. But when I tried to rewrite at same address, it not rewritten to that address.

Please suggest me solution how can I rewrite values to same location of data flash memory?



  • Hi Yogesh,

    Please see RL78 Family Data Flash Library Type04 User's manual, R01US0049EJ, Aug 02, 2013:

    2. 3 Cautions on Programming Environment
    "(14)Writing to the data flash memory can be performed only to an area in the blank state or the area that has been erased. It is impossible to rewrite (overwrite) to an area that has been written unless it has been erased. When rewriting is performed without erasing data, the data flash memory might be damaged."

    So after you write a value to a data flash byte, you cannot write it again until after you erase it first. However, Data flash erase can only be done on 1KB block. Erased (blank) data flash has 0xFF value.
    To save the Erase/write cycles, you can write to sequential Data flash bytes until you fill up one 1KB Data flash block. Of course your software has search thru a 1KB block to determine the last updated/saved Data flash values.

    Please read RL78 Family Data Flash Library Type04 User's manual, R01US0049EJ completely.

  • In reply to Mike Clodfelter:

    Thank you Mike.
    My problem is solved.
    I used following method-
    -> All values that need to store in data flash are saved to temporary variables.
    -> Erase a block of data flash
    -> Save all values including new change values to same location again.
  • In reply to yogesh:

    I am facing the same problem. When I reach the last address of the last block, I save the data in temporary variables.
    If I reset my device at that time, I lose the data.
    Please tell me how do I do it.
  • In reply to Murtaza Poonawala:

    As explain above if you want to save values of variable x,y,z to data flash then follow this:-
    -> Save values of x,y,z to location 0x00, 0x01, 0x02
    -> If you want to rewrite value of y to same location then take values from 0x00, 0x01, 0x02 and save it to temporary variable a,b,c
    -> Erase total block
    -> change value of b with y
    -> Then rewrite all temporary value of a,b,c to location 0x00, 0x01, 0x02
    here a=x, b=y, c=z

    It will take some program memory but problem get solved
    try this :)