Skip to content

Commit 7aae121

Browse files
tiennguyenzgKhiemNguyenT
authored andcommitted
hal: renesas: Add Flash support for RZ/N series
Add XSPI_QSPI FSP HAL driver to support Zephyr Flash driver for RZ/N2L Signed-off-by: Tien Nguyen <[email protected]>
1 parent 891f563 commit 7aae121

File tree

5 files changed

+1748
-0
lines changed

5 files changed

+1748
-0
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
* @addtogroup XSPI_QSPI
9+
* @{
10+
**********************************************************************************************************************/
11+
12+
#ifndef R_XSPI_QSPI_H
13+
#define R_XSPI_QSPI_H
14+
15+
/***********************************************************************************************************************
16+
* Includes
17+
**********************************************************************************************************************/
18+
#include "bsp_api.h"
19+
#include <string.h>
20+
#include "r_xspi_qspi_cfg.h"
21+
#include "r_spi_flash_api.h"
22+
23+
/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
24+
FSP_HEADER
25+
26+
/***********************************************************************************************************************
27+
* Macro definitions
28+
**********************************************************************************************************************/
29+
30+
/***********************************************************************************************************************
31+
* Typedef definitions
32+
**********************************************************************************************************************/
33+
34+
/* QSPI Flash chip select */
35+
typedef enum e_xspi_qspi_chip_select
36+
{
37+
XSPI_QSPI_CHIP_SELECT_0, ///< Device connected to Chip-Select 0
38+
XSPI_QSPI_CHIP_SELECT_1, ///< Device connected to Chip-Select 1
39+
} xspi_qspi_chip_select_t;
40+
41+
/* QSPI Flash memory size */
42+
typedef enum e_xspi_qspi_memory_size
43+
{
44+
XSPI_QSPI_MEMORY_SIZE_1MB = 0x00, ///< Memory size 1MB
45+
XSPI_QSPI_MEMORY_SIZE_2MB = 0x01, ///< Memory size 2MB
46+
XSPI_QSPI_MEMORY_SIZE_4MB = 0x03, ///< Memory size 4MB
47+
XSPI_QSPI_MEMORY_SIZE_8MB = 0x07, ///< Memory size 8MB
48+
XSPI_QSPI_MEMORY_SIZE_16MB = 0x0F, ///< Memory size 16MB
49+
XSPI_QSPI_MEMORY_SIZE_32MB = 0x1F, ///< Memory size 32MB
50+
XSPI_QSPI_MEMORY_SIZE_64MB = 0x3F, ///< Memory size 64MB
51+
} xspi_qspi_memory_size_t;
52+
53+
/* QSPI command to command interval*/
54+
typedef enum e_xspi_qspi_command_interval_clocks
55+
{
56+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_1, ///< 1 interval clocks
57+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_2, ///< 2 interval clocks
58+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_3, ///< 3 interval clocks
59+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_4, ///< 4 interval clocks
60+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_5, ///< 5 interval clocks
61+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_6, ///< 6 interval clocks
62+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_7, ///< 7 interval clocks
63+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_8, ///< 8 interval clocks
64+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_9, ///< 9 interval clocks
65+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_10, ///< 10 interval clocks
66+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_11, ///< 11 interval clocks
67+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_12, ///< 12 interval clocks
68+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_13, ///< 13 interval clocks
69+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_14, ///< 14 interval clocks
70+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_15, ///< 15 interval clocks
71+
XSPI_QSPI_COMMAND_INTERVAL_CLOCKS_16, ///< 16 interval clocks
72+
} xspi_qspi_command_interval_clocks_t;
73+
74+
/* QSPI chip select de-assertion duration */
75+
typedef enum e_xspi_qspi_cs_pullup_clocks
76+
{
77+
XSPI_QSPI_CS_PULLUP_CLOCKS_NO_EXTENSION = 0, ///< CS asserting No extension
78+
XSPI_QSPI_CS_PULLUP_CLOCKS_1, ///< CS asserting Extend 1 cycle
79+
} xspi_qspi_cs_pullup_clocks_t;
80+
81+
/* QSPI chip select assertion duration */
82+
typedef enum e_xspi_qspi_cs_pulldown_clocks
83+
{
84+
XSPI_QSPI_CS_PULLDOWN_CLOCKS_NO_EXTENSION = 0, ///< CS negating No extension
85+
XSPI_QSPI_CS_PULLDOWN_CLOCKS_1, ///< CS negating Extend 1 cycle
86+
} xspi_qspi_cs_pulldown_clocks_t;
87+
88+
/* Memory mapped timing */
89+
typedef struct st_qspi_timing_setting
90+
{
91+
xspi_qspi_command_interval_clocks_t command_to_command_interval; ///< Interval between 2 consecutive commands
92+
xspi_qspi_cs_pullup_clocks_t cs_pullup_lag; ///< Duration to de-assert CS line after the last command
93+
xspi_qspi_cs_pulldown_clocks_t cs_pulldown_lead; ///< Duration to assert CS line before the first command
94+
} xspi_qspi_timing_setting_t;
95+
96+
/* Prefetch function settings */
97+
typedef enum e_xspi_qspi_prefetch_function
98+
{
99+
XSPI_QSPI_PREFETCH_FUNCTION_DISABLE = 0x00, ///< Prefetch function disable
100+
XSPI_QSPI_PREFETCH_FUNCTION_ENABLE = 0x01, ///< Prefetch function enable
101+
} xspi_qspi_prefetch_function_t;
102+
103+
/* IO voltage settings */
104+
typedef enum e_xspi_qspi_io_voltage
105+
{
106+
XSPI_QSPI_IO_VOLTAGE_1_8V = 0x00, ///< IO voltage 1.8V
107+
XSPI_QSPI_IO_VOLTAGE_3_3V = 0x01, ///< IO voltage 3.3V
108+
} xspi_qspi_io_voltage_t;
109+
110+
/* Address space settings */
111+
typedef struct st_qspi_address_space
112+
{
113+
uint32_t unit0_cs0_end_address; ///< xSPI unit0 cs0 end address
114+
uint32_t unit0_cs1_start_address; ///< xSPI unit0 cs1 start address
115+
uint32_t unit0_cs1_end_address; ///< xSPI unit0 cs1 end address
116+
uint32_t unit1_cs0_end_address; ///< xSPI unit1 cs0 end address
117+
uint32_t unit1_cs1_start_address; ///< xSPI unit1 cs1 start address
118+
uint32_t unit1_cs1_end_address; ///< xSPI unit1 cs1 end address
119+
} xspi_qspi_address_space_t;
120+
121+
/* Extended configuration. */
122+
typedef struct st_xspi_qspi_extended_cfg
123+
{
124+
uint8_t unit; ///< Unit number of xSPI
125+
xspi_qspi_chip_select_t chip_select; ///< Device number to be used for memory device
126+
xspi_qspi_memory_size_t memory_size; ///< Size of memory device
127+
xspi_qspi_timing_setting_t const * p_timing_settings; ///< Memory mapped timing settings
128+
xspi_qspi_prefetch_function_t prefetch_en; ///< Prefetch function settings
129+
xspi_qspi_io_voltage_t io_voltage; ///< Voltage setting of xSPI IO domain
130+
xspi_qspi_address_space_t const * p_address_space; ///< Address space settings when custom address space enabled
131+
} xspi_qspi_extended_cfg_t;
132+
133+
/** Instance control block. DO NOT INITIALIZE. Initialization occurs when @ref spi_flash_api_t::open is called */
134+
typedef struct st_xspi_qspi_instance_ctrl
135+
{
136+
spi_flash_cfg_t const * p_cfg; // Pointer to initial configuration
137+
spi_flash_data_lines_t data_lines; // Data lines
138+
uint32_t total_size_bytes; // Total size of the flash in bytes
139+
uint32_t open; // Whether or not driver is open
140+
R_XSPI0_Type * p_reg; // Base register for this channel
141+
spi_flash_protocol_t spi_protocol; // Current SPI protocol selected
142+
} xspi_qspi_instance_ctrl_t;
143+
144+
/**********************************************************************************************************************
145+
* Exported global variables
146+
**********************************************************************************************************************/
147+
148+
/** @cond INC_HEADER_DEFS_SEC */
149+
/** Filled in Interface API structure for this Instance. */
150+
extern const spi_flash_api_t g_spi_flash_on_xspi_qspi;
151+
152+
/** @endcond */
153+
154+
fsp_err_t R_XSPI_QSPI_Open(spi_flash_ctrl_t * p_ctrl, spi_flash_cfg_t const * const p_cfg);
155+
fsp_err_t R_XSPI_QSPI_Close(spi_flash_ctrl_t * p_ctrl);
156+
fsp_err_t R_XSPI_QSPI_DirectWrite(spi_flash_ctrl_t * p_ctrl,
157+
uint8_t const * const p_src,
158+
uint32_t const bytes,
159+
bool const read_after_write);
160+
fsp_err_t R_XSPI_QSPI_DirectRead(spi_flash_ctrl_t * p_ctrl, uint8_t * const p_dest, uint32_t const bytes);
161+
fsp_err_t R_XSPI_QSPI_SpiProtocolSet(spi_flash_ctrl_t * p_ctrl, spi_flash_protocol_t spi_protocol);
162+
fsp_err_t R_XSPI_QSPI_XipEnter(spi_flash_ctrl_t * p_ctrl);
163+
fsp_err_t R_XSPI_QSPI_XipExit(spi_flash_ctrl_t * p_ctrl);
164+
fsp_err_t R_XSPI_QSPI_Write(spi_flash_ctrl_t * p_ctrl,
165+
uint8_t const * const p_src,
166+
uint8_t * const p_dest,
167+
uint32_t byte_count);
168+
fsp_err_t R_XSPI_QSPI_Erase(spi_flash_ctrl_t * p_ctrl, uint8_t * const p_device_address, uint32_t byte_count);
169+
fsp_err_t R_XSPI_QSPI_StatusGet(spi_flash_ctrl_t * p_ctrl, spi_flash_status_t * const p_status);
170+
fsp_err_t R_XSPI_QSPI_BankSet(spi_flash_ctrl_t * p_ctrl, uint32_t bank);
171+
fsp_err_t R_XSPI_QSPI_DirectTransfer(spi_flash_ctrl_t * p_ctrl,
172+
spi_flash_direct_transfer_t * const p_transfer,
173+
spi_flash_direct_transfer_dir_t direction);
174+
fsp_err_t R_XSPI_QSPI_AutoCalibrate(spi_flash_ctrl_t * p_ctrl);
175+
176+
/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
177+
FSP_FOOTER
178+
179+
#endif
180+
181+
/*******************************************************************************************************************//**
182+
* @} (end defgroup XSPI_QSPI)
183+
**********************************************************************************************************************/

drivers/rz/fsp/src/rzn/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(srcs
1111
bsp/mcu/all/bsp_io.c
1212
bsp/mcu/all/bsp_irq.c
1313
bsp/mcu/all/bsp_register_protection.c
14+
bsp/mcu/all/bsp_reset.c
1415
bsp/mcu/all/cr/bsp_delay_core.c
1516
)
1617

0 commit comments

Comments
 (0)