Skip to content

Commit 2c34da9

Browse files
iandmorrisaescolar
authored andcommitted
drivers: clock_control: ra: fix issue with setting memwait cycles
Setting the number of memory wait cycles must take place while the clock is set to 32MHz or less. This patch ensure the MEMWAIT register is changed before the clock is changed from its default value (of 8MHz). Note that in order to set MEMWAIT to 1 the power control mode must be set to high speed (which is why the lines of code interacting with the OPCCR register have also been moved). Signed-off-by: Ian Morris <[email protected]>
1 parent 971a0d1 commit 2c34da9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/clock_control/clock_control_renesas_ra.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,20 @@ static int clock_control_ra_init(const struct device *dev)
286286
}
287287
}
288288

289+
SYSTEM_write8(OPCCR_OFFSET, 0);
290+
while ((SYSTEM_read8(OPCCR_OFFSET) & BIT(OPCCR_OPCMTSF_POS)) != 0) {
291+
;
292+
}
293+
294+
SYSTEM_write8(MEMWAIT_OFFSET, 1);
295+
289296
SYSTEM_write32(SCKDIVCR_OFFSET, SCKDIVCR_INIT_VALUE);
290297
SYSTEM_write8(SCKSCR_OFFSET, SCKSCR_INIT_VALUE);
291298

292299
/* re-read system clock setting and apply to hw_cycles */
293300
sysclk = SYSTEM_read8(SCKSCR_OFFSET);
294301
z_clock_hw_cycles_per_sec = clock_freqs[sysclk];
295302

296-
SYSTEM_write8(OPCCR_OFFSET, 0);
297-
while ((SYSTEM_read8(OPCCR_OFFSET) & BIT(OPCCR_OPCMTSF_POS)) != 0) {
298-
;
299-
}
300-
301-
SYSTEM_write8(MEMWAIT_OFFSET, 1);
302303
SYSTEM_write16(PRCR_OFFSET, PRCR_KEY);
303304

304305
return 0;

0 commit comments

Comments
 (0)