1 /* 2 * Copyright 2021-2024 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef QSPI_IP_H 8 #define QSPI_IP_H 9 10 /** 11 * @file Qspi_Ip.h 12 * 13 * @defgroup IPV_QSPI QSPI IPV Driver 14 * @{ 15 */ 16 17 18 #ifdef __cplusplus 19 extern "C"{ 20 #endif 21 22 #include "Qspi_Ip_Types.h" 23 #include "Qspi_Ip_Cfg.h" 24 25 /*================================================================================================== 26 * SOURCE FILE VERSION INFORMATION 27 ==================================================================================================*/ 28 #define QSPI_IP_VENDOR_ID_H 43 29 #define QSPI_IP_AR_RELEASE_MAJOR_VERSION_H 4 30 #define QSPI_IP_AR_RELEASE_MINOR_VERSION_H 7 31 #define QSPI_IP_AR_RELEASE_REVISION_VERSION_H 0 32 #define QSPI_IP_SW_MAJOR_VERSION_H 2 33 #define QSPI_IP_SW_MINOR_VERSION_H 0 34 #define QSPI_IP_SW_PATCH_VERSION_H 0 35 36 /*================================================================================================== 37 * FILE VERSION CHECKS 38 ==================================================================================================*/ 39 /* Check if current file and Qspi_Ip_Types header file are of the same vendor */ 40 #if (QSPI_IP_TYPES_VENDOR_ID_CFG != QSPI_IP_VENDOR_ID_H) 41 #error "Qspi_Ip.h and Qspi_Ip_Types.h have different vendor ids" 42 #endif 43 /* Check if current file and Qspi_Ip_Types header file are of the same Autosar version */ 44 #if ((QSPI_IP_TYPES_AR_RELEASE_MAJOR_VERSION_CFG != QSPI_IP_AR_RELEASE_MAJOR_VERSION_H) || \ 45 (QSPI_IP_TYPES_AR_RELEASE_MINOR_VERSION_CFG != QSPI_IP_AR_RELEASE_MINOR_VERSION_H) || \ 46 (QSPI_IP_TYPES_AR_RELEASE_REVISION_VERSION_CFG != QSPI_IP_AR_RELEASE_REVISION_VERSION_H) \ 47 ) 48 #error "AutoSar Version Numbers of Qspi_Ip.h and Qspi_Ip_Types.h are different" 49 #endif 50 /* Check if current file and Qspi_Ip_Types header file are of the same Software version */ 51 #if ((QSPI_IP_TYPES_SW_MAJOR_VERSION_CFG != QSPI_IP_SW_MAJOR_VERSION_H) || \ 52 (QSPI_IP_TYPES_SW_MINOR_VERSION_CFG != QSPI_IP_SW_MINOR_VERSION_H) || \ 53 (QSPI_IP_TYPES_SW_PATCH_VERSION_CFG != QSPI_IP_SW_PATCH_VERSION_H) \ 54 ) 55 #error "Software Version Numbers of Qspi_Ip.h and Qspi_Ip_Types.h are different" 56 #endif 57 58 /* Check if current file and Qspi_Ip_Cfg header file are of the same vendor */ 59 #if (QSPI_IP_VENDOR_ID_H != QSPI_IP_VENDOR_ID_CFG) 60 #error "Qspi_Ip.h and Qspi_Ip_Cfg.h have different vendor ids" 61 #endif 62 /* Check if current file and Qspi_Ip_Cfg header file are of the same Autosar version */ 63 #if ((QSPI_IP_AR_RELEASE_MAJOR_VERSION_H != QSPI_IP_AR_RELEASE_MAJOR_VERSION_CFG) || \ 64 (QSPI_IP_AR_RELEASE_MINOR_VERSION_H != QSPI_IP_AR_RELEASE_MINOR_VERSION_CFG) || \ 65 (QSPI_IP_AR_RELEASE_REVISION_VERSION_H != QSPI_IP_AR_RELEASE_REVISION_VERSION_CFG) \ 66 ) 67 #error "AutoSar Version Numbers of Qspi_Ip.h and Qspi_Ip_Cfg.h are different" 68 #endif 69 /* Check if current file and Qspi_Ip_Cfg header file are of the same Software version */ 70 #if ((QSPI_IP_SW_MAJOR_VERSION_H != QSPI_IP_SW_MAJOR_VERSION_CFG) || \ 71 (QSPI_IP_SW_MINOR_VERSION_H != QSPI_IP_SW_MINOR_VERSION_CFG) || \ 72 (QSPI_IP_SW_PATCH_VERSION_H != QSPI_IP_SW_PATCH_VERSION_CFG) \ 73 ) 74 #error "Software Version Numbers of Qspi_Ip.h and Qspi_Ip_Cfg.h are different" 75 #endif 76 77 /******************************************************************************* 78 * Definitions. 79 ******************************************************************************/ 80 81 /*! Maximum number of bytes then can be read in one operation */ 82 #define QSPI_IP_MAX_READ_SIZE (FEATURE_QSPI_RX_BUF_SIZE) 83 /*! Maximum number of bytes then can be written in one operation */ 84 #define QSPI_IP_MAX_WRITE_SIZE (FEATURE_QSPI_TX_BUF_SIZE) 85 86 /******************************************************************************* 87 * API 88 ******************************************************************************/ 89 #define MEM_43_EXFLS_START_SEC_CODE 90 #include "Mem_43_EXFLS_MemMap.h" 91 92 /*! 93 * @brief Initializes the serial flash memory driver 94 * 95 * This function initializes the external flash driver and prepares it for operation. 96 * 97 * @param instance External flash instance number 98 * @param pConfig Pointer to the driver configuration structure. 99 * @param pConnect Pointer to the flash device connection structure. 100 * @return Error or success status returned by API 101 */ 102 Qspi_Ip_StatusType Qspi_Ip_Init(uint32 instance, 103 const Qspi_Ip_MemoryConfigType * pConfig, 104 const Qspi_Ip_MemoryConnectionType * pConnect 105 ); 106 107 108 /*! 109 * @brief De-initializes the serial flash memory driver 110 * 111 * This function de-initializes the qspi driver. The driver can't be used 112 * again until reinitialized. The state structure is no longer needed by the driver and 113 * may be freed after calling this function. 114 * 115 * @param instance External flash instance number 116 * @return void 117 */ 118 Qspi_Ip_StatusType Qspi_Ip_Deinit(uint32 instance); 119 120 121 /*! 122 * @brief Erase a sector in the serial flash. 123 * 124 * This function performs one erase sector (block) operation on the external flash. The erase size must match one of 125 * the device's erase types. 126 * 127 * @param instance External flash instance number 128 * @param address Address of sector to be erased 129 * @param size Size of the sector to be erase. The sector size must match one of the supported erase sizes of the device. 130 * @return Error or success status returned by API 131 */ 132 Qspi_Ip_StatusType Qspi_Ip_EraseBlock(uint32 instance, 133 uint32 address, 134 uint32 size 135 ); 136 137 /*! 138 * @brief Erase the entire serial flash 139 * 140 * @param instance External flash instance number 141 * @return Error or success status returned by API 142 */ 143 Qspi_Ip_StatusType Qspi_Ip_EraseChip(uint32 instance); 144 145 /*! 146 * @brief Check the status of the flash device 147 * 148 * @param instance External flash instance number 149 * @return Error or success status returned by API 150 */ 151 Qspi_Ip_StatusType Qspi_Ip_GetMemoryStatus(uint32 instance); 152 153 154 /*! 155 * @brief Sets the protection bits to the requested value. 156 * 157 * @param instance External flash instance number 158 * @param value New value for the protection bits 159 * @return Error or success status returned by API 160 */ 161 Qspi_Ip_StatusType Qspi_Ip_SetProtection(uint32 instance, 162 uint8 value 163 ); 164 165 166 /*! 167 * @brief Returns the current value of the protection bits 168 * 169 * @param instance External flash instance number 170 * @param value Current value of the protection bits 171 * @return Error or success status returned by API 172 */ 173 Qspi_Ip_StatusType Qspi_Ip_GetProtection(uint32 instance, 174 uint8 *value 175 ); 176 177 178 /*! 179 * @brief Resets the flash device 180 * 181 * @param instance External flash instance number 182 * @return Error or success status returned by API 183 */ 184 Qspi_Ip_StatusType Qspi_Ip_Reset(uint32 instance); 185 186 187 /*! 188 * @brief Enters 0-X-X (no command) mode. This mode assumes only reads are performed. 189 * 190 * @param instance External flash instance number 191 * @return Error or success status returned by API 192 */ 193 Qspi_Ip_StatusType Qspi_Ip_Enter0XX(uint32 instance); 194 195 196 /*! 197 * @brief Exits 0-X-X (no command) mode. This allows operations other than reads to be performed. 198 * 199 * @param instance External flash instance number 200 * @return Error or success status returned by API 201 */ 202 Qspi_Ip_StatusType Qspi_Ip_Exit0XX(uint32 instance); 203 204 205 /*! 206 * @brief Suspends a program operation. 207 * 208 * @param instance External flash instance number 209 * @return Error or success status returned by API 210 */ 211 Qspi_Ip_StatusType Qspi_Ip_ProgramSuspend(uint32 instance); 212 213 214 /*! 215 * @brief Resumes a program operation. 216 * 217 * @param instance External flash instance number 218 * @return Error or success status returned by API 219 */ 220 Qspi_Ip_StatusType Qspi_Ip_ProgramResume(uint32 instance); 221 222 223 /*! 224 * @brief Suspends an erase operation. 225 * 226 * @param instance External flash instance number 227 * @return Error or success status returned by API 228 */ 229 Qspi_Ip_StatusType Qspi_Ip_EraseSuspend(uint32 instance); 230 231 232 /*! 233 * @brief Resumes an erase operation. 234 * 235 * @param instance External flash instance number 236 * @return Error or success status returned by API 237 */ 238 Qspi_Ip_StatusType Qspi_Ip_EraseResume(uint32 instance); 239 240 241 /*! 242 * @brief Read data from serial flash 243 * 244 * @param instance External flash instance number 245 * @param address Start address for read operation 246 * @param data Buffer where to store read data 247 * @param size Size of data buffer 248 * @return Error or success status returned by API 249 */ 250 Qspi_Ip_StatusType Qspi_Ip_Read(uint32 instance, 251 uint32 address, 252 uint8 * data, 253 uint32 size 254 ); 255 256 257 /*! 258 * @brief Read manufacturer ID/device ID from serial flash 259 * 260 * @param instance External flash instance number 261 * @param data Buffer where to store read data. Buffer size must match ReadId initialization settings. 262 * @return Error or success status returned by API 263 */ 264 Qspi_Ip_StatusType Qspi_Ip_ReadId(uint32 instance, 265 uint8 * data 266 ); 267 268 269 /*! 270 * @brief Verifies the correctness of the programmed data 271 * 272 * @param instance External flash instance number 273 * @param address Start address of area to be verified 274 * @param data Data to be verified 275 * @param size Size of area to be verified 276 * @return Error or success status returned by API 277 */ 278 Qspi_Ip_StatusType Qspi_Ip_ProgramVerify(uint32 instance, 279 uint32 address, 280 const uint8 * data, 281 uint32 size 282 ); 283 284 285 /*! 286 * @brief Checks whether or not an area in the serial flash is erased 287 * 288 * @param instance External flash instance number 289 * @param address Start address of area to be verified 290 * @param size Size of area to be verified 291 * @return Error or success status returned by API 292 */ 293 Qspi_Ip_StatusType Qspi_Ip_EraseVerify(uint32 instance, 294 uint32 address, 295 uint32 size 296 ); 297 298 /*! 299 * @brief Writes data in serial flash 300 * 301 * @details Writes data in serial flash memory then exits (Async mode) 302 * The status of the flash memory must be verified by calling asynchronously the Qspi_Ip_GetMemoryStatus function 303 * until it is not busy, meaning that the write operation is complete. 304 * The maximum supported size is equal to the Qspi hardware TxBuffer size. 305 * 306 * @param instance External flash instance number 307 * @param address Start address of area to be programmed 308 * @param data Data to be programmed in flash 309 * @param size Size of data buffer 310 * @return Error or success status returned by API 311 */ 312 Qspi_Ip_StatusType Qspi_Ip_Program(uint32 instance, 313 uint32 address, 314 const uint8 * data, 315 uint32 size 316 ); 317 318 319 /*! 320 * @brief Launches a simple command for the serial flash. 321 * 322 * @param instance External flash instance number 323 * @param lut Index of command in virtual LUT 324 * @param addr Address used in the command, or base address of the target serial flash 325 * @return Error or success status returned by API 326 */ 327 Qspi_Ip_StatusType Qspi_Ip_RunCommand(uint32 instance, 328 uint16 lut, 329 uint32 addr 330 ); 331 332 333 /*! 334 * @brief Launches a read command for the serial flash 335 * 336 * This function can launch a read command in 3 modes: 337 * - normal read (dataRead != NULL_PTR): Data is read from serial flash and placed in the buffer 338 * - verify (dataRead == NULL_PTR, dataCmp != NULL_PTR): Data is read from serial flash and compared to the reference buffer 339 * - blank check (dataRead == NULL_PTR, dataCmp == NULL_PTR): Data is read from serial flash and compared to 0xFF 340 * 341 * @param instance External flash instance number 342 * @param lut Index of command in virtual LUT 343 * @param addr Start address for read operation in serial flash 344 * @param dataRead Buffer where to store read data 345 * @param dataCmp Buffer to be compared to read data 346 * @param size Size of data buffer 347 * @return Error or success status returned by API 348 */ 349 Qspi_Ip_StatusType Qspi_Ip_RunReadCommand(uint32 instance, 350 uint16 lut, 351 uint32 addr, 352 uint8 * dataRead, 353 const uint8 * dataCmp, 354 uint32 size 355 ); 356 357 358 /*! 359 * @brief Launches a write command for the serial flash 360 * 361 * @param instance External flash instance number 362 * @param lut Index of command in virtual LUT 363 * @param addr Start address for write operation in serial flash 364 * @param data Data to be programmed in flash 365 * @param size Size of data buffer 366 * @return Error or success status returned by API 367 */ 368 Qspi_Ip_StatusType Qspi_Ip_RunWriteCommand(uint32 instance, 369 uint16 lut, 370 uint32 addr, 371 const uint8 * data, 372 uint32 size 373 ); 374 375 /*! 376 * @brief Sets up AHB reads to the serial flash 377 * 378 * @param instance External flash instance number 379 * @return Error or success status returned by API 380 */ 381 Qspi_Ip_StatusType Qspi_Ip_AhbReadEnable(uint32 instance); 382 383 384 /*! 385 * @brief Check the status of the QSPI controller 386 * 387 * @param instance QSPI peripheral instance number 388 * @return Error or success status returned by API 389 */ 390 Qspi_Ip_StatusType Qspi_Ip_ControllerGetStatus(uint32 instance); 391 392 393 /*! 394 * @brief Initializes the qspi driver 395 * 396 * This function initializes the qspi driver and prepares it for operation. 397 * 398 * @param instance QSPI peripheral instance number 399 * @param userConfigPtr Pointer to the qspi configuration structure. 400 * @return Error or success status returned by API 401 */ 402 Qspi_Ip_StatusType Qspi_Ip_ControllerInit(uint32 instance, 403 const Qspi_Ip_ControllerConfigType * userConfigPtr 404 ); 405 406 /*! 407 * @brief De-initialize the qspi driver 408 * 409 * This function de-initializes the qspi driver. The driver can't be used 410 * again until reinitialized. The context structure is no longer needed by the driver and 411 * can be freed after calling this function. 412 * 413 * @param instance QSPI peripheral instance number 414 * @return Error or success status returned by API 415 */ 416 Qspi_Ip_StatusType Qspi_Ip_ControllerDeinit(uint32 instance); 417 418 /*! 419 * @brief Aborts any on-going transactions 420 * 421 * Force the Qspi controller to cancel the on-going IP transaction by performing the software reset sequence. 422 * 423 * @param instance QSPI peripheral instance number 424 * @return Error or success status returned by API 425 */ 426 Qspi_Ip_StatusType Qspi_Ip_Abort(uint32 instance); 427 428 /*! 429 * @brief Initializes the serial flash memory configuration from SFDP table 430 * 431 * This function uses the information in the SFDP table to auto-fill the memory configuration structure. 432 * 433 * @param pConfig Pointer to the driver configuration structure. 434 * @param pConnect Pointer to the flash device connection structure. 435 * @return Error or success status returned by API 436 */ 437 Qspi_Ip_StatusType Qspi_Ip_ReadSfdp(Qspi_Ip_MemoryConfigType * pConfig, 438 const Qspi_Ip_MemoryConnectionType * pConnect 439 ); 440 441 #define MEM_43_EXFLS_STOP_SEC_CODE 442 #include "Mem_43_EXFLS_MemMap.h" 443 444 445 #if defined(__cplusplus) 446 } 447 #endif 448 449 /** @} */ 450 451 #endif /* QSPI_IP_H */ 452 453