1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792 |
- /**
- ******************************************************************************
- * @file stm32l4xx_hal_pssi.c
- * @author MCD Application Team
- * @brief PSSI HAL module driver.
- * This file provides firmware functions to manage the following
- * functionalities of the Parallel Synchronous Slave Interface (PSSI) peripheral:
- * + Initialization and de-initialization functions
- * + IO operation functions
- * + Peripheral State and Errors functions
- *
- ******************************************************************************
- * @attention
- *
- * Copyright (c) 2019 STMicroelectronics.
- * All rights reserved.
- *
- * This software is licensed under terms that can be found in the LICENSE file
- * in the root directory of this software component.
- * If no LICENSE file comes with this software, it is provided AS-IS.
- *
- ******************************************************************************
- @verbatim
- ==============================================================================
- ##### How to use this driver #####
- ==============================================================================
- [..]
- The PSSI HAL driver can be used as follows:
- (#) Declare a PSSI_HandleTypeDef handle structure, for example:
- PSSI_HandleTypeDef hpssi;
- (#) Initialize the PSSI low level resources by implementing the @ref HAL_PSSI_MspInit() API:
- (##) Enable the PSSIx interface clock
- (##) PSSI pins configuration
- (+++) Enable the clock for the PSSI GPIOs
- (+++) Configure PSSI pins as alternate function open-drain
- (##) NVIC configuration if you need to use interrupt process
- (+++) Configure the PSSIx interrupt priority
- (+++) Enable the NVIC PSSI IRQ Channel
- (##) DMA Configuration if you need to use DMA process
- (+++) Declare DMA_HandleTypeDef handles structure for the transmit and receive
- (+++) Enable the DMAx interface clock
- (+++) Configure the DMA handle parameters
- (+++) Configure the DMA Tx and Rx
- (+++) Associate the initialized DMA handle to the hpssi DMA Tx and Rx handle
- (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on
- the DMA Tx and Rx
- (#) Configure the Communication Bus Width, Control Signals, Input Polarity and Output Polarity
- in the hpssi Init structure.
- (#) Initialize the PSSI registers by calling the @ref HAL_PSSI_Init(), configure also the low level Hardware
- (GPIO, CLOCK, NVIC...etc) by calling the customized @ref HAL_PSSI_MspInit(&hpssi) API.
- (#) For PSSI IO operations, two operation modes are available within this driver :
- *** Polling mode IO operation ***
- =================================
- [..]
- (+) Transmit an amount of data by byte in blocking mode using @ref HAL_PSSI_Transmit()
- (+) Receive an amount of data by byte in blocking mode using @ref HAL_PSSI_Receive()
- *** DMA mode IO operation ***
- ==============================
- [..]
- (+) Transmit an amount of data in non-blocking mode (DMA) using
- @ref HAL_PSSI_Transmit_DMA()
- (+) At transmission end of transfer, @ref HAL_PSSI_TxCpltCallback() is executed and user can
- add his own code by customization of function pointer @ref HAL_PSSI_TxCpltCallback()
- (+) Receive an amount of data in non-blocking mode (DMA) using
- @ref HAL_PSSI_Receive_DMA()
- (+) At reception end of transfer, @ref HAL_PSSI_RxCpltCallback() is executed and user can
- add his own code by customization of function pointer @ref HAL_PSSI_RxCpltCallback()
- (+) In case of transfer Error, @ref HAL_PSSI_ErrorCallback() function is executed and user can
- add his own code by customization of function pointer @ref HAL_PSSI_ErrorCallback()
- (+) Abort a PSSI process communication with Interrupt using @ref HAL_PSSI_Abort_IT()
- (+) End of abort process, @ref HAL_PSSI_AbortCpltCallback() is executed and user can
- add his own code by customization of function pointer @ref HAL_PSSI_AbortCpltCallback()
- *** PSSI HAL driver macros list ***
- ==================================
- [..]
- Below the list of most used macros in PSSI HAL driver.
- (+) @ref HAL_PSSI_ENABLE : Enable the PSSI peripheral
- (+) @ref HAL_PSSI_DISABLE : Disable the PSSI peripheral
- (+) @ref HAL_PSSI_GET_FLAG : Check whether the specified PSSI flag is set or not
- (+) @ref HAL_PSSI_CLEAR_FLAG : Clear the specified PSSI pending flag
- (+) @ref HAL_PSSI_ENABLE_IT : Enable the specified PSSI interrupt
- (+) @ref HAL_PSSI_DISABLE_IT : Disable the specified PSSI interrupt
- *** Callback registration ***
- =============================================
- Use Functions @ref HAL_PSSI_RegisterCallback() or @ref HAL_PSSI_RegisterAddrCallback()
- to register an interrupt callback.
- Function @ref HAL_PSSI_RegisterCallback() allows to register following callbacks:
- (+) TxCpltCallback : callback for transmission end of transfer.
- (+) RxCpltCallback : callback for reception end of transfer.
- (+) ErrorCallback : callback for error detection.
- (+) AbortCpltCallback : callback for abort completion process.
- (+) MspInitCallback : callback for Msp Init.
- (+) MspDeInitCallback : callback for Msp DeInit.
- This function takes as parameters the HAL peripheral handle, the Callback ID
- and a pointer to the user callback function.
- Use function @ref HAL_PSSI_UnRegisterCallback to reset a callback to the default
- weak function.
- @ref HAL_PSSI_UnRegisterCallback takes as parameters the HAL peripheral handle,
- and the Callback ID.
- This function allows to reset following callbacks:
- (+) TxCpltCallback : callback for transmission end of transfer.
- (+) RxCpltCallback : callback for reception end of transfer.
- (+) ErrorCallback : callback for error detection.
- (+) AbortCpltCallback : callback for abort completion process.
- (+) MspInitCallback : callback for Msp Init.
- (+) MspDeInitCallback : callback for Msp DeInit.
- By default, after the @ref HAL_PSSI_Init() and when the state is @ref HAL_PSSI_STATE_RESET
- all callbacks are set to the corresponding weak functions:
- examples @ref HAL_PSSI_TxCpltCallback(), @ref HAL_PSSI_RxCpltCallback().
- Exception done for MspInit and MspDeInit functions that are
- reset to the legacy weak functions in the @ref HAL_PSSI_Init()/ @ref HAL_PSSI_DeInit() only when
- these callbacks are null (not registered beforehand).
- If MspInit or MspDeInit are not null, the @ref HAL_PSSI_Init()/ @ref HAL_PSSI_DeInit()
- keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
- Callbacks can be registered/unregistered in @ref HAL_PSSI_STATE_READY state only.
- Exception for MspInit/MspDeInit functions that can be registered/unregistered
- in @ref HAL_PSSI_STATE_READY or @ref HAL_PSSI_STATE_RESET state,
- thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
- Then, the user first registers the MspInit/MspDeInit user callbacks
- using @ref HAL_PSSI_RegisterCallback() before calling @ref HAL_PSSI_DeInit()
- or @ref HAL_PSSI_Init() function.
- [..]
- (@) You can refer to the PSSI HAL driver header file for more useful macros
- @endverbatim
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm32l4xx_hal.h"
- /** @addtogroup STM32L4xx_HAL_Driver
- * @{
- */
- #if defined(PSSI)
- /** @addtogroup PSSI PSSI
- * @brief PSSI HAL module driver
- * @{
- */
- #ifdef HAL_PSSI_MODULE_ENABLED
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------*/
- /** @defgroup PSSI_Private_Functions PSSI Private Functions
- * @{
- */
- /* Private functions to handle DMA transfer */
- void PSSI_DMATransmitCplt(DMA_HandleTypeDef *hdma);
- void PSSI_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
- void PSSI_DMAError(DMA_HandleTypeDef *hdma);
- void PSSI_DMAAbort(DMA_HandleTypeDef *hdma);
- /* Private functions to handle IT transfer */
- static void PSSI_Error(PSSI_HandleTypeDef *hpssi, uint32_t ErrorCode);
- /* Private functions for PSSI transfer IRQ handler */
- /* Private functions to handle flags during polling transfer */
- static HAL_StatusTypeDef PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef *hpssi, uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart);
- /**
- * @}
- */
- /* Exported functions --------------------------------------------------------*/
- /** @addtogroup PSSI_Exported_Functions PSSI Exported Functions
- * @{
- */
- /** @addtogroup PSSI_Exported_Functions_Group1 Initialization and de-initialization functions
- * @brief Initialization and Configuration functions
- *
- @verbatim
- ===============================================================================
- ##### Initialization and de-initialization functions #####
- ===============================================================================
- [..] This subsection provides a set of functions allowing to initialize and
- de-initialize the PSSIx peripheral:
- (+) User must implement HAL_PSSI_MspInit() function in which he configures
- all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
- (+) Call the function HAL_PSSI_Init() to configure the selected device with
- the selected configuration:
- (++) Data Width
- (++) Control Signals
- (++) Input Clock polarity
- (++) Output Clock polarity
- (+) Call the function HAL_PSSI_DeInit() to restore the default configuration
- of the selected PSSIx peripheral.
- @endverbatim
- * @{
- */
- /**
- * @brief Initializes the PSSI according to the specified parameters
- * in the PSSI_InitTypeDef and initializes the associated handle.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_PSSI_Init(PSSI_HandleTypeDef *hpssi)
- {
- /* Check the PSSI handle allocation */
- if (hpssi == NULL)
- {
- return HAL_ERROR;
- }
- /* Check the parameters */
- assert_param(IS_PSSI_ALL_INSTANCE(hpssi->Instance));
- assert_param(IS_PSSI_CONTROL_SIGNAL(hpssi->Init.ControlSignal));
- assert_param(IS_PSSI_BUSWIDTH(hpssi->Init.BusWidth));
- assert_param(IS_PSSI_CLOCK_POLARITY(hpssi->Init.ClockPolarity));
- assert_param(IS_PSSI_DE_POLARITY(hpssi->Init.DataEnablePolarity));
- assert_param(IS_PSSI_RDY_POLARITY(hpssi->Init.ReadyPolarity));
- if (hpssi->State == HAL_PSSI_STATE_RESET)
- {
- /* Allocate lock resource and initialize it */
- hpssi->Lock = HAL_UNLOCKED;
- /* Init the PSSI Callback settings */
- hpssi->TxCpltCallback = HAL_PSSI_TxCpltCallback; /* Legacy weak TxCpltCallback */
- hpssi->RxCpltCallback = HAL_PSSI_RxCpltCallback; /* Legacy weak RxCpltCallback */
- hpssi->ErrorCallback = HAL_PSSI_ErrorCallback; /* Legacy weak ErrorCallback */
- hpssi->AbortCpltCallback = HAL_PSSI_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
- if (hpssi->MspInitCallback == NULL)
- {
- hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit */
- }
- /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
- hpssi->MspInitCallback(hpssi);
- }
- hpssi->State = HAL_PSSI_STATE_BUSY;
- /* Disable the selected PSSI peripheral */
- HAL_PSSI_DISABLE(hpssi);
- /*---------------------------- PSSIx CR Configuration ----------------------*/
- /* Configure PSSIx: Control Signal and Bus Width*/
- MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DERDYCFG|PSSI_CR_EDM|PSSI_CR_DEPOL|PSSI_CR_RDYPOL,
- hpssi->Init.ControlSignal|hpssi->Init.DataEnablePolarity|hpssi->Init.ReadyPolarity|hpssi->Init.BusWidth);
- hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
- hpssi->State = HAL_PSSI_STATE_READY;
- return HAL_OK;
- }
- /**
- * @brief De-Initialize the PSSI peripheral.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_PSSI_DeInit(PSSI_HandleTypeDef *hpssi)
- {
- /* Check the PSSI handle allocation */
- if (hpssi == NULL)
- {
- return HAL_ERROR;
- }
- /* Check the parameters */
- assert_param(IS_PSSI_ALL_INSTANCE(hpssi->Instance));
- hpssi->State = HAL_PSSI_STATE_BUSY;
- /* Disable the PSSI Peripheral Clock */
- HAL_PSSI_DISABLE(hpssi);
- if (hpssi->MspDeInitCallback == NULL)
- {
- hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit */
- }
- /* De-Init the low level hardware: GPIO, CLOCK, NVIC */
- hpssi->MspDeInitCallback(hpssi);
- hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
- hpssi->State = HAL_PSSI_STATE_RESET;
- /* Release Lock */
- __HAL_UNLOCK(hpssi);
- return HAL_OK;
- }
- /**
- * @brief Initialize the PSSI MSP.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @retval None
- */
- __weak void HAL_PSSI_MspInit(PSSI_HandleTypeDef *hpssi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hpssi);
- /* NOTE : This function should not be modified; when the callback is needed,
- the HAL_PSSI_MspInit can be implemented in the user file
- */
- }
- /**
- * @brief De-Initialize the PSSI MSP.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @retval None
- */
- __weak void HAL_PSSI_MspDeInit(PSSI_HandleTypeDef *hpssi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hpssi);
- /* NOTE : This function should not be modified; when the callback is needed,
- the HAL_PSSI_MspDeInit can be implemented in the user file
- */
- }
- /**
- * @brief Register a User PSSI Callback
- * To be used instead of the weak predefined callback
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @param CallbackID ID of the callback to be registered
- * This parameter can be one of the following values:
- * @arg @ref HAL_PSSI_TX_COMPLETE_CB_ID Tx Transfer completed callback ID
- * @arg @ref HAL_PSSI_RX_COMPLETE_CB_ID Rx Transfer completed callback ID
- * @arg @ref HAL_PSSI_ERROR_CB_ID Error callback ID
- * @arg @ref HAL_PSSI_ABORT_CB_ID Abort callback ID
- * @arg @ref HAL_PSSI_MSPINIT_CB_ID MspInit callback ID
- * @arg @ref HAL_PSSI_MSPDEINIT_CB_ID MspDeInit callback ID
- * @param pCallback pointer to the Callback function
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_PSSI_RegisterCallback(PSSI_HandleTypeDef *hpssi, HAL_PSSI_CallbackIDTypeDef CallbackID, pPSSI_CallbackTypeDef pCallback)
- {
- HAL_StatusTypeDef status = HAL_OK;
- if (pCallback == NULL)
- {
- /* Update the error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
- return HAL_ERROR;
- }
- /* Process locked */
- __HAL_LOCK(hpssi);
- if (HAL_PSSI_STATE_READY == hpssi->State)
- {
- switch (CallbackID)
- {
- case HAL_PSSI_TX_COMPLETE_CB_ID :
- hpssi->TxCpltCallback = pCallback;
- break;
- case HAL_PSSI_RX_COMPLETE_CB_ID :
- hpssi->RxCpltCallback = pCallback;
- break;
- case HAL_PSSI_ERROR_CB_ID :
- hpssi->ErrorCallback = pCallback;
- break;
- case HAL_PSSI_ABORT_CB_ID :
- hpssi->AbortCpltCallback = pCallback;
- break;
- case HAL_PSSI_MSPINIT_CB_ID :
- hpssi->MspInitCallback = pCallback;
- break;
- case HAL_PSSI_MSPDEINIT_CB_ID :
- hpssi->MspDeInitCallback = pCallback;
- break;
- default :
- /* Update the error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
- /* Return error status */
- status = HAL_ERROR;
- break;
- }
- }
- else if (HAL_PSSI_STATE_RESET == hpssi->State)
- {
- switch (CallbackID)
- {
- case HAL_PSSI_MSPINIT_CB_ID :
- hpssi->MspInitCallback = pCallback;
- break;
- case HAL_PSSI_MSPDEINIT_CB_ID :
- hpssi->MspDeInitCallback = pCallback;
- break;
- default :
- /* Update the error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
- /* Return error status */
- status = HAL_ERROR;
- break;
- }
- }
- else
- {
- /* Update the error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
- /* Return error status */
- status = HAL_ERROR;
- }
- /* Release Lock */
- __HAL_UNLOCK(hpssi);
- return status;
- }
- /**
- * @brief Unregister a PSSI Callback
- * PSSI callback is redirected to the weak predefined callback
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @param CallbackID ID of the callback to be unregistered
- * This parameter can be one of the following values:
- * @arg @ref HAL_PSSI_TX_COMPLETE_CB_ID Tx Transfer completed callback ID
- * @arg @ref HAL_PSSI_RX_COMPLETE_CB_ID Rx Transfer completed callback ID
- * @arg @ref HAL_PSSI_ERROR_CB_ID Error callback ID
- * @arg @ref HAL_PSSI_ABORT_CB_ID Abort callback ID
- * @arg @ref HAL_PSSI_MSPINIT_CB_ID MspInit callback ID
- * @arg @ref HAL_PSSI_MSPDEINIT_CB_ID MspDeInit callback ID
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_PSSI_UnRegisterCallback(PSSI_HandleTypeDef *hpssi, HAL_PSSI_CallbackIDTypeDef CallbackID)
- {
- HAL_StatusTypeDef status = HAL_OK;
- /* Process locked */
- __HAL_LOCK(hpssi);
- if (HAL_PSSI_STATE_READY == hpssi->State)
- {
- switch (CallbackID)
- {
- case HAL_PSSI_TX_COMPLETE_CB_ID :
- hpssi->TxCpltCallback = HAL_PSSI_TxCpltCallback; /* Legacy weak TxCpltCallback */
- break;
- case HAL_PSSI_RX_COMPLETE_CB_ID :
- hpssi->RxCpltCallback = HAL_PSSI_RxCpltCallback; /* Legacy weak RxCpltCallback */
- break;
- case HAL_PSSI_ERROR_CB_ID :
- hpssi->ErrorCallback = HAL_PSSI_ErrorCallback; /* Legacy weak ErrorCallback */
- break;
- case HAL_PSSI_ABORT_CB_ID :
- hpssi->AbortCpltCallback = HAL_PSSI_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
- break;
- case HAL_PSSI_MSPINIT_CB_ID :
- hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit */
- break;
- case HAL_PSSI_MSPDEINIT_CB_ID :
- hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit */
- break;
- default :
- /* Update the error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
- /* Return error status */
- status = HAL_ERROR;
- break;
- }
- }
- else if (HAL_PSSI_STATE_RESET == hpssi->State)
- {
- switch (CallbackID)
- {
- case HAL_PSSI_MSPINIT_CB_ID :
- hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit */
- break;
- case HAL_PSSI_MSPDEINIT_CB_ID :
- hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit */
- break;
- default :
- /* Update the error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
- /* Return error status */
- status = HAL_ERROR;
- break;
- }
- }
- else
- {
- /* Update the error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
- /* Return error status */
- status = HAL_ERROR;
- }
- /* Release Lock */
- __HAL_UNLOCK(hpssi);
- return status;
- }
- /**
- * @}
- */
- /** @addtogroup PSSI_Exported_Functions_Group2 Input and Output operation functions
- * @brief Data transfers functions
- *
- @verbatim
- ===============================================================================
- ##### IO operation functions #####
- ===============================================================================
- [..]
- This subsection provides a set of functions allowing to manage the PSSI data
- transfers.
- (#) There are two modes of transfer:
- (++) Blocking mode : The communication is performed in the polling mode.
- The status of all data processing is returned by the same function
- after finishing transfer.
- (++) No-Blocking mode : The communication is performed using DMA.
- These functions return the status of the transfer startup.
- The end of the data processing will be indicated through the
- dedicated DMA IRQ .
- (#) Blocking mode functions are :
- (++) HAL_PSSI_Transmit()
- (++) HAL_PSSI_Receive()
- (#) No-Blocking mode functions with DMA are :
- (++) HAL_PSSI_Transmit_DMA()
- (++) HAL_PSSI_Receive_DMA()
- (#) A set of callbacks are provided in non Blocking mode:
- (++) HAL_PSSI_TxCpltCallback()
- (++) HAL_PSSI_RxCpltCallback()
- (++) HAL_PSSI_ErrorCallback()
- (++) HAL_PSSI_AbortCpltCallback()
- @endverbatim
- * @{
- */
- /**
- * @brief Transmits in master mode an amount of data in blocking mode.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @param pData Pointer to data buffer
- * @param Size Amount of data to be sent (in bytes)
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_PSSI_Transmit(PSSI_HandleTypeDef *hpssi, uint8_t *pData, uint32_t Size, uint32_t Timeout)
- {
- uint32_t tickstart;
- uint32_t transfer_size = Size;
- if (((hpssi->Init.DataWidth == HAL_PSSI_8BITS) && (hpssi->Init.BusWidth != HAL_PSSI_8LINES)) ||
- ((hpssi->Init.DataWidth == HAL_PSSI_16BITS) && ((Size%2U) != 0U)) ||
- ((hpssi->Init.DataWidth == HAL_PSSI_32BITS) && ((Size%4U) != 0U)))
- {
- hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
- return HAL_ERROR;
- }
- if (hpssi->State == HAL_PSSI_STATE_READY)
- {
- /* Process Locked */
- __HAL_LOCK(hpssi);
- hpssi->State = HAL_PSSI_STATE_BUSY;
- hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
- /* Disable the selected PSSI peripheral */
- HAL_PSSI_DISABLE(hpssi);
- /* Configure transfer parameters */
- hpssi->Instance->CR |= PSSI_CR_OUTEN_OUTPUT |
- ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?0U:PSSI_CR_CKPOL);
- /* DMA Disable */
- hpssi->Instance->CR &= PSSI_CR_DMA_DISABLE;
- /* Enable the selected PSSI peripheral */
- HAL_PSSI_ENABLE(hpssi);
- if (hpssi->Init.DataWidth == HAL_PSSI_8BITS)
- {
- uint8_t *pbuffer = pData;
- while (transfer_size > 0U)
- {
- /* Init tickstart for timeout management*/
- tickstart = HAL_GetTick();
- /* Wait until Fifo is ready (until one byte flag is set) to transfer */
- if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT1B, RESET, Timeout, tickstart) != HAL_OK)
- {
- hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- /* Write data to DR */
- *(__IO uint8_t *)(&hpssi->Instance->DR) = *(uint8_t *)pbuffer;
- /* Increment Buffer pointer */
- pbuffer++;
- transfer_size--;
- }
- }
- else if (hpssi->Init.DataWidth == HAL_PSSI_16BITS)
- {
- uint8_t *pbuffer = pData;
- uint16_t data;
- while (transfer_size > 0U)
- {
- /* Init tickstart for timeout management*/
- tickstart = HAL_GetTick();
- /* Wait until Fifo is ready (until four bytes flag is set) to transfer */
- if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
- {
- hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- /* Write data to DR */
- data = (uint16_t)*pbuffer ;
- pbuffer++;
- data = (((uint16_t)*pbuffer) << 8U) | data;
- pbuffer++;
- *(__IO uint32_t *)((uint32_t)(&hpssi->Instance->DR)) = data;
- /* Decrement Transfer Size */
- transfer_size -= 2U;
- }
- }
- else if (hpssi->Init.DataWidth == HAL_PSSI_32BITS)
- {
- uint8_t *pbuffer = pData;
- uint32_t data;
- while (transfer_size > 0U)
- {
- /* Init tickstart for timeout management*/
- tickstart = HAL_GetTick();
- /* Wait until Fifo is ready (until four bytes flag is set) to transfer */
- if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
- {
- hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- /* Write data to DR */
- data = (uint32_t)*pbuffer ;
- pbuffer++;
- data = (((uint32_t)*pbuffer) << 8U) | data;
- pbuffer++;
- data = (((uint32_t)*pbuffer) << 16U) | data;
- pbuffer++;
- data = (((uint32_t)*pbuffer) << 24U) | data;
- pbuffer++;
- *(__IO uint32_t *)(&hpssi->Instance->DR) = data;
- /* Decrement Transfer Size */
- transfer_size -= 4U;
- }
- }
- else
- {
- hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- /* Check Errors Flags */
- if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_RIS) != 0U)
- {
- HAL_PSSI_CLEAR_FLAG(hpssi, PSSI_FLAG_OVR_RIS);
- HAL_PSSI_DISABLE(hpssi);
- hpssi->ErrorCode = HAL_PSSI_ERROR_UNDER_RUN;
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_OK;
- }
- else
- {
- return HAL_BUSY;
- }
- }
- /**
- * @brief Receives an amount of data in blocking mode.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @param pData Pointer to data buffer
- * @param Size Amount of data to be received (in bytes)
- * @param Timeout Timeout duration
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_PSSI_Receive(PSSI_HandleTypeDef *hpssi, uint8_t *pData, uint32_t Size, uint32_t Timeout)
- {
- uint32_t tickstart;
- uint32_t transfer_size = Size;
- if (((hpssi->Init.DataWidth == HAL_PSSI_8BITS) && (hpssi->Init.BusWidth != HAL_PSSI_8LINES)) ||
- ((hpssi->Init.DataWidth == HAL_PSSI_16BITS) && ((Size%2U) != 0U)) ||
- ((hpssi->Init.DataWidth == HAL_PSSI_32BITS) && ((Size%4U) != 0U)))
- {
- hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
- return HAL_ERROR;
- }
- if (hpssi->State == HAL_PSSI_STATE_READY)
- {
- /* Process Locked */
- __HAL_LOCK(hpssi);
- hpssi->State = HAL_PSSI_STATE_BUSY;
- hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
- /* Disable the selected PSSI peripheral */
- HAL_PSSI_DISABLE(hpssi);
- /* Configure transfer parameters */
- hpssi->Instance->CR |= PSSI_CR_OUTEN_INPUT |((hpssi->Init.ClockPolarity == HAL_PSSI_FALLING_EDGE)?0U:PSSI_CR_CKPOL);
-
-
- /* DMA Disable */
- hpssi->Instance->CR &= PSSI_CR_DMA_DISABLE;
- /* Enable the selected PSSI peripheral */
- HAL_PSSI_ENABLE(hpssi);
- if (hpssi->Init.DataWidth == HAL_PSSI_8BITS)
- {
- uint8_t *pbuffer = pData;
- while (transfer_size > 0U)
- {
- /* Init tickstart for timeout management*/
- tickstart = HAL_GetTick();
- /* Wait until Fifo is ready (until one byte flag is set) to receive */
- if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT1B, RESET, Timeout, tickstart) != HAL_OK)
- {
- hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- /* Read data from DR */
- *pbuffer = *(__IO uint8_t *)(&hpssi->Instance->DR);
- pbuffer++;
- transfer_size--;
- }
- }
- else if (hpssi->Init.DataWidth == HAL_PSSI_16BITS)
- {
- uint8_t *pbuffer = pData;
- uint16_t data;
- while (transfer_size > 0U)
- {
- /* Init tickstart for timeout management*/
- tickstart = HAL_GetTick();
- /* Wait until Fifo is ready (until four bytes flag is set) to receive */
- if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
- {
- hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- /* Read data from DR */
- data = *(__IO uint32_t *)((uint32_t)&hpssi->Instance->DR);
- *pbuffer = (uint8_t)(data & 0x0FFU);
- pbuffer++;
- *pbuffer = (uint8_t)(data >> 8U);
- pbuffer++;
- transfer_size -= 2U;
- }
- }
- else if (hpssi->Init.DataWidth == HAL_PSSI_32BITS)
- {
- uint8_t *pbuffer = pData;
- uint32_t data;
- while (transfer_size > 0U)
- {
- /* Init tickstart for timeout management*/
- tickstart = HAL_GetTick();
- /* Wait until Fifo is ready (until four bytes flag is set) to receive */
- if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
- {
- hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- /* Read data from DR */
- data = *(__IO uint32_t *)(&hpssi->Instance->DR);
- *pbuffer = (uint8_t)(data & 0x0FFU);
- pbuffer++;
- *pbuffer = (uint8_t)((data & 0x0FF00U) >> 8U);
- pbuffer++;
- *pbuffer = (uint8_t)((data & 0x0FF0000U) >> 16U);
- pbuffer++;
- *pbuffer = (uint8_t)((data & 0xFF000000U) >> 24U);
- pbuffer++;
- transfer_size -= 4U;
- }
- }
- else
- {
- hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- /* Check Errors Flags */
- if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_RIS) != 0U)
- {
- HAL_PSSI_CLEAR_FLAG(hpssi, PSSI_FLAG_OVR_RIS);
- hpssi->ErrorCode = HAL_PSSI_ERROR_OVER_RUN;
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_OK;
- }
- else
- {
- return HAL_BUSY;
- }
- }
- /**
- * @brief Transmit an amount of data in non-blocking mode with DMA
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @param pData Pointer to data buffer
- * @param Size Amount of data to be sent (in bytes)
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_PSSI_Transmit_DMA(PSSI_HandleTypeDef *hpssi, uint32_t *pData, uint32_t Size)
- {
- HAL_StatusTypeDef dmaxferstatus;
- if (hpssi->State == HAL_PSSI_STATE_READY)
- {
- /* Process Locked */
- __HAL_LOCK(hpssi);
- hpssi->State = HAL_PSSI_STATE_BUSY_TX;
- hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
- /* Disable the selected PSSI peripheral */
- HAL_PSSI_DISABLE(hpssi);
- /* Prepare transfer parameters */
- hpssi->pBuffPtr = pData;
- hpssi->XferCount = Size;
- if (hpssi->XferCount > PSSI_MAX_NBYTE_SIZE)
- {
- hpssi->XferSize = PSSI_MAX_NBYTE_SIZE;
- }
- else
- {
- hpssi->XferSize = hpssi->XferCount;
- }
- if (hpssi->XferSize > 0U)
- {
- if (hpssi->hdmatx != NULL)
- {
- /* Configure BusWidth */
- if( hpssi->hdmatx->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
- {
- MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DMAEN|PSSI_CR_OUTEN|PSSI_CR_CKPOL,PSSI_CR_DMA_ENABLE | PSSI_CR_OUTEN_OUTPUT |
- ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?0U:PSSI_CR_CKPOL));
- }
- else
- {
- MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DMAEN|PSSI_CR_OUTEN|PSSI_CR_CKPOL,PSSI_CR_DMA_ENABLE | hpssi->Init.BusWidth | PSSI_CR_OUTEN_OUTPUT |
- ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?0U:PSSI_CR_CKPOL));
- }
- /* Set the PSSI DMA transfer complete callback */
- hpssi->hdmatx->XferCpltCallback = PSSI_DMATransmitCplt;
- /* Set the DMA error callback */
- hpssi->hdmatx->XferErrorCallback = PSSI_DMAError;
- /* Set the unused DMA callbacks to NULL */
- hpssi->hdmatx->XferHalfCpltCallback = NULL;
- hpssi->hdmatx->XferAbortCallback = NULL;
- /* Enable the DMA */
- dmaxferstatus = HAL_DMA_Start_IT(hpssi->hdmatx, (uint32_t)pData, (uint32_t)&hpssi->Instance->DR, hpssi->XferSize);
- }
- else
- {
- /* Update PSSI state */
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Update PSSI error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- if (dmaxferstatus == HAL_OK)
- {
- /* Update XferCount value */
- hpssi->XferCount -= hpssi->XferSize;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Note : The PSSI interrupts must be enabled after unlocking current process
- to avoid the risk of PSSI interrupt handle execution before current
- process unlock */
- /* Enable ERR interrupt */
- HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
- /* Enable DMA Request */
- hpssi->Instance->CR |= PSSI_CR_DMA_ENABLE;
- /* Enable the selected PSSI peripheral */
- HAL_PSSI_ENABLE(hpssi);
- }
- else
- {
- /* Update PSSI state */
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Update PSSI error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- }
- else
- {
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Note : The PSSI interrupts must be enabled after unlocking current process
- to avoid the risk of PSSI interrupt handle execution before current
- process unlock */
- /* Enable ERRinterrupt */
- /* possible to enable all of these */
- HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
- }
- return HAL_OK;
- }
- else
- {
- return HAL_BUSY;
- }
- }
- /**
- * @brief Receive an amount of data in non-blocking mode with DMA
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @param pData Pointer to data buffer
- * @param Size Amount of data to be received (in bytes)
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_PSSI_Receive_DMA(PSSI_HandleTypeDef *hpssi, uint32_t *pData, uint32_t Size)
- {
- HAL_StatusTypeDef dmaxferstatus;
- if (hpssi->State == HAL_PSSI_STATE_READY)
- {
- /* Disable the selected PSSI peripheral */
- HAL_PSSI_DISABLE(hpssi);
- /* Process Locked */
- __HAL_LOCK(hpssi);
- hpssi->State = HAL_PSSI_STATE_BUSY_RX;
- hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
- /* Prepare transfer parameters */
- hpssi->pBuffPtr = pData;
- hpssi->XferCount = Size;
- if (hpssi->XferCount > PSSI_MAX_NBYTE_SIZE)
- {
- hpssi->XferSize = PSSI_MAX_NBYTE_SIZE;
- }
- else
- {
- hpssi->XferSize = hpssi->XferCount;
- }
- if (hpssi->XferSize > 0U)
- {
- if (hpssi->hdmarx != NULL)
- {
-
- /* Configure BusWidth */
- if( hpssi->hdmatx->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
- {
- MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DMAEN|PSSI_CR_OUTEN|PSSI_CR_CKPOL,PSSI_CR_DMA_ENABLE |
- ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?PSSI_CR_CKPOL:0U));
- }
- else
- {
- MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DMAEN|PSSI_CR_OUTEN|PSSI_CR_CKPOL,PSSI_CR_DMA_ENABLE | hpssi->Init.BusWidth |
- ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?PSSI_CR_CKPOL:0U));
- }
- /* Set the PSSI DMA transfer complete callback */
- hpssi->hdmarx->XferCpltCallback = PSSI_DMAReceiveCplt;
- /* Set the DMA error callback */
- hpssi->hdmarx->XferErrorCallback = PSSI_DMAError;
- /* Set the unused DMA callbacks to NULL */
- hpssi->hdmarx->XferHalfCpltCallback = NULL;
- hpssi->hdmarx->XferAbortCallback = NULL;
- /* Enable the DMA */
- dmaxferstatus = HAL_DMA_Start_IT(hpssi->hdmarx, (uint32_t)&hpssi->Instance->DR, (uint32_t)pData, hpssi->XferSize);
- }
- else
- {
- /* Update PSSI state */
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Update PSSI error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- if (dmaxferstatus == HAL_OK)
- {
- /* Update XferCount value */
- hpssi->XferCount -= hpssi->XferSize;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Note : The PSSI interrupts must be enabled after unlocking current process
- to avoid the risk of PSSI interrupt handle execution before current
- process unlock */
- /* Enable ERR interrupt */
- HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
- /* Enable DMA Request */
- hpssi->Instance->CR |= PSSI_CR_DMA_ENABLE;
- /* Enable the selected PSSI peripheral */
- HAL_PSSI_ENABLE(hpssi);
- }
- else
- {
- /* Update PSSI state */
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Update PSSI error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- }
- else
- {
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Enable ERR,interrupt */
- HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
- }
- return HAL_OK;
- }
- else
- {
- return HAL_BUSY;
- }
- }
- /**
- * @brief Abort a DMA process communication with Interrupt.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_PSSI_Abort_DMA(PSSI_HandleTypeDef *hpssi)
- {
- /* Process Locked */
- __HAL_LOCK(hpssi);
- /* Disable Interrupts */
- HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
- /* Set State at HAL_PSSI_STATE_ABORT */
- hpssi->State = HAL_PSSI_STATE_ABORT;
- /* Abort DMA TX transfer if any */
- if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
- {
- if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
- {
- hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
- if (hpssi->hdmatx != NULL)
- {
- /* Set the PSSI DMA Abort callback :
- will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
- hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
- /* Abort DMA TX */
- if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
- {
- /* Call Directly XferAbortCallback function in case of error */
- hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
- }
- }
- }
- /* Abort DMA RX transfer if any */
- else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
- {
- hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
- if (hpssi->hdmarx != NULL)
- {
- /* Set the PSSI DMA Abort callback :
- will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
- hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
- /* Abort DMA RX */
- if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
- {
- /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
- hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
- }
- }
- }
- else
- {
- /* Call the error callback */
- hpssi->ErrorCallback(hpssi);
- }
- }
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Note : The PSSI interrupts must be enabled after unlocking current process
- to avoid the risk of PSSI interrupt handle execution before current
- process unlock */
- HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
- return HAL_OK;
- }
- /**
- * @}
- */
- /** @addtogroup PSSI_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
- * @{
- */
- /**
- * @brief This function handles PSSI event interrupt request.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @retval None
- */
- void HAL_PSSI_IRQHandler(PSSI_HandleTypeDef *hpssi)
- {
- /* Overrun/ Underrun Errors */
- if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_MIS) != 0U)
- {
- /* Reset handle parameters */
- hpssi->XferCount = 0U;
- /* Disable all interrupts */
- HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
- /* Abort DMA TX transfer if any */
- if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
- {
- if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
- {
- /* Set new error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_UNDER_RUN;
- hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
- if (hpssi->hdmatx != NULL)
- {
- /* Set the PSSI DMA Abort callback :
- will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
- hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Abort DMA TX */
- if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
- {
- /* Call Directly XferAbortCallback function in case of error */
- hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
- }
- }
- }
- /* Abort DMA RX transfer if any */
- else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
- {
- /* Set new error code */
- hpssi->ErrorCode |= HAL_PSSI_ERROR_OVER_RUN;
- hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
- if (hpssi->hdmarx != NULL)
- {
- /* Set the PSSI DMA Abort callback :
- will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
- hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Abort DMA RX */
- if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
- {
- /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
- hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
- }
- }
- }
- else
- {
- /* Call the corresponding callback to inform upper layer of the error */
- hpssi->ErrorCallback(hpssi);
- }
- }
- /* If state is an abort treatment on going, don't change state */
- if (hpssi->State == HAL_PSSI_STATE_ABORT)
- {
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- }
- else
- {
- /* Set HAL_PSSI_STATE_READY */
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- hpssi->ErrorCallback(hpssi);
- }
- }
- }
- /**
- * @brief Tx Transfer complete callback.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @retval None
- */
- __weak void HAL_PSSI_TxCpltCallback(PSSI_HandleTypeDef *hpssi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hpssi);
- /* NOTE : This function should not be modified; when the callback is needed,
- the HAL_PSSI_TxCpltCallback can be implemented in the user file
- */
- }
- /**
- * @brief Rx Transfer complete callback.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @retval None
- */
- __weak void HAL_PSSI_RxCpltCallback(PSSI_HandleTypeDef *hpssi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hpssi);
- /* NOTE : This function should not be modified; when the callback is needed,
- the HAL_PSSI_RxCpltCallback can be implemented in the user file
- */
- }
- /**
- * @brief PSSI error callback.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @retval None
- */
- __weak void HAL_PSSI_ErrorCallback(PSSI_HandleTypeDef *hpssi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hpssi);
- /* NOTE : This function should not be modified; when the callback is needed,
- the HAL_PSSI_ErrorCallback can be implemented in the user file
- */
- }
- /**
- * @brief PSSI abort callback.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @retval None
- */
- __weak void HAL_PSSI_AbortCpltCallback(PSSI_HandleTypeDef *hpssi)
- {
- /* Prevent unused argument(s) compilation warning */
- UNUSED(hpssi);
- /* NOTE : This function should not be modified; when the callback is needed,
- the HAL_PSSI_AbortCpltCallback can be implemented in the user file
- */
- }
- /**
- * @}
- */
- /** @addtogroup PSSI_Exported_Functions_Group3 Peripheral State, Mode and Error functions
- * @brief Peripheral State, Mode and Error functions
- *
- @verbatim
- ===============================================================================
- ##### Peripheral State, Mode and Error functions #####
- ===============================================================================
- [..]
- This subsection permit to get in run-time the status of the peripheral
- and the data flow.
- @endverbatim
- * @{
- */
- /**
- * @brief Return the PSSI handle state.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @retval HAL state
- */
- HAL_PSSI_StateTypeDef HAL_PSSI_GetState(PSSI_HandleTypeDef *hpssi)
- {
- /* Return PSSI handle state */
- return hpssi->State;
- }
- /**
- * @brief Return the PSSI error code.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @retval PSSI Error Code
- */
- uint32_t HAL_PSSI_GetError(PSSI_HandleTypeDef *hpssi)
- {
- return hpssi->ErrorCode;
- }
- /**
- * @}
- */
- /**
- * @}
- */
- /** @addtogroup PSSI_Private_Functions
- * @{
- */
- /**
- * @brief PSSI Errors process.
- * @param hpssi PSSI handle.
- * @param ErrorCode Error code to handle.
- * @retval None
- */
- static void PSSI_Error(PSSI_HandleTypeDef *hpssi, uint32_t ErrorCode)
- {
- /* Reset handle parameters */
- hpssi->XferCount = 0U;
- /* Set new error code */
- hpssi->ErrorCode |= ErrorCode;
- /* Disable all interrupts */
- HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
- /* Abort DMA TX transfer if any */
- if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
- {
- if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
- {
- hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
- if (hpssi->hdmatx != NULL)
- {
- /* Set the PSSI DMA Abort callback :
- will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
- hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Abort DMA TX */
- if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
- {
- /* Call Directly XferAbortCallback function in case of error */
- hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
- }
- }
- }
- /* Abort DMA RX transfer if any */
- else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
- {
- hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
- if (hpssi->hdmarx != NULL)
- {
- /* Set the PSSI DMA Abort callback :
- will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
- hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Abort DMA RX */
- if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
- {
- /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
- hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
- }
- }
- }
- else
- {
- /*Nothing to do*/
- }
- }
- /* If state is an abort treatment on going, don't change state */
- if (hpssi->State == HAL_PSSI_STATE_ABORT)
- {
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- }
- else
- {
- /* Set HAL_PSSI_STATE_READY */
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- hpssi->ErrorCallback(hpssi);
- }
- }
- /**
- * @brief DMA PSSI slave transmit process complete callback.
- * @param hdma DMA handle
- * @retval None
- */
- void PSSI_DMATransmitCplt(DMA_HandleTypeDef *hdma)
- {
- PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
- uint32_t tmperror;
- /* Disable Interrupts */
- HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
- /* Store current volatile hpssi->ErrorCode, misra rule */
- tmperror = hpssi->ErrorCode;
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
- {
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- PSSI_Error(hpssi, hpssi->ErrorCode);
- }
- /* hpssi->State == HAL_PSSI_STATE_BUSY_TX */
- else
- {
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- hpssi->TxCpltCallback(hpssi);
- }
- }
- /**
- * @brief DMA PSSI master receive process complete callback.
- * @param hdma DMA handle
- * @retval None
- */
- void PSSI_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
- {
- PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
- uint32_t tmperror;
- /* Disable Interrupts */
- HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
- /* Store current volatile hpssi->ErrorCode, misra rule */
- tmperror = hpssi->ErrorCode;
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
- {
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- PSSI_Error(hpssi, hpssi->ErrorCode);
- }
- /* hpssi->State == HAL_PSSI_STATE_BUSY_RX */
- else
- {
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- hpssi->RxCpltCallback(hpssi);
- }
- }
- /**
- * @brief DMA PSSI communication abort callback
- * (To be called at end of DMA Abort procedure).
- * @param hdma DMA handle.
- * @retval None
- */
- void PSSI_DMAAbort(DMA_HandleTypeDef *hdma)
- {
- PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
- /* Reset AbortCpltCallback */
- hpssi->hdmatx->XferAbortCallback = NULL;
- hpssi->hdmarx->XferAbortCallback = NULL;
- /* Check if come from abort from user */
- if (hpssi->State == HAL_PSSI_STATE_ABORT)
- {
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- hpssi->AbortCpltCallback(hpssi);
- }
- else
- {
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- hpssi->ErrorCallback(hpssi);
- }
- }
- /**
- * @brief This function handles PSSI Communication Timeout.
- * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
- * the configuration information for the specified PSSI.
- * @param Flag Specifies the PSSI flag to check.
- * @param Status The new Flag status (SET or RESET).
- * @param Timeout Timeout duration
- * @param Tickstart Tick start value
- * @retval HAL status
- */
- static HAL_StatusTypeDef PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef *hpssi, uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart)
- {
- while ((HAL_PSSI_GET_STATUS(hpssi, Flag) & Flag) == (uint32_t)Status)
- {
- /* Check for the Timeout */
- if (Timeout != HAL_MAX_DELAY)
- {
- if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
- {
- hpssi->ErrorCode |= HAL_PSSI_ERROR_TIMEOUT;
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- return HAL_ERROR;
- }
- }
- }
- return HAL_OK;
- }
- /**
- * @brief DMA PSSI communication error callback
- * @param hdma DMA handle.
- * @retval None
- */
- void PSSI_DMAError(DMA_HandleTypeDef *hdma)
- {
- PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
- uint32_t tmperror;
- /* Disable the selected PSSI peripheral */
- HAL_PSSI_DISABLE(hpssi);
- /* Disable Interrupts */
- HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
- /* Store current volatile hpssi->ErrorCode, misra rule */
- tmperror = hpssi->ErrorCode;
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
- {
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- PSSI_Error(hpssi, hpssi->ErrorCode);
- }
- else
- {
- hpssi->State = HAL_PSSI_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hpssi);
- /* Call the corresponding callback to inform upper layer of End of Transfer */
- hpssi->ErrorCallback(hpssi);
- }
- }
- /**
- * @}
- */
- #endif /* HAL_PSSI_MODULE_ENABLED */
- /**
- * @}
- */
- #endif /* PSSI */
- /**
- * @}
- */
|