123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781 |
- /**
- ******************************************************************************
- * @file stm32f4xx_hal_qspi.c
- * @author MCD Application Team
- * @brief QSPI HAL module driver.
- * This file provides firmware functions to manage the following
- * functionalities of the QuadSPI interface (QSPI).
- * + Initialization and de-initialization functions
- * + Indirect functional mode management
- * + Memory-mapped functional mode management
- * + Auto-polling functional mode management
- * + Interrupts and flags management
- * + DMA channel configuration for indirect functional mode
- * + Errors management and abort functionality
- *
- *
- @verbatim
- ===============================================================================
- ##### How to use this driver #####
- ===============================================================================
- [..]
- *** Initialization ***
- ======================
- [..]
- (#) As prerequisite, fill in the HAL_QSPI_MspInit() :
- (++) Enable QuadSPI clock interface with __HAL_RCC_QSPI_CLK_ENABLE().
- (++) Reset QuadSPI IP with __HAL_RCC_QSPI_FORCE_RESET() and __HAL_RCC_QSPI_RELEASE_RESET().
- (++) Enable the clocks for the QuadSPI GPIOS with __HAL_RCC_GPIOx_CLK_ENABLE().
- (++) Configure these QuadSPI pins in alternate mode using HAL_GPIO_Init().
- (++) If interrupt mode is used, enable and configure QuadSPI global
- interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
- (++) If DMA mode is used, enable the clocks for the QuadSPI DMA channel
- with __HAL_RCC_DMAx_CLK_ENABLE(), configure DMA with HAL_DMA_Init(),
- link it with QuadSPI handle using __HAL_LINKDMA(), enable and configure
- DMA channel global interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
- (#) Configure the flash size, the clock prescaler, the fifo threshold, the
- clock mode, the sample shifting and the CS high time using the HAL_QSPI_Init() function.
- *** Indirect functional mode ***
- ================================
- [..]
- (#) Configure the command sequence using the HAL_QSPI_Command() or HAL_QSPI_Command_IT()
- functions :
- (++) Instruction phase : the mode used and if present the instruction opcode.
- (++) Address phase : the mode used and if present the size and the address value.
- (++) Alternate-bytes phase : the mode used and if present the size and the alternate
- bytes values.
- (++) Dummy-cycles phase : the number of dummy cycles (mode used is same as data phase).
- (++) Data phase : the mode used and if present the number of bytes.
- (++) Double Data Rate (DDR) mode : the activation (or not) of this mode and the delay
- if activated.
- (++) Sending Instruction Only Once (SIOO) mode : the activation (or not) of this mode.
- (#) If no data is required for the command, it is sent directly to the memory :
- (++) In polling mode, the output of the function is done when the transfer is complete.
- (++) In interrupt mode, HAL_QSPI_CmdCpltCallback() will be called when the transfer is complete.
- (#) For the indirect write mode, use HAL_QSPI_Transmit(), HAL_QSPI_Transmit_DMA() or
- HAL_QSPI_Transmit_IT() after the command configuration :
- (++) In polling mode, the output of the function is done when the transfer is complete.
- (++) In interrupt mode, HAL_QSPI_FifoThresholdCallback() will be called when the fifo threshold
- is reached and HAL_QSPI_TxCpltCallback() will be called when the transfer is complete.
- (++) In DMA mode, HAL_QSPI_TxHalfCpltCallback() will be called at the half transfer and
- HAL_QSPI_TxCpltCallback() will be called when the transfer is complete.
- (#) For the indirect read mode, use HAL_QSPI_Receive(), HAL_QSPI_Receive_DMA() or
- HAL_QSPI_Receive_IT() after the command configuration :
- (++) In polling mode, the output of the function is done when the transfer is complete.
- (++) In interrupt mode, HAL_QSPI_FifoThresholdCallback() will be called when the fifo threshold
- is reached and HAL_QSPI_RxCpltCallback() will be called when the transfer is complete.
- (++) In DMA mode, HAL_QSPI_RxHalfCpltCallback() will be called at the half transfer and
- HAL_QSPI_RxCpltCallback() will be called when the transfer is complete.
- *** Auto-polling functional mode ***
- ====================================
- [..]
- (#) Configure the command sequence and the auto-polling functional mode using the
- HAL_QSPI_AutoPolling() or HAL_QSPI_AutoPolling_IT() functions :
- (++) Instruction phase : the mode used and if present the instruction opcode.
- (++) Address phase : the mode used and if present the size and the address value.
- (++) Alternate-bytes phase : the mode used and if present the size and the alternate
- bytes values.
- (++) Dummy-cycles phase : the number of dummy cycles (mode used is same as data phase).
- (++) Data phase : the mode used.
- (++) Double Data Rate (DDR) mode : the activation (or not) of this mode and the delay
- if activated.
- (++) Sending Instruction Only Once (SIOO) mode : the activation (or not) of this mode.
- (++) The size of the status bytes, the match value, the mask used, the match mode (OR/AND),
- the polling interval and the automatic stop activation.
- (#) After the configuration :
- (++) In polling mode, the output of the function is done when the status match is reached. The
- automatic stop is activated to avoid an infinite loop.
- (++) In interrupt mode, HAL_QSPI_StatusMatchCallback() will be called each time the status match is reached.
- *** Memory-mapped functional mode ***
- =====================================
- [..]
- (#) Configure the command sequence and the memory-mapped functional mode using the
- HAL_QSPI_MemoryMapped() functions :
- (++) Instruction phase : the mode used and if present the instruction opcode.
- (++) Address phase : the mode used and the size.
- (++) Alternate-bytes phase : the mode used and if present the size and the alternate
- bytes values.
- (++) Dummy-cycles phase : the number of dummy cycles (mode used is same as data phase).
- (++) Data phase : the mode used.
- (++) Double Data Rate (DDR) mode : the activation (or not) of this mode and the delay
- if activated.
- (++) Sending Instruction Only Once (SIOO) mode : the activation (or not) of this mode.
- (++) The timeout activation and the timeout period.
- (#) After the configuration, the QuadSPI will be used as soon as an access on the AHB is done on
- the address range. HAL_QSPI_TimeOutCallback() will be called when the timeout expires.
- *** Errors management and abort functionality ***
- ==================================================
- [..]
- (#) HAL_QSPI_GetError() function gives the error raised during the last operation.
- (#) HAL_QSPI_Abort() and HAL_QSPI_AbortIT() functions aborts any on-going operation and
- flushes the fifo :
- (++) In polling mode, the output of the function is done when the transfer
- complete bit is set and the busy bit cleared.
- (++) In interrupt mode, HAL_QSPI_AbortCpltCallback() will be called when
- the transfer complete bi is set.
- *** Control functions ***
- =========================
- [..]
- (#) HAL_QSPI_GetState() function gives the current state of the HAL QuadSPI driver.
- (#) HAL_QSPI_SetTimeout() function configures the timeout value used in the driver.
- (#) HAL_QSPI_SetFifoThreshold() function configures the threshold on the Fifo of the QSPI IP.
- (#) HAL_QSPI_GetFifoThreshold() function gives the current of the Fifo's threshold
- *** Callback registration ***
- =============================================
- [..]
- The compilation define USE_HAL_QSPI_REGISTER_CALLBACKS when set to 1
- allows the user to configure dynamically the driver callbacks.
- Use Functions @ref HAL_QSPI_RegisterCallback() to register a user callback,
- it allows to register following callbacks:
- (+) ErrorCallback : callback when error occurs.
- (+) AbortCpltCallback : callback when abort is completed.
- (+) FifoThresholdCallback : callback when the fifo threshold is reached.
- (+) CmdCpltCallback : callback when a command without data is completed.
- (+) RxCpltCallback : callback when a reception transfer is completed.
- (+) TxCpltCallback : callback when a transmission transfer is completed.
- (+) RxHalfCpltCallback : callback when half of the reception transfer is completed.
- (+) TxHalfCpltCallback : callback when half of the transmission transfer is completed.
- (+) StatusMatchCallback : callback when a status match occurs.
- (+) TimeOutCallback : callback when the timeout perioed expires.
- (+) MspInitCallback : QSPI MspInit.
- (+) MspDeInitCallback : QSPI MspDeInit.
- This function takes as parameters the HAL peripheral handle, the Callback ID
- and a pointer to the user callback function.
- Use function @ref HAL_QSPI_UnRegisterCallback() to reset a callback to the default
- weak (surcharged) function. It allows to reset following callbacks:
- (+) ErrorCallback : callback when error occurs.
- (+) AbortCpltCallback : callback when abort is completed.
- (+) FifoThresholdCallback : callback when the fifo threshold is reached.
- (+) CmdCpltCallback : callback when a command without data is completed.
- (+) RxCpltCallback : callback when a reception transfer is completed.
- (+) TxCpltCallback : callback when a transmission transfer is completed.
- (+) RxHalfCpltCallback : callback when half of the reception transfer is completed.
- (+) TxHalfCpltCallback : callback when half of the transmission transfer is completed.
- (+) StatusMatchCallback : callback when a status match occurs.
- (+) TimeOutCallback : callback when the timeout perioed expires.
- (+) MspInitCallback : QSPI MspInit.
- (+) MspDeInitCallback : QSPI MspDeInit.
- This function) takes as parameters the HAL peripheral handle and the Callback ID.
- By default, after the @ref HAL_QSPI_Init and if the state is HAL_QSPI_STATE_RESET
- all callbacks are reset to the corresponding legacy weak (surcharged) functions.
- Exception done for MspInit and MspDeInit callbacks that are respectively
- reset to the legacy weak (surcharged) functions in the @ref HAL_QSPI_Init
- and @ref HAL_QSPI_DeInit only when these callbacks are null (not registered beforehand).
- If not, MspInit or MspDeInit are not null, the @ref HAL_QSPI_Init and @ref HAL_QSPI_DeInit
- keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
- Callbacks can be registered/unregistered in READY state only.
- Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
- in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
- during the Init/DeInit.
- In that case first register the MspInit/MspDeInit user callbacks
- using @ref HAL_QSPI_RegisterCallback before calling @ref HAL_QSPI_DeInit
- or @ref HAL_QSPI_Init function.
- When The compilation define USE_HAL_QSPI_REGISTER_CALLBACKS is set to 0 or
- not defined, the callback registering feature is not available
- and weak (surcharged) callbacks are used.
- *** Workarounds linked to Silicon Limitation ***
- ====================================================
- [..]
- (#) Workarounds Implemented inside HAL Driver
- (++) Extra data written in the FIFO at the end of a read transfer
- @endverbatim
- ******************************************************************************
- * @attention
- *
- * <h2><center>© Copyright (c) 2017 STMicroelectronics.
- * All rights reserved.</center></h2>
- *
- * This software component is licensed by ST under BSD 3-Clause license,
- * the "License"; You may not use this file except in compliance with the
- * License. You may obtain a copy of the License at:
- * opensource.org/licenses/BSD-3-Clause
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f4xx_hal.h"
- /** @addtogroup STM32F4xx_HAL_Driver
- * @{
- */
- /** @defgroup QSPI QSPI
- * @brief QSPI HAL module driver
- * @{
- */
- #ifdef HAL_QSPI_MODULE_ENABLED
- #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
- defined(STM32F412Rx) || defined(STM32F413xx) || defined(STM32F423xx)
-
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /** @addtogroup QSPI_Private_Constants
- * @{
- */
- #define QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE 0x00000000U /*!<Indirect write mode*/
- #define QSPI_FUNCTIONAL_MODE_INDIRECT_READ ((uint32_t)QUADSPI_CCR_FMODE_0) /*!<Indirect read mode*/
- #define QSPI_FUNCTIONAL_MODE_AUTO_POLLING ((uint32_t)QUADSPI_CCR_FMODE_1) /*!<Automatic polling mode*/
- #define QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED ((uint32_t)QUADSPI_CCR_FMODE) /*!<Memory-mapped mode*/
- /**
- * @}
- */
-
- /* Private macro -------------------------------------------------------------*/
- /** @addtogroup QSPI_Private_Macros QSPI Private Macros
- * @{
- */
- #define IS_QSPI_FUNCTIONAL_MODE(MODE) (((MODE) == QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE) || \
- ((MODE) == QSPI_FUNCTIONAL_MODE_INDIRECT_READ) || \
- ((MODE) == QSPI_FUNCTIONAL_MODE_AUTO_POLLING) || \
- ((MODE) == QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED))
- /**
- * @}
- */
-
- /* Private variables ---------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------*/
- /** @addtogroup QSPI_Private_Functions QSPI Private Functions
- * @{
- */
- static void QSPI_DMARxCplt(DMA_HandleTypeDef *hdma);
- static void QSPI_DMATxCplt(DMA_HandleTypeDef *hdma);
- static void QSPI_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
- static void QSPI_DMATxHalfCplt(DMA_HandleTypeDef *hdma);
- static void QSPI_DMAError(DMA_HandleTypeDef *hdma);
- static void QSPI_DMAAbortCplt(DMA_HandleTypeDef *hdma);
- static HAL_StatusTypeDef QSPI_WaitFlagStateUntilTimeout(QSPI_HandleTypeDef *hqspi, uint32_t Flag, FlagStatus State, uint32_t tickstart, uint32_t Timeout);
- static void QSPI_Config(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, uint32_t FunctionalMode);
- /**
- * @}
- */
-
- /* Exported functions ---------------------------------------------------------*/
- /** @defgroup QSPI_Exported_Functions QSPI Exported Functions
- * @{
- */
- /** @defgroup QSPI_Exported_Functions_Group1 Initialization/de-initialization functions
- * @brief Initialization and Configuration functions
- *
- @verbatim
- ===============================================================================
- ##### Initialization and Configuration functions #####
- ===============================================================================
- [..]
- This subsection provides a set of functions allowing to :
- (+) Initialize the QuadSPI.
- (+) De-initialize the QuadSPI.
-
- @endverbatim
- * @{
- */
- /**
- * @brief Initializes the QSPI mode according to the specified parameters
- * in the QSPI_InitTypeDef and creates the associated handle.
- * @param hqspi qspi handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_Init(QSPI_HandleTypeDef *hqspi)
- {
- HAL_StatusTypeDef status = HAL_ERROR;
- uint32_t tickstart = HAL_GetTick();
-
- /* Check the QSPI handle allocation */
- if(hqspi == NULL)
- {
- return HAL_ERROR;
- }
- /* Check the parameters */
- assert_param(IS_QSPI_ALL_INSTANCE(hqspi->Instance));
- assert_param(IS_QSPI_CLOCK_PRESCALER(hqspi->Init.ClockPrescaler));
- assert_param(IS_QSPI_FIFO_THRESHOLD(hqspi->Init.FifoThreshold));
- assert_param(IS_QSPI_SSHIFT(hqspi->Init.SampleShifting));
- assert_param(IS_QSPI_FLASH_SIZE(hqspi->Init.FlashSize));
- assert_param(IS_QSPI_CS_HIGH_TIME(hqspi->Init.ChipSelectHighTime));
- assert_param(IS_QSPI_CLOCK_MODE(hqspi->Init.ClockMode));
- assert_param(IS_QSPI_DUAL_FLASH_MODE(hqspi->Init.DualFlash));
- if (hqspi->Init.DualFlash != QSPI_DUALFLASH_ENABLE )
- {
- assert_param(IS_QSPI_FLASH_ID(hqspi->Init.FlashID));
- }
-
- if(hqspi->State == HAL_QSPI_STATE_RESET)
- {
- /* Allocate lock resource and initialize it */
- hqspi->Lock = HAL_UNLOCKED;
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- /* Reset Callback pointers in HAL_QSPI_STATE_RESET only */
- hqspi->ErrorCallback = HAL_QSPI_ErrorCallback;
- hqspi->AbortCpltCallback = HAL_QSPI_AbortCpltCallback;
- hqspi->FifoThresholdCallback = HAL_QSPI_FifoThresholdCallback;
- hqspi->CmdCpltCallback = HAL_QSPI_CmdCpltCallback;
- hqspi->RxCpltCallback = HAL_QSPI_RxCpltCallback;
- hqspi->TxCpltCallback = HAL_QSPI_TxCpltCallback;
- hqspi->RxHalfCpltCallback = HAL_QSPI_RxHalfCpltCallback;
- hqspi->TxHalfCpltCallback = HAL_QSPI_TxHalfCpltCallback;
- hqspi->StatusMatchCallback = HAL_QSPI_StatusMatchCallback;
- hqspi->TimeOutCallback = HAL_QSPI_TimeOutCallback;
- if(hqspi->MspInitCallback == NULL)
- {
- hqspi->MspInitCallback = HAL_QSPI_MspInit;
- }
- /* Init the low level hardware */
- hqspi->MspInitCallback(hqspi);
- #else
- /* Init the low level hardware : GPIO, CLOCK */
- HAL_QSPI_MspInit(hqspi);
- #endif
- /* Configure the default timeout for the QSPI memory access */
- HAL_QSPI_SetTimeout(hqspi, HAL_QPSI_TIMEOUT_DEFAULT_VALUE);
- }
-
- /* Configure QSPI FIFO Threshold */
- MODIFY_REG(hqspi->Instance->CR, QUADSPI_CR_FTHRES, ((hqspi->Init.FifoThreshold - 1U) << 8U));
- /* Wait till BUSY flag reset */
- status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_BUSY, RESET, tickstart, hqspi->Timeout);
- if(status == HAL_OK)
- {
-
- /* Configure QSPI Clock Prescaler and Sample Shift */
- MODIFY_REG(hqspi->Instance->CR,(QUADSPI_CR_PRESCALER | QUADSPI_CR_SSHIFT | QUADSPI_CR_FSEL | QUADSPI_CR_DFM), ((hqspi->Init.ClockPrescaler << 24U)| hqspi->Init.SampleShifting | hqspi->Init.FlashID| hqspi->Init.DualFlash ));
-
- /* Configure QSPI Flash Size, CS High Time and Clock Mode */
- MODIFY_REG(hqspi->Instance->DCR, (QUADSPI_DCR_FSIZE | QUADSPI_DCR_CSHT | QUADSPI_DCR_CKMODE),
- ((hqspi->Init.FlashSize << 16U) | hqspi->Init.ChipSelectHighTime | hqspi->Init.ClockMode));
-
- /* Enable the QSPI peripheral */
- __HAL_QSPI_ENABLE(hqspi);
-
- /* Set QSPI error code to none */
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
- /* Initialize the QSPI state */
- hqspi->State = HAL_QSPI_STATE_READY;
- }
-
- /* Release Lock */
- __HAL_UNLOCK(hqspi);
- /* Return function status */
- return status;
- }
- /**
- * @brief DeInitializes the QSPI peripheral
- * @param hqspi qspi handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_DeInit(QSPI_HandleTypeDef *hqspi)
- {
- /* Check the QSPI handle allocation */
- if(hqspi == NULL)
- {
- return HAL_ERROR;
- }
- /* Disable the QSPI Peripheral Clock */
- __HAL_QSPI_DISABLE(hqspi);
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- if(hqspi->MspDeInitCallback == NULL)
- {
- hqspi->MspDeInitCallback = HAL_QSPI_MspDeInit;
- }
- /* DeInit the low level hardware */
- hqspi->MspDeInitCallback(hqspi);
- #else
- /* DeInit the low level hardware: GPIO, CLOCK, NVIC... */
- HAL_QSPI_MspDeInit(hqspi);
- #endif
- /* Set QSPI error code to none */
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
- /* Initialize the QSPI state */
- hqspi->State = HAL_QSPI_STATE_RESET;
- /* Release Lock */
- __HAL_UNLOCK(hqspi);
- return HAL_OK;
- }
- /**
- * @brief QSPI MSP Init
- * @param hqspi QSPI handle
- * @retval None
- */
- __weak void HAL_QSPI_MspInit(QSPI_HandleTypeDef *hqspi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hqspi);
-
- /* NOTE : This function should not be modified, when the callback is needed,
- the HAL_QSPI_MspInit can be implemented in the user file
- */
- }
- /**
- * @brief QSPI MSP DeInit
- * @param hqspi QSPI handle
- * @retval None
- */
- __weak void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef *hqspi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hqspi);
-
- /* NOTE : This function should not be modified, when the callback is needed,
- the HAL_QSPI_MspDeInit can be implemented in the user file
- */
- }
- /**
- * @}
- */
- /** @defgroup QSPI_Exported_Functions_Group2 IO operation functions
- * @brief QSPI Transmit/Receive functions
- *
- @verbatim
- ===============================================================================
- ##### IO operation functions #####
- ===============================================================================
- [..]
- This subsection provides a set of functions allowing to :
- (+) Handle the interrupts.
- (+) Handle the command sequence.
- (+) Transmit data in blocking, interrupt or DMA mode.
- (+) Receive data in blocking, interrupt or DMA mode.
- (+) Manage the auto-polling functional mode.
- (+) Manage the memory-mapped functional mode.
- @endverbatim
- * @{
- */
- /**
- * @brief This function handles QSPI interrupt request.
- * @param hqspi QSPI handle
- * @retval None.
- */
- void HAL_QSPI_IRQHandler(QSPI_HandleTypeDef *hqspi)
- {
- __IO uint32_t *data_reg;
- uint32_t flag = READ_REG(hqspi->Instance->SR);
- uint32_t itsource = READ_REG(hqspi->Instance->CR);
- /* QSPI Fifo Threshold interrupt occurred ----------------------------------*/
- if(((flag & QSPI_FLAG_FT)!= RESET) && ((itsource & QSPI_IT_FT)!= RESET))
- {
- data_reg = &hqspi->Instance->DR;
- if(hqspi->State == HAL_QSPI_STATE_BUSY_INDIRECT_TX)
- {
- /* Transmission process */
- while(__HAL_QSPI_GET_FLAG(hqspi, QSPI_FLAG_FT) != 0U)
- {
- if (hqspi->TxXferCount > 0U)
- {
- /* Fill the FIFO until it is full */
- *(__IO uint8_t *)data_reg = *hqspi->pTxBuffPtr++;
- hqspi->TxXferCount--;
- }
- else
- {
- /* No more data available for the transfer */
- /* Disable the QSPI FIFO Threshold Interrupt */
- __HAL_QSPI_DISABLE_IT(hqspi, QSPI_IT_FT);
- break;
- }
- }
- }
- else if(hqspi->State == HAL_QSPI_STATE_BUSY_INDIRECT_RX)
- {
- /* Receiving Process */
- while(__HAL_QSPI_GET_FLAG(hqspi, QSPI_FLAG_FT) != 0U)
- {
- if (hqspi->RxXferCount > 0U)
- {
- /* Read the FIFO until it is empty */
- *hqspi->pRxBuffPtr++ = *(__IO uint8_t *)data_reg;
- hqspi->RxXferCount--;
- }
- else
- {
- /* All data have been received for the transfer */
- /* Disable the QSPI FIFO Threshold Interrupt */
- __HAL_QSPI_DISABLE_IT(hqspi, QSPI_IT_FT);
- break;
- }
- }
- }
-
- /* FIFO Threshold callback */
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->FifoThresholdCallback(hqspi);
- #else
- HAL_QSPI_FifoThresholdCallback(hqspi);
- #endif
- }
- /* QSPI Transfer Complete interrupt occurred -------------------------------*/
- else if(((flag & QSPI_FLAG_TC)!= RESET) && ((itsource & QSPI_IT_TC)!= RESET))
- {
- /* Clear interrupt */
- WRITE_REG(hqspi->Instance->FCR, QSPI_FLAG_TC);
- /* Disable the QSPI FIFO Threshold, Transfer Error and Transfer complete Interrupts */
- __HAL_QSPI_DISABLE_IT(hqspi, QSPI_IT_TC | QSPI_IT_TE | QSPI_IT_FT);
-
- /* Transfer complete callback */
- if(hqspi->State == HAL_QSPI_STATE_BUSY_INDIRECT_TX)
- {
- if ((hqspi->Instance->CR & QUADSPI_CR_DMAEN)!= RESET)
- {
- /* Disable the DMA transfer by clearing the DMAEN bit in the QSPI CR register */
- CLEAR_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN);
-
- /* Disable the DMA channel */
- __HAL_DMA_DISABLE(hqspi->hdma);
- }
- /* Clear Busy bit */
- HAL_QSPI_Abort_IT(hqspi);
-
- /* Change state of QSPI */
- hqspi->State = HAL_QSPI_STATE_READY;
- /* TX Complete callback */
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->TxCpltCallback(hqspi);
- #else
- HAL_QSPI_TxCpltCallback(hqspi);
- #endif
- }
- else if(hqspi->State == HAL_QSPI_STATE_BUSY_INDIRECT_RX)
- {
- if ((hqspi->Instance->CR & QUADSPI_CR_DMAEN)!= RESET)
- {
- /* Disable the DMA transfer by clearing the DMAEN bit in the QSPI CR register */
- CLEAR_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN);
-
- /* Disable the DMA channel */
- __HAL_DMA_DISABLE(hqspi->hdma);
- }
- else
- {
- data_reg = &hqspi->Instance->DR;
- while(READ_BIT(hqspi->Instance->SR, QUADSPI_SR_FLEVEL) != 0U)
- {
- if (hqspi->RxXferCount > 0U)
- {
- /* Read the last data received in the FIFO until it is empty */
- *hqspi->pRxBuffPtr++ = *(__IO uint8_t *)data_reg;
- hqspi->RxXferCount--;
- }
- else
- {
- /* All data have been received for the transfer */
- break;
- }
- }
- }
- /* Workaround - Extra data written in the FIFO at the end of a read transfer */
- HAL_QSPI_Abort_IT(hqspi);
-
- /* Change state of QSPI */
- hqspi->State = HAL_QSPI_STATE_READY;
- /* RX Complete callback */
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->RxCpltCallback(hqspi);
- #else
- HAL_QSPI_RxCpltCallback(hqspi);
- #endif
- }
- else if(hqspi->State == HAL_QSPI_STATE_BUSY)
- {
- /* Change state of QSPI */
- hqspi->State = HAL_QSPI_STATE_READY;
- /* Command Complete callback */
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->CmdCpltCallback(hqspi);
- #else
- HAL_QSPI_CmdCpltCallback(hqspi);
- #endif
- }
- else if(hqspi->State == HAL_QSPI_STATE_ABORT)
- {
- /* Change state of QSPI */
- hqspi->State = HAL_QSPI_STATE_READY;
- if (hqspi->ErrorCode == HAL_QSPI_ERROR_NONE)
- {
- /* Abort called by the user */
- /* Abort Complete callback */
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->AbortCpltCallback(hqspi);
- #else
- HAL_QSPI_AbortCpltCallback(hqspi);
- #endif
- }
- else
- {
- /* Abort due to an error (eg : DMA error) */
- /* Error callback */
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->ErrorCallback(hqspi);
- #else
- HAL_QSPI_ErrorCallback(hqspi);
- #endif
- }
- }
- }
- /* QSPI Status Match interrupt occurred ------------------------------------*/
- else if(((flag & QSPI_FLAG_SM)!= RESET) && ((itsource & QSPI_IT_SM)!= RESET))
- {
- /* Clear interrupt */
- WRITE_REG(hqspi->Instance->FCR, QSPI_FLAG_SM);
-
- /* Check if the automatic poll mode stop is activated */
- if(READ_BIT(hqspi->Instance->CR, QUADSPI_CR_APMS) != 0U)
- {
- /* Disable the QSPI Transfer Error and Status Match Interrupts */
- __HAL_QSPI_DISABLE_IT(hqspi, (QSPI_IT_SM | QSPI_IT_TE));
- /* Change state of QSPI */
- hqspi->State = HAL_QSPI_STATE_READY;
- }
- /* Status match callback */
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->StatusMatchCallback(hqspi);
- #else
- HAL_QSPI_StatusMatchCallback(hqspi);
- #endif
- }
- /* QSPI Transfer Error interrupt occurred ----------------------------------*/
- else if(((flag & QSPI_FLAG_TE)!= RESET) && ((itsource & QSPI_IT_TE)!= RESET))
- {
- /* Clear interrupt */
- WRITE_REG(hqspi->Instance->FCR, QSPI_FLAG_TE);
-
- /* Disable all the QSPI Interrupts */
- __HAL_QSPI_DISABLE_IT(hqspi, QSPI_IT_SM | QSPI_IT_TC | QSPI_IT_TE | QSPI_IT_FT);
- /* Set error code */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_TRANSFER;
-
- if ((hqspi->Instance->CR & QUADSPI_CR_DMAEN)!= RESET)
- {
- /* Disable the DMA transfer by clearing the DMAEN bit in the QSPI CR register */
- CLEAR_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN);
-
- /* Disable the DMA channel */
- hqspi->hdma->XferAbortCallback = QSPI_DMAAbortCplt;
- if (HAL_DMA_Abort_IT(hqspi->hdma) != HAL_OK)
- {
- /* Set error code to DMA */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_DMA;
- /* Change state of QSPI */
- hqspi->State = HAL_QSPI_STATE_READY;
-
- /* Error callback */
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->ErrorCallback(hqspi);
- #else
- HAL_QSPI_ErrorCallback(hqspi);
- #endif
- }
- }
- else
- {
- /* Change state of QSPI */
- hqspi->State = HAL_QSPI_STATE_READY;
-
- /* Error callback */
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->ErrorCallback(hqspi);
- #else
- HAL_QSPI_ErrorCallback(hqspi);
- #endif
- }
- }
- /* QSPI Timeout interrupt occurred -----------------------------------------*/
- else if(((flag & QSPI_FLAG_TO)!= RESET) && ((itsource & QSPI_IT_TO)!= RESET))
- {
- /* Clear interrupt */
- WRITE_REG(hqspi->Instance->FCR, QSPI_FLAG_TO);
- /* Timeout callback */
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->TimeOutCallback(hqspi);
- #else
- HAL_QSPI_TimeOutCallback(hqspi);
- #endif
- }
- }
- /**
- * @brief Sets the command configuration.
- * @param hqspi QSPI handle
- * @param cmd structure that contains the command configuration information
- * @param Timeout Time out duration
- * @note This function is used only in Indirect Read or Write Modes
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_Command(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, uint32_t Timeout)
- {
- HAL_StatusTypeDef status = HAL_ERROR;
- uint32_t tickstart = HAL_GetTick();
-
- /* Check the parameters */
- assert_param(IS_QSPI_INSTRUCTION_MODE(cmd->InstructionMode));
- if (cmd->InstructionMode != QSPI_INSTRUCTION_NONE)
- {
- assert_param(IS_QSPI_INSTRUCTION(cmd->Instruction));
- }
- assert_param(IS_QSPI_ADDRESS_MODE(cmd->AddressMode));
- if (cmd->AddressMode != QSPI_ADDRESS_NONE)
- {
- assert_param(IS_QSPI_ADDRESS_SIZE(cmd->AddressSize));
- }
- assert_param(IS_QSPI_ALTERNATE_BYTES_MODE(cmd->AlternateByteMode));
- if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE)
- {
- assert_param(IS_QSPI_ALTERNATE_BYTES_SIZE(cmd->AlternateBytesSize));
- }
- assert_param(IS_QSPI_DUMMY_CYCLES(cmd->DummyCycles));
- assert_param(IS_QSPI_DATA_MODE(cmd->DataMode));
- assert_param(IS_QSPI_DDR_MODE(cmd->DdrMode));
- assert_param(IS_QSPI_DDR_HHC(cmd->DdrHoldHalfCycle));
- assert_param(IS_QSPI_SIOO_MODE(cmd->SIOOMode));
-
- /* Process locked */
- __HAL_LOCK(hqspi);
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
-
- /* Update QSPI state */
- hqspi->State = HAL_QSPI_STATE_BUSY;
-
- /* Wait till BUSY flag reset */
- status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_BUSY, RESET, tickstart, Timeout);
-
- if (status == HAL_OK)
- {
- /* Call the configuration function */
- QSPI_Config(hqspi, cmd, QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE);
-
- if (cmd->DataMode == QSPI_DATA_NONE)
- {
- /* When there is no data phase, the transfer start as soon as the configuration is done
- so wait until TC flag is set to go back in idle state */
- status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_TC, SET, tickstart, Timeout);
- if (status == HAL_OK)
- {
- __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TC);
-
- /* Update QSPI state */
- hqspi->State = HAL_QSPI_STATE_READY;
- }
-
- }
- else
- {
- /* Update QSPI state */
- hqspi->State = HAL_QSPI_STATE_READY;
- }
- }
- }
- else
- {
- status = HAL_BUSY;
- }
-
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- /* Return function status */
- return status;
- }
- /**
- * @brief Sets the command configuration in interrupt mode.
- * @param hqspi QSPI handle
- * @param cmd structure that contains the command configuration information
- * @note This function is used only in Indirect Read or Write Modes
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_Command_IT(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd)
- {
- __IO uint32_t count = 0U;
- HAL_StatusTypeDef status = HAL_OK;
-
- /* Check the parameters */
- assert_param(IS_QSPI_INSTRUCTION_MODE(cmd->InstructionMode));
- if (cmd->InstructionMode != QSPI_INSTRUCTION_NONE)
- {
- assert_param(IS_QSPI_INSTRUCTION(cmd->Instruction));
- }
- assert_param(IS_QSPI_ADDRESS_MODE(cmd->AddressMode));
- if (cmd->AddressMode != QSPI_ADDRESS_NONE)
- {
- assert_param(IS_QSPI_ADDRESS_SIZE(cmd->AddressSize));
- }
- assert_param(IS_QSPI_ALTERNATE_BYTES_MODE(cmd->AlternateByteMode));
- if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE)
- {
- assert_param(IS_QSPI_ALTERNATE_BYTES_SIZE(cmd->AlternateBytesSize));
- }
- assert_param(IS_QSPI_DUMMY_CYCLES(cmd->DummyCycles));
- assert_param(IS_QSPI_DATA_MODE(cmd->DataMode));
- assert_param(IS_QSPI_DDR_MODE(cmd->DdrMode));
- assert_param(IS_QSPI_DDR_HHC(cmd->DdrHoldHalfCycle));
- assert_param(IS_QSPI_SIOO_MODE(cmd->SIOOMode));
-
- /* Process locked */
- __HAL_LOCK(hqspi);
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
-
- /* Update QSPI state */
- hqspi->State = HAL_QSPI_STATE_BUSY;
-
- /* Wait till BUSY flag reset */
- count = (hqspi->Timeout) * (SystemCoreClock / 16U / 1000U);
- do
- {
- if (count-- == 0U)
- {
- hqspi->State = HAL_QSPI_STATE_ERROR;
- hqspi->ErrorCode |= HAL_QSPI_ERROR_TIMEOUT;
- status = HAL_TIMEOUT;
- }
- }
- while ((__HAL_QSPI_GET_FLAG(hqspi, QSPI_FLAG_BUSY)) != RESET);
-
- if (status == HAL_OK)
- {
- if (cmd->DataMode == QSPI_DATA_NONE)
- {
- /* Clear interrupt */
- __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TE | QSPI_FLAG_TC);
- }
-
- /* Call the configuration function */
- QSPI_Config(hqspi, cmd, QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE);
-
- if (cmd->DataMode == QSPI_DATA_NONE)
- {
- /* When there is no data phase, the transfer start as soon as the configuration is done
- so activate TC and TE interrupts */
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- /* Enable the QSPI Transfer Error Interrupt */
- __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TE | QSPI_IT_TC);
- }
- else
- {
- /* Update QSPI state */
- hqspi->State = HAL_QSPI_STATE_READY;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- }
- else
- {
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- }
- else
- {
- status = HAL_BUSY;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
-
- /* Return function status */
- return status;
- }
- /**
- * @brief Transmit an amount of data in blocking mode.
- * @param hqspi QSPI handle
- * @param pData pointer to data buffer
- * @param Timeout Time out duration
- * @note This function is used only in Indirect Write Mode
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_Transmit(QSPI_HandleTypeDef *hqspi, uint8_t *pData, uint32_t Timeout)
- {
- HAL_StatusTypeDef status = HAL_OK;
- uint32_t tickstart = HAL_GetTick();
- __IO uint32_t *data_reg = &hqspi->Instance->DR;
- /* Process locked */
- __HAL_LOCK(hqspi);
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
- if(pData != NULL )
- {
- /* Update state */
- hqspi->State = HAL_QSPI_STATE_BUSY_INDIRECT_TX;
-
- /* Configure counters and size of the handle */
- hqspi->TxXferCount = READ_REG(hqspi->Instance->DLR) + 1U;
- hqspi->TxXferSize = READ_REG(hqspi->Instance->DLR) + 1U;
- hqspi->pTxBuffPtr = pData;
-
- /* Configure QSPI: CCR register with functional as indirect write */
- MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE);
- while(hqspi->TxXferCount > 0U)
- {
- /* Wait until FT flag is set to send data */
- status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_FT, SET, tickstart, Timeout);
- if (status != HAL_OK)
- {
- break;
- }
- *(__IO uint8_t *)data_reg = *hqspi->pTxBuffPtr++;
- hqspi->TxXferCount--;
- }
-
- if (status == HAL_OK)
- {
- /* Wait until TC flag is set to go back in idle state */
- status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_TC, SET, tickstart, Timeout);
- if (status == HAL_OK)
- {
- /* Clear Transfer Complete bit */
- __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TC);
-
- /* Clear Busy bit */
- status = HAL_QSPI_Abort(hqspi);
- }
- }
-
- /* Update QSPI state */
- hqspi->State = HAL_QSPI_STATE_READY;
- }
- else
- {
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM;
- status = HAL_ERROR;
- }
- }
- else
- {
- status = HAL_BUSY;
- }
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- return status;
- }
- /**
- * @brief Receive an amount of data in blocking mode
- * @param hqspi QSPI handle
- * @param pData pointer to data buffer
- * @param Timeout Time out duration
- * @note This function is used only in Indirect Read Mode
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_Receive(QSPI_HandleTypeDef *hqspi, uint8_t *pData, uint32_t Timeout)
- {
- HAL_StatusTypeDef status = HAL_OK;
- uint32_t tickstart = HAL_GetTick();
- uint32_t addr_reg = READ_REG(hqspi->Instance->AR);
- __IO uint32_t *data_reg = &hqspi->Instance->DR;
- /* Process locked */
- __HAL_LOCK(hqspi);
-
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
- if(pData != NULL )
- {
- /* Update state */
- hqspi->State = HAL_QSPI_STATE_BUSY_INDIRECT_RX;
-
- /* Configure counters and size of the handle */
- hqspi->RxXferCount = READ_REG(hqspi->Instance->DLR) + 1U;
- hqspi->RxXferSize = READ_REG(hqspi->Instance->DLR) + 1U;
- hqspi->pRxBuffPtr = pData;
- /* Configure QSPI: CCR register with functional as indirect read */
- MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_READ);
- /* Start the transfer by re-writing the address in AR register */
- WRITE_REG(hqspi->Instance->AR, addr_reg);
-
- while(hqspi->RxXferCount > 0U)
- {
- /* Wait until FT or TC flag is set to read received data */
- status = QSPI_WaitFlagStateUntilTimeout(hqspi, (QSPI_FLAG_FT | QSPI_FLAG_TC), SET, tickstart, Timeout);
- if (status != HAL_OK)
- {
- break;
- }
- *hqspi->pRxBuffPtr++ = *(__IO uint8_t *)data_reg;
- hqspi->RxXferCount--;
- }
-
- if (status == HAL_OK)
- {
- /* Wait until TC flag is set to go back in idle state */
- status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_TC, SET, tickstart, Timeout);
- if (status == HAL_OK)
- {
- /* Clear Transfer Complete bit */
- __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TC);
-
- /* Workaround - Extra data written in the FIFO at the end of a read transfer */
- status = HAL_QSPI_Abort(hqspi);
- }
- }
- /* Update QSPI state */
- hqspi->State = HAL_QSPI_STATE_READY;
- }
- else
- {
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM;
- status = HAL_ERROR;
- }
- }
- else
- {
- status = HAL_BUSY;
- }
-
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- return status;
- }
- /**
- * @brief Send an amount of data in interrupt mode
- * @param hqspi QSPI handle
- * @param pData pointer to data buffer
- * @note This function is used only in Indirect Write Mode
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_Transmit_IT(QSPI_HandleTypeDef *hqspi, uint8_t *pData)
- {
- HAL_StatusTypeDef status = HAL_OK;
-
- /* Process locked */
- __HAL_LOCK(hqspi);
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
- if(pData != NULL )
- {
- /* Update state */
- hqspi->State = HAL_QSPI_STATE_BUSY_INDIRECT_TX;
- /* Configure counters and size of the handle */
- hqspi->TxXferCount = READ_REG(hqspi->Instance->DLR) + 1U;
- hqspi->TxXferSize = READ_REG(hqspi->Instance->DLR) + 1U;
- hqspi->pTxBuffPtr = pData;
-
- /* Configure QSPI: CCR register with functional as indirect write */
- MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE);
-
- /* Clear interrupt */
- __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TE | QSPI_FLAG_TC);
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
-
- /* Enable the QSPI transfer error, FIFO threshold and transfer complete Interrupts */
- __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TE | QSPI_IT_FT | QSPI_IT_TC);
-
- }
- else
- {
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM;
- status = HAL_ERROR;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- }
- else
- {
- status = HAL_BUSY;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- return status;
- }
- /**
- * @brief Receive an amount of data in no-blocking mode with Interrupt
- * @param hqspi QSPI handle
- * @param pData pointer to data buffer
- * @note This function is used only in Indirect Read Mode
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_Receive_IT(QSPI_HandleTypeDef *hqspi, uint8_t *pData)
- {
- HAL_StatusTypeDef status = HAL_OK;
- uint32_t addr_reg = READ_REG(hqspi->Instance->AR);
-
- /* Process locked */
- __HAL_LOCK(hqspi);
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
-
- if(pData != NULL )
- {
- /* Update state */
- hqspi->State = HAL_QSPI_STATE_BUSY_INDIRECT_RX;
-
- /* Configure counters and size of the handle */
- hqspi->RxXferCount = READ_REG(hqspi->Instance->DLR) + 1U;
- hqspi->RxXferSize = READ_REG(hqspi->Instance->DLR) + 1U;
- hqspi->pRxBuffPtr = pData;
- /* Configure QSPI: CCR register with functional as indirect read */
- MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_READ);
- /* Start the transfer by re-writing the address in AR register */
- WRITE_REG(hqspi->Instance->AR, addr_reg);
- /* Clear interrupt */
- __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TE | QSPI_FLAG_TC);
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- /* Enable the QSPI transfer error, FIFO threshold and transfer complete Interrupts */
- __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TE | QSPI_IT_FT | QSPI_IT_TC);
- }
- else
- {
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM;
- status = HAL_ERROR;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- }
- else
- {
- status = HAL_BUSY;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- return status;
- }
- /**
- * @brief Sends an amount of data in non blocking mode with DMA.
- * @param hqspi QSPI handle
- * @param pData pointer to data buffer
- * @note This function is used only in Indirect Write Mode
- * @note If DMA peripheral access is configured as halfword, the number
- * of data and the fifo threshold should be aligned on halfword
- * @note If DMA peripheral access is configured as word, the number
- * of data and the fifo threshold should be aligned on word
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_Transmit_DMA(QSPI_HandleTypeDef *hqspi, uint8_t *pData)
- {
- HAL_StatusTypeDef status = HAL_OK;
- uint32_t *tmp;
- uint32_t data_size = (READ_REG(hqspi->Instance->DLR) + 1U);
- /* Process locked */
- __HAL_LOCK(hqspi);
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- /* Clear the error code */
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
- if(pData != NULL )
- {
- /* Configure counters of the handle */
- if (hqspi->hdma->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
- {
- hqspi->TxXferCount = data_size;
- }
- else if (hqspi->hdma->Init.PeriphDataAlignment == DMA_PDATAALIGN_HALFWORD)
- {
- if (((data_size % 2U) != 0U) || ((hqspi->Init.FifoThreshold % 2U) != 0U))
- {
- /* The number of data or the fifo threshold is not aligned on halfword
- => no transfer possible with DMA peripheral access configured as halfword */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM;
- status = HAL_ERROR;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- else
- {
- hqspi->TxXferCount = (data_size >> 1);
- }
- }
- else if (hqspi->hdma->Init.PeriphDataAlignment == DMA_PDATAALIGN_WORD)
- {
- if (((data_size % 4U) != 0U) || ((hqspi->Init.FifoThreshold % 4U) != 0U))
- {
- /* The number of data or the fifo threshold is not aligned on word
- => no transfer possible with DMA peripheral access configured as word */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM;
- status = HAL_ERROR;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- else
- {
- hqspi->TxXferCount = (data_size >> 2U);
- }
- }
- if (status == HAL_OK)
- {
- /* Update state */
- hqspi->State = HAL_QSPI_STATE_BUSY_INDIRECT_TX;
- /* Clear interrupt */
- __HAL_QSPI_CLEAR_FLAG(hqspi, (QSPI_FLAG_TE | QSPI_FLAG_TC));
- /* Configure size and pointer of the handle */
- hqspi->TxXferSize = hqspi->TxXferCount;
- hqspi->pTxBuffPtr = pData;
- /* Configure QSPI: CCR register with functional mode as indirect write */
- MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE);
- /* Set the QSPI DMA transfer complete callback */
- hqspi->hdma->XferCpltCallback = QSPI_DMATxCplt;
- /* Set the QSPI DMA Half transfer complete callback */
- hqspi->hdma->XferHalfCpltCallback = QSPI_DMATxHalfCplt;
- /* Set the DMA error callback */
- hqspi->hdma->XferErrorCallback = QSPI_DMAError;
- /* Clear the DMA abort callback */
- hqspi->hdma->XferAbortCallback = NULL;
- #if defined (QSPI1_V2_1L)
- /* Bug "ES0305 section 2.1.8 In some specific cases, DMA2 data corruption occurs when managing
- AHB and APB2 peripherals in a concurrent way" Workaround Implementation:
- Change the following configuration of DMA peripheral
- - Enable peripheral increment
- - Disable memory increment
- - Set DMA direction as peripheral to memory mode */
- /* Enable peripheral increment mode of the DMA */
- hqspi->hdma->Init.PeriphInc = DMA_PINC_ENABLE;
- /* Disable memory increment mode of the DMA */
- hqspi->hdma->Init.MemInc = DMA_MINC_DISABLE;
-
- /* Update peripheral/memory increment mode bits */
- MODIFY_REG(hqspi->hdma->Instance->CR, (DMA_SxCR_MINC | DMA_SxCR_PINC), (hqspi->hdma->Init.MemInc | hqspi->hdma->Init.PeriphInc));
- /* Configure the direction of the DMA */
- hqspi->hdma->Init.Direction = DMA_PERIPH_TO_MEMORY;
- #else
- /* Configure the direction of the DMA */
- hqspi->hdma->Init.Direction = DMA_MEMORY_TO_PERIPH;
- #endif /* QSPI1_V2_1L */
- /* Update direction mode bit */
- MODIFY_REG(hqspi->hdma->Instance->CR, DMA_SxCR_DIR, hqspi->hdma->Init.Direction);
- /* Enable the QSPI transmit DMA Channel */
- tmp = (uint32_t*)&pData;
- HAL_DMA_Start_IT(hqspi->hdma, *(uint32_t*)tmp, (uint32_t)&hqspi->Instance->DR, hqspi->TxXferSize);
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- /* Enable the QSPI transfer error Interrupt */
- __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TE);
- /* Enable the DMA transfer by setting the DMAEN bit in the QSPI CR register */
- SET_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN);
- }
- }
- else
- {
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM;
- status = HAL_ERROR;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- }
- else
- {
- status = HAL_BUSY;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- return status;
- }
- /**
- * @brief Receives an amount of data in non blocking mode with DMA.
- * @param hqspi QSPI handle
- * @param pData pointer to data buffer.
- * @note This function is used only in Indirect Read Mode
- * @note If DMA peripheral access is configured as halfword, the number
- * of data and the fifo threshold should be aligned on halfword
- * @note If DMA peripheral access is configured as word, the number
- * of data and the fifo threshold should be aligned on word
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_Receive_DMA(QSPI_HandleTypeDef *hqspi, uint8_t *pData)
- {
- HAL_StatusTypeDef status = HAL_OK;
- uint32_t *tmp;
- uint32_t addr_reg = READ_REG(hqspi->Instance->AR);
- uint32_t data_size = (READ_REG(hqspi->Instance->DLR) + 1U);
- /* Process locked */
- __HAL_LOCK(hqspi);
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
- if(pData != NULL )
- {
- /* Configure counters of the handle */
- if (hqspi->hdma->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
- {
- hqspi->RxXferCount = data_size;
- }
- else if (hqspi->hdma->Init.PeriphDataAlignment == DMA_PDATAALIGN_HALFWORD)
- {
- if (((data_size % 2U) != 0U) || ((hqspi->Init.FifoThreshold % 2U) != 0U))
- {
- /* The number of data or the fifo threshold is not aligned on halfword
- => no transfer possible with DMA peripheral access configured as halfword */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM;
- status = HAL_ERROR;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- else
- {
- hqspi->RxXferCount = (data_size >> 1U);
- }
- }
- else if (hqspi->hdma->Init.PeriphDataAlignment == DMA_PDATAALIGN_WORD)
- {
- if (((data_size % 4U) != 0U) || ((hqspi->Init.FifoThreshold % 4U) != 0U))
- {
- /* The number of data or the fifo threshold is not aligned on word
- => no transfer possible with DMA peripheral access configured as word */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM;
- status = HAL_ERROR;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- else
- {
- hqspi->RxXferCount = (data_size >> 2U);
- }
- }
- if (status == HAL_OK)
- {
- /* Update state */
- hqspi->State = HAL_QSPI_STATE_BUSY_INDIRECT_RX;
- /* Clear interrupt */
- __HAL_QSPI_CLEAR_FLAG(hqspi, (QSPI_FLAG_TE | QSPI_FLAG_TC));
- /* Configure size and pointer of the handle */
- hqspi->RxXferSize = hqspi->RxXferCount;
- hqspi->pRxBuffPtr = pData;
- /* Set the QSPI DMA transfer complete callback */
- hqspi->hdma->XferCpltCallback = QSPI_DMARxCplt;
- /* Set the QSPI DMA Half transfer complete callback */
- hqspi->hdma->XferHalfCpltCallback = QSPI_DMARxHalfCplt;
- /* Set the DMA error callback */
- hqspi->hdma->XferErrorCallback = QSPI_DMAError;
- /* Clear the DMA abort callback */
- hqspi->hdma->XferAbortCallback = NULL;
- #if defined (QSPI1_V2_1L)
- /* Bug "ES0305 section 2.1.8 In some specific cases, DMA2 data corruption occurs when managing
- AHB and APB2 peripherals in a concurrent way" Workaround Implementation:
- Change the following configuration of DMA peripheral
- - Enable peripheral increment
- - Disable memory increment
- - Set DMA direction as memory to peripheral mode
- - 4 Extra words (32-bits) are added for read operation to guarantee
- the last data is transferred from DMA FIFO to RAM memory */
- /* Enable peripheral increment of the DMA */
- hqspi->hdma->Init.PeriphInc = DMA_PINC_ENABLE;
- /* Disable memory increment of the DMA */
- hqspi->hdma->Init.MemInc = DMA_MINC_DISABLE;
- /* Update peripheral/memory increment mode bits */
- MODIFY_REG(hqspi->hdma->Instance->CR, (DMA_SxCR_MINC | DMA_SxCR_PINC), (hqspi->hdma->Init.MemInc | hqspi->hdma->Init.PeriphInc));
- /* Configure the direction of the DMA */
- hqspi->hdma->Init.Direction = DMA_MEMORY_TO_PERIPH;
- /* 4 Extra words (32-bits) are needed for read operation to guarantee
- the last data is transferred from DMA FIFO to RAM memory */
- WRITE_REG(hqspi->Instance->DLR, (data_size - 1U + 16U));
- /* Update direction mode bit */
- MODIFY_REG(hqspi->hdma->Instance->CR, DMA_SxCR_DIR, hqspi->hdma->Init.Direction);
- /* Configure QSPI: CCR register with functional as indirect read */
- MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_READ);
- /* Start the transfer by re-writing the address in AR register */
- WRITE_REG(hqspi->Instance->AR, addr_reg);
- /* Enable the DMA Channel */
- tmp = (uint32_t*)&pData;
- HAL_DMA_Start_IT(hqspi->hdma, (uint32_t)&hqspi->Instance->DR, *(uint32_t*)tmp, hqspi->RxXferSize);
- /* Enable the DMA transfer by setting the DMAEN bit in the QSPI CR register */
- SET_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN);
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- /* Enable the QSPI transfer error Interrupt */
- __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TE);
- #else
- /* Configure the direction of the DMA */
- hqspi->hdma->Init.Direction = DMA_PERIPH_TO_MEMORY;
- MODIFY_REG(hqspi->hdma->Instance->CR, DMA_SxCR_DIR, hqspi->hdma->Init.Direction);
- /* Enable the DMA Channel */
- tmp = (uint32_t*)&pData;
- HAL_DMA_Start_IT(hqspi->hdma, (uint32_t)&hqspi->Instance->DR, *(uint32_t*)tmp, hqspi->RxXferSize);
- /* Configure QSPI: CCR register with functional as indirect read */
- MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_READ);
- /* Start the transfer by re-writing the address in AR register */
- WRITE_REG(hqspi->Instance->AR, addr_reg);
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- /* Enable the QSPI transfer error Interrupt */
- __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TE);
- /* Enable the DMA transfer by setting the DMAEN bit in the QSPI CR register */
- SET_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN);
- #endif /* QSPI1_V2_1L */
- }
- }
- else
- {
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM;
- status = HAL_ERROR;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- }
- else
- {
- status = HAL_BUSY;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- return status;
- }
- /**
- * @brief Configure the QSPI Automatic Polling Mode in blocking mode.
- * @param hqspi QSPI handle
- * @param cmd structure that contains the command configuration information.
- * @param cfg structure that contains the polling configuration information.
- * @param Timeout Time out duration
- * @note This function is used only in Automatic Polling Mode
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_AutoPolling(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, QSPI_AutoPollingTypeDef *cfg, uint32_t Timeout)
- {
- HAL_StatusTypeDef status = HAL_ERROR;
- uint32_t tickstart = HAL_GetTick();
-
- /* Check the parameters */
- assert_param(IS_QSPI_INSTRUCTION_MODE(cmd->InstructionMode));
- if (cmd->InstructionMode != QSPI_INSTRUCTION_NONE)
- {
- assert_param(IS_QSPI_INSTRUCTION(cmd->Instruction));
- }
-
- assert_param(IS_QSPI_ADDRESS_MODE(cmd->AddressMode));
- if (cmd->AddressMode != QSPI_ADDRESS_NONE)
- {
- assert_param(IS_QSPI_ADDRESS_SIZE(cmd->AddressSize));
- }
-
- assert_param(IS_QSPI_ALTERNATE_BYTES_MODE(cmd->AlternateByteMode));
- if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE)
- {
- assert_param(IS_QSPI_ALTERNATE_BYTES_SIZE(cmd->AlternateBytesSize));
- }
-
- assert_param(IS_QSPI_DUMMY_CYCLES(cmd->DummyCycles));
- assert_param(IS_QSPI_DATA_MODE(cmd->DataMode));
-
- assert_param(IS_QSPI_DDR_MODE(cmd->DdrMode));
- assert_param(IS_QSPI_DDR_HHC(cmd->DdrHoldHalfCycle));
- assert_param(IS_QSPI_SIOO_MODE(cmd->SIOOMode));
-
- assert_param(IS_QSPI_INTERVAL(cfg->Interval));
- assert_param(IS_QSPI_STATUS_BYTES_SIZE(cfg->StatusBytesSize));
- assert_param(IS_QSPI_MATCH_MODE(cfg->MatchMode));
-
- /* Process locked */
- __HAL_LOCK(hqspi);
-
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
-
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
-
- /* Update state */
- hqspi->State = HAL_QSPI_STATE_BUSY_AUTO_POLLING;
-
- /* Wait till BUSY flag reset */
- status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_BUSY, RESET, tickstart, Timeout);
-
- if (status == HAL_OK)
- {
- /* Configure QSPI: PSMAR register with the status match value */
- WRITE_REG(hqspi->Instance->PSMAR, cfg->Match);
-
- /* Configure QSPI: PSMKR register with the status mask value */
- WRITE_REG(hqspi->Instance->PSMKR, cfg->Mask);
-
- /* Configure QSPI: PIR register with the interval value */
- WRITE_REG(hqspi->Instance->PIR, cfg->Interval);
-
- /* Configure QSPI: CR register with Match mode and Automatic stop enabled
- (otherwise there will be an infinite loop in blocking mode) */
- MODIFY_REG(hqspi->Instance->CR, (QUADSPI_CR_PMM | QUADSPI_CR_APMS),
- (cfg->MatchMode | QSPI_AUTOMATIC_STOP_ENABLE));
-
- /* Call the configuration function */
- cmd->NbData = cfg->StatusBytesSize;
- QSPI_Config(hqspi, cmd, QSPI_FUNCTIONAL_MODE_AUTO_POLLING);
-
- /* Wait until SM flag is set to go back in idle state */
- status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_SM, SET, tickstart, Timeout);
- if (status == HAL_OK)
- {
- __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_SM);
-
- /* Update state */
- hqspi->State = HAL_QSPI_STATE_READY;
- }
- }
- }
- else
- {
- status = HAL_BUSY;
- }
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
-
- /* Return function status */
- return status;
- }
- /**
- * @brief Configure the QSPI Automatic Polling Mode in non-blocking mode.
- * @param hqspi QSPI handle
- * @param cmd structure that contains the command configuration information.
- * @param cfg structure that contains the polling configuration information.
- * @note This function is used only in Automatic Polling Mode
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_AutoPolling_IT(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, QSPI_AutoPollingTypeDef *cfg)
- {
- __IO uint32_t count = 0U;
- HAL_StatusTypeDef status = HAL_OK;
-
- /* Check the parameters */
- assert_param(IS_QSPI_INSTRUCTION_MODE(cmd->InstructionMode));
- if (cmd->InstructionMode != QSPI_INSTRUCTION_NONE)
- {
- assert_param(IS_QSPI_INSTRUCTION(cmd->Instruction));
- }
-
- assert_param(IS_QSPI_ADDRESS_MODE(cmd->AddressMode));
- if (cmd->AddressMode != QSPI_ADDRESS_NONE)
- {
- assert_param(IS_QSPI_ADDRESS_SIZE(cmd->AddressSize));
- }
-
- assert_param(IS_QSPI_ALTERNATE_BYTES_MODE(cmd->AlternateByteMode));
- if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE)
- {
- assert_param(IS_QSPI_ALTERNATE_BYTES_SIZE(cmd->AlternateBytesSize));
- }
-
- assert_param(IS_QSPI_DUMMY_CYCLES(cmd->DummyCycles));
- assert_param(IS_QSPI_DATA_MODE(cmd->DataMode));
-
- assert_param(IS_QSPI_DDR_MODE(cmd->DdrMode));
- assert_param(IS_QSPI_DDR_HHC(cmd->DdrHoldHalfCycle));
- assert_param(IS_QSPI_SIOO_MODE(cmd->SIOOMode));
-
- assert_param(IS_QSPI_INTERVAL(cfg->Interval));
- assert_param(IS_QSPI_STATUS_BYTES_SIZE(cfg->StatusBytesSize));
- assert_param(IS_QSPI_MATCH_MODE(cfg->MatchMode));
- assert_param(IS_QSPI_AUTOMATIC_STOP(cfg->AutomaticStop));
-
- /* Process locked */
- __HAL_LOCK(hqspi);
-
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
-
- /* Update state */
- hqspi->State = HAL_QSPI_STATE_BUSY_AUTO_POLLING;
- /* Wait till BUSY flag reset */
- count = (hqspi->Timeout) * (SystemCoreClock / 16U / 1000U);
- do
- {
- if (count-- == 0U)
- {
- hqspi->State = HAL_QSPI_STATE_ERROR;
- hqspi->ErrorCode |= HAL_QSPI_ERROR_TIMEOUT;
- status = HAL_TIMEOUT;
- }
- }
- while ((__HAL_QSPI_GET_FLAG(hqspi, QSPI_FLAG_BUSY)) != RESET);
-
- if (status == HAL_OK)
- {
- /* Configure QSPI: PSMAR register with the status match value */
- WRITE_REG(hqspi->Instance->PSMAR, cfg->Match);
-
- /* Configure QSPI: PSMKR register with the status mask value */
- WRITE_REG(hqspi->Instance->PSMKR, cfg->Mask);
-
- /* Configure QSPI: PIR register with the interval value */
- WRITE_REG(hqspi->Instance->PIR, cfg->Interval);
-
- /* Configure QSPI: CR register with Match mode and Automatic stop mode */
- MODIFY_REG(hqspi->Instance->CR, (QUADSPI_CR_PMM | QUADSPI_CR_APMS),
- (cfg->MatchMode | cfg->AutomaticStop));
-
- /* Clear interrupt */
- __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TE | QSPI_FLAG_SM);
-
- /* Call the configuration function */
- cmd->NbData = cfg->StatusBytesSize;
- QSPI_Config(hqspi, cmd, QSPI_FUNCTIONAL_MODE_AUTO_POLLING);
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
-
- /* Enable the QSPI Transfer Error and status match Interrupt */
- __HAL_QSPI_ENABLE_IT(hqspi, (QSPI_IT_SM | QSPI_IT_TE));
- }
- else
- {
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
- }
- else
- {
- status = HAL_BUSY;
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- }
-
- /* Return function status */
- return status;
- }
- /**
- * @brief Configure the Memory Mapped mode.
- * @param hqspi QSPI handle
- * @param cmd structure that contains the command configuration information.
- * @param cfg structure that contains the memory mapped configuration information.
- * @note This function is used only in Memory mapped Mode
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_MemoryMapped(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, QSPI_MemoryMappedTypeDef *cfg)
- {
- HAL_StatusTypeDef status = HAL_ERROR;
- uint32_t tickstart = HAL_GetTick();
-
- /* Check the parameters */
- assert_param(IS_QSPI_INSTRUCTION_MODE(cmd->InstructionMode));
- if (cmd->InstructionMode != QSPI_INSTRUCTION_NONE)
- {
- assert_param(IS_QSPI_INSTRUCTION(cmd->Instruction));
- }
- assert_param(IS_QSPI_ADDRESS_MODE(cmd->AddressMode));
- if (cmd->AddressMode != QSPI_ADDRESS_NONE)
- {
- assert_param(IS_QSPI_ADDRESS_SIZE(cmd->AddressSize));
- }
- assert_param(IS_QSPI_ALTERNATE_BYTES_MODE(cmd->AlternateByteMode));
- if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE)
- {
- assert_param(IS_QSPI_ALTERNATE_BYTES_SIZE(cmd->AlternateBytesSize));
- }
- assert_param(IS_QSPI_DUMMY_CYCLES(cmd->DummyCycles));
- assert_param(IS_QSPI_DATA_MODE(cmd->DataMode));
- assert_param(IS_QSPI_DDR_MODE(cmd->DdrMode));
- assert_param(IS_QSPI_DDR_HHC(cmd->DdrHoldHalfCycle));
- assert_param(IS_QSPI_SIOO_MODE(cmd->SIOOMode));
- assert_param(IS_QSPI_TIMEOUT_ACTIVATION(cfg->TimeOutActivation));
-
- /* Process locked */
- __HAL_LOCK(hqspi);
-
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- hqspi->ErrorCode = HAL_QSPI_ERROR_NONE;
-
- /* Update state */
- hqspi->State = HAL_QSPI_STATE_BUSY_MEM_MAPPED;
-
- /* Wait till BUSY flag reset */
- status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_BUSY, RESET, tickstart, hqspi->Timeout);
-
- if (status == HAL_OK)
- {
- /* Configure QSPI: CR register with timeout counter enable */
- MODIFY_REG(hqspi->Instance->CR, QUADSPI_CR_TCEN, cfg->TimeOutActivation);
- if (cfg->TimeOutActivation == QSPI_TIMEOUT_COUNTER_ENABLE)
- {
- assert_param(IS_QSPI_TIMEOUT_PERIOD(cfg->TimeOutPeriod));
-
- /* Configure QSPI: LPTR register with the low-power timeout value */
- WRITE_REG(hqspi->Instance->LPTR, cfg->TimeOutPeriod);
-
- /* Clear interrupt */
- __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TO);
- /* Enable the QSPI TimeOut Interrupt */
- __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TO);
- }
-
- /* Call the configuration function */
- QSPI_Config(hqspi, cmd, QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED);
- }
- }
- else
- {
- status = HAL_BUSY;
- }
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
-
- /* Return function status */
- return status;
- }
- /**
- * @brief Transfer Error callbacks
- * @param hqspi QSPI handle
- * @retval None
- */
- __weak void HAL_QSPI_ErrorCallback(QSPI_HandleTypeDef *hqspi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hqspi);
-
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_QSPI_ErrorCallback could be implemented in the user file
- */
- }
- /**
- * @brief Abort completed callback.
- * @param hqspi QSPI handle
- * @retval None
- */
- __weak void HAL_QSPI_AbortCpltCallback(QSPI_HandleTypeDef *hqspi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hqspi);
- /* NOTE: This function should not be modified, when the callback is needed,
- the HAL_QSPI_AbortCpltCallback could be implemented in the user file
- */
- }
- /**
- * @brief Command completed callback.
- * @param hqspi QSPI handle
- * @retval None
- */
- __weak void HAL_QSPI_CmdCpltCallback(QSPI_HandleTypeDef *hqspi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hqspi);
-
- /* NOTE: This function Should not be modified, when the callback is needed,
- the HAL_QSPI_CmdCpltCallback could be implemented in the user file
- */
- }
- /**
- * @brief Rx Transfer completed callbacks.
- * @param hqspi QSPI handle
- * @retval None
- */
- __weak void HAL_QSPI_RxCpltCallback(QSPI_HandleTypeDef *hqspi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hqspi);
-
- /* NOTE: This function Should not be modified, when the callback is needed,
- the HAL_QSPI_RxCpltCallback could be implemented in the user file
- */
- }
- /**
- * @brief Tx Transfer completed callbacks.
- * @param hqspi QSPI handle
- * @retval None
- */
- __weak void HAL_QSPI_TxCpltCallback(QSPI_HandleTypeDef *hqspi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hqspi);
-
- /* NOTE: This function Should not be modified, when the callback is needed,
- the HAL_QSPI_TxCpltCallback could be implemented in the user file
- */
- }
- /**
- * @brief Rx Half Transfer completed callbacks.
- * @param hqspi QSPI handle
- * @retval None
- */
- __weak void HAL_QSPI_RxHalfCpltCallback(QSPI_HandleTypeDef *hqspi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hqspi);
-
- /* NOTE: This function Should not be modified, when the callback is needed,
- the HAL_QSPI_RxHalfCpltCallback could be implemented in the user file
- */
- }
- /**
- * @brief Tx Half Transfer completed callbacks.
- * @param hqspi QSPI handle
- * @retval None
- */
- __weak void HAL_QSPI_TxHalfCpltCallback(QSPI_HandleTypeDef *hqspi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hqspi);
-
- /* NOTE: This function Should not be modified, when the callback is needed,
- the HAL_QSPI_TxHalfCpltCallback could be implemented in the user file
- */
- }
- /**
- * @brief FIFO Threshold callbacks
- * @param hqspi QSPI handle
- * @retval None
- */
- __weak void HAL_QSPI_FifoThresholdCallback(QSPI_HandleTypeDef *hqspi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hqspi);
-
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_QSPI_FIFOThresholdCallback could be implemented in the user file
- */
- }
- /**
- * @brief Status Match callbacks
- * @param hqspi QSPI handle
- * @retval None
- */
- __weak void HAL_QSPI_StatusMatchCallback(QSPI_HandleTypeDef *hqspi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hqspi);
-
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_QSPI_StatusMatchCallback could be implemented in the user file
- */
- }
- /**
- * @brief Timeout callbacks
- * @param hqspi QSPI handle
- * @retval None
- */
- __weak void HAL_QSPI_TimeOutCallback(QSPI_HandleTypeDef *hqspi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hqspi);
-
- /* NOTE : This function Should not be modified, when the callback is needed,
- the HAL_QSPI_TimeOutCallback could be implemented in the user file
- */
- }
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- /**
- * @brief Register a User QSPI Callback
- * To be used instead of the weak (surcharged) predefined callback
- * @param hqspi : QSPI handle
- * @param CallbackId : ID of the callback to be registered
- * This parameter can be one of the following values:
- * @arg @ref HAL_QSPI_ERROR_CB_ID QSPI Error Callback ID
- * @arg @ref HAL_QSPI_ABORT_CB_ID QSPI Abort Callback ID
- * @arg @ref HAL_QSPI_FIFO_THRESHOLD_CB_ID QSPI FIFO Threshold Callback ID
- * @arg @ref HAL_QSPI_CMD_CPLT_CB_ID QSPI Command Complete Callback ID
- * @arg @ref HAL_QSPI_RX_CPLT_CB_ID QSPI Rx Complete Callback ID
- * @arg @ref HAL_QSPI_TX_CPLT_CB_ID QSPI Tx Complete Callback ID
- * @arg @ref HAL_QSPI_RX_HALF_CPLT_CB_ID QSPI Rx Half Complete Callback ID
- * @arg @ref HAL_QSPI_TX_HALF_CPLT_CB_ID QSPI Tx Half Complete Callback ID
- * @arg @ref HAL_QSPI_STATUS_MATCH_CB_ID QSPI Status Match Callback ID
- * @arg @ref HAL_QSPI_TIMEOUT_CB_ID QSPI Timeout Callback ID
- * @arg @ref HAL_QSPI_MSP_INIT_CB_ID QSPI MspInit callback ID
- * @arg @ref HAL_QSPI_MSP_DEINIT_CB_ID QSPI MspDeInit callback ID
- * @param pCallback : pointer to the Callback function
- * @retval status
- */
- HAL_StatusTypeDef HAL_QSPI_RegisterCallback (QSPI_HandleTypeDef *hqspi, HAL_QSPI_CallbackIDTypeDef CallbackId, pQSPI_CallbackTypeDef pCallback)
- {
- HAL_StatusTypeDef status = HAL_OK;
- if(pCallback == NULL)
- {
- /* Update the error code */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK;
- return HAL_ERROR;
- }
- /* Process locked */
- __HAL_LOCK(hqspi);
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- switch (CallbackId)
- {
- case HAL_QSPI_ERROR_CB_ID :
- hqspi->ErrorCallback = pCallback;
- break;
- case HAL_QSPI_ABORT_CB_ID :
- hqspi->AbortCpltCallback = pCallback;
- break;
- case HAL_QSPI_FIFO_THRESHOLD_CB_ID :
- hqspi->FifoThresholdCallback = pCallback;
- break;
- case HAL_QSPI_CMD_CPLT_CB_ID :
- hqspi->CmdCpltCallback = pCallback;
- break;
- case HAL_QSPI_RX_CPLT_CB_ID :
- hqspi->RxCpltCallback = pCallback;
- break;
- case HAL_QSPI_TX_CPLT_CB_ID :
- hqspi->TxCpltCallback = pCallback;
- break;
- case HAL_QSPI_RX_HALF_CPLT_CB_ID :
- hqspi->RxHalfCpltCallback = pCallback;
- break;
- case HAL_QSPI_TX_HALF_CPLT_CB_ID :
- hqspi->TxHalfCpltCallback = pCallback;
- break;
- case HAL_QSPI_STATUS_MATCH_CB_ID :
- hqspi->StatusMatchCallback = pCallback;
- break;
- case HAL_QSPI_TIMEOUT_CB_ID :
- hqspi->TimeOutCallback = pCallback;
- break;
- case HAL_QSPI_MSP_INIT_CB_ID :
- hqspi->MspInitCallback = pCallback;
- break;
- case HAL_QSPI_MSP_DEINIT_CB_ID :
- hqspi->MspDeInitCallback = pCallback;
- break;
- default :
- /* Update the error code */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK;
- /* update return status */
- status = HAL_ERROR;
- break;
- }
- }
- else if (hqspi->State == HAL_QSPI_STATE_RESET)
- {
- switch (CallbackId)
- {
- case HAL_QSPI_MSP_INIT_CB_ID :
- hqspi->MspInitCallback = pCallback;
- break;
- case HAL_QSPI_MSP_DEINIT_CB_ID :
- hqspi->MspDeInitCallback = pCallback;
- break;
- default :
- /* Update the error code */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK;
- /* update return status */
- status = HAL_ERROR;
- break;
- }
- }
- else
- {
- /* Update the error code */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK;
- /* update return status */
- status = HAL_ERROR;
- }
- /* Release Lock */
- __HAL_UNLOCK(hqspi);
- return status;
- }
- /**
- * @brief Unregister a User QSPI Callback
- * QSPI Callback is redirected to the weak (surcharged) predefined callback
- * @param hqspi : QSPI handle
- * @param CallbackId : ID of the callback to be unregistered
- * This parameter can be one of the following values:
- * @arg @ref HAL_QSPI_ERROR_CB_ID QSPI Error Callback ID
- * @arg @ref HAL_QSPI_ABORT_CB_ID QSPI Abort Callback ID
- * @arg @ref HAL_QSPI_FIFO_THRESHOLD_CB_ID QSPI FIFO Threshold Callback ID
- * @arg @ref HAL_QSPI_CMD_CPLT_CB_ID QSPI Command Complete Callback ID
- * @arg @ref HAL_QSPI_RX_CPLT_CB_ID QSPI Rx Complete Callback ID
- * @arg @ref HAL_QSPI_TX_CPLT_CB_ID QSPI Tx Complete Callback ID
- * @arg @ref HAL_QSPI_RX_HALF_CPLT_CB_ID QSPI Rx Half Complete Callback ID
- * @arg @ref HAL_QSPI_TX_HALF_CPLT_CB_ID QSPI Tx Half Complete Callback ID
- * @arg @ref HAL_QSPI_STATUS_MATCH_CB_ID QSPI Status Match Callback ID
- * @arg @ref HAL_QSPI_TIMEOUT_CB_ID QSPI Timeout Callback ID
- * @arg @ref HAL_QSPI_MSP_INIT_CB_ID QSPI MspInit callback ID
- * @arg @ref HAL_QSPI_MSP_DEINIT_CB_ID QSPI MspDeInit callback ID
- * @retval status
- */
- HAL_StatusTypeDef HAL_QSPI_UnRegisterCallback (QSPI_HandleTypeDef *hqspi, HAL_QSPI_CallbackIDTypeDef CallbackId)
- {
- HAL_StatusTypeDef status = HAL_OK;
- /* Process locked */
- __HAL_LOCK(hqspi);
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- switch (CallbackId)
- {
- case HAL_QSPI_ERROR_CB_ID :
- hqspi->ErrorCallback = HAL_QSPI_ErrorCallback;
- break;
- case HAL_QSPI_ABORT_CB_ID :
- hqspi->AbortCpltCallback = HAL_QSPI_AbortCpltCallback;
- break;
- case HAL_QSPI_FIFO_THRESHOLD_CB_ID :
- hqspi->FifoThresholdCallback = HAL_QSPI_FifoThresholdCallback;
- break;
- case HAL_QSPI_CMD_CPLT_CB_ID :
- hqspi->CmdCpltCallback = HAL_QSPI_CmdCpltCallback;
- break;
- case HAL_QSPI_RX_CPLT_CB_ID :
- hqspi->RxCpltCallback = HAL_QSPI_RxCpltCallback;
- break;
- case HAL_QSPI_TX_CPLT_CB_ID :
- hqspi->TxCpltCallback = HAL_QSPI_TxCpltCallback;
- break;
- case HAL_QSPI_RX_HALF_CPLT_CB_ID :
- hqspi->RxHalfCpltCallback = HAL_QSPI_RxHalfCpltCallback;
- break;
- case HAL_QSPI_TX_HALF_CPLT_CB_ID :
- hqspi->TxHalfCpltCallback = HAL_QSPI_TxHalfCpltCallback;
- break;
- case HAL_QSPI_STATUS_MATCH_CB_ID :
- hqspi->StatusMatchCallback = HAL_QSPI_StatusMatchCallback;
- break;
- case HAL_QSPI_TIMEOUT_CB_ID :
- hqspi->TimeOutCallback = HAL_QSPI_TimeOutCallback;
- break;
- case HAL_QSPI_MSP_INIT_CB_ID :
- hqspi->MspInitCallback = HAL_QSPI_MspInit;
- break;
- case HAL_QSPI_MSP_DEINIT_CB_ID :
- hqspi->MspDeInitCallback = HAL_QSPI_MspDeInit;
- break;
- default :
- /* Update the error code */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK;
- /* update return status */
- status = HAL_ERROR;
- break;
- }
- }
- else if (hqspi->State == HAL_QSPI_STATE_RESET)
- {
- switch (CallbackId)
- {
- case HAL_QSPI_MSP_INIT_CB_ID :
- hqspi->MspInitCallback = HAL_QSPI_MspInit;
- break;
- case HAL_QSPI_MSP_DEINIT_CB_ID :
- hqspi->MspDeInitCallback = HAL_QSPI_MspDeInit;
- break;
- default :
- /* Update the error code */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK;
- /* update return status */
- status = HAL_ERROR;
- break;
- }
- }
- else
- {
- /* Update the error code */
- hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK;
- /* update return status */
- status = HAL_ERROR;
- }
- /* Release Lock */
- __HAL_UNLOCK(hqspi);
- return status;
- }
- #endif
- /**
- * @}
- */
- /** @defgroup QSPI_Exported_Functions_Group3 Peripheral Control and State functions
- * @brief QSPI control and State functions
- *
- @verbatim
- ===============================================================================
- ##### Peripheral Control and State functions #####
- ===============================================================================
- [..]
- This subsection provides a set of functions allowing to :
- (+) Check in run-time the state of the driver.
- (+) Check the error code set during last operation.
- (+) Abort any operation.
- @endverbatim
- * @{
- */
- /**
- * @brief Return the QSPI handle state.
- * @param hqspi QSPI handle
- * @retval HAL state
- */
- HAL_QSPI_StateTypeDef HAL_QSPI_GetState(QSPI_HandleTypeDef *hqspi)
- {
- /* Return QSPI handle state */
- return hqspi->State;
- }
- /**
- * @brief Return the QSPI error code
- * @param hqspi QSPI handle
- * @retval QSPI Error Code
- */
- uint32_t HAL_QSPI_GetError(QSPI_HandleTypeDef *hqspi)
- {
- return hqspi->ErrorCode;
- }
- /**
- * @brief Abort the current transmission
- * @param hqspi QSPI handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_Abort(QSPI_HandleTypeDef *hqspi)
- {
- HAL_StatusTypeDef status = HAL_OK;
- uint32_t tickstart = HAL_GetTick();
-
- /* Check if the state is in one of the busy states */
- if ((hqspi->State & 0x2U) != 0U)
- {
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- if ((hqspi->Instance->CR & QUADSPI_CR_DMAEN)!= RESET)
- {
- /* Disable the DMA transfer by clearing the DMAEN bit in the QSPI CR register */
- CLEAR_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN);
-
- /* Abort DMA channel */
- status = HAL_DMA_Abort(hqspi->hdma);
- if(status != HAL_OK)
- {
- hqspi->ErrorCode |= HAL_QSPI_ERROR_DMA;
- }
- }
-
- /* Configure QSPI: CR register with Abort request */
- SET_BIT(hqspi->Instance->CR, QUADSPI_CR_ABORT);
-
- /* Wait until TC flag is set to go back in idle state */
- status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_TC, SET, tickstart, hqspi->Timeout);
- if(status == HAL_OK)
- {
- __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TC);
-
- /* Wait until BUSY flag is reset */
- status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_BUSY, RESET, tickstart, hqspi->Timeout);
- }
-
- if (status == HAL_OK)
- {
- /* Update state */
- hqspi->State = HAL_QSPI_STATE_READY;
- }
- }
- return status;
- }
- /**
- * @brief Abort the current transmission (non-blocking function)
- * @param hqspi QSPI handle
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_Abort_IT(QSPI_HandleTypeDef *hqspi)
- {
- HAL_StatusTypeDef status = HAL_OK;
-
- /* Check if the state is in one of the busy states */
- if ((hqspi->State & 0x2U) != 0U)
- {
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
-
- /* Update QSPI state */
- hqspi->State = HAL_QSPI_STATE_ABORT;
-
- /* Disable all interrupts */
- __HAL_QSPI_DISABLE_IT(hqspi, (QSPI_IT_TO | QSPI_IT_SM | QSPI_IT_FT | QSPI_IT_TC | QSPI_IT_TE));
-
- if ((hqspi->Instance->CR & QUADSPI_CR_DMAEN)!= RESET)
- {
- /* Disable the DMA transfer by clearing the DMAEN bit in the QSPI CR register */
- CLEAR_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN);
-
- /* Abort DMA channel */
- hqspi->hdma->XferAbortCallback = QSPI_DMAAbortCplt;
- if (HAL_DMA_Abort_IT(hqspi->hdma) != HAL_OK)
- {
- /* Change state of QSPI */
- hqspi->State = HAL_QSPI_STATE_READY;
-
- /* Abort Complete callback */
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->AbortCpltCallback(hqspi);
- #else
- HAL_QSPI_AbortCpltCallback(hqspi);
- #endif
- }
- }
- else
- {
- /* Clear interrupt */
- __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TC);
-
- /* Enable the QSPI Transfer Complete Interrupt */
- __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TC);
-
- /* Configure QSPI: CR register with Abort request */
- SET_BIT(hqspi->Instance->CR, QUADSPI_CR_ABORT);
- }
- }
- return status;
- }
- /** @brief Set QSPI timeout
- * @param hqspi QSPI handle.
- * @param Timeout Timeout for the QSPI memory access.
- * @retval None
- */
- void HAL_QSPI_SetTimeout(QSPI_HandleTypeDef *hqspi, uint32_t Timeout)
- {
- hqspi->Timeout = Timeout;
- }
- /** @brief Set QSPI Fifo threshold.
- * @param hqspi QSPI handle.
- * @param Threshold Threshold of the Fifo (value between 1 and 16).
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_QSPI_SetFifoThreshold(QSPI_HandleTypeDef *hqspi, uint32_t Threshold)
- {
- HAL_StatusTypeDef status = HAL_OK;
- /* Process locked */
- __HAL_LOCK(hqspi);
- if(hqspi->State == HAL_QSPI_STATE_READY)
- {
- /* Synchronize init structure with new FIFO threshold value */
- hqspi->Init.FifoThreshold = Threshold;
-
- /* Configure QSPI FIFO Threshold */
- MODIFY_REG(hqspi->Instance->CR, QUADSPI_CR_FTHRES,
- ((hqspi->Init.FifoThreshold - 1U) << QUADSPI_CR_FTHRES_Pos));
- }
- else
- {
- status = HAL_BUSY;
- }
-
- /* Process unlocked */
- __HAL_UNLOCK(hqspi);
- /* Return function status */
- return status;
- }
- /** @brief Get QSPI Fifo threshold.
- * @param hqspi QSPI handle.
- * @retval Fifo threshold (value between 1 and 16)
- */
- uint32_t HAL_QSPI_GetFifoThreshold(QSPI_HandleTypeDef *hqspi)
- {
- return ((READ_BIT(hqspi->Instance->CR, QUADSPI_CR_FTHRES) >> QUADSPI_CR_FTHRES_Pos) + 1U);
- }
- /**
- * @}
- */
- /* Private functions ---------------------------------------------------------*/
-
- /**
- * @brief DMA QSPI receive process complete callback.
- * @param hdma DMA handle
- * @retval None
- */
- static void QSPI_DMARxCplt(DMA_HandleTypeDef *hdma)
- {
- QSPI_HandleTypeDef* hqspi = ( QSPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
- hqspi->RxXferCount = 0U;
-
- /* Enable the QSPI transfer complete Interrupt */
- __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TC);
- }
- /**
- * @brief DMA QSPI transmit process complete callback.
- * @param hdma DMA handle
- * @retval None
- */
- static void QSPI_DMATxCplt(DMA_HandleTypeDef *hdma)
- {
- QSPI_HandleTypeDef* hqspi = ( QSPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
- hqspi->TxXferCount = 0U;
-
- /* Enable the QSPI transfer complete Interrupt */
- __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TC);
- }
- /**
- * @brief DMA QSPI receive process half complete callback
- * @param hdma DMA handle
- * @retval None
- */
- static void QSPI_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
- {
- QSPI_HandleTypeDef* hqspi = (QSPI_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->RxHalfCpltCallback(hqspi);
- #else
- HAL_QSPI_RxHalfCpltCallback(hqspi);
- #endif
- }
- /**
- * @brief DMA QSPI transmit process half complete callback
- * @param hdma DMA handle
- * @retval None
- */
- static void QSPI_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
- {
- QSPI_HandleTypeDef* hqspi = (QSPI_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
- #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1)
- hqspi->TxHalfCpltCallback(hqspi);
- #else
- HAL_QSPI_TxHalfCpltCallback(hqspi);
- #endif
- }
- /**
- * @brief DMA QSPI communication error callback.
- * @param hdma DMA handle
- * @retval None
- */
- static void QSPI_DMAError(DMA_HandleTypeDef *hdma)
- {
- QSPI_HandleTypeDef* hqspi = ( QSPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
-
- /* if DMA error is FIFO error ignore it */
- if(HAL_DMA_GetError(hdma) != HAL_DMA_ERROR_FE)
- {
- hqspi->RxXferCount = 0U;
- hqspi->TxXferCount = 0U;
- hqspi->ErrorCode |= HAL_QSPI_ERROR_DMA;
-
- /* Disable the DMA transfer by clearing the DMAEN bit in the QSPI CR register */
- CLEAR_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN);
-
- /* Abort the QSPI */
- HAL_QSPI_Abort_IT(hqspi);
- }
- }
- /**
- * @brief DMA QSPI abort complete callback.
- * @param hdma DMA handle
- * @retval None
- */
- static void QSPI_DMAAbortCplt(DMA_HandleTypeDef *hdma)
- {
- QSPI_HandleTypeDef* hqspi = ( QSPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
- hqspi->RxXferCount = 0U;
- hqspi->TxXferCount = 0U;
- if(hqspi->State == HAL_QSPI_STATE_ABORT)
- {
- /* DMA Abort called by QSPI abort */
- /* Clear interrupt */
- __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TC);
-
- /* Enable the QSPI Transfer Complete Interrupt */
- __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TC);
-
- /* Configure QSPI: CR register with Abort request */
- SET_BIT(hqspi->Instance->CR, QUADSPI_CR_ABORT);
- }
- else
- {
- /* DMA Abort called due to a transfer error interrupt */
- /* Change state of QSPI */
- hqspi->State = HAL_QSPI_STATE_READY;
-
- /* Error callback */
- HAL_QSPI_ErrorCallback(hqspi);
- }
- }
- /**
- * @brief Wait for a flag state until timeout.
- * @param hqspi QSPI handle
- * @param Flag Flag checked
- * @param State Value of the flag expected
- * @param Timeout Duration of the time out
- * @param tickstart tick start value
- * @retval HAL status
- */
- static HAL_StatusTypeDef QSPI_WaitFlagStateUntilTimeout(QSPI_HandleTypeDef *hqspi, uint32_t Flag,
- FlagStatus State, uint32_t tickstart, uint32_t Timeout)
- {
- /* Wait until flag is in expected state */
- while((FlagStatus)(__HAL_QSPI_GET_FLAG(hqspi, Flag)) != State)
- {
- /* Check for the Timeout */
- if (Timeout != HAL_MAX_DELAY)
- {
- if((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout))
- {
- hqspi->State = HAL_QSPI_STATE_ERROR;
- hqspi->ErrorCode |= HAL_QSPI_ERROR_TIMEOUT;
-
- return HAL_ERROR;
- }
- }
- }
- return HAL_OK;
- }
- /**
- * @brief Configure the communication registers.
- * @param hqspi QSPI handle
- * @param cmd structure that contains the command configuration information
- * @param FunctionalMode functional mode to configured
- * This parameter can be one of the following values:
- * @arg QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE: Indirect write mode
- * @arg QSPI_FUNCTIONAL_MODE_INDIRECT_READ: Indirect read mode
- * @arg QSPI_FUNCTIONAL_MODE_AUTO_POLLING: Automatic polling mode
- * @arg QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED: Memory-mapped mode
- * @retval None
- */
- static void QSPI_Config(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, uint32_t FunctionalMode)
- {
- assert_param(IS_QSPI_FUNCTIONAL_MODE(FunctionalMode));
- if ((cmd->DataMode != QSPI_DATA_NONE) && (FunctionalMode != QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED))
- {
- /* Configure QSPI: DLR register with the number of data to read or write */
- WRITE_REG(hqspi->Instance->DLR, (cmd->NbData - 1U));
- }
-
- if (cmd->InstructionMode != QSPI_INSTRUCTION_NONE)
- {
- if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE)
- {
- /* Configure QSPI: ABR register with alternate bytes value */
- WRITE_REG(hqspi->Instance->ABR, cmd->AlternateBytes);
- if (cmd->AddressMode != QSPI_ADDRESS_NONE)
- {
- /*---- Command with instruction, address and alternate bytes ----*/
- /* Configure QSPI: CCR register with all communications parameters */
- WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode |
- cmd->DataMode | (cmd->DummyCycles << 18U) | cmd->AlternateBytesSize |
- cmd->AlternateByteMode | cmd->AddressSize | cmd->AddressMode |
- cmd->InstructionMode | cmd->Instruction | FunctionalMode));
- if (FunctionalMode != QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED)
- {
- /* Configure QSPI: AR register with address value */
- WRITE_REG(hqspi->Instance->AR, cmd->Address);
- }
- }
- else
- {
- /*---- Command with instruction and alternate bytes ----*/
- /* Configure QSPI: CCR register with all communications parameters */
- WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode |
- cmd->DataMode | (cmd->DummyCycles << 18U) | cmd->AlternateBytesSize |
- cmd->AlternateByteMode | cmd->AddressMode | cmd->InstructionMode |
- cmd->Instruction | FunctionalMode));
- }
- }
- else
- {
- if (cmd->AddressMode != QSPI_ADDRESS_NONE)
- {
- /*---- Command with instruction and address ----*/
- /* Configure QSPI: CCR register with all communications parameters */
- WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode |
- cmd->DataMode | (cmd->DummyCycles << 18U) | cmd->AlternateByteMode |
- cmd->AddressSize | cmd->AddressMode | cmd->InstructionMode |
- cmd->Instruction | FunctionalMode));
- if (FunctionalMode != QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED)
- {
- /* Configure QSPI: AR register with address value */
- WRITE_REG(hqspi->Instance->AR, cmd->Address);
- }
- }
- else
- {
- /*---- Command with only instruction ----*/
- /* Configure QSPI: CCR register with all communications parameters */
- WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode |
- cmd->DataMode | (cmd->DummyCycles << 18U) | cmd->AlternateByteMode |
- cmd->AddressMode | cmd->InstructionMode | cmd->Instruction |
- FunctionalMode));
- }
- }
- }
- else
- {
- if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE)
- {
- /* Configure QSPI: ABR register with alternate bytes value */
- WRITE_REG(hqspi->Instance->ABR, cmd->AlternateBytes);
- if (cmd->AddressMode != QSPI_ADDRESS_NONE)
- {
- /*---- Command with address and alternate bytes ----*/
- /* Configure QSPI: CCR register with all communications parameters */
- WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode |
- cmd->DataMode | (cmd->DummyCycles << 18U) | cmd->AlternateBytesSize |
- cmd->AlternateByteMode | cmd->AddressSize | cmd->AddressMode |
- cmd->InstructionMode | FunctionalMode));
- if (FunctionalMode != QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED)
- {
- /* Configure QSPI: AR register with address value */
- WRITE_REG(hqspi->Instance->AR, cmd->Address);
- }
- }
- else
- {
- /*---- Command with only alternate bytes ----*/
- /* Configure QSPI: CCR register with all communications parameters */
- WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode |
- cmd->DataMode | (cmd->DummyCycles << 18U) | cmd->AlternateBytesSize |
- cmd->AlternateByteMode | cmd->AddressMode | cmd->InstructionMode |
- FunctionalMode));
- }
- }
- else
- {
- if (cmd->AddressMode != QSPI_ADDRESS_NONE)
- {
- /*---- Command with only address ----*/
- /* Configure QSPI: CCR register with all communications parameters */
- WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode |
- cmd->DataMode | (cmd->DummyCycles << 18U) | cmd->AlternateByteMode |
- cmd->AddressSize | cmd->AddressMode | cmd->InstructionMode |
- FunctionalMode));
- if (FunctionalMode != QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED)
- {
- /* Configure QSPI: AR register with address value */
- WRITE_REG(hqspi->Instance->AR, cmd->Address);
- }
- }
- else
- {
- /*---- Command with only data phase ----*/
- if (cmd->DataMode != QSPI_DATA_NONE)
- {
- /* Configure QSPI: CCR register with all communications parameters */
- WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode |
- cmd->DataMode | (cmd->DummyCycles << 18U) | cmd->AlternateByteMode |
- cmd->AddressMode | cmd->InstructionMode | FunctionalMode));
- }
- }
- }
- }
- }
- /**
- * @}
- */
- #endif /* STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Vx || STM32F412Rx
- STM32F413xx || STM32F423xx */
- #endif /* HAL_QSPI_MODULE_ENABLED */
- /**
- * @}
- */
- /**
- * @}
- */
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|