RTEMS 6.1-rc1
stm32h747i_eval_qspi.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause */
20/*
21 * RTEMS committer clarification comment on license above:
22 *
23 * This file comes from STM32CubeH7 project and is located here:
24 * https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Drivers/BSP/STM32H747I-EVAL/stm32h747i_eval_qspi.h
25 *
26 * The file root directory is:
27 * https://github.com/STMicroelectronics/STM32CubeH7/tree/master/Drivers/BSP/STM32H747I-EVAL
28 *
29 * This directory contains LICENSE.md file with a following license text:
30 *
31 * Copyright 2019 STMicroelectronics.
32 * All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without modification,
35 * are permitted provided that the following conditions are met:
36 *
37 * 1. Redistributions of source code must retain the above copyright notice, this
38 * list of conditions and the following disclaimer.
39 *
40 * 2. Redistributions in binary form must reproduce the above copyright notice,
41 * this list of conditions and the following disclaimer in the documentation and/or
42 * other materials provided with the distribution.
43 *
44 * 3. Neither the name of the copyright holder nor the names of its contributors
45 * may be used to endorse or promote products derived from this software without
46 * specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
50 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
51 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
52 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
53 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
55 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
57 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 */
59/* Define to prevent recursive inclusion -------------------------------------*/
60#ifndef STM32H747I_EVAL_QSPI_H
61#define STM32H747I_EVAL_QSPI_H
62
63#ifdef __cplusplus
64 extern "C" {
65#endif
66
67/* Includes ------------------------------------------------------------------*/
68#include "stm32h747i_eval_conf.h"
70#include "../Components/mt25tl01g/mt25tl01g.h"
71
83/* Exported types ------------------------------------------------------------*/
87#define BSP_QSPI_Info_t MT25TL01G_Info_t
88#define BSP_QSPI_Interface_t MT25TL01G_Interface_t
89#define BSP_QSPI_Transfer_t MT25TL01G_Transfer_t
90#define BSP_QSPI_DualFlash_t MT25TL01G_DualFlash_t
91#define BSP_QSPI_ODS_t MT25TL01G_ODS_t
92
93typedef enum
94{
101
102typedef enum
103{
108
109typedef struct
110{
112 BSP_QSPI_Interface_t InterfaceMode;
113 BSP_QSPI_Transfer_t TransferRate;
114 uint32_t DualFlashMode;
115 uint32_t IsMspCallbacksValid;
117
118typedef struct
119{
120 BSP_QSPI_Interface_t InterfaceMode;
121 BSP_QSPI_Transfer_t TransferRate;
122 BSP_QSPI_DualFlash_t DualFlashMode;
124
125typedef struct
126{
127 uint32_t FlashSize;
128 uint32_t ClockPrescaler;
129 uint32_t SampleShifting;
130 uint32_t DualFlashMode;
132#if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
133typedef struct
134{
135 void(*pMspInitCb)(pQSPI_CallbackTypeDef);
136 void(*pMspDeInitCb)(pQSPI_CallbackTypeDef);
137}BSP_QSPI_Cb_t;
138#endif /* (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) */
139
144/* Exported constants --------------------------------------------------------*/
148/* QSPI instances number */
149#define QSPI_INSTANCES_NUMBER 1U
150
151/* Definition for QSPI modes */
152#define BSP_QSPI_SPI_MODE (BSP_QSPI_Interface_t)MT25TL01G_SPI_MODE /* 1 Cmd Line, 1 Address Line and 1 Data Line */
153#define BSP_QSPI_SPI_1I2O_MODE (BSP_QSPI_Interface_t)MT25TL01G_SPI_1I2O_MODE /* 1 Cmd Line, 1 Address Line and 2 Data Lines */
154#define BSP_QSPI_SPI_2IO_MODE (BSP_QSPI_Interface_t)MT25TL01G_SPI_2IO_MODE /* 1 Cmd Line, 2 Address Lines and 2 Data Lines */
155#define BSP_QSPI_SPI_1I4O_MODE (BSP_QSPI_Interface_t)MT25TL01G_SPI_1I4O_MODE /* 1 Cmd Line, 1 Address Line and 4 Data Lines */
156#define BSP_QSPI_SPI_4IO_MODE (BSP_QSPI_Interface_t)MT25TL01G_SPI_4IO_MODE /* 1 Cmd Line, 4 Address Lines and 4 Data Lines */
157#define BSP_QSPI_DPI_MODE (BSP_QSPI_Interface_t)MT25TL01G_DPI_MODE /* 2 Cmd Lines, 2 Address Lines and 2 Data Lines */
158#define BSP_QSPI_QPI_MODE (BSP_QSPI_Interface_t)MT25TL01G_QPI_MODE /* 4 Cmd Lines, 4 Address Lines and 4 Data Lines */
159
160/* Definition for QSPI transfer rates */
161#define BSP_QSPI_STR_TRANSFER (BSP_QSPI_Transfer_t)MT25TL01G_STR_TRANSFER /* Single Transfer Rate */
162#define BSP_QSPI_DTR_TRANSFER (BSP_QSPI_Transfer_t)MT25TL01G_DTR_TRANSFER /* Double Transfer Rate */
163
164/* Definition for QSPI dual flash mode */
165#define BSP_QSPI_DUALFLASH_DISABLE (BSP_QSPI_DualFlash_t)MT25TL01G_DUALFLASH_DISABLE /* Dual flash mode enabled */
166/* Definition for QSPI Flash ID */
167#define BSP_QSPI_FLASH_ID QSPI_FLASH_ID_1
168
169/* QSPI block sizes for dual flash */
170#define BSP_QSPI_BLOCK_8K MT25TL01G_SECTOR_4K
171#define BSP_QSPI_BLOCK_64K MT25TL01G_BLOCK_32K
172#define BSP_QSPI_BLOCK_128K MT25TL01G_BLOCK_64K
173
174/* Definition for QSPI clock resources */
175#define QSPI_CLK_ENABLE() __HAL_RCC_QSPI_CLK_ENABLE()
176#define QSPI_CLK_DISABLE() __HAL_RCC_QSPI_CLK_DISABLE()
177#define QSPI_CLK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
178#define QSPI_BK1_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
179#define QSPI_BK1_D0_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
180#define QSPI_BK1_D1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
181#define QSPI_BK1_D2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
182#define QSPI_BK1_D3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE()
183#define QSPI_BK2_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
184#define QSPI_BK2_D0_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE()
185#define QSPI_BK2_D1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE()
186#define QSPI_BK2_D2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
187#define QSPI_BK2_D3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
188
189
190#define QSPI_FORCE_RESET() __HAL_RCC_QSPI_FORCE_RESET()
191#define QSPI_RELEASE_RESET() __HAL_RCC_QSPI_RELEASE_RESET()
192
193/* Definition for QSPI Pins */
194#define QSPI_CLK_PIN GPIO_PIN_2
195#define QSPI_CLK_GPIO_PORT GPIOB
196/* Bank 1 */
197#define QSPI_BK1_CS_PIN GPIO_PIN_6
198#define QSPI_BK1_CS_GPIO_PORT GPIOG
199#define QSPI_BK1_D0_PIN GPIO_PIN_8
200#define QSPI_BK1_D0_GPIO_PORT GPIOF
201#define QSPI_BK1_D1_PIN GPIO_PIN_9
202#define QSPI_BK1_D1_GPIO_PORT GPIOF
203#define QSPI_BK1_D2_PIN GPIO_PIN_7
204#define QSPI_BK1_D2_GPIO_PORT GPIOF
205#define QSPI_BK1_D3_PIN GPIO_PIN_6
206#define QSPI_BK1_D3_GPIO_PORT GPIOF
207
208/* Bank 2 */
209#define QSPI_BK2_CS_PIN GPIO_PIN_11
210#define QSPI_BK2_CS_GPIO_PORT GPIOC
211#define QSPI_BK2_D0_PIN GPIO_PIN_2
212#define QSPI_BK2_D0_GPIO_PORT GPIOH
213#define QSPI_BK2_D1_PIN GPIO_PIN_3
214#define QSPI_BK2_D1_GPIO_PORT GPIOH
215#define QSPI_BK2_D2_PIN GPIO_PIN_9
216#define QSPI_BK2_D2_GPIO_PORT GPIOG
217#define QSPI_BK2_D3_PIN GPIO_PIN_14
218#define QSPI_BK2_D3_GPIO_PORT GPIOG
219
220
221/* MT25TL01G Micron memory */
222/* Size of the flash */
223#define QSPI_FLASH_SIZE 26 /* Address bus width to access whole memory space */
224#define QSPI_PAGE_SIZE 256
225
226/* QSPI Base Address */
227#define QSPI_BASE_ADDRESS 0x90000000
235extern QSPI_HandleTypeDef hqspi;
236extern BSP_QSPI_Ctx_t QSPI_Ctx[];
241/* Exported functions --------------------------------------------------------*/
245int32_t BSP_QSPI_Init(uint32_t Instance, BSP_QSPI_Init_t *Init);
246int32_t BSP_QSPI_DeInit(uint32_t Instance);
247#if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
248int32_t BSP_QSPI_RegisterMspCallbacks (uint32_t Instance, BSP_QSPI_Cb_t *CallBacks);
249int32_t BSP_QSPI_RegisterDefaultMspCallbacks (uint32_t Instance);
250#endif /* (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) */
251int32_t BSP_QSPI_Read(uint32_t Instance, uint8_t *pData, uint32_t ReadAddr, uint32_t Size);
252int32_t BSP_QSPI_Write(uint32_t Instance, uint8_t *pData, uint32_t WriteAddr, uint32_t Size);
253int32_t BSP_QSPI_EraseBlock(uint32_t Instance, uint32_t BlockAddress, BSP_QSPI_Erase_t BlockSize);
254int32_t BSP_QSPI_EraseChip(uint32_t Instance);
255int32_t BSP_QSPI_GetStatus(uint32_t Instance);
256int32_t BSP_QSPI_GetInfo(uint32_t Instance, BSP_QSPI_Info_t *pInfo);
257int32_t BSP_QSPI_EnableMemoryMappedMode(uint32_t Instance);
258int32_t BSP_QSPI_DisableMemoryMappedMode(uint32_t Instance);
259int32_t BSP_QSPI_ReadID(uint32_t Instance, uint8_t *Id);
260int32_t BSP_QSPI_ConfigFlash(uint32_t Instance, BSP_QSPI_Interface_t Mode, BSP_QSPI_Transfer_t Rate);
261
262/* These functions can be modified in case the current settings
263 need to be changed for specific application needs */
264HAL_StatusTypeDef MX_QSPI_Init(QSPI_HandleTypeDef *hQspi, MX_QSPI_Init_t *Config);
265
274#ifdef __cplusplus
275}
276#endif
277#endif /* __STM32H747I_EVAL_QSPI_H */
@ MT25TL01G_ERASE_32K
Definition: mt25tl01g.h:111
@ MT25TL01G_ERASE_64K
Definition: mt25tl01g.h:112
@ MT25TL01G_ERASE_CHIP
Definition: mt25tl01g.h:113
@ MT25TL01G_ERASE_4K
Definition: mt25tl01g.h:110
int32_t BSP_QSPI_EraseBlock(uint32_t Instance, uint32_t BlockAddress, BSP_QSPI_Erase_t BlockSize)
Erases the specified block of the QSPI memory. MT25TL01G support 4K, 32K, 64K size block erase comman...
Definition: stm32h747i_eval_qspi.c:490
int32_t BSP_QSPI_Read(uint32_t Instance, uint8_t *pData, uint32_t ReadAddr, uint32_t Size)
Reads an amount of data from the QSPI memory.
Definition: stm32h747i_eval_qspi.c:381
int32_t BSP_QSPI_EnableMemoryMappedMode(uint32_t Instance)
Configure the QSPI in memory-mapped mode Only 1 Instance can running MMP mode. And it will lock syste...
Definition: stm32h747i_eval_qspi.c:629
int32_t BSP_QSPI_Write(uint32_t Instance, uint8_t *pData, uint32_t WriteAddr, uint32_t Size)
Writes an amount of data to the QSPI memory.
Definition: stm32h747i_eval_qspi.c:420
__weak HAL_StatusTypeDef MX_QSPI_Init(QSPI_HandleTypeDef *hQspi, MX_QSPI_Init_t *Config)
Initializes the QSPI interface.
Definition: stm32h747i_eval_qspi.c:283
int32_t BSP_QSPI_Init(uint32_t Instance, BSP_QSPI_Init_t *Init)
Initializes the QSPI interface.
Definition: stm32h747i_eval_qspi.c:149
int32_t BSP_QSPI_DeInit(uint32_t Instance)
De-Initializes the QSPI interface.
Definition: stm32h747i_eval_qspi.c:234
int32_t BSP_QSPI_GetStatus(uint32_t Instance)
Reads current status of the QSPI memory. If WIP != 0 then return busy.
Definition: stm32h747i_eval_qspi.c:569
int32_t BSP_QSPI_EraseChip(uint32_t Instance)
Erases the entire QSPI memory.
Definition: stm32h747i_eval_qspi.c:529
int32_t BSP_QSPI_DisableMemoryMappedMode(uint32_t Instance)
Exit form memory-mapped mode Only 1 Instance can running MMP mode. And it will lock system at this mo...
Definition: stm32h747i_eval_qspi.c:674
int32_t BSP_QSPI_ConfigFlash(uint32_t Instance, BSP_QSPI_Interface_t Mode, BSP_QSPI_Transfer_t Rate)
Set Flash to desired Interface mode. And this instance becomes current instance. If current instance ...
Definition: stm32h747i_eval_qspi.c:755
int32_t BSP_QSPI_ReadID(uint32_t Instance, uint8_t *Id)
Get flash ID, 3 Byte Manufacturer ID, Memory type, Memory density.
Definition: stm32h747i_eval_qspi.c:725
int32_t BSP_QSPI_GetInfo(uint32_t Instance, BSP_QSPI_Info_t *pInfo)
Return the configuration of the QSPI memory.
Definition: stm32h747i_eval_qspi.c:605
BSP_QSPI_Erase_t
Definition: stm32h747i_eval_qspi.h:94
BSP_QSPI_Access_t
Definition: stm32h747i_eval_qspi.h:103
@ BSP_QSPI_ERASE_CHIP
Definition: stm32h747i_eval_qspi.h:98
@ BSP_QSPI_ERASE_64K
Definition: stm32h747i_eval_qspi.h:96
@ BSP_QSPI_ERASE_128K
Definition: stm32h747i_eval_qspi.h:97
@ BSP_QSPI_ERASE_8K
Definition: stm32h747i_eval_qspi.h:95
@ QSPI_ACCESS_INDIRECT
Definition: stm32h747i_eval_qspi.h:105
@ QSPI_ACCESS_MMP
Definition: stm32h747i_eval_qspi.h:106
@ QSPI_ACCESS_NONE
Definition: stm32h747i_eval_qspi.h:104
HAL_StatusTypeDef
HAL Status structures definition.
Definition: stm32h7xx_hal_def.h:47
Definition: stm32h747i_eval_qspi.h:110
uint32_t DualFlashMode
Definition: stm32h747i_eval_qspi.h:114
BSP_QSPI_Access_t IsInitialized
Definition: stm32h747i_eval_qspi.h:111
Definition: stm32h747i_eval_qspi.h:119
Definition: stm32h747i_eval_qspi.h:126