Skip to content

Commit d5ef467

Browse files
committed
Support large Flash in Flash iap driver of Renesas
I addressed the cases Flash size is larger than 0x1000000.
1 parent d295eba commit d5ef467

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

targets/TARGET_RENESAS/TARGET_RZ_A1XX/flash_api.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,22 @@
1818
#include "mbed_critical.h"
1919

2020
#if DEVICE_FLASH
21+
#include <string.h>
2122
#include "iodefine.h"
2223
#include "spibsc_iobitmask.h"
2324
#include "spibsc.h"
2425
#include "mbed_drv_cfg.h"
2526

2627
/* ---- serial flash command ---- */
28+
#if (FLASH_SIZE > 0x1000000)
29+
#define SPIBSC_OUTPUT_ADDR SPIBSC_OUTPUT_ADDR_32
30+
#define SFLASHCMD_SECTOR_ERASE (0x21u) /* SE4B 4-byte address(1bit) */
31+
#define SFLASHCMD_PAGE_PROGRAM (0x12u) /* PP4B 4-byte address(1bit), data(1bit) */
32+
#else
33+
#define SPIBSC_OUTPUT_ADDR SPIBSC_OUTPUT_ADDR_24
2734
#define SFLASHCMD_SECTOR_ERASE (0x20u) /* SE 3-byte address(1bit) */
2835
#define SFLASHCMD_PAGE_PROGRAM (0x02u) /* PP 3-byte address(1bit), data(1bit) */
36+
#endif
2937
#define SFLASHCMD_READ_STATUS_REG (0x05u) /* RDSR data(1bit) */
3038
#define SFLASHCMD_WRITE_ENABLE (0x06u) /* WREN */
3139
/* ---- serial flash register definitions ---- */
@@ -74,10 +82,6 @@ typedef struct {
7482
uint32_t smwdr[2]; /* write data */
7583
} st_spibsc_spimd_reg_t;
7684

77-
/* SPI Multi-I/O bus address space address definitions */
78-
#define SPIBSC_ADDR_START (0x18000000uL)
79-
#define SPIBSC_ADDR_END (0x1BFFFFFFuL)
80-
8185
typedef struct {
8286
uint32_t b0 : 1 ; /* bit 0 : - (0) */
8387
uint32_t b1 : 1 ; /* bit 1 : - (1) */
@@ -96,7 +100,7 @@ typedef struct {
96100
uint32_t base_addr : 12; /* bit 31-20 : PA[31:20] PA(physical address) bits:bit31-20 */
97101
} mmu_ttbl_desc_section_t;
98102

99-
static mmu_ttbl_desc_section_t desc_tbl[(SPIBSC_ADDR_END >> 20) - (SPIBSC_ADDR_START >> 20) + 1];
103+
static mmu_ttbl_desc_section_t desc_tbl[(FLASH_SIZE >> 20)];
100104
static volatile struct st_spibsc* SPIBSC = &SPIBSC0;
101105
static st_spibsc_spimd_reg_t spimd_reg;
102106
static uint8_t write_tmp_buf[FLASH_PAGE_SIZE];
@@ -193,7 +197,7 @@ int32_t _sector_erase(uint32_t addr)
193197
spimd_reg.cmd = SFLASHCMD_SECTOR_ERASE;
194198

195199
/* ---- address ---- */
196-
spimd_reg.ade = SPIBSC_OUTPUT_ADDR_24;
200+
spimd_reg.ade = SPIBSC_OUTPUT_ADDR;
197201
spimd_reg.addre = SPIBSC_SDR_TRANS; /* SDR */
198202
spimd_reg.adb = SPIBSC_1BIT;
199203
spimd_reg.addr = addr;
@@ -252,7 +256,7 @@ int32_t _page_program(uint32_t addr, const uint8_t * buf, int32_t size)
252256
spimd_reg.cmd = SFLASHCMD_PAGE_PROGRAM;
253257

254258
/* ---- address ---- */
255-
spimd_reg.ade = SPIBSC_OUTPUT_ADDR_24;
259+
spimd_reg.ade = SPIBSC_OUTPUT_ADDR;
256260
spimd_reg.addre = SPIBSC_SDR_TRANS; /* SDR */
257261
spimd_reg.adb = SPIBSC_1BIT;
258262
spimd_reg.addr = addr;
@@ -687,16 +691,16 @@ static void change_mmu_ttbl_spibsc(uint32_t type)
687691
mmu_ttbl_desc_section_t * table = (mmu_ttbl_desc_section_t *)TTB;
688692

689693
/* ==== Modify SPI Multi-I/O bus space settings in the MMU translation table ==== */
690-
for (index = (SPIBSC_ADDR_START >> 20); index <= (SPIBSC_ADDR_END >> 20); index++) {
694+
for (index = (FLASH_BASE >> 20); index < ((FLASH_BASE + FLASH_SIZE) >> 20); index++) {
691695
/* Modify memory attribute descriptor */
692696
if (type == 0) { /* Spi */
693697
desc = table[index];
694-
desc_tbl[index - (SPIBSC_ADDR_START >> 20)] = desc;
698+
desc_tbl[index - (FLASH_BASE >> 20)] = desc;
695699
desc.AP1_0 = 0x0u; /* AP[2:0] = b'000 (No access) */
696700
desc.AP2 = 0x0u;
697701
desc.XN = 0x1u; /* XN = 1 (Execute never) */
698702
} else { /* Xip */
699-
desc = desc_tbl[index - (SPIBSC_ADDR_START >> 20)];
703+
desc = desc_tbl[index - (FLASH_BASE >> 20)];
700704
}
701705
/* Write descriptor back to translation table */
702706
table[index] = desc;

0 commit comments

Comments
 (0)