Skip to content

Commit d295eba

Browse files
committed
Improve Flash iap driver of Renesas
I changed _page_program() func because "buf" which is an argument of data_send() for writing must be a RAM address in order to operate in SPI mode. (ex: if it is ROM table data, writing will be failure.) Also, I changed the period of interrupt disable/enable at _page_program() func and _sector_erase() func because lock period is too long.
1 parent 920db63 commit d295eba

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

targets/TARGET_RENESAS/TARGET_RZ_A1XX/flash_api.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ typedef struct {
9999
static mmu_ttbl_desc_section_t desc_tbl[(SPIBSC_ADDR_END >> 20) - (SPIBSC_ADDR_START >> 20) + 1];
100100
static volatile struct st_spibsc* SPIBSC = &SPIBSC0;
101101
static st_spibsc_spimd_reg_t spimd_reg;
102+
static uint8_t write_tmp_buf[FLASH_PAGE_SIZE];
102103

103104
#if defined(__ICCARM__)
104105
#define RAM_CODE_SEC __ramfunc
@@ -136,24 +137,12 @@ int32_t flash_free(flash_t *obj)
136137

137138
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
138139
{
139-
int32_t ret;
140-
141-
core_util_critical_section_enter();
142-
ret = _sector_erase(address - FLASH_BASE);
143-
core_util_critical_section_exit();
144-
145-
return ret;
140+
return _sector_erase(address - FLASH_BASE);
146141
}
147142

148143
int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size)
149144
{
150-
int32_t ret;
151-
152-
core_util_critical_section_enter();
153-
ret = _page_program(address - FLASH_BASE, data, size);
154-
core_util_critical_section_exit();
155-
156-
return ret;
145+
return _page_program(address - FLASH_BASE, data, size);
157146
}
158147

159148
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
@@ -184,12 +173,14 @@ int32_t _sector_erase(uint32_t addr)
184173
{
185174
int32_t ret;
186175

176+
core_util_critical_section_enter();
187177
spi_mode();
188178

189179
/* ---- Write enable ---- */
190180
ret = write_enable(); /* WREN Command */
191181
if (ret != 0) {
192182
ex_mode();
183+
core_util_critical_section_exit();
193184
return ret;
194185
}
195186

@@ -210,12 +201,14 @@ int32_t _sector_erase(uint32_t addr)
210201
ret = spibsc_transfer(&spimd_reg);
211202
if (ret != 0) {
212203
ex_mode();
204+
core_util_critical_section_exit();
213205
return ret;
214206
}
215207

216208
ret = busy_wait();
217209

218210
ex_mode();
211+
core_util_critical_section_exit();
219212
return ret;
220213
}
221214

@@ -226,8 +219,6 @@ int32_t _page_program(uint32_t addr, const uint8_t * buf, int32_t size)
226219
int32_t remainder;
227220
int32_t idx = 0;
228221

229-
spi_mode();
230-
231222
while (size > 0) {
232223
if (size > FLASH_PAGE_SIZE) {
233224
program_size = FLASH_PAGE_SIZE;
@@ -239,10 +230,15 @@ int32_t _page_program(uint32_t addr, const uint8_t * buf, int32_t size)
239230
program_size = remainder;
240231
}
241232

233+
core_util_critical_section_enter();
234+
memcpy(write_tmp_buf, &buf[idx], program_size);
235+
spi_mode();
236+
242237
/* ---- Write enable ---- */
243238
ret = write_enable(); /* WREN Command */
244239
if (ret != 0) {
245240
ex_mode();
241+
core_util_critical_section_exit();
246242
return ret;
247243
}
248244

@@ -267,28 +263,33 @@ int32_t _page_program(uint32_t addr, const uint8_t * buf, int32_t size)
267263
ret = spibsc_transfer(&spimd_reg); /* Command,Address */
268264
if (ret != 0) {
269265
ex_mode();
266+
core_util_critical_section_exit();
270267
return ret;
271268
}
272269

273270
/* ----------- 2. Data ---------------*/
274-
ret = data_send(SPIBSC_1BIT, SPIBSC_SPISSL_NEGATE, &buf[idx], program_size);
271+
ret = data_send(SPIBSC_1BIT, SPIBSC_SPISSL_NEGATE, write_tmp_buf, program_size);
275272
if (ret != 0) {
276273
ex_mode();
274+
core_util_critical_section_exit();
277275
return ret;
278276
}
279277

280278
ret = busy_wait();
281279
if (ret != 0) {
282280
ex_mode();
281+
core_util_critical_section_exit();
283282
return ret;
284283
}
285284

285+
ex_mode();
286+
core_util_critical_section_exit();
287+
286288
addr += program_size;
287289
idx += program_size;
288290
size -= program_size;
289291
}
290292

291-
ex_mode();
292293
return ret;
293294
}
294295

0 commit comments

Comments
 (0)