Skip to content

Commit

Permalink
Fixes for RX internal flash erase/write. "Flash Test Passed".
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Jul 15, 2024
1 parent bc7a403 commit 0e0b6cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions hal/renesas-rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,17 +466,23 @@ 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;

/* 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;
}
Expand Down Expand Up @@ -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<sizeof(pageData); i++) {
((uint8_t*)pageData)[i] = (i & 0xff);
}
hal_flash_unlock();
ret = hal_flash_write(TEST_ADDRESS, (uint8_t*)pageData, sizeof(pageData));
hal_flash_lock();
wolfBoot_printf("Write Page: Ret %d\n", ret);
#endif /* !TEST_FLASH_READONLY */

Expand Down
3 changes: 2 additions & 1 deletion hal/renesas-rx.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ void hal_delay_us(uint32_t us);
#define FLASH_FAEINT_CFAEIE (1 << 7)

#define FLASH_FSADDR (*(volatile uint32_t *)(0x007FE030))
#define FLASH_FEADDR (*(volatile uint32_t *)(0x007FE034))

#define FLASH_FAWMON (*(volatile uint32_t *)(0x007FE0DC))
#define FLASH_FAWMON_FAWS(a) ((a) & 0xFFF) /* Flash Access Window Start Address * 2 */
Expand Down Expand Up @@ -221,7 +222,7 @@ void hal_delay_us(uint32_t us);

/* FCAI Commands (RX72N RM Table 62.11) */
#define FLASH_FACI_CMD_PROGRAM 0xE8
#define FLASH_FACI_CMD_PROGRAM_CODE_LENGTH 128
#define FLASH_FACI_CMD_PROGRAM_CODE_LENGTH 64
#define FLASH_FACI_CMD_PROGRAM_DATA_LENGTH 2
#define FLASH_FACI_CMD_BLOCK_ERASE 0x20
#define FLASH_FACI_CMD_PROGRAM_ERASE_SUSPEND 0xB0
Expand Down

0 comments on commit 0e0b6cc

Please sign in to comment.