CPU Rewrite Mode in IAR with E8a Debugger


I'm using R32C121 with IAR Embedded Workbench, and I have serious problems with debugging in CPU Rewrite mode. The whole thing goes off and freezes, if I go into EW1 mode by this code:

void FLASH_CPUReWriteMode(EWMODE selected_ewmode){


  ewm_e2fm=0; //With this bit set to 1, FEW should not be set to 1

  prr = 0xAA; //Protection feloldása FMCR regiszter írásához

  fmcr = 0x00; //few = 0;

  fmcr = 0x81; //few = 1;

  prr = 0x00; //prr = 0;


     fpr0 = 0x01; //Protection feloldása FMR0 regiszter írásához, pr0 = 1;

     ewm = 0;

     fpr0 = 0x00; //pr0 = 0;



     fpr0 = 0x01; //Protection feloldása FMR0 regiszter írásához, pr0 = 1;

     ewm = 1;

     fpr0 = 0x00; //pr0 = 0;



Am I misunderstanding something or doing it wrong? I've look at the FLASH api from Renesas, which has almost the same code like mine, but there are no differences in entering Rewrite Mode. I've already tried this with writing just few=1; and pr0=1; also not getting a working code. I've tried to run through all of my FLASH functions, not interrupting them through debug, which also didn't do anything good. If I go through FLASH rewriting codes, the debug freezes and I have to restart the whole program. Could you please help me in this case? Thank You!

  • Did you also select the "Debugging of CPU rewrite mode" in the E8a initial dialog?

    Did you take care that the E8a firmware is not erased, and that the E8a work RAM is not overwritten?

  • Yes, I've tried to debug in "Erase Flash and Connect" mode also just as in "Debug of CPU rewrite mode". I've viewed the map file in the output folder, which consists the follows:

    DIFUNCT                                 FFFA1000                     rel    0

    CSTART                             FFFA1000 - FFFA1049          4A   rel    2

    1                         FFFA104A - FFFA16C0         677   rel    0

    INTVEC                             FFFA16C4 - FFFA18C3         200   com    2

    DATA24_C                           FFFA18C4 - FFFA18C7           4   rel    2

    NMIVEC                             FFFFFFDC - FFFFFFFF          24   com    0

    The data above means there's no such program data at FFFB0000h, which I tried to program, nor at 00061000h (Block B I think)  in the Data Flash. I'm consequently switching between these addresses to avoid problems caused by wrong addresses. But the whole program freezes when I try to set the few bit to 1, or the whole register, fmcr = 0x81;. I've tried to debug without breakpoints, having a led blinking while(1) cycle at the bottom of the program, after exiting the rewrite mode. Of course, I didn't see such a blink, because every time it frozes. I've set the prr to AAh, then after setting few to 1, back to non-AA (0), so unlocking shouldn't be a problem also. I've made my API by myself, and I compared it to the API what Renesas gave out, and it was the same (at the beginning, since I inserted a few things into it, like slowing down CPU clock, etc.).

    I've read about febc0 and febc3 registers, although my ior32c121.h does not include such registers, just a simple febc. Can this be a problem? I think the febc0 and febc3 registers are for 118 series, am I right? (The funny thing is that the febc register is used for bus timing setting, and I'm not even getting to the point where I can use this bus.)

  • The answer: Do not try to access the Bus Timing register (febc) bit-wise, though the datasheet doesn't say it, write it only as a whole. Rewriting it bit-by-bit results in crashing ONLY when entering CPU rewrite mode, and not during initialization. Great bug, was even greater to debug. happy