stm32l4xx_hal_pssi.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_pssi.c
  4. * @author MCD Application Team
  5. * @brief PSSI HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Parallel Synchronous Slave Interface (PSSI) peripheral:
  8. * + Initialization and de-initialization functions
  9. * + IO operation functions
  10. * + Peripheral State and Errors functions
  11. *
  12. ******************************************************************************
  13. * @attention
  14. *
  15. * Copyright (c) 2019 STMicroelectronics.
  16. * All rights reserved.
  17. *
  18. * This software is licensed under terms that can be found in the LICENSE file
  19. * in the root directory of this software component.
  20. * If no LICENSE file comes with this software, it is provided AS-IS.
  21. *
  22. ******************************************************************************
  23. @verbatim
  24. ==============================================================================
  25. ##### How to use this driver #####
  26. ==============================================================================
  27. [..]
  28. The PSSI HAL driver can be used as follows:
  29. (#) Declare a PSSI_HandleTypeDef handle structure, for example:
  30. PSSI_HandleTypeDef hpssi;
  31. (#) Initialize the PSSI low level resources by implementing the @ref HAL_PSSI_MspInit() API:
  32. (##) Enable the PSSIx interface clock
  33. (##) PSSI pins configuration
  34. (+++) Enable the clock for the PSSI GPIOs
  35. (+++) Configure PSSI pins as alternate function open-drain
  36. (##) NVIC configuration if you need to use interrupt process
  37. (+++) Configure the PSSIx interrupt priority
  38. (+++) Enable the NVIC PSSI IRQ Channel
  39. (##) DMA Configuration if you need to use DMA process
  40. (+++) Declare DMA_HandleTypeDef handles structure for the transmit and receive
  41. (+++) Enable the DMAx interface clock
  42. (+++) Configure the DMA handle parameters
  43. (+++) Configure the DMA Tx and Rx
  44. (+++) Associate the initialized DMA handle to the hpssi DMA Tx and Rx handle
  45. (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on
  46. the DMA Tx and Rx
  47. (#) Configure the Communication Bus Width, Control Signals, Input Polarity and Output Polarity
  48. in the hpssi Init structure.
  49. (#) Initialize the PSSI registers by calling the @ref HAL_PSSI_Init(), configure also the low level Hardware
  50. (GPIO, CLOCK, NVIC...etc) by calling the customized @ref HAL_PSSI_MspInit(&hpssi) API.
  51. (#) For PSSI IO operations, two operation modes are available within this driver :
  52. *** Polling mode IO operation ***
  53. =================================
  54. [..]
  55. (+) Transmit an amount of data by byte in blocking mode using @ref HAL_PSSI_Transmit()
  56. (+) Receive an amount of data by byte in blocking mode using @ref HAL_PSSI_Receive()
  57. *** DMA mode IO operation ***
  58. ==============================
  59. [..]
  60. (+) Transmit an amount of data in non-blocking mode (DMA) using
  61. @ref HAL_PSSI_Transmit_DMA()
  62. (+) At transmission end of transfer, @ref HAL_PSSI_TxCpltCallback() is executed and user can
  63. add his own code by customization of function pointer @ref HAL_PSSI_TxCpltCallback()
  64. (+) Receive an amount of data in non-blocking mode (DMA) using
  65. @ref HAL_PSSI_Receive_DMA()
  66. (+) At reception end of transfer, @ref HAL_PSSI_RxCpltCallback() is executed and user can
  67. add his own code by customization of function pointer @ref HAL_PSSI_RxCpltCallback()
  68. (+) In case of transfer Error, @ref HAL_PSSI_ErrorCallback() function is executed and user can
  69. add his own code by customization of function pointer @ref HAL_PSSI_ErrorCallback()
  70. (+) Abort a PSSI process communication with Interrupt using @ref HAL_PSSI_Abort_IT()
  71. (+) End of abort process, @ref HAL_PSSI_AbortCpltCallback() is executed and user can
  72. add his own code by customization of function pointer @ref HAL_PSSI_AbortCpltCallback()
  73. *** PSSI HAL driver macros list ***
  74. ==================================
  75. [..]
  76. Below the list of most used macros in PSSI HAL driver.
  77. (+) @ref HAL_PSSI_ENABLE : Enable the PSSI peripheral
  78. (+) @ref HAL_PSSI_DISABLE : Disable the PSSI peripheral
  79. (+) @ref HAL_PSSI_GET_FLAG : Check whether the specified PSSI flag is set or not
  80. (+) @ref HAL_PSSI_CLEAR_FLAG : Clear the specified PSSI pending flag
  81. (+) @ref HAL_PSSI_ENABLE_IT : Enable the specified PSSI interrupt
  82. (+) @ref HAL_PSSI_DISABLE_IT : Disable the specified PSSI interrupt
  83. *** Callback registration ***
  84. =============================================
  85. Use Functions @ref HAL_PSSI_RegisterCallback() or @ref HAL_PSSI_RegisterAddrCallback()
  86. to register an interrupt callback.
  87. Function @ref HAL_PSSI_RegisterCallback() allows to register following callbacks:
  88. (+) TxCpltCallback : callback for transmission end of transfer.
  89. (+) RxCpltCallback : callback for reception end of transfer.
  90. (+) ErrorCallback : callback for error detection.
  91. (+) AbortCpltCallback : callback for abort completion process.
  92. (+) MspInitCallback : callback for Msp Init.
  93. (+) MspDeInitCallback : callback for Msp DeInit.
  94. This function takes as parameters the HAL peripheral handle, the Callback ID
  95. and a pointer to the user callback function.
  96. Use function @ref HAL_PSSI_UnRegisterCallback to reset a callback to the default
  97. weak function.
  98. @ref HAL_PSSI_UnRegisterCallback takes as parameters the HAL peripheral handle,
  99. and the Callback ID.
  100. This function allows to reset following callbacks:
  101. (+) TxCpltCallback : callback for transmission end of transfer.
  102. (+) RxCpltCallback : callback for reception end of transfer.
  103. (+) ErrorCallback : callback for error detection.
  104. (+) AbortCpltCallback : callback for abort completion process.
  105. (+) MspInitCallback : callback for Msp Init.
  106. (+) MspDeInitCallback : callback for Msp DeInit.
  107. By default, after the @ref HAL_PSSI_Init() and when the state is @ref HAL_PSSI_STATE_RESET
  108. all callbacks are set to the corresponding weak functions:
  109. examples @ref HAL_PSSI_TxCpltCallback(), @ref HAL_PSSI_RxCpltCallback().
  110. Exception done for MspInit and MspDeInit functions that are
  111. reset to the legacy weak functions in the @ref HAL_PSSI_Init()/ @ref HAL_PSSI_DeInit() only when
  112. these callbacks are null (not registered beforehand).
  113. If MspInit or MspDeInit are not null, the @ref HAL_PSSI_Init()/ @ref HAL_PSSI_DeInit()
  114. keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
  115. Callbacks can be registered/unregistered in @ref HAL_PSSI_STATE_READY state only.
  116. Exception for MspInit/MspDeInit functions that can be registered/unregistered
  117. in @ref HAL_PSSI_STATE_READY or @ref HAL_PSSI_STATE_RESET state,
  118. thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
  119. Then, the user first registers the MspInit/MspDeInit user callbacks
  120. using @ref HAL_PSSI_RegisterCallback() before calling @ref HAL_PSSI_DeInit()
  121. or @ref HAL_PSSI_Init() function.
  122. [..]
  123. (@) You can refer to the PSSI HAL driver header file for more useful macros
  124. @endverbatim
  125. ******************************************************************************
  126. */
  127. /* Includes ------------------------------------------------------------------*/
  128. #include "stm32l4xx_hal.h"
  129. /** @addtogroup STM32L4xx_HAL_Driver
  130. * @{
  131. */
  132. #if defined(PSSI)
  133. /** @addtogroup PSSI PSSI
  134. * @brief PSSI HAL module driver
  135. * @{
  136. */
  137. #ifdef HAL_PSSI_MODULE_ENABLED
  138. /* Private typedef -----------------------------------------------------------*/
  139. /* Private define ------------------------------------------------------------*/
  140. /* Private macro -------------------------------------------------------------*/
  141. /* Private variables ---------------------------------------------------------*/
  142. /* Private function prototypes -----------------------------------------------*/
  143. /** @defgroup PSSI_Private_Functions PSSI Private Functions
  144. * @{
  145. */
  146. /* Private functions to handle DMA transfer */
  147. void PSSI_DMATransmitCplt(DMA_HandleTypeDef *hdma);
  148. void PSSI_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
  149. void PSSI_DMAError(DMA_HandleTypeDef *hdma);
  150. void PSSI_DMAAbort(DMA_HandleTypeDef *hdma);
  151. /* Private functions to handle IT transfer */
  152. static void PSSI_Error(PSSI_HandleTypeDef *hpssi, uint32_t ErrorCode);
  153. /* Private functions for PSSI transfer IRQ handler */
  154. /* Private functions to handle flags during polling transfer */
  155. static HAL_StatusTypeDef PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef *hpssi, uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart);
  156. /**
  157. * @}
  158. */
  159. /* Exported functions --------------------------------------------------------*/
  160. /** @addtogroup PSSI_Exported_Functions PSSI Exported Functions
  161. * @{
  162. */
  163. /** @addtogroup PSSI_Exported_Functions_Group1 Initialization and de-initialization functions
  164. * @brief Initialization and Configuration functions
  165. *
  166. @verbatim
  167. ===============================================================================
  168. ##### Initialization and de-initialization functions #####
  169. ===============================================================================
  170. [..] This subsection provides a set of functions allowing to initialize and
  171. de-initialize the PSSIx peripheral:
  172. (+) User must implement HAL_PSSI_MspInit() function in which he configures
  173. all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
  174. (+) Call the function HAL_PSSI_Init() to configure the selected device with
  175. the selected configuration:
  176. (++) Data Width
  177. (++) Control Signals
  178. (++) Input Clock polarity
  179. (++) Output Clock polarity
  180. (+) Call the function HAL_PSSI_DeInit() to restore the default configuration
  181. of the selected PSSIx peripheral.
  182. @endverbatim
  183. * @{
  184. */
  185. /**
  186. * @brief Initializes the PSSI according to the specified parameters
  187. * in the PSSI_InitTypeDef and initializes the associated handle.
  188. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  189. * the configuration information for the specified PSSI.
  190. * @retval HAL status
  191. */
  192. HAL_StatusTypeDef HAL_PSSI_Init(PSSI_HandleTypeDef *hpssi)
  193. {
  194. /* Check the PSSI handle allocation */
  195. if (hpssi == NULL)
  196. {
  197. return HAL_ERROR;
  198. }
  199. /* Check the parameters */
  200. assert_param(IS_PSSI_ALL_INSTANCE(hpssi->Instance));
  201. assert_param(IS_PSSI_CONTROL_SIGNAL(hpssi->Init.ControlSignal));
  202. assert_param(IS_PSSI_BUSWIDTH(hpssi->Init.BusWidth));
  203. assert_param(IS_PSSI_CLOCK_POLARITY(hpssi->Init.ClockPolarity));
  204. assert_param(IS_PSSI_DE_POLARITY(hpssi->Init.DataEnablePolarity));
  205. assert_param(IS_PSSI_RDY_POLARITY(hpssi->Init.ReadyPolarity));
  206. if (hpssi->State == HAL_PSSI_STATE_RESET)
  207. {
  208. /* Allocate lock resource and initialize it */
  209. hpssi->Lock = HAL_UNLOCKED;
  210. /* Init the PSSI Callback settings */
  211. hpssi->TxCpltCallback = HAL_PSSI_TxCpltCallback; /* Legacy weak TxCpltCallback */
  212. hpssi->RxCpltCallback = HAL_PSSI_RxCpltCallback; /* Legacy weak RxCpltCallback */
  213. hpssi->ErrorCallback = HAL_PSSI_ErrorCallback; /* Legacy weak ErrorCallback */
  214. hpssi->AbortCpltCallback = HAL_PSSI_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
  215. if (hpssi->MspInitCallback == NULL)
  216. {
  217. hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit */
  218. }
  219. /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
  220. hpssi->MspInitCallback(hpssi);
  221. }
  222. hpssi->State = HAL_PSSI_STATE_BUSY;
  223. /* Disable the selected PSSI peripheral */
  224. HAL_PSSI_DISABLE(hpssi);
  225. /*---------------------------- PSSIx CR Configuration ----------------------*/
  226. /* Configure PSSIx: Control Signal and Bus Width*/
  227. MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DERDYCFG|PSSI_CR_EDM|PSSI_CR_DEPOL|PSSI_CR_RDYPOL,
  228. hpssi->Init.ControlSignal|hpssi->Init.DataEnablePolarity|hpssi->Init.ReadyPolarity|hpssi->Init.BusWidth);
  229. hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
  230. hpssi->State = HAL_PSSI_STATE_READY;
  231. return HAL_OK;
  232. }
  233. /**
  234. * @brief De-Initialize the PSSI peripheral.
  235. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  236. * the configuration information for the specified PSSI.
  237. * @retval HAL status
  238. */
  239. HAL_StatusTypeDef HAL_PSSI_DeInit(PSSI_HandleTypeDef *hpssi)
  240. {
  241. /* Check the PSSI handle allocation */
  242. if (hpssi == NULL)
  243. {
  244. return HAL_ERROR;
  245. }
  246. /* Check the parameters */
  247. assert_param(IS_PSSI_ALL_INSTANCE(hpssi->Instance));
  248. hpssi->State = HAL_PSSI_STATE_BUSY;
  249. /* Disable the PSSI Peripheral Clock */
  250. HAL_PSSI_DISABLE(hpssi);
  251. if (hpssi->MspDeInitCallback == NULL)
  252. {
  253. hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit */
  254. }
  255. /* De-Init the low level hardware: GPIO, CLOCK, NVIC */
  256. hpssi->MspDeInitCallback(hpssi);
  257. hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
  258. hpssi->State = HAL_PSSI_STATE_RESET;
  259. /* Release Lock */
  260. __HAL_UNLOCK(hpssi);
  261. return HAL_OK;
  262. }
  263. /**
  264. * @brief Initialize the PSSI MSP.
  265. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  266. * the configuration information for the specified PSSI.
  267. * @retval None
  268. */
  269. __weak void HAL_PSSI_MspInit(PSSI_HandleTypeDef *hpssi)
  270. {
  271. /* Prevent unused argument(s) compilation warning */
  272. UNUSED(hpssi);
  273. /* NOTE : This function should not be modified; when the callback is needed,
  274. the HAL_PSSI_MspInit can be implemented in the user file
  275. */
  276. }
  277. /**
  278. * @brief De-Initialize the PSSI MSP.
  279. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  280. * the configuration information for the specified PSSI.
  281. * @retval None
  282. */
  283. __weak void HAL_PSSI_MspDeInit(PSSI_HandleTypeDef *hpssi)
  284. {
  285. /* Prevent unused argument(s) compilation warning */
  286. UNUSED(hpssi);
  287. /* NOTE : This function should not be modified; when the callback is needed,
  288. the HAL_PSSI_MspDeInit can be implemented in the user file
  289. */
  290. }
  291. /**
  292. * @brief Register a User PSSI Callback
  293. * To be used instead of the weak predefined callback
  294. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  295. * the configuration information for the specified PSSI.
  296. * @param CallbackID ID of the callback to be registered
  297. * This parameter can be one of the following values:
  298. * @arg @ref HAL_PSSI_TX_COMPLETE_CB_ID Tx Transfer completed callback ID
  299. * @arg @ref HAL_PSSI_RX_COMPLETE_CB_ID Rx Transfer completed callback ID
  300. * @arg @ref HAL_PSSI_ERROR_CB_ID Error callback ID
  301. * @arg @ref HAL_PSSI_ABORT_CB_ID Abort callback ID
  302. * @arg @ref HAL_PSSI_MSPINIT_CB_ID MspInit callback ID
  303. * @arg @ref HAL_PSSI_MSPDEINIT_CB_ID MspDeInit callback ID
  304. * @param pCallback pointer to the Callback function
  305. * @retval HAL status
  306. */
  307. HAL_StatusTypeDef HAL_PSSI_RegisterCallback(PSSI_HandleTypeDef *hpssi, HAL_PSSI_CallbackIDTypeDef CallbackID, pPSSI_CallbackTypeDef pCallback)
  308. {
  309. HAL_StatusTypeDef status = HAL_OK;
  310. if (pCallback == NULL)
  311. {
  312. /* Update the error code */
  313. hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
  314. return HAL_ERROR;
  315. }
  316. /* Process locked */
  317. __HAL_LOCK(hpssi);
  318. if (HAL_PSSI_STATE_READY == hpssi->State)
  319. {
  320. switch (CallbackID)
  321. {
  322. case HAL_PSSI_TX_COMPLETE_CB_ID :
  323. hpssi->TxCpltCallback = pCallback;
  324. break;
  325. case HAL_PSSI_RX_COMPLETE_CB_ID :
  326. hpssi->RxCpltCallback = pCallback;
  327. break;
  328. case HAL_PSSI_ERROR_CB_ID :
  329. hpssi->ErrorCallback = pCallback;
  330. break;
  331. case HAL_PSSI_ABORT_CB_ID :
  332. hpssi->AbortCpltCallback = pCallback;
  333. break;
  334. case HAL_PSSI_MSPINIT_CB_ID :
  335. hpssi->MspInitCallback = pCallback;
  336. break;
  337. case HAL_PSSI_MSPDEINIT_CB_ID :
  338. hpssi->MspDeInitCallback = pCallback;
  339. break;
  340. default :
  341. /* Update the error code */
  342. hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
  343. /* Return error status */
  344. status = HAL_ERROR;
  345. break;
  346. }
  347. }
  348. else if (HAL_PSSI_STATE_RESET == hpssi->State)
  349. {
  350. switch (CallbackID)
  351. {
  352. case HAL_PSSI_MSPINIT_CB_ID :
  353. hpssi->MspInitCallback = pCallback;
  354. break;
  355. case HAL_PSSI_MSPDEINIT_CB_ID :
  356. hpssi->MspDeInitCallback = pCallback;
  357. break;
  358. default :
  359. /* Update the error code */
  360. hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
  361. /* Return error status */
  362. status = HAL_ERROR;
  363. break;
  364. }
  365. }
  366. else
  367. {
  368. /* Update the error code */
  369. hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
  370. /* Return error status */
  371. status = HAL_ERROR;
  372. }
  373. /* Release Lock */
  374. __HAL_UNLOCK(hpssi);
  375. return status;
  376. }
  377. /**
  378. * @brief Unregister a PSSI Callback
  379. * PSSI callback is redirected to the weak predefined callback
  380. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  381. * the configuration information for the specified PSSI.
  382. * @param CallbackID ID of the callback to be unregistered
  383. * This parameter can be one of the following values:
  384. * @arg @ref HAL_PSSI_TX_COMPLETE_CB_ID Tx Transfer completed callback ID
  385. * @arg @ref HAL_PSSI_RX_COMPLETE_CB_ID Rx Transfer completed callback ID
  386. * @arg @ref HAL_PSSI_ERROR_CB_ID Error callback ID
  387. * @arg @ref HAL_PSSI_ABORT_CB_ID Abort callback ID
  388. * @arg @ref HAL_PSSI_MSPINIT_CB_ID MspInit callback ID
  389. * @arg @ref HAL_PSSI_MSPDEINIT_CB_ID MspDeInit callback ID
  390. * @retval HAL status
  391. */
  392. HAL_StatusTypeDef HAL_PSSI_UnRegisterCallback(PSSI_HandleTypeDef *hpssi, HAL_PSSI_CallbackIDTypeDef CallbackID)
  393. {
  394. HAL_StatusTypeDef status = HAL_OK;
  395. /* Process locked */
  396. __HAL_LOCK(hpssi);
  397. if (HAL_PSSI_STATE_READY == hpssi->State)
  398. {
  399. switch (CallbackID)
  400. {
  401. case HAL_PSSI_TX_COMPLETE_CB_ID :
  402. hpssi->TxCpltCallback = HAL_PSSI_TxCpltCallback; /* Legacy weak TxCpltCallback */
  403. break;
  404. case HAL_PSSI_RX_COMPLETE_CB_ID :
  405. hpssi->RxCpltCallback = HAL_PSSI_RxCpltCallback; /* Legacy weak RxCpltCallback */
  406. break;
  407. case HAL_PSSI_ERROR_CB_ID :
  408. hpssi->ErrorCallback = HAL_PSSI_ErrorCallback; /* Legacy weak ErrorCallback */
  409. break;
  410. case HAL_PSSI_ABORT_CB_ID :
  411. hpssi->AbortCpltCallback = HAL_PSSI_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
  412. break;
  413. case HAL_PSSI_MSPINIT_CB_ID :
  414. hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit */
  415. break;
  416. case HAL_PSSI_MSPDEINIT_CB_ID :
  417. hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit */
  418. break;
  419. default :
  420. /* Update the error code */
  421. hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
  422. /* Return error status */
  423. status = HAL_ERROR;
  424. break;
  425. }
  426. }
  427. else if (HAL_PSSI_STATE_RESET == hpssi->State)
  428. {
  429. switch (CallbackID)
  430. {
  431. case HAL_PSSI_MSPINIT_CB_ID :
  432. hpssi->MspInitCallback = HAL_PSSI_MspInit; /* Legacy weak MspInit */
  433. break;
  434. case HAL_PSSI_MSPDEINIT_CB_ID :
  435. hpssi->MspDeInitCallback = HAL_PSSI_MspDeInit; /* Legacy weak MspDeInit */
  436. break;
  437. default :
  438. /* Update the error code */
  439. hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
  440. /* Return error status */
  441. status = HAL_ERROR;
  442. break;
  443. }
  444. }
  445. else
  446. {
  447. /* Update the error code */
  448. hpssi->ErrorCode |= HAL_PSSI_ERROR_INVALID_CALLBACK;
  449. /* Return error status */
  450. status = HAL_ERROR;
  451. }
  452. /* Release Lock */
  453. __HAL_UNLOCK(hpssi);
  454. return status;
  455. }
  456. /**
  457. * @}
  458. */
  459. /** @addtogroup PSSI_Exported_Functions_Group2 Input and Output operation functions
  460. * @brief Data transfers functions
  461. *
  462. @verbatim
  463. ===============================================================================
  464. ##### IO operation functions #####
  465. ===============================================================================
  466. [..]
  467. This subsection provides a set of functions allowing to manage the PSSI data
  468. transfers.
  469. (#) There are two modes of transfer:
  470. (++) Blocking mode : The communication is performed in the polling mode.
  471. The status of all data processing is returned by the same function
  472. after finishing transfer.
  473. (++) No-Blocking mode : The communication is performed using DMA.
  474. These functions return the status of the transfer startup.
  475. The end of the data processing will be indicated through the
  476. dedicated DMA IRQ .
  477. (#) Blocking mode functions are :
  478. (++) HAL_PSSI_Transmit()
  479. (++) HAL_PSSI_Receive()
  480. (#) No-Blocking mode functions with DMA are :
  481. (++) HAL_PSSI_Transmit_DMA()
  482. (++) HAL_PSSI_Receive_DMA()
  483. (#) A set of callbacks are provided in non Blocking mode:
  484. (++) HAL_PSSI_TxCpltCallback()
  485. (++) HAL_PSSI_RxCpltCallback()
  486. (++) HAL_PSSI_ErrorCallback()
  487. (++) HAL_PSSI_AbortCpltCallback()
  488. @endverbatim
  489. * @{
  490. */
  491. /**
  492. * @brief Transmits in master mode an amount of data in blocking mode.
  493. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  494. * the configuration information for the specified PSSI.
  495. * @param pData Pointer to data buffer
  496. * @param Size Amount of data to be sent (in bytes)
  497. * @param Timeout Timeout duration
  498. * @retval HAL status
  499. */
  500. HAL_StatusTypeDef HAL_PSSI_Transmit(PSSI_HandleTypeDef *hpssi, uint8_t *pData, uint32_t Size, uint32_t Timeout)
  501. {
  502. uint32_t tickstart;
  503. uint32_t transfer_size = Size;
  504. if (((hpssi->Init.DataWidth == HAL_PSSI_8BITS) && (hpssi->Init.BusWidth != HAL_PSSI_8LINES)) ||
  505. ((hpssi->Init.DataWidth == HAL_PSSI_16BITS) && ((Size%2U) != 0U)) ||
  506. ((hpssi->Init.DataWidth == HAL_PSSI_32BITS) && ((Size%4U) != 0U)))
  507. {
  508. hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
  509. return HAL_ERROR;
  510. }
  511. if (hpssi->State == HAL_PSSI_STATE_READY)
  512. {
  513. /* Process Locked */
  514. __HAL_LOCK(hpssi);
  515. hpssi->State = HAL_PSSI_STATE_BUSY;
  516. hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
  517. /* Disable the selected PSSI peripheral */
  518. HAL_PSSI_DISABLE(hpssi);
  519. /* Configure transfer parameters */
  520. hpssi->Instance->CR |= PSSI_CR_OUTEN_OUTPUT |
  521. ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?0U:PSSI_CR_CKPOL);
  522. /* DMA Disable */
  523. hpssi->Instance->CR &= PSSI_CR_DMA_DISABLE;
  524. /* Enable the selected PSSI peripheral */
  525. HAL_PSSI_ENABLE(hpssi);
  526. if (hpssi->Init.DataWidth == HAL_PSSI_8BITS)
  527. {
  528. uint8_t *pbuffer = pData;
  529. while (transfer_size > 0U)
  530. {
  531. /* Init tickstart for timeout management*/
  532. tickstart = HAL_GetTick();
  533. /* Wait until Fifo is ready (until one byte flag is set) to transfer */
  534. if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT1B, RESET, Timeout, tickstart) != HAL_OK)
  535. {
  536. hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
  537. hpssi->State = HAL_PSSI_STATE_READY;
  538. /* Process Unlocked */
  539. __HAL_UNLOCK(hpssi);
  540. return HAL_ERROR;
  541. }
  542. /* Write data to DR */
  543. *(__IO uint8_t *)(&hpssi->Instance->DR) = *(uint8_t *)pbuffer;
  544. /* Increment Buffer pointer */
  545. pbuffer++;
  546. transfer_size--;
  547. }
  548. }
  549. else if (hpssi->Init.DataWidth == HAL_PSSI_16BITS)
  550. {
  551. uint8_t *pbuffer = pData;
  552. uint16_t data;
  553. while (transfer_size > 0U)
  554. {
  555. /* Init tickstart for timeout management*/
  556. tickstart = HAL_GetTick();
  557. /* Wait until Fifo is ready (until four bytes flag is set) to transfer */
  558. if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
  559. {
  560. hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
  561. hpssi->State = HAL_PSSI_STATE_READY;
  562. /* Process Unlocked */
  563. __HAL_UNLOCK(hpssi);
  564. return HAL_ERROR;
  565. }
  566. /* Write data to DR */
  567. data = (uint16_t)*pbuffer ;
  568. pbuffer++;
  569. data = (((uint16_t)*pbuffer) << 8U) | data;
  570. pbuffer++;
  571. *(__IO uint32_t *)((uint32_t)(&hpssi->Instance->DR)) = data;
  572. /* Decrement Transfer Size */
  573. transfer_size -= 2U;
  574. }
  575. }
  576. else if (hpssi->Init.DataWidth == HAL_PSSI_32BITS)
  577. {
  578. uint8_t *pbuffer = pData;
  579. uint32_t data;
  580. while (transfer_size > 0U)
  581. {
  582. /* Init tickstart for timeout management*/
  583. tickstart = HAL_GetTick();
  584. /* Wait until Fifo is ready (until four bytes flag is set) to transfer */
  585. if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
  586. {
  587. hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
  588. hpssi->State = HAL_PSSI_STATE_READY;
  589. /* Process Unlocked */
  590. __HAL_UNLOCK(hpssi);
  591. return HAL_ERROR;
  592. }
  593. /* Write data to DR */
  594. data = (uint32_t)*pbuffer ;
  595. pbuffer++;
  596. data = (((uint32_t)*pbuffer) << 8U) | data;
  597. pbuffer++;
  598. data = (((uint32_t)*pbuffer) << 16U) | data;
  599. pbuffer++;
  600. data = (((uint32_t)*pbuffer) << 24U) | data;
  601. pbuffer++;
  602. *(__IO uint32_t *)(&hpssi->Instance->DR) = data;
  603. /* Decrement Transfer Size */
  604. transfer_size -= 4U;
  605. }
  606. }
  607. else
  608. {
  609. hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
  610. hpssi->State = HAL_PSSI_STATE_READY;
  611. /* Process Unlocked */
  612. __HAL_UNLOCK(hpssi);
  613. return HAL_ERROR;
  614. }
  615. /* Check Errors Flags */
  616. if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_RIS) != 0U)
  617. {
  618. HAL_PSSI_CLEAR_FLAG(hpssi, PSSI_FLAG_OVR_RIS);
  619. HAL_PSSI_DISABLE(hpssi);
  620. hpssi->ErrorCode = HAL_PSSI_ERROR_UNDER_RUN;
  621. hpssi->State = HAL_PSSI_STATE_READY;
  622. /* Process Unlocked */
  623. __HAL_UNLOCK(hpssi);
  624. return HAL_ERROR;
  625. }
  626. hpssi->State = HAL_PSSI_STATE_READY;
  627. /* Process Unlocked */
  628. __HAL_UNLOCK(hpssi);
  629. return HAL_OK;
  630. }
  631. else
  632. {
  633. return HAL_BUSY;
  634. }
  635. }
  636. /**
  637. * @brief Receives an amount of data in blocking mode.
  638. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  639. * the configuration information for the specified PSSI.
  640. * @param pData Pointer to data buffer
  641. * @param Size Amount of data to be received (in bytes)
  642. * @param Timeout Timeout duration
  643. * @retval HAL status
  644. */
  645. HAL_StatusTypeDef HAL_PSSI_Receive(PSSI_HandleTypeDef *hpssi, uint8_t *pData, uint32_t Size, uint32_t Timeout)
  646. {
  647. uint32_t tickstart;
  648. uint32_t transfer_size = Size;
  649. if (((hpssi->Init.DataWidth == HAL_PSSI_8BITS) && (hpssi->Init.BusWidth != HAL_PSSI_8LINES)) ||
  650. ((hpssi->Init.DataWidth == HAL_PSSI_16BITS) && ((Size%2U) != 0U)) ||
  651. ((hpssi->Init.DataWidth == HAL_PSSI_32BITS) && ((Size%4U) != 0U)))
  652. {
  653. hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
  654. return HAL_ERROR;
  655. }
  656. if (hpssi->State == HAL_PSSI_STATE_READY)
  657. {
  658. /* Process Locked */
  659. __HAL_LOCK(hpssi);
  660. hpssi->State = HAL_PSSI_STATE_BUSY;
  661. hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
  662. /* Disable the selected PSSI peripheral */
  663. HAL_PSSI_DISABLE(hpssi);
  664. /* Configure transfer parameters */
  665. hpssi->Instance->CR |= PSSI_CR_OUTEN_INPUT |((hpssi->Init.ClockPolarity == HAL_PSSI_FALLING_EDGE)?0U:PSSI_CR_CKPOL);
  666. /* DMA Disable */
  667. hpssi->Instance->CR &= PSSI_CR_DMA_DISABLE;
  668. /* Enable the selected PSSI peripheral */
  669. HAL_PSSI_ENABLE(hpssi);
  670. if (hpssi->Init.DataWidth == HAL_PSSI_8BITS)
  671. {
  672. uint8_t *pbuffer = pData;
  673. while (transfer_size > 0U)
  674. {
  675. /* Init tickstart for timeout management*/
  676. tickstart = HAL_GetTick();
  677. /* Wait until Fifo is ready (until one byte flag is set) to receive */
  678. if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT1B, RESET, Timeout, tickstart) != HAL_OK)
  679. {
  680. hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
  681. hpssi->State = HAL_PSSI_STATE_READY;
  682. /* Process Unlocked */
  683. __HAL_UNLOCK(hpssi);
  684. return HAL_ERROR;
  685. }
  686. /* Read data from DR */
  687. *pbuffer = *(__IO uint8_t *)(&hpssi->Instance->DR);
  688. pbuffer++;
  689. transfer_size--;
  690. }
  691. }
  692. else if (hpssi->Init.DataWidth == HAL_PSSI_16BITS)
  693. {
  694. uint8_t *pbuffer = pData;
  695. uint16_t data;
  696. while (transfer_size > 0U)
  697. {
  698. /* Init tickstart for timeout management*/
  699. tickstart = HAL_GetTick();
  700. /* Wait until Fifo is ready (until four bytes flag is set) to receive */
  701. if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
  702. {
  703. hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
  704. hpssi->State = HAL_PSSI_STATE_READY;
  705. /* Process Unlocked */
  706. __HAL_UNLOCK(hpssi);
  707. return HAL_ERROR;
  708. }
  709. /* Read data from DR */
  710. data = *(__IO uint32_t *)((uint32_t)&hpssi->Instance->DR);
  711. *pbuffer = (uint8_t)(data & 0x0FFU);
  712. pbuffer++;
  713. *pbuffer = (uint8_t)(data >> 8U);
  714. pbuffer++;
  715. transfer_size -= 2U;
  716. }
  717. }
  718. else if (hpssi->Init.DataWidth == HAL_PSSI_32BITS)
  719. {
  720. uint8_t *pbuffer = pData;
  721. uint32_t data;
  722. while (transfer_size > 0U)
  723. {
  724. /* Init tickstart for timeout management*/
  725. tickstart = HAL_GetTick();
  726. /* Wait until Fifo is ready (until four bytes flag is set) to receive */
  727. if (PSSI_WaitOnStatusUntilTimeout(hpssi, PSSI_FLAG_RTT4B, RESET, Timeout, tickstart) != HAL_OK)
  728. {
  729. hpssi->ErrorCode = HAL_PSSI_ERROR_TIMEOUT;
  730. hpssi->State = HAL_PSSI_STATE_READY;
  731. /* Process Unlocked */
  732. __HAL_UNLOCK(hpssi);
  733. return HAL_ERROR;
  734. }
  735. /* Read data from DR */
  736. data = *(__IO uint32_t *)(&hpssi->Instance->DR);
  737. *pbuffer = (uint8_t)(data & 0x0FFU);
  738. pbuffer++;
  739. *pbuffer = (uint8_t)((data & 0x0FF00U) >> 8U);
  740. pbuffer++;
  741. *pbuffer = (uint8_t)((data & 0x0FF0000U) >> 16U);
  742. pbuffer++;
  743. *pbuffer = (uint8_t)((data & 0xFF000000U) >> 24U);
  744. pbuffer++;
  745. transfer_size -= 4U;
  746. }
  747. }
  748. else
  749. {
  750. hpssi->ErrorCode = HAL_PSSI_ERROR_NOT_SUPPORTED;
  751. hpssi->State = HAL_PSSI_STATE_READY;
  752. /* Process Unlocked */
  753. __HAL_UNLOCK(hpssi);
  754. return HAL_ERROR;
  755. }
  756. /* Check Errors Flags */
  757. if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_RIS) != 0U)
  758. {
  759. HAL_PSSI_CLEAR_FLAG(hpssi, PSSI_FLAG_OVR_RIS);
  760. hpssi->ErrorCode = HAL_PSSI_ERROR_OVER_RUN;
  761. __HAL_UNLOCK(hpssi);
  762. return HAL_ERROR;
  763. }
  764. hpssi->State = HAL_PSSI_STATE_READY;
  765. /* Process Unlocked */
  766. __HAL_UNLOCK(hpssi);
  767. return HAL_OK;
  768. }
  769. else
  770. {
  771. return HAL_BUSY;
  772. }
  773. }
  774. /**
  775. * @brief Transmit an amount of data in non-blocking mode with DMA
  776. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  777. * the configuration information for the specified PSSI.
  778. * @param pData Pointer to data buffer
  779. * @param Size Amount of data to be sent (in bytes)
  780. * @retval HAL status
  781. */
  782. HAL_StatusTypeDef HAL_PSSI_Transmit_DMA(PSSI_HandleTypeDef *hpssi, uint32_t *pData, uint32_t Size)
  783. {
  784. HAL_StatusTypeDef dmaxferstatus;
  785. if (hpssi->State == HAL_PSSI_STATE_READY)
  786. {
  787. /* Process Locked */
  788. __HAL_LOCK(hpssi);
  789. hpssi->State = HAL_PSSI_STATE_BUSY_TX;
  790. hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
  791. /* Disable the selected PSSI peripheral */
  792. HAL_PSSI_DISABLE(hpssi);
  793. /* Prepare transfer parameters */
  794. hpssi->pBuffPtr = pData;
  795. hpssi->XferCount = Size;
  796. if (hpssi->XferCount > PSSI_MAX_NBYTE_SIZE)
  797. {
  798. hpssi->XferSize = PSSI_MAX_NBYTE_SIZE;
  799. }
  800. else
  801. {
  802. hpssi->XferSize = hpssi->XferCount;
  803. }
  804. if (hpssi->XferSize > 0U)
  805. {
  806. if (hpssi->hdmatx != NULL)
  807. {
  808. /* Configure BusWidth */
  809. if( hpssi->hdmatx->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
  810. {
  811. MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DMAEN|PSSI_CR_OUTEN|PSSI_CR_CKPOL,PSSI_CR_DMA_ENABLE | PSSI_CR_OUTEN_OUTPUT |
  812. ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?0U:PSSI_CR_CKPOL));
  813. }
  814. else
  815. {
  816. 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 |
  817. ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?0U:PSSI_CR_CKPOL));
  818. }
  819. /* Set the PSSI DMA transfer complete callback */
  820. hpssi->hdmatx->XferCpltCallback = PSSI_DMATransmitCplt;
  821. /* Set the DMA error callback */
  822. hpssi->hdmatx->XferErrorCallback = PSSI_DMAError;
  823. /* Set the unused DMA callbacks to NULL */
  824. hpssi->hdmatx->XferHalfCpltCallback = NULL;
  825. hpssi->hdmatx->XferAbortCallback = NULL;
  826. /* Enable the DMA */
  827. dmaxferstatus = HAL_DMA_Start_IT(hpssi->hdmatx, (uint32_t)pData, (uint32_t)&hpssi->Instance->DR, hpssi->XferSize);
  828. }
  829. else
  830. {
  831. /* Update PSSI state */
  832. hpssi->State = HAL_PSSI_STATE_READY;
  833. /* Update PSSI error code */
  834. hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
  835. /* Process Unlocked */
  836. __HAL_UNLOCK(hpssi);
  837. return HAL_ERROR;
  838. }
  839. if (dmaxferstatus == HAL_OK)
  840. {
  841. /* Update XferCount value */
  842. hpssi->XferCount -= hpssi->XferSize;
  843. /* Process Unlocked */
  844. __HAL_UNLOCK(hpssi);
  845. /* Note : The PSSI interrupts must be enabled after unlocking current process
  846. to avoid the risk of PSSI interrupt handle execution before current
  847. process unlock */
  848. /* Enable ERR interrupt */
  849. HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
  850. /* Enable DMA Request */
  851. hpssi->Instance->CR |= PSSI_CR_DMA_ENABLE;
  852. /* Enable the selected PSSI peripheral */
  853. HAL_PSSI_ENABLE(hpssi);
  854. }
  855. else
  856. {
  857. /* Update PSSI state */
  858. hpssi->State = HAL_PSSI_STATE_READY;
  859. /* Update PSSI error code */
  860. hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
  861. /* Process Unlocked */
  862. __HAL_UNLOCK(hpssi);
  863. return HAL_ERROR;
  864. }
  865. }
  866. else
  867. {
  868. /* Process Unlocked */
  869. __HAL_UNLOCK(hpssi);
  870. /* Note : The PSSI interrupts must be enabled after unlocking current process
  871. to avoid the risk of PSSI interrupt handle execution before current
  872. process unlock */
  873. /* Enable ERRinterrupt */
  874. /* possible to enable all of these */
  875. HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
  876. }
  877. return HAL_OK;
  878. }
  879. else
  880. {
  881. return HAL_BUSY;
  882. }
  883. }
  884. /**
  885. * @brief Receive an amount of data in non-blocking mode with DMA
  886. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  887. * the configuration information for the specified PSSI.
  888. * @param pData Pointer to data buffer
  889. * @param Size Amount of data to be received (in bytes)
  890. * @retval HAL status
  891. */
  892. HAL_StatusTypeDef HAL_PSSI_Receive_DMA(PSSI_HandleTypeDef *hpssi, uint32_t *pData, uint32_t Size)
  893. {
  894. HAL_StatusTypeDef dmaxferstatus;
  895. if (hpssi->State == HAL_PSSI_STATE_READY)
  896. {
  897. /* Disable the selected PSSI peripheral */
  898. HAL_PSSI_DISABLE(hpssi);
  899. /* Process Locked */
  900. __HAL_LOCK(hpssi);
  901. hpssi->State = HAL_PSSI_STATE_BUSY_RX;
  902. hpssi->ErrorCode = HAL_PSSI_ERROR_NONE;
  903. /* Prepare transfer parameters */
  904. hpssi->pBuffPtr = pData;
  905. hpssi->XferCount = Size;
  906. if (hpssi->XferCount > PSSI_MAX_NBYTE_SIZE)
  907. {
  908. hpssi->XferSize = PSSI_MAX_NBYTE_SIZE;
  909. }
  910. else
  911. {
  912. hpssi->XferSize = hpssi->XferCount;
  913. }
  914. if (hpssi->XferSize > 0U)
  915. {
  916. if (hpssi->hdmarx != NULL)
  917. {
  918. /* Configure BusWidth */
  919. if( hpssi->hdmatx->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE)
  920. {
  921. MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DMAEN|PSSI_CR_OUTEN|PSSI_CR_CKPOL,PSSI_CR_DMA_ENABLE |
  922. ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?PSSI_CR_CKPOL:0U));
  923. }
  924. else
  925. {
  926. MODIFY_REG(hpssi->Instance->CR,PSSI_CR_DMAEN|PSSI_CR_OUTEN|PSSI_CR_CKPOL,PSSI_CR_DMA_ENABLE | hpssi->Init.BusWidth |
  927. ((hpssi->Init.ClockPolarity == HAL_PSSI_RISING_EDGE)?PSSI_CR_CKPOL:0U));
  928. }
  929. /* Set the PSSI DMA transfer complete callback */
  930. hpssi->hdmarx->XferCpltCallback = PSSI_DMAReceiveCplt;
  931. /* Set the DMA error callback */
  932. hpssi->hdmarx->XferErrorCallback = PSSI_DMAError;
  933. /* Set the unused DMA callbacks to NULL */
  934. hpssi->hdmarx->XferHalfCpltCallback = NULL;
  935. hpssi->hdmarx->XferAbortCallback = NULL;
  936. /* Enable the DMA */
  937. dmaxferstatus = HAL_DMA_Start_IT(hpssi->hdmarx, (uint32_t)&hpssi->Instance->DR, (uint32_t)pData, hpssi->XferSize);
  938. }
  939. else
  940. {
  941. /* Update PSSI state */
  942. hpssi->State = HAL_PSSI_STATE_READY;
  943. /* Update PSSI error code */
  944. hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
  945. /* Process Unlocked */
  946. __HAL_UNLOCK(hpssi);
  947. return HAL_ERROR;
  948. }
  949. if (dmaxferstatus == HAL_OK)
  950. {
  951. /* Update XferCount value */
  952. hpssi->XferCount -= hpssi->XferSize;
  953. /* Process Unlocked */
  954. __HAL_UNLOCK(hpssi);
  955. /* Note : The PSSI interrupts must be enabled after unlocking current process
  956. to avoid the risk of PSSI interrupt handle execution before current
  957. process unlock */
  958. /* Enable ERR interrupt */
  959. HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
  960. /* Enable DMA Request */
  961. hpssi->Instance->CR |= PSSI_CR_DMA_ENABLE;
  962. /* Enable the selected PSSI peripheral */
  963. HAL_PSSI_ENABLE(hpssi);
  964. }
  965. else
  966. {
  967. /* Update PSSI state */
  968. hpssi->State = HAL_PSSI_STATE_READY;
  969. /* Update PSSI error code */
  970. hpssi->ErrorCode |= HAL_PSSI_ERROR_DMA;
  971. /* Process Unlocked */
  972. __HAL_UNLOCK(hpssi);
  973. return HAL_ERROR;
  974. }
  975. }
  976. else
  977. {
  978. /* Process Unlocked */
  979. __HAL_UNLOCK(hpssi);
  980. /* Enable ERR,interrupt */
  981. HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
  982. }
  983. return HAL_OK;
  984. }
  985. else
  986. {
  987. return HAL_BUSY;
  988. }
  989. }
  990. /**
  991. * @brief Abort a DMA process communication with Interrupt.
  992. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  993. * the configuration information for the specified PSSI.
  994. * @retval HAL status
  995. */
  996. HAL_StatusTypeDef HAL_PSSI_Abort_DMA(PSSI_HandleTypeDef *hpssi)
  997. {
  998. /* Process Locked */
  999. __HAL_LOCK(hpssi);
  1000. /* Disable Interrupts */
  1001. HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
  1002. /* Set State at HAL_PSSI_STATE_ABORT */
  1003. hpssi->State = HAL_PSSI_STATE_ABORT;
  1004. /* Abort DMA TX transfer if any */
  1005. if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
  1006. {
  1007. if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
  1008. {
  1009. hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
  1010. if (hpssi->hdmatx != NULL)
  1011. {
  1012. /* Set the PSSI DMA Abort callback :
  1013. will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
  1014. hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
  1015. /* Abort DMA TX */
  1016. if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
  1017. {
  1018. /* Call Directly XferAbortCallback function in case of error */
  1019. hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
  1020. }
  1021. }
  1022. }
  1023. /* Abort DMA RX transfer if any */
  1024. else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
  1025. {
  1026. hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
  1027. if (hpssi->hdmarx != NULL)
  1028. {
  1029. /* Set the PSSI DMA Abort callback :
  1030. will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
  1031. hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
  1032. /* Abort DMA RX */
  1033. if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
  1034. {
  1035. /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
  1036. hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
  1037. }
  1038. }
  1039. }
  1040. else
  1041. {
  1042. /* Call the error callback */
  1043. hpssi->ErrorCallback(hpssi);
  1044. }
  1045. }
  1046. /* Process Unlocked */
  1047. __HAL_UNLOCK(hpssi);
  1048. /* Note : The PSSI interrupts must be enabled after unlocking current process
  1049. to avoid the risk of PSSI interrupt handle execution before current
  1050. process unlock */
  1051. HAL_PSSI_ENABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
  1052. return HAL_OK;
  1053. }
  1054. /**
  1055. * @}
  1056. */
  1057. /** @addtogroup PSSI_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
  1058. * @{
  1059. */
  1060. /**
  1061. * @brief This function handles PSSI event interrupt request.
  1062. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  1063. * the configuration information for the specified PSSI.
  1064. * @retval None
  1065. */
  1066. void HAL_PSSI_IRQHandler(PSSI_HandleTypeDef *hpssi)
  1067. {
  1068. /* Overrun/ Underrun Errors */
  1069. if (HAL_PSSI_GET_FLAG(hpssi, PSSI_FLAG_OVR_MIS) != 0U)
  1070. {
  1071. /* Reset handle parameters */
  1072. hpssi->XferCount = 0U;
  1073. /* Disable all interrupts */
  1074. HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
  1075. /* Abort DMA TX transfer if any */
  1076. if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
  1077. {
  1078. if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
  1079. {
  1080. /* Set new error code */
  1081. hpssi->ErrorCode |= HAL_PSSI_ERROR_UNDER_RUN;
  1082. hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
  1083. if (hpssi->hdmatx != NULL)
  1084. {
  1085. /* Set the PSSI DMA Abort callback :
  1086. will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
  1087. hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
  1088. /* Process Unlocked */
  1089. __HAL_UNLOCK(hpssi);
  1090. /* Abort DMA TX */
  1091. if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
  1092. {
  1093. /* Call Directly XferAbortCallback function in case of error */
  1094. hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
  1095. }
  1096. }
  1097. }
  1098. /* Abort DMA RX transfer if any */
  1099. else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
  1100. {
  1101. /* Set new error code */
  1102. hpssi->ErrorCode |= HAL_PSSI_ERROR_OVER_RUN;
  1103. hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
  1104. if (hpssi->hdmarx != NULL)
  1105. {
  1106. /* Set the PSSI DMA Abort callback :
  1107. will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
  1108. hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
  1109. /* Process Unlocked */
  1110. __HAL_UNLOCK(hpssi);
  1111. /* Abort DMA RX */
  1112. if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
  1113. {
  1114. /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
  1115. hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
  1116. }
  1117. }
  1118. }
  1119. else
  1120. {
  1121. /* Call the corresponding callback to inform upper layer of the error */
  1122. hpssi->ErrorCallback(hpssi);
  1123. }
  1124. }
  1125. /* If state is an abort treatment on going, don't change state */
  1126. if (hpssi->State == HAL_PSSI_STATE_ABORT)
  1127. {
  1128. /* Process Unlocked */
  1129. __HAL_UNLOCK(hpssi);
  1130. }
  1131. else
  1132. {
  1133. /* Set HAL_PSSI_STATE_READY */
  1134. hpssi->State = HAL_PSSI_STATE_READY;
  1135. /* Process Unlocked */
  1136. __HAL_UNLOCK(hpssi);
  1137. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1138. hpssi->ErrorCallback(hpssi);
  1139. }
  1140. }
  1141. }
  1142. /**
  1143. * @brief Tx Transfer complete callback.
  1144. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  1145. * the configuration information for the specified PSSI.
  1146. * @retval None
  1147. */
  1148. __weak void HAL_PSSI_TxCpltCallback(PSSI_HandleTypeDef *hpssi)
  1149. {
  1150. /* Prevent unused argument(s) compilation warning */
  1151. UNUSED(hpssi);
  1152. /* NOTE : This function should not be modified; when the callback is needed,
  1153. the HAL_PSSI_TxCpltCallback can be implemented in the user file
  1154. */
  1155. }
  1156. /**
  1157. * @brief Rx Transfer complete callback.
  1158. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  1159. * the configuration information for the specified PSSI.
  1160. * @retval None
  1161. */
  1162. __weak void HAL_PSSI_RxCpltCallback(PSSI_HandleTypeDef *hpssi)
  1163. {
  1164. /* Prevent unused argument(s) compilation warning */
  1165. UNUSED(hpssi);
  1166. /* NOTE : This function should not be modified; when the callback is needed,
  1167. the HAL_PSSI_RxCpltCallback can be implemented in the user file
  1168. */
  1169. }
  1170. /**
  1171. * @brief PSSI error callback.
  1172. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  1173. * the configuration information for the specified PSSI.
  1174. * @retval None
  1175. */
  1176. __weak void HAL_PSSI_ErrorCallback(PSSI_HandleTypeDef *hpssi)
  1177. {
  1178. /* Prevent unused argument(s) compilation warning */
  1179. UNUSED(hpssi);
  1180. /* NOTE : This function should not be modified; when the callback is needed,
  1181. the HAL_PSSI_ErrorCallback can be implemented in the user file
  1182. */
  1183. }
  1184. /**
  1185. * @brief PSSI abort callback.
  1186. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  1187. * the configuration information for the specified PSSI.
  1188. * @retval None
  1189. */
  1190. __weak void HAL_PSSI_AbortCpltCallback(PSSI_HandleTypeDef *hpssi)
  1191. {
  1192. /* Prevent unused argument(s) compilation warning */
  1193. UNUSED(hpssi);
  1194. /* NOTE : This function should not be modified; when the callback is needed,
  1195. the HAL_PSSI_AbortCpltCallback can be implemented in the user file
  1196. */
  1197. }
  1198. /**
  1199. * @}
  1200. */
  1201. /** @addtogroup PSSI_Exported_Functions_Group3 Peripheral State, Mode and Error functions
  1202. * @brief Peripheral State, Mode and Error functions
  1203. *
  1204. @verbatim
  1205. ===============================================================================
  1206. ##### Peripheral State, Mode and Error functions #####
  1207. ===============================================================================
  1208. [..]
  1209. This subsection permit to get in run-time the status of the peripheral
  1210. and the data flow.
  1211. @endverbatim
  1212. * @{
  1213. */
  1214. /**
  1215. * @brief Return the PSSI handle state.
  1216. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  1217. * the configuration information for the specified PSSI.
  1218. * @retval HAL state
  1219. */
  1220. HAL_PSSI_StateTypeDef HAL_PSSI_GetState(PSSI_HandleTypeDef *hpssi)
  1221. {
  1222. /* Return PSSI handle state */
  1223. return hpssi->State;
  1224. }
  1225. /**
  1226. * @brief Return the PSSI error code.
  1227. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  1228. * the configuration information for the specified PSSI.
  1229. * @retval PSSI Error Code
  1230. */
  1231. uint32_t HAL_PSSI_GetError(PSSI_HandleTypeDef *hpssi)
  1232. {
  1233. return hpssi->ErrorCode;
  1234. }
  1235. /**
  1236. * @}
  1237. */
  1238. /**
  1239. * @}
  1240. */
  1241. /** @addtogroup PSSI_Private_Functions
  1242. * @{
  1243. */
  1244. /**
  1245. * @brief PSSI Errors process.
  1246. * @param hpssi PSSI handle.
  1247. * @param ErrorCode Error code to handle.
  1248. * @retval None
  1249. */
  1250. static void PSSI_Error(PSSI_HandleTypeDef *hpssi, uint32_t ErrorCode)
  1251. {
  1252. /* Reset handle parameters */
  1253. hpssi->XferCount = 0U;
  1254. /* Set new error code */
  1255. hpssi->ErrorCode |= ErrorCode;
  1256. /* Disable all interrupts */
  1257. HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
  1258. /* Abort DMA TX transfer if any */
  1259. if ((hpssi->Instance->CR & PSSI_CR_DMAEN) == PSSI_CR_DMAEN)
  1260. {
  1261. if (hpssi->State == HAL_PSSI_STATE_BUSY_TX)
  1262. {
  1263. hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
  1264. if (hpssi->hdmatx != NULL)
  1265. {
  1266. /* Set the PSSI DMA Abort callback :
  1267. will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
  1268. hpssi->hdmatx->XferAbortCallback = PSSI_DMAAbort;
  1269. /* Process Unlocked */
  1270. __HAL_UNLOCK(hpssi);
  1271. /* Abort DMA TX */
  1272. if (HAL_DMA_Abort_IT(hpssi->hdmatx) != HAL_OK)
  1273. {
  1274. /* Call Directly XferAbortCallback function in case of error */
  1275. hpssi->hdmatx->XferAbortCallback(hpssi->hdmatx);
  1276. }
  1277. }
  1278. }
  1279. /* Abort DMA RX transfer if any */
  1280. else if (hpssi->State == HAL_PSSI_STATE_BUSY_RX)
  1281. {
  1282. hpssi->Instance->CR &= ~PSSI_CR_DMAEN;
  1283. if (hpssi->hdmarx != NULL)
  1284. {
  1285. /* Set the PSSI DMA Abort callback :
  1286. will lead to call HAL_PSSI_ErrorCallback() at end of DMA abort procedure */
  1287. hpssi->hdmarx->XferAbortCallback = PSSI_DMAAbort;
  1288. /* Process Unlocked */
  1289. __HAL_UNLOCK(hpssi);
  1290. /* Abort DMA RX */
  1291. if (HAL_DMA_Abort_IT(hpssi->hdmarx) != HAL_OK)
  1292. {
  1293. /* Call Directly hpssi->hdma->XferAbortCallback function in case of error */
  1294. hpssi->hdmarx->XferAbortCallback(hpssi->hdmarx);
  1295. }
  1296. }
  1297. }
  1298. else
  1299. {
  1300. /*Nothing to do*/
  1301. }
  1302. }
  1303. /* If state is an abort treatment on going, don't change state */
  1304. if (hpssi->State == HAL_PSSI_STATE_ABORT)
  1305. {
  1306. /* Process Unlocked */
  1307. __HAL_UNLOCK(hpssi);
  1308. }
  1309. else
  1310. {
  1311. /* Set HAL_PSSI_STATE_READY */
  1312. hpssi->State = HAL_PSSI_STATE_READY;
  1313. /* Process Unlocked */
  1314. __HAL_UNLOCK(hpssi);
  1315. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1316. hpssi->ErrorCallback(hpssi);
  1317. }
  1318. }
  1319. /**
  1320. * @brief DMA PSSI slave transmit process complete callback.
  1321. * @param hdma DMA handle
  1322. * @retval None
  1323. */
  1324. void PSSI_DMATransmitCplt(DMA_HandleTypeDef *hdma)
  1325. {
  1326. PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
  1327. uint32_t tmperror;
  1328. /* Disable Interrupts */
  1329. HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
  1330. /* Store current volatile hpssi->ErrorCode, misra rule */
  1331. tmperror = hpssi->ErrorCode;
  1332. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1333. if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
  1334. {
  1335. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1336. PSSI_Error(hpssi, hpssi->ErrorCode);
  1337. }
  1338. /* hpssi->State == HAL_PSSI_STATE_BUSY_TX */
  1339. else
  1340. {
  1341. hpssi->State = HAL_PSSI_STATE_READY;
  1342. /* Process Unlocked */
  1343. __HAL_UNLOCK(hpssi);
  1344. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1345. hpssi->TxCpltCallback(hpssi);
  1346. }
  1347. }
  1348. /**
  1349. * @brief DMA PSSI master receive process complete callback.
  1350. * @param hdma DMA handle
  1351. * @retval None
  1352. */
  1353. void PSSI_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
  1354. {
  1355. PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
  1356. uint32_t tmperror;
  1357. /* Disable Interrupts */
  1358. HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
  1359. /* Store current volatile hpssi->ErrorCode, misra rule */
  1360. tmperror = hpssi->ErrorCode;
  1361. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1362. if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
  1363. {
  1364. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1365. PSSI_Error(hpssi, hpssi->ErrorCode);
  1366. }
  1367. /* hpssi->State == HAL_PSSI_STATE_BUSY_RX */
  1368. else
  1369. {
  1370. hpssi->State = HAL_PSSI_STATE_READY;
  1371. /* Process Unlocked */
  1372. __HAL_UNLOCK(hpssi);
  1373. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1374. hpssi->RxCpltCallback(hpssi);
  1375. }
  1376. }
  1377. /**
  1378. * @brief DMA PSSI communication abort callback
  1379. * (To be called at end of DMA Abort procedure).
  1380. * @param hdma DMA handle.
  1381. * @retval None
  1382. */
  1383. void PSSI_DMAAbort(DMA_HandleTypeDef *hdma)
  1384. {
  1385. PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
  1386. /* Reset AbortCpltCallback */
  1387. hpssi->hdmatx->XferAbortCallback = NULL;
  1388. hpssi->hdmarx->XferAbortCallback = NULL;
  1389. /* Check if come from abort from user */
  1390. if (hpssi->State == HAL_PSSI_STATE_ABORT)
  1391. {
  1392. hpssi->State = HAL_PSSI_STATE_READY;
  1393. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1394. hpssi->AbortCpltCallback(hpssi);
  1395. }
  1396. else
  1397. {
  1398. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1399. hpssi->ErrorCallback(hpssi);
  1400. }
  1401. }
  1402. /**
  1403. * @brief This function handles PSSI Communication Timeout.
  1404. * @param hpssi Pointer to a PSSI_HandleTypeDef structure that contains
  1405. * the configuration information for the specified PSSI.
  1406. * @param Flag Specifies the PSSI flag to check.
  1407. * @param Status The new Flag status (SET or RESET).
  1408. * @param Timeout Timeout duration
  1409. * @param Tickstart Tick start value
  1410. * @retval HAL status
  1411. */
  1412. static HAL_StatusTypeDef PSSI_WaitOnStatusUntilTimeout(PSSI_HandleTypeDef *hpssi, uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart)
  1413. {
  1414. while ((HAL_PSSI_GET_STATUS(hpssi, Flag) & Flag) == (uint32_t)Status)
  1415. {
  1416. /* Check for the Timeout */
  1417. if (Timeout != HAL_MAX_DELAY)
  1418. {
  1419. if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
  1420. {
  1421. hpssi->ErrorCode |= HAL_PSSI_ERROR_TIMEOUT;
  1422. hpssi->State = HAL_PSSI_STATE_READY;
  1423. /* Process Unlocked */
  1424. __HAL_UNLOCK(hpssi);
  1425. return HAL_ERROR;
  1426. }
  1427. }
  1428. }
  1429. return HAL_OK;
  1430. }
  1431. /**
  1432. * @brief DMA PSSI communication error callback
  1433. * @param hdma DMA handle.
  1434. * @retval None
  1435. */
  1436. void PSSI_DMAError(DMA_HandleTypeDef *hdma)
  1437. {
  1438. PSSI_HandleTypeDef *hpssi = (PSSI_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
  1439. uint32_t tmperror;
  1440. /* Disable the selected PSSI peripheral */
  1441. HAL_PSSI_DISABLE(hpssi);
  1442. /* Disable Interrupts */
  1443. HAL_PSSI_DISABLE_IT(hpssi, PSSI_FLAG_OVR_RIS);
  1444. /* Store current volatile hpssi->ErrorCode, misra rule */
  1445. tmperror = hpssi->ErrorCode;
  1446. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1447. if ((hpssi->State == HAL_PSSI_STATE_ABORT) || (tmperror != HAL_PSSI_ERROR_NONE))
  1448. {
  1449. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1450. PSSI_Error(hpssi, hpssi->ErrorCode);
  1451. }
  1452. else
  1453. {
  1454. hpssi->State = HAL_PSSI_STATE_READY;
  1455. /* Process Unlocked */
  1456. __HAL_UNLOCK(hpssi);
  1457. /* Call the corresponding callback to inform upper layer of End of Transfer */
  1458. hpssi->ErrorCallback(hpssi);
  1459. }
  1460. }
  1461. /**
  1462. * @}
  1463. */
  1464. #endif /* HAL_PSSI_MODULE_ENABLED */
  1465. /**
  1466. * @}
  1467. */
  1468. #endif /* PSSI */
  1469. /**
  1470. * @}
  1471. */