1 /** 2 ****************************************************************************** 3 * @file stm32l562e_discovery_ospi.h 4 * @author MCD Application Team 5 * @brief This file contains the common defines and functions prototypes for 6 * the stm32l562e_discovery_ospi.c driver. 7 ****************************************************************************** 8 * @attention 9 * 10 * <h2><center>© Copyright (c) 2019 STMicroelectronics. 11 * All rights reserved.</center></h2> 12 * 13 * This software component is licensed by ST under BSD 3-Clause license, 14 * the "License"; You may not use this file except in compliance with the 15 * License. You may obtain a copy of the License at: 16 * opensource.org/licenses/BSD-3-Clause 17 * 18 ****************************************************************************** 19 */ 20 21 /* Define to prevent recursive inclusion -------------------------------------*/ 22 #ifndef STM32L562E_DISCOVERY_OSPI_H 23 #define STM32L562E_DISCOVERY_OSPI_H 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 /* Includes ------------------------------------------------------------------*/ 30 #include "stm32l562e_discovery_conf.h" 31 #include "stm32l562e_discovery_errno.h" 32 #include "../Components/mx25lm51245g/mx25lm51245g.h" 33 34 /** @addtogroup BSP 35 * @{ 36 */ 37 38 /** @addtogroup STM32L562E-DK 39 * @{ 40 */ 41 42 /** @addtogroup STM32L562E-DK_OSPI 43 * @{ 44 */ 45 46 /* Exported types ------------------------------------------------------------*/ 47 /** @defgroup STM32L562E-DK_OSPI_Exported_Types STM32L562E-DK OSPI Exported Types 48 * @{ 49 */ 50 typedef enum { 51 OSPI_ACCESS_NONE = 0, /*!< Instance not initialized, */ 52 OSPI_ACCESS_INDIRECT, /*!< Instance use indirect mode access */ 53 OSPI_ACCESS_MMP /*!< Instance use Memory Mapped Mode read */ 54 } OSPI_Access_t; 55 56 #if (USE_HAL_OSPI_REGISTER_CALLBACKS == 1) 57 typedef struct 58 { 59 pOSPI_CallbackTypeDef pMspInitCb; 60 pOSPI_CallbackTypeDef pMspDeInitCb; 61 }BSP_OSPI_Cb_t; 62 #endif /* (USE_HAL_OSPI_REGISTER_CALLBACKS == 1) */ 63 64 typedef struct 65 { 66 uint32_t MemorySize; 67 uint32_t ClockPrescaler; 68 uint32_t SampleShifting; 69 uint32_t TransferRate; 70 } MX_OSPI_InitTypeDef; 71 /** 72 * @} 73 */ 74 75 /** @defgroup STM32L562E-DK_OSPI_NOR_Exported_Types STM32L562E-DK OSPI_NOR Exported Types 76 * @{ 77 */ 78 #define BSP_OSPI_NOR_Info_t MX25LM51245G_Info_t 79 #define BSP_OSPI_NOR_Interface_t MX25LM51245G_Interface_t 80 #define BSP_OSPI_NOR_Transfer_t MX25LM51245G_Transfer_t 81 #define BSP_OSPI_NOR_Erase_t MX25LM51245G_Erase_t 82 83 typedef struct 84 { 85 OSPI_Access_t IsInitialized; /*!< Instance access Flash method */ 86 BSP_OSPI_NOR_Interface_t InterfaceMode; /*!< Flash Interface mode of Instance */ 87 BSP_OSPI_NOR_Transfer_t TransferRate; /*!< Flash Transfer mode of Instance */ 88 } OSPI_NOR_Ctx_t; 89 90 typedef struct 91 { 92 BSP_OSPI_NOR_Interface_t InterfaceMode; /*!< Current Flash Interface mode */ 93 BSP_OSPI_NOR_Transfer_t TransferRate; /*!< Current Flash Transfer rate */ 94 } BSP_OSPI_NOR_Init_t; 95 /** 96 * @} 97 */ 98 99 /* Exported constants --------------------------------------------------------*/ 100 /** @defgroup STM32L562E-DK_OSPI_Exported_Constants STM32L562E-DK OSPI Exported Constants 101 * @{ 102 */ 103 104 105 /* Definition for OSPI clock resources */ 106 #define OSPI_CLK_ENABLE() __HAL_RCC_OSPI1_CLK_ENABLE() 107 #define OSPI_CLK_DISABLE() __HAL_RCC_OSPI1_CLK_DISABLE() 108 109 #define OSPI_CLK_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() 110 #define OSPI_DQS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() 111 #define OSPI_CS_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() 112 #define OSPI_D0_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() 113 #define OSPI_D1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() 114 #define OSPI_D2_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() 115 #define OSPI_D3_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() 116 #define OSPI_D4_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() 117 #define OSPI_D5_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() 118 #define OSPI_D6_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() 119 #define OSPI_D7_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() 120 121 #define OSPI_FORCE_RESET() __HAL_RCC_OSPI1_FORCE_RESET() 122 #define OSPI_RELEASE_RESET() __HAL_RCC_OSPI1_RELEASE_RESET() 123 124 /* Definition for OSPI Pins */ 125 /* OSPI_CLK */ 126 #define OSPI_CLK_PIN GPIO_PIN_3 127 #define OSPI_CLK_GPIO_PORT GPIOA 128 #define OSPI_CLK_PIN_AF GPIO_AF10_OCTOSPI1 129 /* OSPI_DQS */ 130 #define OSPI_DQS_PIN GPIO_PIN_2 131 #define OSPI_DQS_GPIO_PORT GPIOB 132 #define OSPI_DQS_PIN_AF GPIO_AF10_OCTOSPI1 133 /* OSPI_CS */ 134 #define OSPI_CS_PIN GPIO_PIN_2 135 #define OSPI_CS_GPIO_PORT GPIOA 136 #define OSPI_CS_PIN_AF GPIO_AF10_OCTOSPI1 137 /* OSPI_D0 */ 138 #define OSPI_D0_PIN GPIO_PIN_1 139 #define OSPI_D0_GPIO_PORT GPIOB 140 #define OSPI_D0_PIN_AF GPIO_AF10_OCTOSPI1 141 /* OSPI_D1 */ 142 #define OSPI_D1_PIN GPIO_PIN_0 143 #define OSPI_D1_GPIO_PORT GPIOB 144 #define OSPI_D1_PIN_AF GPIO_AF10_OCTOSPI1 145 /* OSPI_D2 */ 146 #define OSPI_D2_PIN GPIO_PIN_7 147 #define OSPI_D2_GPIO_PORT GPIOA 148 #define OSPI_D2_PIN_AF GPIO_AF10_OCTOSPI1 149 /* OSPI_D3 */ 150 #define OSPI_D3_PIN GPIO_PIN_6 151 #define OSPI_D3_GPIO_PORT GPIOA 152 #define OSPI_D3_PIN_AF GPIO_AF10_OCTOSPI1 153 /* OSPI_D4 */ 154 #define OSPI_D4_PIN GPIO_PIN_1 155 #define OSPI_D4_GPIO_PORT GPIOC 156 #define OSPI_D4_PIN_AF GPIO_AF10_OCTOSPI1 157 /* OSPI_D5 */ 158 #define OSPI_D5_PIN GPIO_PIN_2 159 #define OSPI_D5_GPIO_PORT GPIOC 160 #define OSPI_D5_PIN_AF GPIO_AF10_OCTOSPI1 161 /* OSPI_D6 */ 162 #define OSPI_D6_PIN GPIO_PIN_3 163 #define OSPI_D6_GPIO_PORT GPIOC 164 #define OSPI_D6_PIN_AF GPIO_AF10_OCTOSPI1 165 /* OSPI_D7 */ 166 #define OSPI_D7_PIN GPIO_PIN_0 167 #define OSPI_D7_GPIO_PORT GPIOC 168 #define OSPI_D7_PIN_AF GPIO_AF3_OCTOSPI1 169 170 /** 171 * @} 172 */ 173 174 /** @defgroup STM32L562E-DK_OSPI_NOR_Exported_Constants STM32L562E-DK OSPI_NOR Exported Constants 175 * @{ 176 */ 177 #define OSPI_NOR_INSTANCES_NUMBER 1U 178 179 /* Definition for OSPI modes */ 180 #define BSP_OSPI_NOR_SPI_MODE (BSP_OSPI_NOR_Interface_t)MX25LM51245G_SPI_MODE /* 1 Cmd Line, 1 Address Line and 1 Data Line */ 181 #define BSP_OSPI_NOR_OPI_MODE (BSP_OSPI_NOR_Interface_t)MX25LM51245G_OPI_MODE /* 8 Cmd Lines, 8 Address Lines and 8 Data Lines */ 182 183 /* Definition for OSPI transfer rates */ 184 #define BSP_OSPI_NOR_STR_TRANSFER (BSP_OSPI_NOR_Transfer_t)MX25LM51245G_STR_TRANSFER /* Single Transfer Rate */ 185 #define BSP_OSPI_NOR_DTR_TRANSFER (BSP_OSPI_NOR_Transfer_t)MX25LM51245G_DTR_TRANSFER /* Double Transfer Rate */ 186 187 /* OSPI erase types */ 188 #define BSP_OSPI_NOR_ERASE_4K MX25LM51245G_ERASE_4K 189 #define BSP_OSPI_NOR_ERASE_64K MX25LM51245G_ERASE_64K 190 #define BSP_OSPI_NOR_ERASE_CHIP MX25LM51245G_ERASE_BULK 191 192 /* OSPI block sizes */ 193 #define BSP_OSPI_NOR_BLOCK_4K MX25LM51245G_SUBSECTOR_4K 194 #define BSP_OSPI_NOR_BLOCK_64K MX25LM51245G_SECTOR_64K 195 /** 196 * @} 197 */ 198 199 /* Exported variables --------------------------------------------------------*/ 200 /** @defgroup STM32L562E-DK_OSPI_NOR_Exported_Variables STM32L562E-DK OSPI_NOR Exported Variables 201 * @{ 202 */ 203 extern OSPI_HandleTypeDef hospi_nor[OSPI_NOR_INSTANCES_NUMBER]; 204 extern OSPI_NOR_Ctx_t Ospi_Nor_Ctx[OSPI_NOR_INSTANCES_NUMBER]; 205 /** 206 * @} 207 */ 208 209 /* Exported functions --------------------------------------------------------*/ 210 /** @defgroup STM32L562E-DK_OSPI_NOR_Exported_Functions STM32L562E-DK OSPI_NOR Exported Functions 211 * @{ 212 */ 213 int32_t BSP_OSPI_NOR_Init (uint32_t Instance, BSP_OSPI_NOR_Init_t *Init); 214 int32_t BSP_OSPI_NOR_DeInit (uint32_t Instance); 215 #if (USE_HAL_OSPI_REGISTER_CALLBACKS == 1) 216 int32_t BSP_OSPI_NOR_RegisterMspCallbacks (uint32_t Instance, BSP_OSPI_Cb_t *CallBacks); 217 int32_t BSP_OSPI_NOR_RegisterDefaultMspCallbacks (uint32_t Instance); 218 #endif /* (USE_HAL_OSPI_REGISTER_CALLBACKS == 1) */ 219 int32_t BSP_OSPI_NOR_Read (uint32_t Instance, uint8_t* pData, uint32_t ReadAddr, uint32_t Size); 220 int32_t BSP_OSPI_NOR_Write (uint32_t Instance, uint8_t* pData, uint32_t WriteAddr, uint32_t Size); 221 int32_t BSP_OSPI_NOR_Erase_Block (uint32_t Instance, uint32_t BlockAddress, BSP_OSPI_NOR_Erase_t BlockSize); 222 int32_t BSP_OSPI_NOR_Erase_Chip (uint32_t Instance); 223 int32_t BSP_OSPI_NOR_GetStatus (uint32_t Instance); 224 int32_t BSP_OSPI_NOR_GetInfo (uint32_t Instance, BSP_OSPI_NOR_Info_t* pInfo); 225 int32_t BSP_OSPI_NOR_EnableMemoryMappedMode (uint32_t Instance); 226 int32_t BSP_OSPI_NOR_DisableMemoryMappedMode (uint32_t Instance); 227 int32_t BSP_OSPI_NOR_ReadID (uint32_t Instance, uint8_t *Id); 228 int32_t BSP_OSPI_NOR_ConfigFlash (uint32_t Instance, BSP_OSPI_NOR_Interface_t Mode, BSP_OSPI_NOR_Transfer_t Rate); 229 int32_t BSP_OSPI_NOR_SuspendErase (uint32_t Instance); 230 int32_t BSP_OSPI_NOR_ResumeErase (uint32_t Instance); 231 int32_t BSP_OSPI_NOR_EnterDeepPowerDown (uint32_t Instance); 232 int32_t BSP_OSPI_NOR_LeaveDeepPowerDown (uint32_t Instance); 233 234 /* These functions can be modified in case the current settings 235 need to be changed for specific application needs */ 236 HAL_StatusTypeDef MX_OSPI_NOR_Init(OSPI_HandleTypeDef *hospi, MX_OSPI_InitTypeDef *Init); 237 238 /** 239 * @} 240 */ 241 242 /** 243 * @} 244 */ 245 246 /** 247 * @} 248 */ 249 250 /** 251 * @} 252 */ 253 254 #ifdef __cplusplus 255 } 256 #endif 257 258 #endif /* STM32L562E_DISCOVERY_OSPI_H */ 259 260 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 261