Skip to content

Commit

Permalink
Fix for Renesas RX hal_flash_write where length is < 128.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske authored and danielinux committed Jul 25, 2024
1 parent b6e4e22 commit 3f3a3ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ ifeq ($(ARCH),RENESAS_RX)
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_pfa.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_pfb.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_pf1.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_pf5.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_pf6.o \
$(RX_TSIP_SRC_PATH)/ip/s_flash.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_p00.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_p01.o \
Expand All @@ -379,6 +381,8 @@ ifeq ($(ARCH),RENESAS_RX)
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_function010.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_function011.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_function023.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_function027.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_function028.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_function050.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_function051.o \
$(RX_TSIP_SRC_PATH)/ip/r_tsip_rx_function052.o \
Expand Down
19 changes: 11 additions & 8 deletions hal/renesas-rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,20 +454,25 @@ int hal_flash_init(void)
return 0;
}

/* write up to 256 bytes at a time */
/* write up to 128 bytes at a time */
int RAMFUNCTION hal_flash_write(uint32_t addr, const uint8_t *data, int len)
{
int ret, i;
int ret, i, chunk;
const uint16_t* data16 = (const uint16_t*)data;

while (len > 0) {
chunk = len/2;
if (chunk > FLASH_FACI_CMD_PROGRAM_CODE_LENGTH) {
chunk = FLASH_FACI_CMD_PROGRAM_CODE_LENGTH;
}

FLASH_FSADDR = addr;

FLASH_FACI_CMD8 = FLASH_FACI_CMD_PROGRAM;
FLASH_FACI_CMD8 = FLASH_FACI_CMD_PROGRAM_CODE_LENGTH;
FLASH_FACI_CMD8 = chunk;

/* write 64 * 2 bytes */
for (i=0; i < FLASH_FACI_CMD_PROGRAM_CODE_LENGTH; i++) {
for (i=0; i < chunk; i++) {
FLASH_FACI_CMD16 = *data16++;

/* wait for data buffer not full */
Expand All @@ -479,10 +484,8 @@ 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 *
FLASH_FACI_CMD_PROGRAM_DATA_LENGTH);
addr += (FLASH_FACI_CMD_PROGRAM_CODE_LENGTH *
FLASH_FACI_CMD_PROGRAM_DATA_LENGTH);
len -= (chunk * FLASH_FACI_CMD_PROGRAM_DATA_LENGTH);
addr += (chunk * FLASH_FACI_CMD_PROGRAM_DATA_LENGTH);
}
return 0;
}
Expand Down

0 comments on commit 3f3a3ec

Please sign in to comment.