RX651 cannot self program the same 128 byte page twice without erasing

 Hello

I am using the Renesas 65n1 Flash FIT module to program the code flash on the R6519AxFP.

I can program a page of 128 bytes after an erasure.

I tryed with "HEJ", keeping all the other bytes as 0xFF. This works.

The i tried to program the same page of 128 bytes as

"HEJ MOR" but i get a FLASH_ERR_FAILURE error.

I can however write "Hello World! I like Cake!" to the page if i erase the entire block (32 KiB) first and then write to it.

I can also write to other 128 byte pages without erasing, but i cannot rewrite the same page.

Here is my test code:

    hal_flash_init();

    char test[256];
    memset(test,0xFF,256);

    test[0] = hal_flash_erase(0xFFFE8000, 1); //Erase
    hal_flash_read(test, 0xFFFE8080, 128);     //Check data = ok

    test[0] = 'H';
    test[1] = 'E';
    test[2] = 'J';
    test[0] = hal_flash_write(test, 0xFFFE8080, 128); //Works as intended
    hal_flash_read(test, 0xFFFE8000, 256);

    test[0] = 'H';
    test[1] = 'E';
    test[2] = 'J';
    test[3] = ' ';
    test[4] = 'M';
    test[5] = 'O';
    test[6] = 'R';
    test[0] = hal_flash_write(test, 0xFFFE8080, 128);  //Gives error FLASH_ERR_FAILURE
    hal_flash_read(test, 0xFFFE8000, 256);

    test[0] = 'H';
    test[1] = 'E';
    test[2] = 'J';
    test[0] = hal_flash_write(test, 0xFFFE8000, 128); //Works
    hal_flash_read(test, 0xFFFE8000, 256);

Any ideas?