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