diff --git a/hal/renesas-rx.c b/hal/renesas-rx.c index 0cb3fe70f..a31b250bc 100644 --- a/hal/renesas-rx.c +++ b/hal/renesas-rx.c @@ -466,9 +466,12 @@ int RAMFUNCTION hal_flash_write(uint32_t addr, const uint8_t *data, int len) FLASH_FACI_CMD8 = FLASH_FACI_CMD_PROGRAM; FLASH_FACI_CMD8 = FLASH_FACI_CMD_PROGRAM_CODE_LENGTH; - /* write 128 * 2 bytes */ + /* write 64 * 2 bytes */ for (i=0; i < FLASH_FACI_CMD_PROGRAM_CODE_LENGTH; i++) { FLASH_FACI_CMD16 = *data16++; + + /* wait for data buffer not full */ + while (FLASH_FSTATR & FLASH_FSTATR_DBFULL); } FLASH_FACI_CMD8 = FLASH_FACI_CMD_FINAL; @@ -476,7 +479,10 @@ int RAMFUNCTION hal_flash_write(uint32_t addr, const uint8_t *data, int len) /* Wait for FCU operation to complete */ while ((FLASH_FSTATR & FLASH_FSTATR_FRDY) == 0); - len += (FLASH_FACI_CMD_PROGRAM_CODE_LENGTH * 2); + len -= (FLASH_FACI_CMD_PROGRAM_CODE_LENGTH * + FLASH_FACI_CMD_PROGRAM_DATA_LENGTH); + addr += (FLASH_FACI_CMD_PROGRAM_CODE_LENGTH * + FLASH_FACI_CMD_PROGRAM_DATA_LENGTH); } return 0; } @@ -599,14 +605,18 @@ static int test_flash(void) #ifndef TEST_FLASH_READONLY /* Erase sector */ + hal_flash_unlock(); ret = hal_flash_erase(TEST_ADDRESS, sizeof(pageData)); + hal_flash_lock(); wolfBoot_printf("Erase Sector: Ret %d\n", ret); /* Write Pages */ for (i=0; i