Read from data flash (with an external programmer)

Hi,

In our application it would be nice to be able to read the contents of the data flash with an external programmer. I found this post http://renesasrulz.com/renesas_products/rl78/f/26/p/1850/6067.aspx which explains that it is not possible to read the _code_ flash, but as far as I can see, it applies also to the data flash, and basically it makes sense from a security perspective. Is this correct, that is, I cannot read data flash either from an external programmer ?

The thread above also mentions a possibility to read flash contents using OnChip debugging. Is there any specification for the debugging protocol, so I can implement it ?

The reason for asking is that I use the RL78/G12 which has only 1.5 kByte RAM, and the FDL-lib consumes quite a lot of RAM, more than I can afford to loose in my application. So I'm investigating the possibility to read out flash contents via tool0 instead of having to implement functionality in my application to read it out via the UART.

br Håkan

  • I believe that happens to be the case.

  • Hejsan haen,
    I have an idea.

    1. Create a HEX file to read out data flash via UART.
    2. Write it in codeflash by a flash programmer.(set flash programmer keeping data flash area)
    3. Save the data that read out from UART.
    4. Create a new HEX file by merging the read out data(dataflash) with your firmware.
    5. Write new HEX file in codeflash and dataflash.
  • In reply to Kirin:

    Kirin, could you describe your idea it detail? I have some parameters in data flash, and I want to download them and merge with code flash to have default settings for application initialized. How can I do this?

  • In reply to Nomad:

    PS: I use EEL and FDL pools

  • In reply to Nomad:

    Hello Nomad,

    I presented a program that reads out dataflash via TXD0.
    (If just reading dataflash, the library is unnecessary.)
    Please merge reading out data and your firmware in your application.

    //for CubeSuite+
    #pragma sfr
    #pragma nop
    #pragma halt
    void main(){
      unsigned int i;
      unsigned char *p=0x1000; //start address of dataflash
      DFLCTL=1; //set dataflash read enable
      HOCODIV=1; //16MHz
      SAU0EN = 1; // SAU0 enable
      NOP();NOP();NOP();NOP();
      // UART0 TXD setting
      ST0  |= 0x0001; // UART0 disable
      SMR00 = 0x0023; //CK00
      SCR00 = 0x8097; //8bit nonparity stopbit1
      SPS0  = 0x0000; SDR00 = 0x8800; //115200bps=16MHz/(0x88+2)
      STMK0 = 1; // INTST0 mask
      P1 |= 0x04; //TXD0
      PM1 &= 0xFB; //TXD0
      SO0 |= 0x0001;
      SOE0 |= 0x0001; // UART0 output enable
      SS0 |= 0x0001; // start UART
      //read out data flash area
      for (i=0;i<0x800;i++){ //0x800 for Dataflash 2Kbyte
        STIF0 = 0;      // flag clear
        TXD0=*(volatile unsigned char *)(p+i);
        while (0==STIF0);
      }
      HALT(); //end
    }
  • In reply to Kirin:

    Thanks Kirin!

    You code is very useful.

    OK, also I found tool to merge Code flash and Data flash from Renesas:

    DataFlashConverter

    DataFlashEditor.

    But they all want S-REC or HEX format to do this. May be there is a some special tool to convert binary data received via UART (bin) to mot or hex files?

  • In reply to Nomad:

    Hi Nomad,

    I made to output in Intel HEX format.

    //for CubeSuite+
    //G12 dataflash to IntelHEX via TXD0
    #pragma sfr
    #pragma nop
    #pragma halt
    #include <string.h>
    void puttxd(unsigned char *s){
    unsigned int i;
    for(i=0;i<strlen(s);i++){
    STIF0 = 0; // flag clear
    TXD0=*(volatile unsigned char *)(s+i);
    while (0==STIF0);
    }
    }
    void puttxd1(unsigned char s){
    STIF0 = 0; // flag clear
    TXD0=s;
    while (0==STIF0);
    }
    void main(){
    unsigned int i,sum;
    unsigned char *p=0x1000; //start address of dataflash
    unsigned char line1[]={":0400000300000000F9\r\n"},
    line2[]={":02000002F0000C"},
    line3[]={"\r\n:00000001FF\r\n"},
    numtable[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
    DFLCTL=1; //set dataflash enable
    HOCODIV=1; //16MHz
    SAU0EN = 1; // SAU0 enable
    NOP();NOP();NOP();NOP();
    ST0 |= 0x0001; // UART0 disable
    // UART0 TXD
    SMR00 = 0x0023; //CK00
    SCR00 = 0x8097; //8bit nonparity stopbit1
    SPS0 = 0x0000; SDR00 = 0x8800; //115200bps=16MHz/(0x88+2)
    STMK0 = 1; // INTST0 mask
    //PMC1=0xFB; //In case of RL78/G12 of 20pin and 24pin only, change P12/TXD0 digital port by PMC1=0xFB.
    P1 |= 0x04; //TXD0
    PM1 &= 0xFB; //TXD0
    SO0 |= 0x0001;
    SOE0 |= 0x0001; // UART0 output enable
    SS0 |= 0x0001; // start UART
    //read out data flash area
    puttxd(line1);
    puttxd(line2);
    for (i=0;i<0x800;i++){ //0x800 for Dataflash 2Kbyte
    if((i % 0x10)==0x00){
    puttxd("\r\n:10");sum=0x10;
    puttxd1(numtable[((0x1000+i)/0x1000)%0x10]);sum+=((0x1000+i)/0x100)%0x100;
    puttxd1(numtable[((0x1000+i)/0x100)%0x10]);
    puttxd1(numtable[((0x1000+i)/0x10)%0x10]);sum+=(0x1000+i)%0x100;
    puttxd("000");
    }
    puttxd1(numtable[((*(volatile unsigned char *)(p+i))/0x10)%0x10]);sum+=(*(volatile unsigned char *)(p+i));
    puttxd1(numtable[(*(volatile unsigned char *)(p+i))%0x10]);
    if((i % 0x10)==0x0f){
    puttxd1(numtable[((0x100-sum)/0x10)%0x10]);
    puttxd1(numtable[(0x100-sum)%0x10]);
    }
    }
    puttxd(line3);
    HALT(); //end
    }

  • In reply to Kirin:

    Hi,

    Thanks you guys for your interest in this question, even though it is a bit old now.

    /haen

  • In reply to Kirin:

    Hello Kirin,
    I need to read the same processor flash memory too.
    Is it possible?
    Best regards,
    Vasil
    vasil1972@abv.bg
  • In reply to Obrochishte:

    Hi Obrochishte,
    Perhaps you can use it as it was.
  • In reply to Kirin:

    Hi Kirin,
    Thank You for the reply.
    The corect name of MCU is RL78/G13.
    So, is it possible to read the code flash content?
    Thank You in advance.
  • In reply to Obrochishte:

    Hello Obrochishte,
    The UART output channel "TXD0" is assigned to "P12" which common to RL78/G13 and RL78/G12.
    So you can use the source code as it was.
     
    In case of RL78/G12 of 20pin and 24pin only, it necessary to add the code "PMC1=0xFB;" .

  • In reply to Kirin:

    Now I remember!
    Because the code uses address 0xF1000, you have to set the C-compiler small-model(64K) mode.
    Or, correct the part to read the data flash of the source code.

  • In reply to Kirin:

    Hello Kirin, in this case I use E1 emulator conection via TOOL0, pin 2. And the code flash area is from 00000H to 0FFFFH. Is it possible via E1 to read the code flash? Or I must use UART?
    Thank's
  • In reply to Obrochishte:

    Hi Obrochishte,
    Code/Data Flash protected by ID code can not be read using E1 emulator.
    It is possible to read out the flash only by the program with UART previously arranged in the flash memory.
    This thread is for talking about Data Flash. So, create a new thread for reading out Code Flash!