1 /**
2 ******************************************************************************
3 * @file stm32u5xx_hal_gfxmmu.c
4 * @author MCD Application Team
5 * @brief This file provides firmware functions to manage the following
6 * functionalities of the Graphic MMU (GFXMMU) peripheral:
7 * + Initialization and De-initialization.
8 * + LUT configuration.
9 * + Force flush and/or invalidate of cache.
10 * + Modify physical buffer addresses.
11 * + Modify cache and pre-fetch parameters.
12 * + Error management.
13 *
14 ******************************************************************************
15 * @attention
16 *
17 * Copyright (c) 2021 STMicroelectronics.
18 * All rights reserved.
19 *
20 * This software is licensed under terms that can be found in the LICENSE file
21 * in the root directory of this software component.
22 * If no LICENSE file comes with this software, it is provided AS-IS.
23 *
24 ******************************************************************************
25 @verbatim
26 ==============================================================================
27 ##### How to use this driver #####
28 ==============================================================================
29 [..]
30 *** Initialization ***
31 ======================
32 [..]
33 (#) As prerequisite, fill in the HAL_GFXMMU_MspInit() :
34 (++) Enable GFXMMU clock interface with __HAL_RCC_GFXMMU_CLK_ENABLE().
35 (++) If interrupts are used, enable and configure GFXMMU global
36 interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
37 (#) Configure the number of blocks per line, default value, physical
38 buffer addresses, cache and pre-fetch parameters and interrupts
39 using the HAL_GFXMMU_Init() function.
40
41 *** LUT configuration ***
42 =========================
43 [..]
44 (#) Use HAL_GFXMMU_DisableLutLines() to deactivate all LUT lines (or a
45 range of lines).
46 (#) Use HAL_GFXMMU_ConfigLut() to copy LUT from flash to look up RAM.
47 (#) Use HAL_GFXMMU_ConfigLutLine() to configure one line of LUT.
48
49 *** Force flush and/or invalidate of cache ***
50 ==============================================
51 [..]
52 (#) Use HAL_GFXMMU_ConfigForceCache() to flush and/or invalidate cache.
53
54 *** Modify physical buffer addresses ***
55 ========================================
56 [..]
57 (#) Use HAL_GFXMMU_ModifyBuffers() to modify physical buffer addresses.
58
59 *** Modify cache and pre-fetch parameters ***
60 =============================================
61 [..]
62 (#) Use HAL_GFXMMU_ModifyCachePrefetch() to modify cache and pre-fetch
63 parameters.
64
65 *** Modify address cache parameters ***
66 =========================================
67 [..]
68 NOTE : This feature is only available on STM32U5F9/STM32U5G9 devices.
69 (#) Use HAL_GFXMMU_ModifyAddressCache() to modify address cache parameters.
70
71 *** Error management ***
72 ========================
73 [..]
74 (#) If interrupts are used, HAL_GFXMMU_IRQHandler() will be called when
75 an error occurs. This function will call HAL_GFXMMU_ErrorCallback().
76 Use HAL_GFXMMU_GetError() to get the error code.
77
78 *** De-initialization ***
79 =========================
80 [..]
81 (#) As prerequisite, fill in the HAL_GFXMMU_MspDeInit() :
82 (++) Disable GFXMMU clock interface with __HAL_RCC_GFXMMU_CLK_ENABLE().
83 (++) If interrupts has been used, disable GFXMMU global interrupt with
84 HAL_NVIC_DisableIRQ().
85 (#) De-initialize GFXMMU using the HAL_GFXMMU_DeInit() function.
86
87 *** Callback registration ***
88 =============================
89 [..]
90 The compilation define USE_HAL_GFXMMU_REGISTER_CALLBACKS when set to 1
91 allows the user to configure dynamically the driver callbacks.
92 Use functions HAL_GFXMMU_RegisterCallback() to register a user callback.
93
94 [..]
95 Function HAL_GFXMMU_RegisterCallback() allows to register following callbacks:
96 (+) ErrorCallback : GFXMMU error.
97 (+) MspInitCallback : GFXMMU MspInit.
98 (+) MspDeInitCallback : GFXMMU MspDeInit.
99 [..]
100 This function takes as parameters the HAL peripheral handle, the callback ID
101 and a pointer to the user callback function.
102
103 [..]
104 Use function HAL_GFXMMU_UnRegisterCallback() to reset a callback to the default
105 weak (overridden) function.
106 HAL_GFXMMU_UnRegisterCallback() takes as parameters the HAL peripheral handle,
107 and the callback ID.
108 [..]
109 This function allows to reset following callbacks:
110 (+) ErrorCallback : GFXMMU error.
111 (+) MspInitCallback : GFXMMU MspInit.
112 (+) MspDeInitCallback : GFXMMU MspDeInit.
113
114 [..]
115 By default, after the HAL_GFXMMU_Init and if the state is HAL_GFXMMU_STATE_RESET
116 all callbacks are reset to the corresponding legacy weak (overridden) functions:
117 examples HAL_GFXMMU_ErrorCallback().
118 Exception done for MspInit and MspDeInit callbacks that are respectively
119 reset to the legacy weak (overridden) functions in the HAL_GFXMMU_Init
120 and HAL_GFXMMU_DeInit only when these callbacks are null (not registered beforehand).
121 If not, MspInit or MspDeInit are not null, the HAL_GFXMMU_Init and HAL_GFXMMU_DeInit
122 keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
123
124 [..]
125 Callbacks can be registered/unregistered in READY state only.
126 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
127 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
128 during the Init/DeInit.
129 In that case first register the MspInit/MspDeInit user callbacks
130 using HAL_GFXMMU_RegisterCallback before calling HAL_GFXMMU_DeInit
131 or HAL_GFXMMU_Init function.
132
133 [..]
134 When the compilation define USE_HAL_GFXMMU_REGISTER_CALLBACKS is set to 0 or
135 not defined, the callback registering feature is not available
136 and weak (overridden) callbacks are used.
137
138 @endverbatim
139 ******************************************************************************
140 */
141
142 /* Includes ------------------------------------------------------------------*/
143 #include "stm32u5xx_hal.h"
144
145 /** @addtogroup STM32U5xx_HAL_Driver
146 * @{
147 */
148 #ifdef HAL_GFXMMU_MODULE_ENABLED
149 #if defined(GFXMMU)
150 /** @defgroup GFXMMU GFXMMU
151 * @brief GFXMMU HAL driver module
152 * @{
153 */
154
155 /* Private typedef -----------------------------------------------------------*/
156 /* Private define ------------------------------------------------------------*/
157 /** @defgroup GFXMMU_Private_Constants GFXMMU Private Constants
158 * @{
159 */
160 #define GFXMMU_LUTXL_FVB_OFFSET 8U
161 #define GFXMMU_LUTXL_LVB_OFFSET 16U
162 #define GFXMMU_CR_ITS_MASK 0x1FU
163 /**
164 * @}
165 */
166 /* Private macro -------------------------------------------------------------*/
167 /* Private variables ---------------------------------------------------------*/
168 /* Private function prototypes -----------------------------------------------*/
169 /* Exported functions --------------------------------------------------------*/
170 /** @defgroup GFXMMU_Exported_Functions GFXMMU Exported Functions
171 * @{
172 */
173
174 /** @defgroup GFXMMU_Exported_Functions_Group1 Initialization and de-initialization functions
175 * @brief Initialization and de-initialization functions
176 *
177 @verbatim
178 ==============================================================================
179 ##### Initialization and de-initialization functions #####
180 ==============================================================================
181 [..] This section provides functions allowing to:
182 (+) Initialize the GFXMMU.
183 (+) De-initialize the GFXMMU.
184 @endverbatim
185 * @{
186 */
187
188 /**
189 * @brief Initialize the GFXMMU according to the specified parameters in the
190 * GFXMMU_InitTypeDef structure and initialize the associated handle.
191 * @param hgfxmmu GFXMMU handle.
192 * @retval HAL status.
193 */
HAL_GFXMMU_Init(GFXMMU_HandleTypeDef * hgfxmmu)194 HAL_StatusTypeDef HAL_GFXMMU_Init(GFXMMU_HandleTypeDef *hgfxmmu)
195 {
196 HAL_StatusTypeDef status = HAL_OK;
197
198 /* Check GFXMMU handle */
199 if (hgfxmmu == NULL)
200 {
201 status = HAL_ERROR;
202 }
203 else
204 {
205 /* Check parameters */
206 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
207 assert_param(IS_GFXMMU_BLOCKS_PER_LINE(hgfxmmu->Init.BlocksPerLine));
208 assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf0Address));
209 assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf1Address));
210 assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf2Address));
211 assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf3Address));
212 #if defined(GFXMMU_CR_CE)
213 assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.CachePrefetch.Activation));
214 #endif /* GFXMMU_CR_CE */
215 assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.Interrupts.Activation));
216 #if defined(GFXMMU_CR_ACE)
217 assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.AddressCache.Activation));
218 #endif /* GFXMMU_CR_ACE */
219
220 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
221 /* Reset callback pointers to the weak predefined callbacks */
222 hgfxmmu->ErrorCallback = HAL_GFXMMU_ErrorCallback;
223
224 /* Call GFXMMU MSP init function */
225 if (hgfxmmu->MspInitCallback == NULL)
226 {
227 hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
228 }
229 hgfxmmu->MspInitCallback(hgfxmmu);
230 #else
231 /* Call GFXMMU MSP init function */
232 HAL_GFXMMU_MspInit(hgfxmmu);
233 #endif /* USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1 */
234
235 /* Configure GFXMMU_CR register */
236 hgfxmmu->Instance->CR = 0U;
237 hgfxmmu->Instance->CR |= (hgfxmmu->Init.BlocksPerLine);
238 #if defined(GFXMMU_CR_CE)
239 if (hgfxmmu->Init.CachePrefetch.Activation == ENABLE)
240 {
241 assert_param(IS_GFXMMU_CACHE_LOCK(hgfxmmu->Init.CachePrefetch.CacheLock));
242 assert_param(IS_GFXMMU_PREFETCH(hgfxmmu->Init.CachePrefetch.Prefetch));
243 assert_param(IS_GFXMMU_OUTTER_BUFFERABILITY(hgfxmmu->Init.CachePrefetch.OutterBufferability));
244 assert_param(IS_GFXMMU_OUTTER_CACHABILITY(hgfxmmu->Init.CachePrefetch.OutterCachability));
245 hgfxmmu->Instance->CR |= (GFXMMU_CR_CE |
246 hgfxmmu->Init.CachePrefetch.CacheLock |
247 hgfxmmu->Init.CachePrefetch.Prefetch |
248 hgfxmmu->Init.CachePrefetch.OutterBufferability |
249 hgfxmmu->Init.CachePrefetch.OutterCachability);
250 if (hgfxmmu->Init.CachePrefetch.CacheLock == GFXMMU_CACHE_LOCK_ENABLE)
251 {
252 assert_param(IS_GFXMMU_CACHE_LOCK_BUFFER(hgfxmmu->Init.CachePrefetch.CacheLockBuffer));
253 assert_param(IS_GFXMMU_CACHE_FORCE(hgfxmmu->Init.CachePrefetch.CacheForce));
254 hgfxmmu->Instance->CR |= (hgfxmmu->Init.CachePrefetch.CacheLockBuffer |
255 hgfxmmu->Init.CachePrefetch.CacheForce);
256 }
257
258 /* Force invalidate cache if cache is enabled */
259 hgfxmmu->Instance->CCR |= GFXMMU_CACHE_FORCE_INVALIDATE;
260 }
261 #endif /* GFXMMU_CR_CE */
262 #if defined(GFXMMU_CR_ACE)
263 if (hgfxmmu->Init.AddressCache.Activation == ENABLE)
264 {
265 assert_param(IS_GFXMMU_ADDRESSCACHE_LOCK_BUFFER(hgfxmmu->Init.AddressCache.AddressCacheLockBuffer));
266 hgfxmmu->Instance->CR |= GFXMMU_CR_ACE |
267 hgfxmmu->Init.AddressCache.AddressCacheLockBuffer;
268 }
269 #endif /* GFXMMU_CR_ACE */
270 if (hgfxmmu->Init.Interrupts.Activation == ENABLE)
271 {
272 assert_param(IS_GFXMMU_INTERRUPTS(hgfxmmu->Init.Interrupts.UsedInterrupts));
273 hgfxmmu->Instance->CR |= hgfxmmu->Init.Interrupts.UsedInterrupts;
274 }
275
276 /* Configure default value on GFXMMU_DVR register */
277 hgfxmmu->Instance->DVR = hgfxmmu->Init.DefaultValue;
278
279 /* Configure physical buffer addresses on GFXMMU_BxCR registers */
280 hgfxmmu->Instance->B0CR = hgfxmmu->Init.Buffers.Buf0Address;
281 hgfxmmu->Instance->B1CR = hgfxmmu->Init.Buffers.Buf1Address;
282 hgfxmmu->Instance->B2CR = hgfxmmu->Init.Buffers.Buf2Address;
283 hgfxmmu->Instance->B3CR = hgfxmmu->Init.Buffers.Buf3Address;
284
285 /* Reset GFXMMU error code */
286 hgfxmmu->ErrorCode = GFXMMU_ERROR_NONE;
287
288 /* Set GFXMMU to ready state */
289 hgfxmmu->State = HAL_GFXMMU_STATE_READY;
290 }
291 /* Return function status */
292 return status;
293 }
294
295 /**
296 * @brief De-initialize the GFXMMU.
297 * @param hgfxmmu GFXMMU handle.
298 * @retval HAL status.
299 */
HAL_GFXMMU_DeInit(GFXMMU_HandleTypeDef * hgfxmmu)300 HAL_StatusTypeDef HAL_GFXMMU_DeInit(GFXMMU_HandleTypeDef *hgfxmmu)
301 {
302 HAL_StatusTypeDef status = HAL_OK;
303
304 /* Check GFXMMU handle */
305 if (hgfxmmu == NULL)
306 {
307 status = HAL_ERROR;
308 }
309 else
310 {
311 /* Check parameters */
312 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
313
314 /* Disable all interrupts on GFXMMU_CR register */
315 hgfxmmu->Instance->CR &= ~(GFXMMU_CR_B0OIE | GFXMMU_CR_B1OIE | GFXMMU_CR_B2OIE | GFXMMU_CR_B3OIE |
316 GFXMMU_CR_AMEIE);
317
318 /* Call GFXMMU MSP de-init function */
319 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
320 if (hgfxmmu->MspDeInitCallback == NULL)
321 {
322 hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
323 }
324 hgfxmmu->MspDeInitCallback(hgfxmmu);
325 #else
326 HAL_GFXMMU_MspDeInit(hgfxmmu);
327 #endif /* USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1 */
328
329 /* Set GFXMMU to reset state */
330 hgfxmmu->State = HAL_GFXMMU_STATE_RESET;
331 }
332 /* Return function status */
333 return status;
334 }
335
336 /**
337 * @brief Initialize the GFXMMU MSP.
338 * @param hgfxmmu GFXMMU handle.
339 * @retval None.
340 */
HAL_GFXMMU_MspInit(GFXMMU_HandleTypeDef * hgfxmmu)341 __weak void HAL_GFXMMU_MspInit(GFXMMU_HandleTypeDef *hgfxmmu)
342 {
343 /* Prevent unused argument(s) compilation warning */
344 UNUSED(hgfxmmu);
345
346 /* NOTE : This function should not be modified, when the function is needed,
347 the HAL_GFXMMU_MspInit could be implemented in the user file.
348 */
349 }
350
351 /**
352 * @brief De-initialize the GFXMMU MSP.
353 * @param hgfxmmu GFXMMU handle.
354 * @retval None.
355 */
HAL_GFXMMU_MspDeInit(GFXMMU_HandleTypeDef * hgfxmmu)356 __weak void HAL_GFXMMU_MspDeInit(GFXMMU_HandleTypeDef *hgfxmmu)
357 {
358 /* Prevent unused argument(s) compilation warning */
359 UNUSED(hgfxmmu);
360
361 /* NOTE : This function should not be modified, when the function is needed,
362 the HAL_GFXMMU_MspDeInit could be implemented in the user file.
363 */
364 }
365
366 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
367 /**
368 * @brief Register a user GFXMMU callback
369 * to be used instead of the weak predefined callback.
370 * @param hgfxmmu GFXMMU handle.
371 * @param CallbackID ID of the callback to be registered.
372 * This parameter can be one of the following values:
373 * @arg @ref HAL_GFXMMU_ERROR_CB_ID error callback ID.
374 * @arg @ref HAL_GFXMMU_MSPINIT_CB_ID MSP init callback ID.
375 * @arg @ref HAL_GFXMMU_MSPDEINIT_CB_ID MSP de-init callback ID.
376 * @param pCallback pointer to the callback function.
377 * @retval HAL status.
378 */
HAL_GFXMMU_RegisterCallback(GFXMMU_HandleTypeDef * hgfxmmu,HAL_GFXMMU_CallbackIDTypeDef CallbackID,pGFXMMU_CallbackTypeDef pCallback)379 HAL_StatusTypeDef HAL_GFXMMU_RegisterCallback(GFXMMU_HandleTypeDef *hgfxmmu,
380 HAL_GFXMMU_CallbackIDTypeDef CallbackID,
381 pGFXMMU_CallbackTypeDef pCallback)
382 {
383 HAL_StatusTypeDef status = HAL_OK;
384
385 if (pCallback == NULL)
386 {
387 /* update the error code */
388 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
389 /* update return status */
390 status = HAL_ERROR;
391 }
392 else
393 {
394 if (HAL_GFXMMU_STATE_READY == hgfxmmu->State)
395 {
396 switch (CallbackID)
397 {
398 case HAL_GFXMMU_ERROR_CB_ID :
399 hgfxmmu->ErrorCallback = pCallback;
400 break;
401 case HAL_GFXMMU_MSPINIT_CB_ID :
402 hgfxmmu->MspInitCallback = pCallback;
403 break;
404 case HAL_GFXMMU_MSPDEINIT_CB_ID :
405 hgfxmmu->MspDeInitCallback = pCallback;
406 break;
407 default :
408 /* update the error code */
409 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
410 /* update return status */
411 status = HAL_ERROR;
412 break;
413 }
414 }
415 else if (HAL_GFXMMU_STATE_RESET == hgfxmmu->State)
416 {
417 switch (CallbackID)
418 {
419 case HAL_GFXMMU_MSPINIT_CB_ID :
420 hgfxmmu->MspInitCallback = pCallback;
421 break;
422 case HAL_GFXMMU_MSPDEINIT_CB_ID :
423 hgfxmmu->MspDeInitCallback = pCallback;
424 break;
425 default :
426 /* update the error code */
427 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
428 /* update return status */
429 status = HAL_ERROR;
430 break;
431 }
432 }
433 else
434 {
435 /* update the error code */
436 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
437 /* update return status */
438 status = HAL_ERROR;
439 }
440 }
441 return status;
442 }
443
444 /**
445 * @brief Unregister a user GFXMMU callback.
446 * GFXMMU callback is redirected to the weak predefined callback.
447 * @param hgfxmmu GFXMMU handle.
448 * @param CallbackID ID of the callback to be unregistered.
449 * This parameter can be one of the following values:
450 * @arg @ref HAL_GFXMMU_ERROR_CB_ID error callback ID.
451 * @arg @ref HAL_GFXMMU_MSPINIT_CB_ID MSP init callback ID.
452 * @arg @ref HAL_GFXMMU_MSPDEINIT_CB_ID MSP de-init callback ID.
453 * @retval HAL status.
454 */
HAL_GFXMMU_UnRegisterCallback(GFXMMU_HandleTypeDef * hgfxmmu,HAL_GFXMMU_CallbackIDTypeDef CallbackID)455 HAL_StatusTypeDef HAL_GFXMMU_UnRegisterCallback(GFXMMU_HandleTypeDef *hgfxmmu,
456 HAL_GFXMMU_CallbackIDTypeDef CallbackID)
457 {
458 HAL_StatusTypeDef status = HAL_OK;
459
460 if (HAL_GFXMMU_STATE_READY == hgfxmmu->State)
461 {
462 switch (CallbackID)
463 {
464 case HAL_GFXMMU_ERROR_CB_ID :
465 hgfxmmu->ErrorCallback = HAL_GFXMMU_ErrorCallback;
466 break;
467 case HAL_GFXMMU_MSPINIT_CB_ID :
468 hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
469 break;
470 case HAL_GFXMMU_MSPDEINIT_CB_ID :
471 hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
472 break;
473 default :
474 /* update the error code */
475 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
476 /* update return status */
477 status = HAL_ERROR;
478 break;
479 }
480 }
481 else if (HAL_GFXMMU_STATE_RESET == hgfxmmu->State)
482 {
483 switch (CallbackID)
484 {
485 case HAL_GFXMMU_MSPINIT_CB_ID :
486 hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
487 break;
488 case HAL_GFXMMU_MSPDEINIT_CB_ID :
489 hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
490 break;
491 default :
492 /* update the error code */
493 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
494 /* update return status */
495 status = HAL_ERROR;
496 break;
497 }
498 }
499 else
500 {
501 /* update the error code */
502 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
503 /* update return status */
504 status = HAL_ERROR;
505 }
506 return status;
507 }
508 #endif /* USE_HAL_GFXMMU_REGISTER_CALLBACKS */
509
510 /**
511 * @}
512 */
513
514 /** @defgroup GFXMMU_Exported_Functions_Group2 Operations functions
515 * @brief GFXMMU operation functions
516 *
517 @verbatim
518 ==============================================================================
519 ##### Operation functions #####
520 ==============================================================================
521 [..] This section provides functions allowing to:
522 (+) Configure LUT.
523 (+) Force flush and/or invalidate of cache.
524 (+) Modify physical buffer addresses.
525 (+) Modify cache and pre-fetch parameters.
526 (+) Manage error.
527 @endverbatim
528 * @{
529 */
530
531 /**
532 * @brief This function allows to copy LUT from flash to look up RAM.
533 * @param hgfxmmu GFXMMU handle.
534 * @param FirstLine First line enabled on LUT.
535 * This parameter must be a number between Min_Data = 0 and Max_Data = 1023.
536 * @param LinesNumber Number of lines enabled on LUT.
537 * This parameter must be a number between Min_Data = 1 and Max_Data = 1024.
538 * @param Address Start address of LUT in flash.
539 * @retval HAL status.
540 */
HAL_GFXMMU_ConfigLut(GFXMMU_HandleTypeDef * hgfxmmu,uint32_t FirstLine,uint32_t LinesNumber,uint32_t Address)541 HAL_StatusTypeDef HAL_GFXMMU_ConfigLut(GFXMMU_HandleTypeDef *hgfxmmu,
542 uint32_t FirstLine,
543 uint32_t LinesNumber,
544 uint32_t Address)
545 {
546 HAL_StatusTypeDef status = HAL_OK;
547
548 /* Check parameters */
549 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
550 assert_param(IS_GFXMMU_LUT_LINE(FirstLine));
551 assert_param(IS_GFXMMU_LUT_LINES_NUMBER(LinesNumber));
552
553 /* Check GFXMMU state and coherent parameters */
554 if ((hgfxmmu->State != HAL_GFXMMU_STATE_READY) || ((FirstLine + LinesNumber) > 1024U))
555 {
556 status = HAL_ERROR;
557 }
558 else
559 {
560 uint32_t current_address;
561 uint32_t current_line;
562 uint32_t lutxl_address;
563 uint32_t lutxh_address;
564
565 /* Initialize local variables */
566 current_address = Address;
567 current_line = 0U;
568 lutxl_address = (uint32_t) &(hgfxmmu->Instance->LUT[2U * FirstLine]);
569 lutxh_address = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * FirstLine) + 1U]);
570
571 /* Copy LUT from flash to look up RAM */
572 while (current_line < LinesNumber)
573 {
574 *((uint32_t *)lutxl_address) = *((uint32_t *)current_address);
575 current_address += 4U;
576 *((uint32_t *)lutxh_address) = *((uint32_t *)current_address);
577 current_address += 4U;
578 lutxl_address += 8U;
579 lutxh_address += 8U;
580 current_line++;
581 }
582 }
583 /* Return function status */
584 return status;
585 }
586
587 /**
588 * @brief This function allows to disable a range of LUT lines.
589 * @param hgfxmmu GFXMMU handle.
590 * @param FirstLine First line to disable on LUT.
591 * This parameter must be a number between Min_Data = 0 and Max_Data = 1023.
592 * @param LinesNumber Number of lines to disable on LUT.
593 * This parameter must be a number between Min_Data = 1 and Max_Data = 1024.
594 * @retval HAL status.
595 */
HAL_GFXMMU_DisableLutLines(GFXMMU_HandleTypeDef * hgfxmmu,uint32_t FirstLine,uint32_t LinesNumber)596 HAL_StatusTypeDef HAL_GFXMMU_DisableLutLines(GFXMMU_HandleTypeDef *hgfxmmu,
597 uint32_t FirstLine,
598 uint32_t LinesNumber)
599 {
600 HAL_StatusTypeDef status = HAL_OK;
601
602 /* Check parameters */
603 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
604 assert_param(IS_GFXMMU_LUT_LINE(FirstLine));
605 assert_param(IS_GFXMMU_LUT_LINES_NUMBER(LinesNumber));
606
607 /* Check GFXMMU state and coherent parameters */
608 if ((hgfxmmu->State != HAL_GFXMMU_STATE_READY) || ((FirstLine + LinesNumber) > 1024U))
609 {
610 status = HAL_ERROR;
611 }
612 else
613 {
614 uint32_t current_line;
615 uint32_t lutxl_address;
616 uint32_t lutxh_address;
617
618 /* Initialize local variables */
619 current_line = 0U;
620 lutxl_address = (uint32_t) &(hgfxmmu->Instance->LUT[2U * FirstLine]);
621 lutxh_address = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * FirstLine) + 1U]);
622
623 /* Disable LUT lines */
624 while (current_line < LinesNumber)
625 {
626 *((uint32_t *)lutxl_address) = 0U;
627 *((uint32_t *)lutxh_address) = 0U;
628 lutxl_address += 8U;
629 lutxh_address += 8U;
630 current_line++;
631 }
632 }
633 /* Return function status */
634 return status;
635 }
636
637 /**
638 * @brief This function allows to configure one line of LUT.
639 * @param hgfxmmu GFXMMU handle.
640 * @param lutLine LUT line parameters.
641 * @retval HAL status.
642 */
HAL_GFXMMU_ConfigLutLine(GFXMMU_HandleTypeDef * hgfxmmu,GFXMMU_LutLineTypeDef * lutLine)643 HAL_StatusTypeDef HAL_GFXMMU_ConfigLutLine(GFXMMU_HandleTypeDef *hgfxmmu, GFXMMU_LutLineTypeDef *lutLine)
644 {
645 HAL_StatusTypeDef status = HAL_OK;
646
647 /* Check parameters */
648 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
649 assert_param(IS_GFXMMU_LUT_LINE(lutLine->LineNumber));
650 assert_param(IS_GFXMMU_LUT_LINE_STATUS(lutLine->LineStatus));
651 assert_param(IS_GFXMMU_LUT_BLOCK(lutLine->FirstVisibleBlock));
652 assert_param(IS_GFXMMU_LUT_BLOCK(lutLine->LastVisibleBlock));
653 assert_param(IS_GFXMMU_LUT_LINE_OFFSET(lutLine->LineOffset));
654
655 /* Check GFXMMU state */
656 if (hgfxmmu->State != HAL_GFXMMU_STATE_READY)
657 {
658 status = HAL_ERROR;
659 }
660 else
661 {
662 uint32_t lutxl_address;
663 uint32_t lutxh_address;
664
665 /* Initialize local variables */
666 lutxl_address = (uint32_t) &(hgfxmmu->Instance->LUT[2U * lutLine->LineNumber]);
667 lutxh_address = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * lutLine->LineNumber) + 1U]);
668
669 /* Configure LUT line */
670 if (lutLine->LineStatus == GFXMMU_LUT_LINE_ENABLE)
671 {
672 /* Enable and configure LUT line */
673 *((uint32_t *)lutxl_address) = (lutLine->LineStatus |
674 (lutLine->FirstVisibleBlock << GFXMMU_LUTXL_FVB_OFFSET) |
675 (lutLine->LastVisibleBlock << GFXMMU_LUTXL_LVB_OFFSET));
676 *((uint32_t *)lutxh_address) = (uint32_t) lutLine->LineOffset;
677 }
678 else
679 {
680 /* Disable LUT line */
681 *((uint32_t *)lutxl_address) = 0U;
682 *((uint32_t *)lutxh_address) = 0U;
683 }
684 }
685 /* Return function status */
686 return status;
687 }
688 #if defined(GFXMMU_CR_CE)
689
690 /**
691 * @brief This function allows to force flush and/or invalidate of cache.
692 * @param hgfxmmu GFXMMU handle.
693 * @param ForceParam Force cache parameter.
694 * This parameter can be a values combination of @ref GFXMMU_CacheForceParam.
695 * @retval HAL status.
696 * @note This function is only available on STM32U599/STM32U5A9 devices.
697 */
HAL_GFXMMU_ConfigForceCache(GFXMMU_HandleTypeDef * hgfxmmu,uint32_t ForceParam)698 HAL_StatusTypeDef HAL_GFXMMU_ConfigForceCache(GFXMMU_HandleTypeDef *hgfxmmu, uint32_t ForceParam)
699 {
700 HAL_StatusTypeDef status = HAL_OK;
701
702 /* Check parameters */
703 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
704 assert_param(IS_GFXMMU_CACHE_FORCE_ACTION(ForceParam));
705
706 /* Check GFXMMU state and cache status */
707 if (((hgfxmmu->Instance->CR & GFXMMU_CR_CE) != GFXMMU_CR_CE) || (hgfxmmu->State != HAL_GFXMMU_STATE_READY))
708 {
709 status = HAL_ERROR;
710 }
711 else
712 {
713 /* Force flush and/or invalidate cache on GFXMMU_CCR register */
714 hgfxmmu->Instance->CCR |= ForceParam;
715 }
716 /* Return function status */
717 return status;
718 }
719 #endif /* GFXMMU_CR_CE */
720
721 /**
722 * @brief This function allows to modify physical buffer addresses.
723 * @param hgfxmmu GFXMMU handle.
724 * @param Buffers Buffers parameters.
725 * @retval HAL status.
726 * @note This function is only available on STM32U599/STM32U5A9 devices.
727 */
HAL_GFXMMU_ModifyBuffers(GFXMMU_HandleTypeDef * hgfxmmu,GFXMMU_BuffersTypeDef * Buffers)728 HAL_StatusTypeDef HAL_GFXMMU_ModifyBuffers(GFXMMU_HandleTypeDef *hgfxmmu, GFXMMU_BuffersTypeDef *Buffers)
729 {
730 HAL_StatusTypeDef status = HAL_OK;
731
732 /* Check parameters */
733 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
734 assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf0Address));
735 assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf1Address));
736 assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf2Address));
737 assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf3Address));
738
739 /* Check GFXMMU state */
740 if (hgfxmmu->State != HAL_GFXMMU_STATE_READY)
741 {
742 status = HAL_ERROR;
743 }
744 else
745 {
746 /* Modify physical buffer addresses on GFXMMU_BxCR registers */
747 hgfxmmu->Instance->B0CR = Buffers->Buf0Address;
748 hgfxmmu->Instance->B1CR = Buffers->Buf1Address;
749 hgfxmmu->Instance->B2CR = Buffers->Buf2Address;
750 hgfxmmu->Instance->B3CR = Buffers->Buf3Address;
751 }
752 /* Return function status */
753 return status;
754 }
755 #if defined(GFXMMU_CR_CE)
756 /**
757 * @brief This function allows to modify cache and pre-fetch parameters.
758 * @param hgfxmmu GFXMMU handle.
759 * @param CachePrefetch Cache and pre-fetch parameters.
760 * @retval HAL status.
761 * @note This function is only available on STM32U599/STM32U5A9 devices.
762 */
HAL_GFXMMU_ModifyCachePrefetch(GFXMMU_HandleTypeDef * hgfxmmu,GFXMMU_CachePrefetchTypeDef * CachePrefetch)763 HAL_StatusTypeDef HAL_GFXMMU_ModifyCachePrefetch(GFXMMU_HandleTypeDef *hgfxmmu,
764 GFXMMU_CachePrefetchTypeDef *CachePrefetch)
765 {
766 HAL_StatusTypeDef status = HAL_OK;
767 assert_param(IS_FUNCTIONAL_STATE(CachePrefetch->Activation));
768
769 /* Check parameters */
770 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
771
772 /* Check GFXMMU state */
773 if (hgfxmmu->State != HAL_GFXMMU_STATE_READY)
774 {
775 status = HAL_ERROR;
776 }
777 else
778 {
779 /* Modify cache and pre-fetch parameters on GFXMMU_CR register */
780 hgfxmmu->Instance->CR &= ~(GFXMMU_CR_CE | GFXMMU_CR_CL | GFXMMU_CR_CLB | GFXMMU_CR_FC |
781 GFXMMU_CR_PD | GFXMMU_CR_OC | GFXMMU_CR_OB);
782 if (CachePrefetch->Activation == ENABLE)
783 {
784 assert_param(IS_GFXMMU_CACHE_LOCK(CachePrefetch->CacheLock));
785 assert_param(IS_GFXMMU_PREFETCH(CachePrefetch->Prefetch));
786 assert_param(IS_GFXMMU_OUTTER_BUFFERABILITY(CachePrefetch->OutterBufferability));
787 assert_param(IS_GFXMMU_OUTTER_CACHABILITY(CachePrefetch->OutterCachability));
788 hgfxmmu->Instance->CR |= (GFXMMU_CR_CE |
789 CachePrefetch->CacheLock |
790 CachePrefetch->Prefetch |
791 CachePrefetch->OutterBufferability |
792 CachePrefetch->OutterCachability);
793 if (CachePrefetch->CacheLock == GFXMMU_CACHE_LOCK_ENABLE)
794 {
795 assert_param(IS_GFXMMU_CACHE_LOCK_BUFFER(CachePrefetch->CacheLockBuffer));
796 assert_param(IS_GFXMMU_CACHE_FORCE(CachePrefetch->CacheForce));
797 hgfxmmu->Instance->CR |= (CachePrefetch->CacheLockBuffer |
798 CachePrefetch->CacheForce);
799 }
800 }
801 }
802 /* Return function status */
803 return status;
804 }
805
806 #endif /* GFXMMU_CR_CE */
807 #if defined(GFXMMU_CR_ACE)
808
809 /**
810 * @brief This function allows to modify address cache parameters.
811 * @param hgfxmmu GFXMMU handle.
812 * @param AddressCache address cache parameters.
813 * @retval HAL status.
814 * @note This function is only available on STM32U5F9/STM32U5G9 devices.
815 */
HAL_GFXMMU_ModifyAddressCache(GFXMMU_HandleTypeDef * hgfxmmu,GFXMMU_AddressCacheTypeDef * AddressCache)816 HAL_StatusTypeDef HAL_GFXMMU_ModifyAddressCache(GFXMMU_HandleTypeDef *hgfxmmu,
817 GFXMMU_AddressCacheTypeDef *AddressCache)
818 {
819 HAL_StatusTypeDef status = HAL_OK;
820 assert_param(IS_FUNCTIONAL_STATE(AddressCache->Activation));
821 /* Check parameters */
822 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
823 /* Check GFXMMU state */
824 if (hgfxmmu->State != HAL_GFXMMU_STATE_READY)
825 {
826 status = HAL_ERROR;
827 }
828 else
829 {
830 /* Modify Address cache parameters on GFXMMU_CR register */
831 hgfxmmu->Instance->CR &= ~(GFXMMU_CR_ACE | GFXMMU_CR_ACLB);
832 if (AddressCache->Activation == ENABLE)
833 {
834 assert_param(IS_GFXMMU_ADDRESSCACHE_LOCK_BUFFER(AddressCache->AddressCacheLockBuffer));
835 hgfxmmu->Instance->CR |= (GFXMMU_CR_ACE |
836 AddressCache->AddressCacheLockBuffer);
837 }
838 }
839 /* Return function status */
840 return status;
841 }
842
843 #endif /* GFXMMU_CR_ACE */
844 /**
845 * @brief This function handles the GFXMMU interrupts.
846 * @param hgfxmmu GFXMMU handle.
847 * @retval None.
848 */
HAL_GFXMMU_IRQHandler(GFXMMU_HandleTypeDef * hgfxmmu)849 void HAL_GFXMMU_IRQHandler(GFXMMU_HandleTypeDef *hgfxmmu)
850 {
851 uint32_t flags, interrupts, error;
852
853 /* Read current flags and interrupts and determine which error occurs */
854 flags = hgfxmmu->Instance->SR;
855 interrupts = (hgfxmmu->Instance->CR & GFXMMU_CR_ITS_MASK);
856 error = (flags & interrupts);
857
858 if (error != 0U)
859 {
860 /* Clear flags on GFXMMU_FCR register */
861 hgfxmmu->Instance->FCR = error;
862
863 /* Update GFXMMU error code */
864 hgfxmmu->ErrorCode |= error;
865
866 /* Call GFXMMU error callback */
867 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
868 hgfxmmu->ErrorCallback(hgfxmmu);
869 #else
870 HAL_GFXMMU_ErrorCallback(hgfxmmu);
871 #endif /* USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1 */
872 }
873 }
874
875 /**
876 * @brief Error callback.
877 * @param hgfxmmu GFXMMU handle.
878 * @retval None.
879 */
HAL_GFXMMU_ErrorCallback(GFXMMU_HandleTypeDef * hgfxmmu)880 __weak void HAL_GFXMMU_ErrorCallback(GFXMMU_HandleTypeDef *hgfxmmu)
881 {
882 /* Prevent unused argument(s) compilation warning */
883 UNUSED(hgfxmmu);
884
885 /* NOTE : This function should not be modified, when the callback is needed,
886 the HAL_GFXMMU_ErrorCallback could be implemented in the user file.
887 */
888 }
889
890 /**
891 * @}
892 */
893
894 /** @defgroup GFXMMU_Exported_Functions_Group3 State functions
895 * @brief GFXMMU state functions
896 *
897 @verbatim
898 ==============================================================================
899 ##### State functions #####
900 ==============================================================================
901 [..] This section provides functions allowing to:
902 (+) Get GFXMMU handle state.
903 (+) Get GFXMMU error code.
904 @endverbatim
905 * @{
906 */
907
908 /**
909 * @brief This function allows to get the current GFXMMU handle state.
910 * @param hgfxmmu GFXMMU handle.
911 * @retval GFXMMU state.
912 */
HAL_GFXMMU_GetState(GFXMMU_HandleTypeDef * hgfxmmu)913 HAL_GFXMMU_StateTypeDef HAL_GFXMMU_GetState(GFXMMU_HandleTypeDef *hgfxmmu)
914 {
915 /* Return GFXMMU handle state */
916 return hgfxmmu->State;
917 }
918
919 /**
920 * @brief This function allows to get the current GFXMMU error code.
921 * @param hgfxmmu GFXMMU handle.
922 * @retval GFXMMU error code.
923 */
HAL_GFXMMU_GetError(GFXMMU_HandleTypeDef * hgfxmmu)924 uint32_t HAL_GFXMMU_GetError(GFXMMU_HandleTypeDef *hgfxmmu)
925 {
926 uint32_t error_code;
927
928 /* Enter in critical section */
929 __disable_irq();
930
931 /* Store and reset GFXMMU error code */
932 error_code = hgfxmmu->ErrorCode;
933 hgfxmmu->ErrorCode = GFXMMU_ERROR_NONE;
934
935 /* Exit from critical section */
936 __enable_irq();
937
938 /* Return GFXMMU error code */
939 return error_code;
940 }
941
942 /**
943 * @}
944 */
945
946 /**
947 * @}
948 */
949 /* End of exported functions -------------------------------------------------*/
950 /* Private functions ---------------------------------------------------------*/
951 /* End of private functions --------------------------------------------------*/
952
953 /**
954 * @}
955 */
956 #endif /* GFXMMU */
957 #endif /* HAL_GFXMMU_MODULE_ENABLED */
958 /**
959 * @}
960 */
961