-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathb_u585i_iot02a_ospi.h
397 lines (352 loc) · 15.2 KB
/
b_u585i_iot02a_ospi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/**
******************************************************************************
* @file b_u585i_iot02a_ospi.h
* @author MCD Application Team
* @brief This file contains the common defines and functions prototypes for
* the b_u585i_iot02a_ospi.c driver.
******************************************************************************
* @attention
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef B_U585I_IOT02A_OSPI_H
#define B_U585I_IOT02A_OSPI_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "b_u585i_iot02a_conf.h"
#include "b_u585i_iot02a_errno.h"
#include "../Components/mx25lm51245g/mx25lm51245g.h"
#include "../Components/aps6408/aps6408.h"
/** @addtogroup BSP
* @{
*/
/** @addtogroup B_U585I_IOT02A
* @{
*/
/** @addtogroup B_U585I_IOT02A_OSPI
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup B_U585I_IOT02A_OSPI_Exported_Types OSPI Exported Types
* @{
*/
typedef enum
{
OSPI_ACCESS_NONE = 0, /*!< Instance not initialized, */
OSPI_ACCESS_INDIRECT, /*!< Instance use indirect mode access */
OSPI_ACCESS_MMP /*!< Instance use Memory Mapped Mode read */
} OSPI_Access_t;
#if (USE_HAL_OSPI_REGISTER_CALLBACKS == 1)
typedef struct
{
pOSPI_CallbackTypeDef pMspInitCb;
pOSPI_CallbackTypeDef pMspDeInitCb;
} BSP_OSPI_Cb_t;
#endif /* (USE_HAL_OSPI_REGISTER_CALLBACKS == 1) */
typedef struct
{
uint32_t MemorySize;
uint32_t ClockPrescaler;
uint32_t SampleShifting;
uint32_t TransferRate;
} MX_OSPI_InitTypeDef;
/**
* @}
*/
/** @defgroup B_U585I_IOT02A_OSPI_NOR_Exported_Types OSPI NOR Exported Types
* @{
*/
#define BSP_OSPI_NOR_Info_t MX25LM51245G_Info_t
#define BSP_OSPI_NOR_Interface_t MX25LM51245G_Interface_t
#define BSP_OSPI_NOR_Transfer_t MX25LM51245G_Transfer_t
#define BSP_OSPI_NOR_Erase_t MX25LM51245G_Erase_t
typedef struct
{
OSPI_Access_t IsInitialized; /*!< Instance access Flash method */
BSP_OSPI_NOR_Interface_t InterfaceMode; /*!< Flash Interface mode of Instance */
BSP_OSPI_NOR_Transfer_t TransferRate; /*!< Flash Transfer mode of Instance */
} OSPI_NOR_Ctx_t;
typedef struct
{
BSP_OSPI_NOR_Interface_t InterfaceMode; /*!< Current Flash Interface mode */
BSP_OSPI_NOR_Transfer_t TransferRate; /*!< Current Flash Transfer rate */
} BSP_OSPI_NOR_Init_t;
/**
* @}
*/
/** @defgroup B_U585I_IOT02A_OSPI_RAM_Exported_Types OSPI RAM Exported Types
* @{
*/
#define BSP_OSPI_RAM_BurstLength_t APS6408_BurstLength_t
typedef enum
{
BSP_OSPI_RAM_VARIABLE_LATENCY = HAL_OSPI_VARIABLE_LATENCY,
BSP_OSPI_RAM_FIXED_LATENCY = HAL_OSPI_FIXED_LATENCY
} BSP_OSPI_RAM_Latency_t;
typedef enum
{
BSP_OSPI_RAM_HYBRID_BURST = 0,
BSP_OSPI_RAM_LINEAR_BURST
} BSP_OSPI_RAM_BurstType_t;
typedef struct
{
OSPI_Access_t IsInitialized; /*!< Instance access Flash method */
BSP_OSPI_RAM_Latency_t LatencyType; /*!< Latency Type of Instance */
BSP_OSPI_RAM_BurstType_t BurstType; /*!< Burst Type of Instance */
BSP_OSPI_RAM_BurstLength_t BurstLength; /*!< Burst Length of Instance */
} OSPI_RAM_Ctx_t;
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup B_U585I_IOT02A_OSPI_Exported_Constants OSPI Exported Constants
* @{
*/
/* Definition for OSPI clock resources */
#define OSPI_NOR_CLK_ENABLE() __HAL_RCC_OSPI2_CLK_ENABLE()
#define OSPI_NOR_CLK_DISABLE() __HAL_RCC_OSPI2_CLK_DISABLE()
#define OSPI_NOR_CLK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define OSPI_NOR_DQS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define OSPI_NOR_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
#define OSPI_NOR_D0_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define OSPI_NOR_D1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define OSPI_NOR_D2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define OSPI_NOR_D3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define OSPI_NOR_D4_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE()
#define OSPI_NOR_D5_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE()
#define OSPI_NOR_D6_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE()
#define OSPI_NOR_D7_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE()
#define OSPI_NOR_FORCE_RESET() __HAL_RCC_OSPI2_FORCE_RESET()
#define OSPI_NOR_RELEASE_RESET() __HAL_RCC_OSPI2_RELEASE_RESET()
/* Definition for OSPI Pins */
/* OSPI_CLK */
#define OSPI_NOR_CLK_PIN GPIO_PIN_4
#define OSPI_NOR_CLK_GPIO_PORT GPIOF
#define OSPI_NOR_CLK_PIN_AF GPIO_AF5_OCTOSPI2
/* OSPI_DQS */
#define OSPI_NOR_DQS_PIN GPIO_PIN_12
#define OSPI_NOR_DQS_GPIO_PORT GPIOF
#define OSPI_NOR_DQS_PIN_AF GPIO_AF5_OCTOSPI2
/* OSPI_CS */
#define OSPI_NOR_CS_PIN GPIO_PIN_5
#define OSPI_NOR_CS_GPIO_PORT GPIOI
#define OSPI_NOR_CS_PIN_AF GPIO_AF5_OCTOSPI2
/* OSPI_D0 */
#define OSPI_NOR_D0_PIN GPIO_PIN_0
#define OSPI_NOR_D0_GPIO_PORT GPIOF
#define OSPI_NOR_D0_PIN_AF GPIO_AF5_OCTOSPI2
/* OSPI_D1 */
#define OSPI_NOR_D1_PIN GPIO_PIN_1
#define OSPI_NOR_D1_GPIO_PORT GPIOF
#define OSPI_NOR_D1_PIN_AF GPIO_AF5_OCTOSPI2
/* OSPI_D2 */
#define OSPI_NOR_D2_PIN GPIO_PIN_2
#define OSPI_NOR_D2_GPIO_PORT GPIOF
#define OSPI_NOR_D2_PIN_AF GPIO_AF5_OCTOSPI2
/* OSPI_D3 */
#define OSPI_NOR_D3_PIN GPIO_PIN_3
#define OSPI_NOR_D3_GPIO_PORT GPIOF
#define OSPI_NOR_D3_PIN_AF GPIO_AF5_OCTOSPI2
/* OSPI_D4 */
#define OSPI_NOR_D4_PIN GPIO_PIN_9
#define OSPI_NOR_D4_GPIO_PORT GPIOH
#define OSPI_NOR_D4_PIN_AF GPIO_AF5_OCTOSPI2
/* OSPI_D5 */
#define OSPI_NOR_D5_PIN GPIO_PIN_10
#define OSPI_NOR_D5_GPIO_PORT GPIOH
#define OSPI_NOR_D5_PIN_AF GPIO_AF5_OCTOSPI2
/* OSPI_D6 */
#define OSPI_NOR_D6_PIN GPIO_PIN_11
#define OSPI_NOR_D6_GPIO_PORT GPIOH
#define OSPI_NOR_D6_PIN_AF GPIO_AF5_OCTOSPI2
/* OSPI_D7 */
#define OSPI_NOR_D7_PIN GPIO_PIN_12
#define OSPI_NOR_D7_GPIO_PORT GPIOH
#define OSPI_NOR_D7_PIN_AF GPIO_AF5_OCTOSPI2
/* Definition for OSPI RAM clock resources */
#define OSPI_RAM_CLK_ENABLE() __HAL_RCC_OSPI1_CLK_ENABLE()
#define OSPI_RAM_CLK_DISABLE() __HAL_RCC_OSPI1_CLK_DISABLE()
#define OSPI_RAM_CLK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define OSPI_RAM_DQS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOE_CLK_ENABLE()
#define OSPI_RAM_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define OSPI_RAM_D0_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define OSPI_RAM_D1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define OSPI_RAM_D2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define OSPI_RAM_D3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
#define OSPI_RAM_D4_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE()
#define OSPI_RAM_D5_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
#define OSPI_RAM_D6_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define OSPI_RAM_D7_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define OSPI_RAM_FORCE_RESET() __HAL_RCC_OSPI1_FORCE_RESET()
#define OSPI_RAM_RELEASE_RESET() __HAL_RCC_OSPI1_RELEASE_RESET()
/* Definition for OSPI RAM Pins */
/* OSPI_CLK */
#define OSPI_RAM_CLK_PIN GPIO_PIN_10
#define OSPI_RAM_CLK_GPIO_PORT GPIOB
#define OSPI_RAM_CLK_PIN_AF GPIO_AF10_OCTOSPI1
/* OSPI_DQS */
#define OSPI_RAM_DQS_PIN GPIO_PIN_3
#define OSPI_RAM_DQS_GPIO_PORT GPIOE
#define OSPI_RAM_DQS_PIN_AF GPIO_AF3_OCTOSPI1
/* OSPI_CS */
#define OSPI_RAM_CS_PIN GPIO_PIN_11
#define OSPI_RAM_CS_GPIO_PORT GPIOB
#define OSPI_RAM_CS_PIN_AF GPIO_AF10_OCTOSPI1
/* OSPI_D0 */
#define OSPI_RAM_D0_PIN GPIO_PIN_8
#define OSPI_RAM_D0_GPIO_PORT GPIOF
#define OSPI_RAM_D0_PIN_AF GPIO_AF10_OCTOSPI1
/* OSPI_D1 */
#define OSPI_RAM_D1_PIN GPIO_PIN_9
#define OSPI_RAM_D1_GPIO_PORT GPIOF
#define OSPI_RAM_D1_PIN_AF GPIO_AF10_OCTOSPI1
/* OSPI_D2 */
#define OSPI_RAM_D2_PIN GPIO_PIN_7
#define OSPI_RAM_D2_GPIO_PORT GPIOF
#define OSPI_RAM_D2_PIN_AF GPIO_AF10_OCTOSPI1
/* OSPI_D3 */
#define OSPI_RAM_D3_PIN GPIO_PIN_6
#define OSPI_RAM_D3_GPIO_PORT GPIOF
#define OSPI_RAM_D3_PIN_AF GPIO_AF10_OCTOSPI1
/* OSPI_D4 */
#define OSPI_RAM_D4_PIN GPIO_PIN_2
#define OSPI_RAM_D4_GPIO_PORT GPIOH
#define OSPI_RAM_D4_PIN_AF GPIO_AF3_OCTOSPI1
/* OSPI_D5 */
#define OSPI_RAM_D5_PIN GPIO_PIN_0
#define OSPI_RAM_D5_GPIO_PORT GPIOI
#define OSPI_RAM_D5_PIN_AF GPIO_AF3_OCTOSPI1
/* OSPI_D6 */
#define OSPI_RAM_D6_PIN GPIO_PIN_3
#define OSPI_RAM_D6_GPIO_PORT GPIOC
#define OSPI_RAM_D6_PIN_AF GPIO_AF10_OCTOSPI1
/* OSPI_D7 */
#define OSPI_RAM_D7_PIN GPIO_PIN_7
#define OSPI_RAM_D7_GPIO_PORT GPIOD
#define OSPI_RAM_D7_PIN_AF GPIO_AF10_OCTOSPI1
/**
* @}
*/
/** @defgroup B_U585I_IOT02A_OSPI_NOR_Exported_Constants OSPI NOR Exported Constants
* @{
*/
#define OSPI_NOR_INSTANCES_NUMBER 1U
/* Definition for OSPI modes */
#define BSP_OSPI_NOR_SPI_MODE (BSP_OSPI_NOR_Interface_t)MX25LM51245G_SPI_MODE /* 1 Cmd, 1 Address and 1 Data Lines */
#define BSP_OSPI_NOR_OPI_MODE (BSP_OSPI_NOR_Interface_t)MX25LM51245G_OPI_MODE /* 8 Cmd, 8 Address and 8 Data Lines */
/* Definition for OSPI transfer rates */
#define BSP_OSPI_NOR_STR_TRANSFER (BSP_OSPI_NOR_Transfer_t)MX25LM51245G_STR_TRANSFER /* Single Transfer Rate */
#define BSP_OSPI_NOR_DTR_TRANSFER (BSP_OSPI_NOR_Transfer_t)MX25LM51245G_DTR_TRANSFER /* Double Transfer Rate */
/* OSPI erase types */
#define BSP_OSPI_NOR_ERASE_4K MX25LM51245G_ERASE_4K
#define BSP_OSPI_NOR_ERASE_64K MX25LM51245G_ERASE_64K
#define BSP_OSPI_NOR_ERASE_CHIP MX25LM51245G_ERASE_BULK
/* OSPI block sizes */
#define BSP_OSPI_NOR_BLOCK_4K MX25LM51245G_SUBSECTOR_4K
#define BSP_OSPI_NOR_BLOCK_64K MX25LM51245G_SECTOR_64K
/**
* @}
*/
/** @defgroup B_U585I_IOT02A_OSPI_RAM_Exported_Constants OSPI RAM Exported Constants
* @{
*/
#define OSPI_RAM_INSTANCES_NUMBER 1U
/* OSPI Burst length */
#define BSP_OSPI_RAM_BURST_16_BYTES (BSP_OSPI_RAM_BurstLength_t)APS6408_BURST_16_BYTES
#define BSP_OSPI_RAM_BURST_32_BYTES (BSP_OSPI_RAM_BurstLength_t)APS6408_BURST_32_BYTES
#define BSP_OSPI_RAM_BURST_64_BYTES (BSP_OSPI_RAM_BurstLength_t)APS6408_BURST_64_BYTES
#define BSP_OSPI_RAM_BURST_128_BYTES (BSP_OSPI_RAM_BurstLength_t)APS6408_BURST_128_BYTES
/**
* @}
*/
/* Exported variables --------------------------------------------------------*/
/** @defgroup B_U585I_IOT02A_OSPI_NOR_Exported_Variables OSPI NOR Exported Variables
* @{
*/
extern OSPI_HandleTypeDef hospi_nor[OSPI_NOR_INSTANCES_NUMBER];
extern OSPI_NOR_Ctx_t Ospi_Nor_Ctx[OSPI_NOR_INSTANCES_NUMBER];
/**
* @}
*/
/** @defgroup B_U585I_IOT02A_OSPI_RAM_Exported_Variables OSPI RAM Exported Variables
* @{
*/
extern OSPI_HandleTypeDef hospi_ram[OSPI_RAM_INSTANCES_NUMBER];
extern OSPI_RAM_Ctx_t Ospi_Ram_Ctx[OSPI_RAM_INSTANCES_NUMBER];
/**
* @}
*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup B_U585I_IOT02A_OSPI_NOR_Exported_Functions OSPI NOR Exported Functions
* @{
*/
int32_t BSP_OSPI_NOR_Init(uint32_t Instance, BSP_OSPI_NOR_Init_t *Init);
int32_t BSP_OSPI_NOR_DeInit(uint32_t Instance);
#if (USE_HAL_OSPI_REGISTER_CALLBACKS == 1)
int32_t BSP_OSPI_NOR_RegisterMspCallbacks(uint32_t Instance, BSP_OSPI_Cb_t *CallBacks);
int32_t BSP_OSPI_NOR_RegisterDefaultMspCallbacks(uint32_t Instance);
#endif /* (USE_HAL_OSPI_REGISTER_CALLBACKS == 1) */
int32_t BSP_OSPI_NOR_Read(uint32_t Instance, uint8_t *pData, uint32_t ReadAddr, uint32_t Size);
int32_t BSP_OSPI_NOR_Write(uint32_t Instance, const uint8_t *pData, uint32_t WriteAddr, uint32_t Size);
int32_t BSP_OSPI_NOR_Erase_Block(uint32_t Instance, uint32_t BlockAddress, BSP_OSPI_NOR_Erase_t BlockSize);
int32_t BSP_OSPI_NOR_Erase_Chip(uint32_t Instance);
int32_t BSP_OSPI_NOR_GetStatus(uint32_t Instance);
int32_t BSP_OSPI_NOR_GetInfo(uint32_t Instance, BSP_OSPI_NOR_Info_t *pInfo);
int32_t BSP_OSPI_NOR_EnableMemoryMappedMode(uint32_t Instance);
int32_t BSP_OSPI_NOR_DisableMemoryMappedMode(uint32_t Instance);
int32_t BSP_OSPI_NOR_ReadID(uint32_t Instance, uint8_t *Id);
int32_t BSP_OSPI_NOR_ConfigFlash(uint32_t Instance, BSP_OSPI_NOR_Interface_t Mode, BSP_OSPI_NOR_Transfer_t Rate);
int32_t BSP_OSPI_NOR_SuspendErase(uint32_t Instance);
int32_t BSP_OSPI_NOR_ResumeErase(uint32_t Instance);
int32_t BSP_OSPI_NOR_EnterDeepPowerDown(uint32_t Instance);
int32_t BSP_OSPI_NOR_LeaveDeepPowerDown(uint32_t Instance);
/**
* @}
*/
/** @defgroup B_U585I_IOT02A_OSPI_RAM_Exported_Functions OSPI RAM Exported Functions
* @{
*/
int32_t BSP_OSPI_RAM_Init(uint32_t Instance);
int32_t BSP_OSPI_RAM_DeInit(uint32_t Instance);
#if (USE_HAL_OSPI_REGISTER_CALLBACKS == 1)
int32_t BSP_OSPI_RAM_RegisterMspCallbacks(uint32_t Instance, BSP_OSPI_Cb_t *CallBacks);
int32_t BSP_OSPI_RAM_RegisterDefaultMspCallbacks(uint32_t Instance);
#endif /* (USE_HAL_OSPI_REGISTER_CALLBACKS == 1) */
int32_t BSP_OSPI_RAM_Read(uint32_t Instance, uint8_t *pData, uint32_t ReadAddr, uint32_t Size);
int32_t BSP_OSPI_RAM_Write(uint32_t Instance, uint8_t *pData, uint32_t WriteAddr, uint32_t Size);
int32_t BSP_OSPI_RAM_EnableMemoryMappedMode(uint32_t Instance);
int32_t BSP_OSPI_RAM_DisableMemoryMappedMode(uint32_t Instance);
int32_t BSP_OSPI_RAM_ReadID(uint32_t Instance, uint8_t *Id);
/**
* @}
*/
/* These functions can be modified in case the current settings
need to be changed for specific application needs */
HAL_StatusTypeDef MX_OSPI_NOR_Init(OSPI_HandleTypeDef *hospi, MX_OSPI_InitTypeDef *Init);
HAL_StatusTypeDef MX_OSPI_RAM_Init(OSPI_HandleTypeDef *hospi, MX_OSPI_InitTypeDef *Init);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* B_U585I_IOT02A_OSPI_H */