Data Flash: Write to flash from diferent block of flash

Hello,

I use the RX62n and the Renesas Flash API.

Writing to the dataFlash block BLOCK_DB0 or BLOCK_DB1 from the RAM, e.g. a local array with some variables, is no problem via R_FlashWrite() Function. Everything works fine.

Now I want to write to the dataFlash block BLOCK_DB0 from an other dataFlash block (BLOCK_DB1). So basicly a copy from Block BLOCK_DB1 to Block BLOCK_DB0. If I first read from BLOCK_DB1 to a local array and then write from the local array to BLOCK_DB0 it works just fine.

If I try to write directly from block BLOCK_DB1 to BLOCK_DB0 (write from start address to start address) then no error is returned, but the block BLOCK_DB0 contains only zeros.

Any idea what the problem is? Is it even possible to do that without first reading and readit in the RAM?

  • Sorry, this description does not provide enough information.
    How do you read from flash?
    How do you write to flash?
    How do you initialise flash operating modes?
    When you copy from DB1 to DB0, is the contents of DB1 kept after programming?
  • In reply to FrankL:

    Ok I try to clear it, hope that helps how I try it:

    I use the Renesas Flash API. Initialisation is R_FlashDataAreaAccess(SIZE_OF_FLASH, SIZE_OF_FLASH). I dont handle any operating modes, I let the API handle it.

    1. I read from flash via a direct access to the address. So it is something like this:
    u32Crc1 = *(uint32_t*)(cFlash_ROM_begin_Copy1); (where cFlash_ROM_begin_Copy1 is a uint8_t* to the flash address)

    2. I write to the flash using the API function R_FlashWrite()
    R_FlashWrite(cFlash_ROM_begin_Copy0, cFlash_ROM_begin_Copy1, WRITE_BLOCK_SIZE);
    - again, both _Copy0 and _Copy1 are uint8_t* to the desired start addresses in the flash (start of BLOCK_DB0 and start of BLOCK_DB1)

    3. R_FlashDataAreaAccess(SIZE_OF_FLASH, SIZE_OF_FLASH) ant the rest is in the API function R_FlashWrite() I guess.

    4. After the write operation R_FlashWrite(cFlash_ROM_begin_Copy0, cFlash_ROM_begin_Copy1, WRITE_BLOCK_SIZE); the contents of DB1 is the same as before (so everything is allright). The contents of DB0 where i wanted to write to is now full of zeros.
  • In reply to Benjamin:

    Step 3 sounds like you switch all data flash to program/erase mode. I believe you should switch DB1 to read mode only and DB0 to program/erase mode. I could imagine that it will then work.
  • In reply to FrankL:

    3. R_FlashDataAreaAccess(SIZE_OF_FLASH, SIZE_OF_FLASH) is only done once at initialisation so that i can read and write the whole flash. So yes, I switch the data flash to program/erase mode to be able to read and write it.

    I want to be able to read and write everything. If DB1 is read only, then I cant write to it. DB1 is used as a doubleDataBuffer. Basicly I store Calibration Data in the flash. To prevent corrupt data (e.g. Powerfail while writing) I store the data in the second block DB1. If I update the data after modification I first write DB1 and then I write DB0. But to scrape or scip more reading, I thought a copy from DB1 to DB0 would be a good solution, so a write from the data at the adress of DB1 to the adress of DB0.
  • In reply to Benjamin:

    Any more Ideas?
  • In reply to Benjamin:

    Did you see this?

    39.6.1.3 Data Flash P/E Modes
    These modes are for programming and erasure of the data flash memory. Reading out the data flash is not possible.
    Data flash P/E normal mode, data flash status read mode, and data flash lock-bit read mode are the three data flash P/E modes

    It is not possible to have a memory block in P/E AND read mode at the same time. If you enable P/E mode on all data blocks you cannot copy from DB1 to DB0 because you cannot read DB1 as soon as you set FENTRYD bit.

  • In reply to FrankL:

    Im not sure with the P/E modes, the renesas Flash API handles all that stuff. I just use the Flash API for flash writing.
    So with the flash API its not possible?
  • In reply to Benjamin:

    You define in "R_FlashDataAreaAccess" the operating mode of the flash blocks. If you say all data flash blocks switch to P/E, then you cannot read data from one of these blocks.
    If you want to read data from a data flash block you have to make sure it is not set to P/E mode.
  • In reply to FrankL:

    I call R_FlashDataAreaAccess() at the Startup of the program (with 0x7FFF, 0x7FFF).
    I can read from the flash, thats not the problem. Reading is possible whenever I do it.
    But it is not possible to write to a flash Block from another Block as the source of the data. So a copy from one block to another block without storing the data locally. (If the source of the data is a lokal variable or array, then it works).

    Earlier I wrote: "Now I want to write to the dataFlash block BLOCK_DB0 from an other dataFlash block (BLOCK_DB1). So basicly a copy from Block BLOCK_DB1 to Block BLOCK_DB0. If I first read from BLOCK_DB1 to a local array and then write from the local array to BLOCK_DB0 it works just fine.

    If I try to write directly from block BLOCK_DB1 to BLOCK_DB0 (write from start address to start address) then no error is returned, but the block BLOCK_DB0 contains only zeros."
  • In reply to Benjamin:

    This thread will be archived due to inactivity.

    Mike Clements
    RenesasRulz Moderator
  • In reply to Mike Clements:

    Don't archive it. Its not solved yet. I could write again and again something to keep it up front and to have it still active, but I guess thats not helpful
  • In reply to Benjamin:

    Still not solved....
    Moving it to Archives doesn't solve the problem.
    I start to guess you want to hide it that it cant be answered....
  • In reply to Benjamin:

    You kidding me right? Could you maybe stop moving an unresolved issue to Archives?
  • In reply to Benjamin:

    It looks like you can write from code flash to data flash, but it is not possible in one step to write from one block of data flash to another one.
    If you want to do so you first have to copy the contents of the source data flash to a RAM buffer, and then write the RAM buffer to the destination block.