stm32l4xx_hal_pssi.c 57 KB

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