Skip to content

Commit 0968710

Browse files
committed
Revert previous change.
- Do not use memcpy before it is relocated to RAM. - Prefer library functions over RX intrinsics.( Compiler option change)
1 parent 5e203e6 commit 0968710

File tree

2 files changed

+45
-36
lines changed

2 files changed

+45
-36
lines changed

IDE/Renesas/e2studio/RX72N/wolfBoot/.cproject

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
<listOptionValue builtIn="false" value="../../include/target.h"/>
8383
</option>
8484
<option id="com.renesas.cdt.managedbuild.renesas.ccrx.compiler.option.optimize.402664598" name="Optimization level (-optimize)" superClass="com.renesas.cdt.managedbuild.renesas.ccrx.compiler.option.optimize" useByScannerDiscovery="false" value="com.renesas.cdt.managedbuild.renesas.ccrx.compiler.option.optimize.level2" valueType="enumerated"/>
85+
<option id="com.renesas.cdt.managedbuild.renesas.ccrx.compiler.option.library.498855776" name="Execution method of library function that can be expanded to RX instructions (-library)" superClass="com.renesas.cdt.managedbuild.renesas.ccrx.compiler.option.library" value="com.renesas.cdt.managedbuild.renesas.ccrx.compiler.option.library.functions" valueType="enumerated"/>
8586
<inputType id="com.renesas.cdt.managedbuild.renesas.ccrx.compiler.gcc.inputType.1343195127" name="Compiler Input C" superClass="com.renesas.cdt.managedbuild.renesas.ccrx.compiler.gcc.inputType"/>
8687
<inputType id="com.renesas.cdt.managedbuild.renesas.ccrx.compiler.gpp.inputType.1547456010" name="Compiler Input CPP" superClass="com.renesas.cdt.managedbuild.renesas.ccrx.compiler.gpp.inputType"/>
8788
</tool>

hal/renesas-rx.c

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,17 @@ void hal_delay_us(uint32_t us)
107107

108108
static flash_err_t flash_check_error()
109109
{
110-
uint32_t st = FLASH_FSTATR;
110+
uint32_t st = FLASH_FSTATR;
111111

112-
if (st & FLASH_FSTATR_ILGLERR) return FLASH_ERR_ILGL;
113-
if (st & FLASH_FSTATR_PRGERR) return FLASH_ERR_PRG;
114-
if (st & FLASH_FSTATR_ERSERR) return FLASH_ERR_ERS;
115-
if (st & FLASH_FSTATR_FLWEERR) return FLASH_ERR_FLWE;
116-
if (st & FLASH_FSTATR_FESETERR) return FLASH_ERR_FESET;
117-
if (st & FLASH_FSTATR_SECERR) return FLASH_ERR_SEC;
118-
if (st & FLASH_FSTATR_OTERR) return FLASH_ERR_OT;
112+
if (st & FLASH_FSTATR_ILGLERR) return FLASH_ERR_ILGL;
113+
if (st & FLASH_FSTATR_PRGERR) return FLASH_ERR_PRG;
114+
if (st & FLASH_FSTATR_ERSERR) return FLASH_ERR_ERS;
115+
if (st & FLASH_FSTATR_FLWEERR) return FLASH_ERR_FLWE;
116+
if (st & FLASH_FSTATR_FESETERR) return FLASH_ERR_FESET;
117+
if (st & FLASH_FSTATR_SECERR) return FLASH_ERR_SEC;
118+
if (st & FLASH_FSTATR_OTERR) return FLASH_ERR_OT;
119119

120-
return FLASH_OK;
120+
return FLASH_OK;
121121

122122
}
123123
#ifdef DEBUG_UART
@@ -250,15 +250,15 @@ void hal_clk_init(void)
250250
/* Wait for HOCO oscillator stabilization */
251251
while ((SYS_OSCOVFSR & SYS_OSCOVFSR_HCOVF) == 0) { RX_NOP(); }
252252
#else
253-
if (SYS_HOCOCR & SYS_HOCOCR_HCSTP) {
254-
/* Turn off power to HOCO */
255-
SYS_HOCOPCR |= SYS_HOCOPCR_HOCOPCNT;
256-
}
253+
if (SYS_HOCOCR & SYS_HOCOCR_HCSTP) {
254+
/* Turn off power to HOCO */
255+
SYS_HOCOPCR |= SYS_HOCOPCR_HOCOPCNT;
256+
}
257257
#endif
258258

259259
/* ---- Main-Clock ---- */
260260
#if CFG_CKSEL == 2
261-
/* MOFXIN=0 (not controlled), MODRV2=0 (24MHz), MOSEL=0 (resonator) */
261+
/* MOFXIN=0 (not controlled), MODRV2=0 (24MHz), MOSEL=0 (resonator) */
262262
SYS_MOFCR = 0;
263263

264264
/* OSC stabilization time (9.98 ms * (264 kHZ) + 16)/32 = 82.83) */
@@ -500,21 +500,29 @@ void hal_prepare_boot(void)
500500

501501
}
502502

503+
#ifdef __CCRX__
504+
/* copy RAM functions from ROM to RAM */
505+
static void copyfuncs(void)
506+
{
507+
unsigned char *dst, *src;
508+
size_t n;
509+
510+
src = __sectop("PFRAM");
511+
dst = __sectop("RPFRAM");
512+
n = (size_t)((unsigned char*)__secend("PFRAM") -
513+
(unsigned char*)__sectop("PFRAM"));
514+
wolfBoot_printf("RAM Function start = 0x%p\n", __sectop("RPFRAM"));
515+
wolfBoot_printf("RAM Function end = 0x%p\n", __secend("RPFRAM"));
516+
wolfBoot_printf("RAM Function size = %d\n", n);
517+
while(src < __secend("PFRAM")) {
518+
*dst++ = *src++;
519+
}
520+
}
521+
#endif
503522
int hal_flash_init(void)
504523
{
505524
#ifdef __CCRX__
506-
unsigned char *src, *dst;
507-
size_t n;
508-
509-
src = (unsigned char*)__sectop("PFRAM");
510-
dst = (unsigned char*)__sectop("RPFRAM");
511-
512-
n = (size_t)((unsigned char*)__secend("PFRAM") -
513-
(unsigned char*)__sectop("PFRAM"));
514-
wolfBoot_printf("RAM Function start = 0x%p\n", __sectop("RPFRAM"));
515-
wolfBoot_printf("RAM Function end = 0x%p\n", __secend("RPFRAM"));
516-
wolfBoot_printf("RAM Function size = %d\n", n);
517-
memcpy(dst, src, n);
525+
copyfuncs();
518526
#endif
519527
/* Flash Write Enable */
520528
FLASH_FWEPROR = FLASH_FWEPROR_FLWE;
@@ -549,17 +557,17 @@ int RAMFUNCTION hal_flash_write(uint32_t addr, const uint8_t *data, int len)
549557
int ret;
550558

551559
while (len > 0) {
552-
/* Align address to 128-byte boundary */
553-
block_base = addr & ~(FLASH_FACI_CODE_BLOCK_SZ - 1);
554-
offset = addr - block_base;
560+
/* Align address to 128-byte boundary */
561+
block_base = addr & ~(FLASH_FACI_CODE_BLOCK_SZ - 1);
562+
offset = addr - block_base;
555563

556-
memcpy(codeblock, (uint8_t*)block_base, FLASH_FACI_CODE_BLOCK_SZ);
557-
write_size = FLASH_FACI_CODE_BLOCK_SZ - offset;
558-
if (write_size > len)
559-
write_size = len;
564+
memcpy(codeblock, (uint8_t*)block_base, FLASH_FACI_CODE_BLOCK_SZ);
565+
write_size = FLASH_FACI_CODE_BLOCK_SZ - offset;
566+
if (write_size > len)
567+
write_size = len;
560568

561-
memcpy(&codeblock[offset], data, write_size);
562-
data16 = (uint16_t*)codeblock;
569+
memcpy(&codeblock[offset], data, write_size);
570+
data16 = (uint16_t*)codeblock;
563571

564572
FLASH_FSADDR = block_base;
565573
/* flash program command */
@@ -579,7 +587,7 @@ int RAMFUNCTION hal_flash_write(uint32_t addr, const uint8_t *data, int len)
579587
/* Wait for FCU operation to complete */
580588
while ((FLASH_FSTATR & FLASH_FSTATR_FRDY) == 0);
581589
if ((ret = flash_check_error()) != FLASH_OK) {
582-
return ret;
590+
return ret;
583591
}
584592
len -= write_size;
585593
addr += write_size;

0 commit comments

Comments
 (0)