Skip to content

Commit 0fd5365

Browse files
iandmorrisfabiobaltieri
authored andcommitted
soc: renesas: ra: configure option settings memory
An area of flash memory on the RA4M1 MCU is used to store information used to configure the device following a reset. This patch instructs the linker to reserve this memory area and provides kconfig options that are used to populate it (at build time) with the desired device configuration. Signed-off-by: Ian Morris <[email protected]>
1 parent e80bc0d commit 0fd5365

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed

soc/renesas/ra/ra4m1/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,13 @@
33

44
zephyr_include_directories(.)
55

6+
zephyr_library_sources_ifdef(CONFIG_SOC_OPTION_SETTING_MEMORY
7+
soc.c
8+
)
9+
10+
zephyr_linker_sources_ifdef(CONFIG_SOC_OPTION_SETTING_MEMORY
11+
ROM_START
12+
${CMAKE_CURRENT_SOURCE_DIR}/opt_set_mem.ld
13+
)
14+
615
set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "")

soc/renesas/ra/ra4m1/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ config SOC_SERIES_RA4M1
99
select DYNAMIC_INTERRUPTS
1010
select TIMER_READS_ITS_FREQUENCY_AT_RUNTIME
1111
select XIP
12+
13+
config SOC_OPTION_SETTING_MEMORY
14+
bool "Option Setting Memory"
15+
default y
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2024 Ian Morris
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
. = 0x400;
9+
FILL(0xFF)
10+
KEEP(*(.opt_set_mem*))
11+
. = 0x500;

soc/renesas/ra/ra4m1/soc.c

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright (c) 2024 Ian Morris
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <zephyr/kernel.h>
7+
8+
#define HOCO_FREQ DT_PROP(DT_PATH(clocks, hoco), clock_frequency)
9+
10+
#if HOCO_FREQ == MHZ(24)
11+
#define OFS1_HOCO_FREQ 0
12+
#elif HOCO_FREQ == MHZ(32)
13+
#define OFS1_HOCO_FREQ 2
14+
#elif HOCO_FREQ == MHZ(48)
15+
#define OFS1_HOCO_FREQ 4
16+
#elif HOCO_FREQ == MHZ(64)
17+
#define OFS1_HOCO_FREQ 5
18+
#else
19+
#error "Unsupported HOCO frequency"
20+
#endif
21+
22+
struct ofs0_reg {
23+
uint32_t RSVD1: 1;
24+
uint32_t IWDTSTRT: 1;
25+
uint32_t IWDTTOPS: 2;
26+
uint32_t IWDTCKS: 4;
27+
uint32_t IWDTRPES: 2;
28+
uint32_t IWDTRPSS: 2;
29+
uint32_t IWDTRSTIRQS: 1;
30+
uint32_t RSVD2: 1;
31+
uint32_t IWDTSTPCTL: 1;
32+
uint32_t RSVD3: 2;
33+
uint32_t WDTSTRT: 1;
34+
uint32_t WDTTOPS: 2;
35+
uint32_t WDTCKS: 4;
36+
uint32_t WDTRPES: 2;
37+
uint32_t WDTRPSS: 2;
38+
uint32_t WDTRSTIRQS: 1;
39+
uint32_t RSVD4: 1;
40+
uint32_t WDTSTPCTL: 1;
41+
uint32_t RSVD5: 1;
42+
};
43+
44+
struct ofs1_reg {
45+
uint32_t RSVD1: 2;
46+
uint32_t LVDAS: 1;
47+
uint32_t VDSEL1: 3;
48+
uint32_t RSVD2: 2;
49+
uint32_t HOCOEN: 1;
50+
uint32_t RSVD3: 3;
51+
uint32_t HOCOFRQ1: 3;
52+
uint32_t RSVD4: 17;
53+
};
54+
55+
struct mpu_regs {
56+
uint32_t SECMPUPCSO;
57+
uint32_t SECMPUPCEO;
58+
uint32_t SECMPUPCS1;
59+
uint32_t SECMPUPCE1;
60+
uint32_t SECMPUS0;
61+
uint32_t SECMPUE0;
62+
uint32_t SECMPUS1;
63+
uint32_t SECMPUE1;
64+
uint32_t SECMPUS2;
65+
uint32_t SECMPUE2;
66+
uint32_t SECMPUS3;
67+
uint32_t SECMPUE3;
68+
uint32_t SECMPUAC;
69+
};
70+
71+
struct opt_set_mem {
72+
struct ofs0_reg ofs0;
73+
struct ofs1_reg ofs1;
74+
struct mpu_regs mpu;
75+
};
76+
77+
#ifdef CONFIG_SOC_OPTION_SETTING_MEMORY
78+
const struct opt_set_mem ops __attribute__((section(".opt_set_mem"))) = {
79+
.ofs0 = {
80+
/*
81+
* Initial settings for watchdog timers. Set all fields to 1,
82+
* disabling watchdog functionality as config options have not
83+
* yet been implemented.
84+
*/
85+
.RSVD1 = 0x1,
86+
.IWDTSTRT = 0x1, /* Disable independent watchdog timer */
87+
.IWDTTOPS = 0x3,
88+
.IWDTCKS = 0xf,
89+
.IWDTRPES = 0x3,
90+
.IWDTRPSS = 0x3,
91+
.IWDTRSTIRQS = 0x1,
92+
.RSVD2 = 0x1,
93+
.IWDTSTPCTL = 0x1,
94+
.RSVD3 = 0x3,
95+
.WDTSTRT = 0x1, /* Stop watchdog timer following reset */
96+
.WDTTOPS = 0x3,
97+
.WDTCKS = 0xf,
98+
.WDTRPES = 0x3,
99+
.WDTRPSS = 0x3,
100+
.WDTRSTIRQS = 0x1,
101+
.RSVD4 = 0x1,
102+
.WDTSTPCTL = 0x1,
103+
.RSVD5 = 0x1,
104+
},
105+
.ofs1 = {
106+
.RSVD1 = 0x3,
107+
.LVDAS = 0x1, /* Disable voltage monitor 0 following reset */
108+
.VDSEL1 = 0x3,
109+
.RSVD2 = 0x3,
110+
.HOCOEN = !DT_NODE_HAS_STATUS(DT_PATH(clocks, hoco), okay),
111+
.RSVD3 = 0x7,
112+
.HOCOFRQ1 = OFS1_HOCO_FREQ,
113+
.RSVD4 = 0x1ffff,
114+
},
115+
.mpu = {
116+
/*
117+
* Initial settings for MPU. Set all areas to maximum values
118+
* essentially disabling MPU functionality as config options
119+
* have not yet been implemented.
120+
*/
121+
.SECMPUPCSO = 0x00fffffc,
122+
.SECMPUPCEO = 0x00ffffff,
123+
.SECMPUPCS1 = 0x00fffffc,
124+
.SECMPUPCE1 = 0x00ffffff,
125+
.SECMPUS0 = 0x00fffffc,
126+
.SECMPUE0 = 0x00ffffff,
127+
.SECMPUS1 = 0x200ffffc,
128+
.SECMPUE1 = 0x200fffff,
129+
.SECMPUS2 = 0x407ffffc,
130+
.SECMPUE2 = 0x407fffff,
131+
.SECMPUS3 = 0x40dffffc,
132+
.SECMPUE3 = 0x40dfffff,
133+
.SECMPUAC = 0xffffffff,
134+
}
135+
};
136+
#endif

0 commit comments

Comments
 (0)