1 /***********************************************************************************************************************
2 * Copyright [2020-2024] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved.
3 *
4 * This software and documentation are supplied by Renesas Electronics Corporation and/or its affiliates and may only
5 * be used with products of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized.
6 * Renesas products are sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for
7 * the selection and use of Renesas products and Renesas assumes no liability. No license, express or implied, to any
8 * intellectual property right is granted by Renesas. This software is protected under all applicable laws, including
9 * copyright laws. Renesas reserves the right to change or discontinue this software and/or this documentation.
10 * THE SOFTWARE AND DOCUMENTATION IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND
11 * TO THE FULLEST EXTENT PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY,
12 * INCLUDING WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE
13 * SOFTWARE OR DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH.
14 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR
15 * DOCUMENTATION (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER,
16 * INCLUDING, WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY
17 * LOST PROFITS, OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE
18 * POSSIBILITY OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS.
19 **********************************************************************************************************************/
20
21 /***********************************************************************************************************************
22 * Includes <System Includes> , "Project Includes"
23 **********************************************************************************************************************/
24 #include "bsp_api.h"
25
26 /***********************************************************************************************************************
27 * Macro definitions
28 **********************************************************************************************************************/
29 #if defined(__ICCARM__)
30 #define WEAK_ERROR_ATTRIBUTE
31 #define WEAK_INIT_ATTRIBUTE
32 #pragma weak fsp_error_log = fsp_error_log_internal
33 #pragma weak bsp_init = bsp_init_internal
34 #elif defined(__GNUC__)
35
36 #define WEAK_ERROR_ATTRIBUTE __attribute__((weak, alias("fsp_error_log_internal")))
37
38 #define WEAK_INIT_ATTRIBUTE __attribute__((weak, alias("bsp_init_internal")))
39 #endif
40
41 #define FSP_SECTION_VERSION ".version"
42
43 /***********************************************************************************************************************
44 * Typedef definitions
45 **********************************************************************************************************************/
46
47 /***********************************************************************************************************************
48 * Exported global variables (to be accessed by other files)
49 **********************************************************************************************************************/
50
51 /* System clock frequency information */
52 const uint32_t g_bsp_system_clock_select[][2] =
53 {
54 {BSP_PRV_CPU_FREQ_200_MHZ, BSP_PRV_CPU_FREQ_150_MHZ }, // FSP_PRIV_CLOCK_CPU0
55 {0, 0 }, // Reserved
56 {BSP_PRV_ICLK_FREQ_200_MHZ, BSP_PRV_ICLK_FREQ_150_MHZ }, // FSP_PRIV_CLOCK_ICLK
57 {BSP_PRV_PCLKH_FREQ_200_MHZ, BSP_PRV_PCLKH_FREQ_150_MHZ }, // FSP_PRIV_CLOCK_PCLKH
58 {BSP_PRV_PCLKM_FREQ_100_MHZ, BSP_PRV_PCLKM_FREQ_75_MHZ }, // FSP_PRIV_CLOCK_PCLKM
59 {BSP_PRV_PCLKL_FREQ_50_MHZ, BSP_PRV_PCLKL_FREQ_37_5_MHZ }, // FSP_PRIV_CLOCK_PCLKL
60 {BSP_PRV_PCLKADC_FREQ_25_MHZ, BSP_PRV_PCLKADC_FREQ_18_75_MHZ}, // FSP_PRIV_CLOCK_PCLKADC
61 {BSP_PRV_PCLKGPTL_FREQ_400_MHZ, BSP_PRV_PCLKGPTL_FREQ_300_MHZ }, // FSP_PRIV_CLOCK_PCLKGPTL
62 {BSP_PRV_PCLKSPI_FREQ_75_MHZ, BSP_PRV_PCLKSPI_FREQ_96_MHZ }, // FSP_PRIV_CLOCK_PCLKSPI0
63 {BSP_PRV_PCLKSPI_FREQ_75_MHZ, BSP_PRV_PCLKSPI_FREQ_96_MHZ }, // FSP_PRIV_CLOCK_PCLKSPI1
64 {BSP_PRV_PCLKSPI_FREQ_75_MHZ, BSP_PRV_PCLKSPI_FREQ_96_MHZ }, // FSP_PRIV_CLOCK_PCLKSPI2
65 {BSP_PRV_PCLKSPI_FREQ_75_MHZ, BSP_PRV_PCLKSPI_FREQ_96_MHZ }, // FSP_PRIV_CLOCK_PCLKSPI3
66 {BSP_PRV_PCLKSCI_FREQ_75_MHZ, BSP_PRV_PCLKSCI_FREQ_96_MHZ }, // FSP_PRIV_CLOCK_PCLKSCI0
67 {BSP_PRV_PCLKSCI_FREQ_75_MHZ, BSP_PRV_PCLKSCI_FREQ_96_MHZ }, // FSP_PRIV_CLOCK_PCLKSCI1
68 {BSP_PRV_PCLKSCI_FREQ_75_MHZ, BSP_PRV_PCLKSCI_FREQ_96_MHZ }, // FSP_PRIV_CLOCK_PCLKSCI2
69 {BSP_PRV_PCLKSCI_FREQ_75_MHZ, BSP_PRV_PCLKSCI_FREQ_96_MHZ }, // FSP_PRIV_CLOCK_PCLKSCI3
70 {BSP_PRV_PCLKSCI_FREQ_75_MHZ, BSP_PRV_PCLKSCI_FREQ_96_MHZ }, // FSP_PRIV_CLOCK_PCLKSCI4
71 {BSP_PRV_PCLKSCI_FREQ_75_MHZ, BSP_PRV_PCLKSCI_FREQ_96_MHZ }, // FSP_PRIV_CLOCK_PCLKSCI5
72 {BSP_PRV_PCLKCAN_FREQ_80_MHZ, BSP_PRV_PCLKCAN_FREQ_40_MHZ }, // FSP_PRIV_CLOCK_PCLKCAN
73 };
74
75 /* System clock frequency information for CKIO */
76 const uint32_t g_bsp_system_clock_select_ckio[][2] =
77 {
78 {BSP_PRV_CKIO_FREQ_100_MHZ, BSP_PRV_CKIO_FREQ_75_MHZ }, // CKIO = 000b
79 {BSP_PRV_CKIO_FREQ_66_7_MHZ, BSP_PRV_CKIO_FREQ_50_MHZ }, // CKIO = 001b
80 {BSP_PRV_CKIO_FREQ_50_MHZ, BSP_PRV_CKIO_FREQ_37_5_MHZ }, // CKIO = 010b
81 {BSP_PRV_CKIO_FREQ_40_MHZ, BSP_PRV_CKIO_FREQ_30_MHZ }, // CKIO = 011b
82 {BSP_PRV_CKIO_FREQ_33_3_MHZ, BSP_PRV_CKIO_FREQ_25_MHZ }, // CKIO = 100b
83 {BSP_PRV_CKIO_FREQ_28_6_MHZ, BSP_PRV_CKIO_FREQ_21_4_MHZ }, // CKIO = 101b
84 {BSP_PRV_CKIO_FREQ_25_MHZ, BSP_PRV_CKIO_FREQ_18_75_MHZ }, // CKIO = 110b
85 {BSP_PRV_CKIO_FREQ_NOT_SUPPORTED, BSP_PRV_CKIO_FREQ_NOT_SUPPORTED}, // CKIO = 111b
86 };
87
88 /* System clock frequency information for XSPI_CLK */
89 const uint32_t g_bsp_system_clock_select_xspi_clk[][2] =
90 {
91 {BSP_PRV_XSPI_CLK_FREQ_NOT_SUPPORTED, BSP_PRV_XSPI_CLK_FREQ_NOT_SUPPORTED}, // FSELXSPIn = 000b
92 {BSP_PRV_XSPI_CLK_FREQ_NOT_SUPPORTED, BSP_PRV_XSPI_CLK_FREQ_NOT_SUPPORTED}, // FSELXSPIn = 001b
93 {BSP_PRV_XSPI_CLK_FREQ_133_3_MHZ, BSP_PRV_XSPI_CLK_FREQ_NOT_SUPPORTED}, // FSELXSPIn = 010b
94 {BSP_PRV_XSPI_CLK_FREQ_100_MHZ, BSP_PRV_XSPI_CLK_FREQ_75_MHZ }, // FSELXSPIn = 011b
95 {BSP_PRV_XSPI_CLK_FREQ_50_MHZ, BSP_PRV_XSPI_CLK_FREQ_37_5_MHZ }, // FSELXSPIn = 100b
96 {BSP_PRV_XSPI_CLK_FREQ_25_MHZ, BSP_PRV_XSPI_CLK_FREQ_NOT_SUPPORTED}, // FSELXSPIn = 101b
97 {BSP_PRV_XSPI_CLK_FREQ_12_5_MHZ, BSP_PRV_XSPI_CLK_FREQ_NOT_SUPPORTED}, // FSELXSPIn = 110b
98 {BSP_PRV_XSPI_CLK_FREQ_NOT_SUPPORTED, BSP_PRV_XSPI_CLK_FREQ_NOT_SUPPORTED}, // FSELXSPIn = 111b
99 };
100
101 /***********************************************************************************************************************
102 * Private global variables and functions
103 **********************************************************************************************************************/
104
105 /* FSP pack version structure. */
106 static BSP_DONT_REMOVE const fsp_pack_version_t g_fsp_version BSP_PLACE_IN_SECTION (FSP_SECTION_VERSION) =
107 {
108 .version_id_b =
109 {
110 .minor = FSP_VERSION_MINOR,
111 .major = FSP_VERSION_MAJOR,
112 .build = FSP_VERSION_BUILD,
113 .patch = FSP_VERSION_PATCH
114 }
115 };
116
117 /* Public FSP version name. */
118 static BSP_DONT_REMOVE const uint8_t g_fsp_version_string[] BSP_PLACE_IN_SECTION(FSP_SECTION_VERSION) =
119 FSP_VERSION_STRING;
120
121 /* Unique FSP version ID. */
122 static BSP_DONT_REMOVE const uint8_t g_fsp_version_build_string[] BSP_PLACE_IN_SECTION(FSP_SECTION_VERSION) =
123 FSP_VERSION_BUILD_STRING;
124
125 /***********************************************************************************************************************
126 * Private function prototypes
127 **********************************************************************************************************************/
128
129 /** Prototype of initialization function called before main. This prototype sets the weak association of this
130 * function to an internal example implementation. If this function is defined in the application code, the
131 * application code version is used. */
132
133 void bsp_init(void * p_args) WEAK_INIT_ATTRIBUTE;
134
135 void bsp_init_internal(void * p_args); /// Default initialization function
136
137 #if ((1 == BSP_CFG_ERROR_LOG) || (1 == BSP_CFG_ASSERT))
138
139 /** Prototype of function called before errors are returned in FSP code if BSP_CFG_ERROR_LOG is set to 1. This
140 * prototype sets the weak association of this function to an internal example implementation. */
141
142 void fsp_error_log(fsp_err_t err, const char * file, int32_t line) WEAK_ERROR_ATTRIBUTE;
143
144 void fsp_error_log_internal(fsp_err_t err, const char * file, int32_t line); /// Default error logger function
145
146 #endif
147
148 /*******************************************************************************************************************//**
149 * @addtogroup BSP_MCU
150 * @{
151 **********************************************************************************************************************/
152
153 /*******************************************************************************************************************//**
154 * Get the FSP version based on compile time macros.
155 *
156 * @param[out] p_version Memory address to return version information to.
157 *
158 * @retval FSP_SUCCESS Version information stored.
159 * @retval FSP_ERR_ASSERTION The parameter p_version is NULL.
160 **********************************************************************************************************************/
R_FSP_VersionGet(fsp_pack_version_t * const p_version)161 fsp_err_t R_FSP_VersionGet (fsp_pack_version_t * const p_version)
162 {
163 #if BSP_CFG_PARAM_CHECKING_ENABLE
164
165 /** Verify parameters are valid */
166 FSP_ASSERT(NULL != p_version);
167 #endif
168
169 *p_version = g_fsp_version;
170
171 return FSP_SUCCESS;
172 }
173
174 #if ((1 == BSP_CFG_ERROR_LOG) || (1 == BSP_CFG_ASSERT))
175
176 /*******************************************************************************************************************//**
177 * Default error logger function, used only if fsp_error_log is not defined in the user application.
178 *
179 * @param[in] err The error code encountered.
180 * @param[in] file The file name in which the error code was encountered.
181 * @param[in] line The line number at which the error code was encountered.
182 **********************************************************************************************************************/
fsp_error_log_internal(fsp_err_t err,const char * file,int32_t line)183 void fsp_error_log_internal (fsp_err_t err, const char * file, int32_t line)
184 {
185 /** Do nothing. Do not generate any 'unused' warnings. */
186 FSP_PARAMETER_NOT_USED(err);
187 FSP_PARAMETER_NOT_USED(file);
188 FSP_PARAMETER_NOT_USED(line);
189 }
190
191 #endif
192
193 /** @} (end addtogroup BSP_MCU) */
194
195 /*******************************************************************************************************************//**
196 * Default initialization function, used only if bsp_init is not defined in the user application.
197 **********************************************************************************************************************/
bsp_init_internal(void * p_args)198 void bsp_init_internal (void * p_args)
199 {
200 /* Do nothing. */
201 FSP_PARAMETER_NOT_USED(p_args);
202 }
203
204 #if defined(__ARMCC_VERSION)
205
206 /*******************************************************************************************************************//**
207 * Default implementation of assert for AC6.
208 **********************************************************************************************************************/
209 __attribute__((weak, noreturn))
__aeabi_assert(const char * expr,const char * file,int line)210 void __aeabi_assert (const char * expr, const char * file, int line) {
211 FSP_PARAMETER_NOT_USED(expr);
212 FSP_PARAMETER_NOT_USED(file);
213 FSP_PARAMETER_NOT_USED(line);
214 __BKPT(0);
215 while (1)
216 {
217 /* Do nothing. */
218 }
219 }
220
221 #endif
222