Skip to content

Commit 16a7547

Browse files
Danh DoanKhiemNguyenT
authored andcommitted
hal: renesas: ra: initial support for sdram controller
Initial support SDRAM on Renesas RA SoC Signed-off-by: Danh Doan <[email protected]>
1 parent 677984b commit 16a7547

File tree

10 files changed

+448
-0
lines changed

10 files changed

+448
-0
lines changed

drivers/ra/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_SDHI
5757
fsp/src/r_sdhi/r_sdhi.c)
5858
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_OSPI_B_NOR_FLASH
5959
fsp/src/r_ospi_b/r_ospi_b.c)
60+
zephyr_library_sources_ifdef(CONFIG_USE_RA_FSP_SDRAM
61+
fsp/src/bsp/mcu/all/bsp_sdram.c)
6062

6163
if(CONFIG_USE_RA_FSP_SCE)
6264
zephyr_include_directories(

drivers/ra/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,8 @@ Patch List:
7777
drivers/ra/fsp/src/r_ether_phy/targets/KSZ8091RNB/r_ether_phy_target_ksz8091rnb.c
7878
drivers/ra/fsp/inc/instances/r_ether_phy.h
7979
drivers/ra/fsp/inc/instances/r_ether.h
80+
81+
* Add support for SDRAM controllers taken from FSP v5.6.0
82+
Impacted files:
83+
drivers/ra/fsp/src/bsp/mcu/all/bsp_sdram.h
84+
drivers/ra/fsp/src/bsp/mcu/all/bsp_sdram.c
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/*
2+
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
/*******************************************************************************************************************//**
8+
* @defgroup BSP_SDRAM BSP SDRAM support
9+
* @ingroup RENESAS_COMMON
10+
* @brief Code that initializes the SDRAMC and SDR SDRAM device memory.
11+
*
12+
* @{
13+
**********************************************************************************************************************/
14+
15+
/***********************************************************************************************************************
16+
* Includes
17+
**********************************************************************************************************************/
18+
#include "bsp_api.h"
19+
20+
/***********************************************************************************************************************
21+
* Macro definitions
22+
**********************************************************************************************************************/
23+
24+
/* Due to hardware limitations of the SDRAM peripheral,
25+
* it is not expected any of these need to be changable by end user.
26+
* Only sequential, single access at a time is supported. */
27+
#define BSP_PRV_SDRAM_MR_WB_SINGLE_LOC_ACC (1U) /* MR.M9 : Single Location Access */
28+
#define BSP_PRV_SDRAM_MR_OP_MODE (0U) /* MR.M8:M7 : Standard Operation */
29+
#define BSP_PRV_SDRAM_MR_BT_SEQUENTIAL (0U) /* MR.M3 Burst Type : Sequential */
30+
#define BSP_PRV_SDRAM_MR_BURST_LENGTH (0U) /* MR.M2:M0 Burst Length: 0(1 burst) */
31+
32+
/***********************************************************************************************************************
33+
* Typedef definitions
34+
**********************************************************************************************************************/
35+
36+
/***********************************************************************************************************************
37+
* Private function prototypes
38+
**********************************************************************************************************************/
39+
40+
/***********************************************************************************************************************
41+
* Private global variables
42+
**********************************************************************************************************************/
43+
44+
/***********************************************************************************************************************
45+
* Functions
46+
**********************************************************************************************************************/
47+
48+
#if 0 != BSP_FEATURE_SDRAM_START_ADDRESS
49+
50+
/*******************************************************************************************************************//**
51+
* @brief Initializes SDRAM.
52+
* @param init_memory If true, this function will execute the initialization of the external modules.
53+
* Otherwise, it will only initialize the SDRAMC and leave the memory in self-refresh mode.
54+
*
55+
* This function initializes SDRAMC and SDR SDRAM device.
56+
*
57+
* @note This function must only be called once after reset.
58+
**********************************************************************************************************************/
59+
void R_BSP_SdramInit (bool init_memory)
60+
{
61+
/** Setting for SDRAM initialization sequence */
62+
while (R_BUS->SDRAM.SDSR)
63+
{
64+
/* According to h/w manual, need to confirm that all the status bits in SDSR are 0 before SDICR modification. */
65+
}
66+
67+
/* Must only write to SDIR once after reset. */
68+
R_BUS->SDRAM.SDIR = ((BSP_CFG_SDRAM_INIT_ARFI - 3U) << R_BUS_SDRAM_SDIR_ARFI_Pos) |
69+
(BSP_CFG_SDRAM_INIT_ARFC << R_BUS_SDRAM_SDIR_ARFC_Pos) |
70+
((BSP_CFG_SDRAM_INIT_PRC - 3U) << R_BUS_SDRAM_SDIR_PRC_Pos);
71+
72+
R_BUS->SDRAM.SDCCR = (BSP_CFG_SDRAM_BUS_WIDTH << R_BUS_SDRAM_SDCCR_BSIZE_Pos); /* set SDRAM bus width */
73+
74+
if (init_memory)
75+
{
76+
/* Enable the SDCLK output. */
77+
R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_CGC);
78+
R_SYSTEM->SDCKOCR = 1;
79+
R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_CGC);
80+
81+
/** If requested, start SDRAM initialization sequence. */
82+
R_BUS->SDRAM.SDICR = 1U;
83+
while (R_BUS->SDRAM.SDSR_b.INIST)
84+
{
85+
/* Wait the end of initialization sequence. */
86+
}
87+
}
88+
89+
/** Setting for SDRAM controller */
90+
R_BUS->SDRAM.SDAMOD = BSP_CFG_SDRAM_ACCESS_MODE; /* enable continuous access */
91+
R_BUS->SDRAM.SDCMOD = BSP_CFG_SDRAM_ENDIAN_MODE; /* set endian mode for SDRAM address space */
92+
93+
while (R_BUS->SDRAM.SDSR)
94+
{
95+
/* According to h/w manual, need to confirm that all the status bits in SDSR are 0 before SDMOD modification. */
96+
}
97+
98+
if (init_memory)
99+
{
100+
/** Using LMR command, program the mode register */
101+
R_BUS->SDRAM.SDMOD = (BSP_PRV_SDRAM_MR_WB_SINGLE_LOC_ACC << 9) |
102+
(BSP_PRV_SDRAM_MR_OP_MODE << 7) |
103+
(BSP_CFG_SDRAM_TCL << 4) |
104+
(BSP_PRV_SDRAM_MR_BT_SEQUENTIAL << 3) |
105+
(BSP_PRV_SDRAM_MR_BURST_LENGTH << 0);
106+
107+
/** wait at least tMRD time */
108+
while (R_BUS->SDRAM.SDSR_b.MRSST)
109+
{
110+
/* Wait until Mode Register setting done. */
111+
}
112+
}
113+
114+
/** Set timing parameters for SDRAM. Must do in single write. */
115+
R_BUS->SDRAM.SDTR = ((BSP_CFG_SDRAM_TRAS - 1U) << R_BUS_SDRAM_SDTR_RAS_Pos) |
116+
((BSP_CFG_SDRAM_TRCD - 1U) << R_BUS_SDRAM_SDTR_RCD_Pos) |
117+
((BSP_CFG_SDRAM_TRP - 1U) << R_BUS_SDRAM_SDTR_RP_Pos) |
118+
((BSP_CFG_SDRAM_TWR - 1U) << R_BUS_SDRAM_SDTR_WR_Pos) |
119+
(BSP_CFG_SDRAM_TCL << R_BUS_SDRAM_SDTR_CL_Pos);
120+
121+
/** Set row address offset for target SDRAM */
122+
R_BUS->SDRAM.SDADR = BSP_CFG_SDRAM_MULTIPLEX_ADDR_SHIFT;
123+
124+
/* Set Auto-Refresh timings. */
125+
R_BUS->SDRAM.SDRFCR = ((BSP_CFG_SDRAM_TREFW - 1U) << R_BUS_SDRAM_SDRFCR_REFW_Pos) |
126+
((BSP_CFG_SDRAM_TRFC - 1U) << R_BUS_SDRAM_SDRFCR_RFC_Pos);
127+
128+
/** Start Auto-refresh */
129+
R_BUS->SDRAM.SDRFEN = 1U;
130+
131+
if (init_memory)
132+
{
133+
/** Enable SDRAM access */
134+
R_BUS->SDRAM.SDCCR = R_BUS_SDRAM_SDCCR_EXENB_Msk | (BSP_CFG_SDRAM_BUS_WIDTH << R_BUS_SDRAM_SDCCR_BSIZE_Pos);
135+
}
136+
else
137+
{
138+
/* If not initializing memory modules, start in self-refresh mode. */
139+
while (R_BUS->SDRAM.SDCCR_b.EXENB || (0U != R_BUS->SDRAM.SDSR))
140+
{
141+
/* Wait for access to be disabled and no status bits set. */
142+
}
143+
144+
/* Enable the self-refresh mode. */
145+
R_BUS->SDRAM.SDSELF = 1U;
146+
}
147+
}
148+
149+
/*******************************************************************************************************************//**
150+
* @brief Changes SDRAM from Auto-refresh to Self-refresh
151+
*
152+
* This function allows Software Standby and Deep Software Standby modes to be entered without data loss.
153+
*
154+
* @note SDRAM cannot be accessed after calling this function. Use @ref R_BSP_SdramSelfRefreshDisable to resume normal
155+
* SDRAM operation.
156+
**********************************************************************************************************************/
157+
void R_BSP_SdramSelfRefreshEnable (void)
158+
{
159+
R_BUS->SDRAM.SDCCR = (BSP_CFG_SDRAM_BUS_WIDTH << R_BUS_SDRAM_SDCCR_BSIZE_Pos);
160+
while (R_BUS->SDRAM.SDCCR_b.EXENB || (0U != R_BUS->SDRAM.SDSR))
161+
{
162+
/* Wait for access to be disabled and no status bits set. */
163+
}
164+
165+
/* Enable the self-refresh mode. */
166+
R_BUS->SDRAM.SDSELF = 1U;
167+
}
168+
169+
/*******************************************************************************************************************//**
170+
* @brief Changes SDRAM from Self-refresh to Auto-refresh
171+
*
172+
* This function changes back to Auto-refresh and allows normal SDRAM operation to resume.
173+
*
174+
**********************************************************************************************************************/
175+
void R_BSP_SdramSelfRefreshDisable (void)
176+
{
177+
if (0 == R_SYSTEM->SDCKOCR)
178+
{
179+
/* Enable the SDCLK output. It may not already be enabled here if recovering from Deep Software Standby. */
180+
R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_CGC);
181+
R_SYSTEM->SDCKOCR = 1;
182+
R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_CGC);
183+
}
184+
185+
while (0U != R_BUS->SDRAM.SDSR)
186+
{
187+
/* Wait for all status bits to be cleared. */
188+
}
189+
190+
/* Disable the self-refresh mode. */
191+
R_BUS->SDRAM.SDSELF = 0U;
192+
193+
/* Reenable SDRAM bus access. */
194+
R_BUS->SDRAM.SDCCR = R_BUS_SDRAM_SDCCR_EXENB_Msk | (BSP_CFG_SDRAM_BUS_WIDTH << R_BUS_SDRAM_SDCCR_BSIZE_Pos);
195+
}
196+
197+
#endif
198+
199+
/** @} (end addtogroup BSP_SDRAM) */
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef BSP_SDRAM_H
8+
#define BSP_SDRAM_H
9+
10+
#if 0 != BSP_FEATURE_SDRAM_START_ADDRESS
11+
12+
/** Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
13+
FSP_HEADER
14+
15+
/***********************************************************************************************************************
16+
* Macro definitions
17+
**********************************************************************************************************************/
18+
19+
/***********************************************************************************************************************
20+
* Typedef definitions
21+
**********************************************************************************************************************/
22+
23+
/***********************************************************************************************************************
24+
* Exported global variables
25+
**********************************************************************************************************************/
26+
27+
/***********************************************************************************************************************
28+
* Exported global functions (to be accessed by other files)
29+
**********************************************************************************************************************/
30+
void R_BSP_SdramInit(bool init_memory);
31+
void R_BSP_SdramSelfRefreshEnable(void);
32+
void R_BSP_SdramSelfRefreshDisable(void);
33+
34+
/** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
35+
FSP_FOOTER
36+
#endif
37+
#endif

zephyr/ra/portable/bsp_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
/* BSP TFU Includes. */
2626
#include "bsp_tfu.h"
2727

28+
#include "bsp_sdram.h"
29+
2830
#include "bsp_cfg.h"
2931

3032
/** Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */

zephyr/ra/ra_cfg/fsp_cfg/bsp/ra6m2/bsp_mcu_family_cfg.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,44 @@
8181
#define BSP_CFG_ID_CODE_LONG_4 (0xffFFFFFF)
8282
#endif
8383

84+
/* SDRAM controller configuration */
85+
#if DT_NODE_HAS_STATUS_OKAY(DT_INST(0, renesas_ra_sdram))
86+
#define BSP_CFG_SDRAM_TRAS \
87+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 0)
88+
#define BSP_CFG_SDRAM_TRCD \
89+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 1)
90+
#define BSP_CFG_SDRAM_TRP \
91+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 2)
92+
#define BSP_CFG_SDRAM_TWR \
93+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 3)
94+
#define BSP_CFG_SDRAM_TCL \
95+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 4)
96+
#define BSP_CFG_SDRAM_TRFC \
97+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 5)
98+
#define BSP_CFG_SDRAM_TREFW \
99+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 6)
100+
#define BSP_CFG_SDRAM_INIT_ARFI DT_PROP(DT_INST(0, renesas_ra_sdram), auto_refresh_interval)
101+
#define BSP_CFG_SDRAM_INIT_ARFC DT_PROP(DT_INST(0, renesas_ra_sdram), auto_refresh_count)
102+
#define BSP_CFG_SDRAM_INIT_PRC DT_PROP(DT_INST(0, renesas_ra_sdram), precharge_cycle_count)
103+
#define BSP_CFG_SDRAM_MULTIPLEX_ADDR_SHIFT DT_ENUM_IDX(DT_INST(0, renesas_ra_sdram), multiplex_addr_shift)
104+
#define BSP_CFG_SDRAM_ENDIAN_MODE DT_ENUM_IDX(DT_INST(0, renesas_ra_sdram), edian_mode)
105+
#define BSP_CFG_SDRAM_ACCESS_MODE DT_PROP(DT_INST(0, renesas_ra_sdram), continuous_access)
106+
#define BSP_CFG_SDRAM_BUS_WIDTH DT_ENUM_IDX(DT_INST(0, renesas_ra_sdram), bus_width)
107+
#else
108+
#define BSP_CFG_SDRAM_TRAS (0)
109+
#define BSP_CFG_SDRAM_TRCD (0)
110+
#define BSP_CFG_SDRAM_TRP (0)
111+
#define BSP_CFG_SDRAM_TWR (0)
112+
#define BSP_CFG_SDRAM_TCL (0)
113+
#define BSP_CFG_SDRAM_TRFC (0)
114+
#define BSP_CFG_SDRAM_TREFW (0)
115+
#define BSP_CFG_SDRAM_INIT_ARFI (0)
116+
#define BSP_CFG_SDRAM_INIT_ARFC (0)
117+
#define BSP_CFG_SDRAM_INIT_PRC (0)
118+
#define BSP_CFG_SDRAM_MULTIPLEX_ADDR_SHIFT (0)
119+
#define BSP_CFG_SDRAM_ENDIAN_MODE (0)
120+
#define BSP_CFG_SDRAM_ACCESS_MODE (0)
121+
#define BSP_CFG_SDRAM_BUS_WIDTH (0)
122+
#endif /* DT_NODE_HAS_STATUS_OKAY(DT_INST(0, renesas_ra_sdram)) */
123+
84124
#endif /* BSP_MCU_FAMILY_CFG_H_ */

zephyr/ra/ra_cfg/fsp_cfg/bsp/ra6m3/bsp_mcu_family_cfg.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,44 @@
8282
#define BSP_CFG_ID_CODE_LONG_4 (0xffFFFFFF)
8383
#endif
8484

85+
/* SDRAM controller configuration */
86+
#if DT_NODE_HAS_STATUS_OKAY(DT_INST(0, renesas_ra_sdram))
87+
#define BSP_CFG_SDRAM_TRAS \
88+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 0)
89+
#define BSP_CFG_SDRAM_TRCD \
90+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 1)
91+
#define BSP_CFG_SDRAM_TRP \
92+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 2)
93+
#define BSP_CFG_SDRAM_TWR \
94+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 3)
95+
#define BSP_CFG_SDRAM_TCL \
96+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 4)
97+
#define BSP_CFG_SDRAM_TRFC \
98+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 5)
99+
#define BSP_CFG_SDRAM_TREFW \
100+
DT_PROP_BY_IDX(DT_CHILD(DT_INST(0, renesas_ra_sdram), bank_0), renesas_ra_sdram_timing, 6)
101+
#define BSP_CFG_SDRAM_INIT_ARFI DT_PROP(DT_INST(0, renesas_ra_sdram), auto_refresh_interval)
102+
#define BSP_CFG_SDRAM_INIT_ARFC DT_PROP(DT_INST(0, renesas_ra_sdram), auto_refresh_count)
103+
#define BSP_CFG_SDRAM_INIT_PRC DT_PROP(DT_INST(0, renesas_ra_sdram), precharge_cycle_count)
104+
#define BSP_CFG_SDRAM_MULTIPLEX_ADDR_SHIFT DT_ENUM_IDX(DT_INST(0, renesas_ra_sdram), multiplex_addr_shift)
105+
#define BSP_CFG_SDRAM_ENDIAN_MODE DT_ENUM_IDX(DT_INST(0, renesas_ra_sdram), edian_mode)
106+
#define BSP_CFG_SDRAM_ACCESS_MODE DT_PROP(DT_INST(0, renesas_ra_sdram), continuous_access)
107+
#define BSP_CFG_SDRAM_BUS_WIDTH DT_ENUM_IDX(DT_INST(0, renesas_ra_sdram), bus_width)
108+
#else
109+
#define BSP_CFG_SDRAM_TRAS (0)
110+
#define BSP_CFG_SDRAM_TRCD (0)
111+
#define BSP_CFG_SDRAM_TRP (0)
112+
#define BSP_CFG_SDRAM_TWR (0)
113+
#define BSP_CFG_SDRAM_TCL (0)
114+
#define BSP_CFG_SDRAM_TRFC (0)
115+
#define BSP_CFG_SDRAM_TREFW (0)
116+
#define BSP_CFG_SDRAM_INIT_ARFI (0)
117+
#define BSP_CFG_SDRAM_INIT_ARFC (0)
118+
#define BSP_CFG_SDRAM_INIT_PRC (0)
119+
#define BSP_CFG_SDRAM_MULTIPLEX_ADDR_SHIFT (0)
120+
#define BSP_CFG_SDRAM_ENDIAN_MODE (0)
121+
#define BSP_CFG_SDRAM_ACCESS_MODE (0)
122+
#define BSP_CFG_SDRAM_BUS_WIDTH (0)
123+
#endif /* DT_NODE_HAS_STATUS_OKAY(DT_INST(0, renesas_ra_sdram)) */
124+
85125
#endif /* BSP_MCU_FAMILY_CFG_H_ */

0 commit comments

Comments
 (0)