Skip to content

Commit

Permalink
Fixes for RX QSPI and Flash after additional testing. QSPI fixes for …
Browse files Browse the repository at this point in the history
…FIFO and clearing status flags by writing 0. Added native RX support for internal flash erase/write. Enable support for RAM_CODE.
  • Loading branch information
dgarske committed Jun 4, 2024
1 parent 1aee86b commit 6d69959
Show file tree
Hide file tree
Showing 11 changed files with 391 additions and 290 deletions.
2 changes: 1 addition & 1 deletion config/examples/renesas-rx65n.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ALLOW_DOWNGRADE?=0
NVM_FLASH_WRITEONCE?=0
WOLFBOOT_VERSION?=0
SPMATH?=1
RAM_CODE?=0
RAM_CODE?=1
DUALBANK_SWAP?=0

# reserve 1KB for wolfBoot header
Expand Down
6 changes: 3 additions & 3 deletions config/examples/renesas-rx72n.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ALLOW_DOWNGRADE?=0
NVM_FLASH_WRITEONCE?=0
WOLFBOOT_VERSION?=0
SPMATH?=1
RAM_CODE?=0
RAM_CODE?=1
DUALBANK_SWAP?=0

# reserve 1KB for wolfBoot header
Expand All @@ -24,8 +24,8 @@ DUALBANK_SWAP?=0
# Optionally switch to big endian data if MDE is set
#BIG_ENDIAN=1

# Flash is 4MB with 64KB sector size
WOLFBOOT_SECTOR_SIZE?=0x10000
# Flash is 4MB with 32KB sector size
WOLFBOOT_SECTOR_SIZE?=0x8000

# wolfBoot is last sector of flash and includes vector tables
WOLFBOOT_ORIGIN=0xFFFF0000
Expand Down
2 changes: 1 addition & 1 deletion docs/Targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,7 @@ Current Firmware Version: 1
Hit any key to call wolfBoot_success the firmware.
```

Default Onboard Flash Memory Layout (4MB) (64KB sector):
Default Onboard Flash Memory Layout (4MB) (32KB sector):

| Description | Address | Size |
| ----------------- | ---------- | -------------------- |
Expand Down
40 changes: 20 additions & 20 deletions hal/renesas-ra.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* renesas-ra.c
*
* Stubs for custom HAL implementation. Defines the
* Stubs for custom HAL implementation. Defines the
* functions used by wolfboot for a specific target.
*
* Copyright (C) 2023 wolfSSL Inc.
Expand Down Expand Up @@ -64,12 +64,12 @@ void hal_init(void)
#endif
err = R_FLASH_HP_Close(&g_flash0_ctrl);
err = R_FLASH_HP_Open(&g_flash0_ctrl, &g_flash0_cfg);

if(err != FSP_ERR_ALREADY_OPEN && err != FSP_SUCCESS){
printf("ERROR: %d\n", err);
hal_panic();
}

/* Setup Default Block 0 as Startup Setup Block */
err = R_FLASH_HP_StartUpAreaSelect(&g_flash0_ctrl, FLASH_STARTUP_AREA_BLOCK0, true);
if(err != FSP_SUCCESS){
Expand Down Expand Up @@ -120,15 +120,15 @@ static int blockWrite(const uint8_t *data, uint32_t addr, uint32_t len)
for(; len; len-=MINIMUM_BLOCK, data+=MINIMUM_BLOCK, addr+=MINIMUM_BLOCK) {
/* for the case "data" ls a flash address */
memcpy(save, data, MINIMUM_BLOCK);

if(R_FLASH_HP_Write(&g_flash0_ctrl, (uint32_t)save, addr, MINIMUM_BLOCK)
!= FSP_SUCCESS)
return -1;
}
return 0;
}

#define IS_FLASH(addr) (addr) >= 0xffc00000 ? 1 : 0
#define IS_FLASH_ADDR(addr) (addr) >= 0xffc00000 ? 1 : 0

int hal_flash_write(uint32_t addr, const uint8_t *data, int int_len)
{
Expand All @@ -138,21 +138,21 @@ int hal_flash_write(uint32_t addr, const uint8_t *data, int int_len)
uint8_t address_tmp = (uint8_t)(addr - ALIGN_FLASH(addr));

if(addr != ALIGN_FLASH(addr)) {

memset(save, 0, sizeof(save));
save_len = (addr - ALIGN_FLASH(addr)) < len ?

save_len = (addr - ALIGN_FLASH(addr)) < len ?
(addr - ALIGN_FLASH(addr)) : len;
memcpy(save, (const void *)ALIGN_FLASH(addr),

memcpy(save, (const void *)ALIGN_FLASH(addr),
MINIMUM_BLOCK * sizeof(uint32_t));
memcpy(save + (address_tmp), data, save_len);
addr = ALIGN_FLASH(addr);

if((err=R_FLASH_HP_Erase(&g_flash0_ctrl, addr, 1)) != FSP_SUCCESS)
return -1;
if((err=R_FLASH_HP_Write(&g_flash0_ctrl, (uint32_t)save, addr,

if((err=R_FLASH_HP_Write(&g_flash0_ctrl, (uint32_t)save, addr,
MINIMUM_BLOCK * sizeof(uint32_t))) != FSP_SUCCESS)
return -1;

Expand Down Expand Up @@ -180,12 +180,12 @@ int hal_flash_write(uint32_t addr, const uint8_t *data, int int_len)
memcpy(save, data, len);
if(R_FLASH_HP_Erase(&g_flash0_ctrl, addr, 1) != FSP_SUCCESS)
return -1;
if(R_FLASH_HP_Write(&g_flash0_ctrl,
if(R_FLASH_HP_Write(&g_flash0_ctrl,
(uint32_t)save, addr, MINIMUM_BLOCK) != FSP_SUCCESS)
goto error;
}
return 0;

error:
return -1;
}
Expand All @@ -194,7 +194,7 @@ int hal_flash_erase(uint32_t address, int int_len)
{
uint32_t len = (uint32_t)int_len;
#ifdef WOLFBOOT_DUALBANK
uint32_t block_size = (address <= 0x80000 && address >= 0x10000)
uint32_t block_size = (address <= 0x80000 && address >= 0x10000)
|| address >= 0x210000 ? (32*1024) : (8*1024);
#else /* Lenier mode */
uint32_t block_size = address >= 0x10000 ? (32*1024) : (8*1024);
Expand Down Expand Up @@ -234,9 +234,9 @@ void hal_flash_lock(void)
FLASH_START_ADDR, FLASH_END_ADDR)
!= FSP_SUCCESS)
hal_panic();

#ifdef WOLFBOOT_DUALBANK
if(R_FLASH_HP_AccessWindowSet(&g_flash0_ctrl,
if(R_FLASH_HP_AccessWindowSet(&g_flash0_ctrl,
FLASH1_START_ADDR, FLASH1_END_ADDR)
!= FSP_SUCCESS)
hal_panic();
Expand All @@ -250,10 +250,10 @@ void RAMFUNCTION hal_flash_dualbank_swap(void)
flash_cmd_t cmd = FLASH_CMD_SWAPFLAG_TOGGLE;

hal_flash_unlock();

if(R_FLASH_HP_Control(cmd, NULL) != FSP_SUCCESS)
hal_panic();

hal_flash_lock();

}
Expand Down
Loading

0 comments on commit 6d69959

Please sign in to comment.