Skip to main content
Visitor II
March 28, 2025
Question

STM32N6 STM32N6570-DK DMA2D Not working

  • March 28, 2025
  • 1 reply
  • 686 views

Hello,

I'm trying to use the LTDC peripheral with DMA2D to be able to send a image to the display without using the CPU

So first i used the example LTDC_Horizontal_Mirroring to have a working LCD . Compiling it i have the dolphin on my screen and flip horizontally.

Next step i used the same config as the project DMA2D_MemoryTo_Memory. So DMA2D in M2M, ARGB4444 in input /ouput alpha input at 0xFF and enable the interrupt (done in my LTDC_Horizontal_Mirroring project)(Also enable I and D cache for cortex M55).

After i used the same code for the dma in the M2M project , but when i use the debug tool or put the ouput buffer in my screen i have only 0.

I checked all register for DMA and the config and adress for in and out (DMA) correspond to the address of the buffer i gave to DMA.

Any ideas ?

Thanks.

 

/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file : main.c
 * @brief : Main program body
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2024 STMicroelectronics.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "dolphin_156x129_565.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define LAYER_SIZE_X				16
#define LAYER_SIZE_Y				32
#define LAYER_NB_BYTES_PER_PIXEL	2 /* because ARGB4444 format in input texture */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

DMA2D_HandleTypeDef hdma2d;

LTDC_HandleTypeDef hltdc;

/* USER CODE BEGIN PV */
__ALIGN_BEGIN uint32_t aBufferResult[(LAYER_SIZE_X * LAYER_SIZE_Y * LAYER_NB_BYTES_PER_PIXEL) / 4] __attribute__((aligned(16))) __NON_CACHEABLE = {0};

/* ARGB4444 input buffer 16bpp */
__ALIGN_BEGIN uint32_t aBufferInput[(LAYER_SIZE_X * LAYER_SIZE_Y * LAYER_NB_BYTES_PER_PIXEL) / 4] __attribute__((aligned(16))) =
{0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203,
0xEFFFFFF2, 0xAB1FFFF0, 0x0504044E, 0x89ADCDEF, 0x15248722, 0x5201245E, 0x01025FDE, 0xFE010203} ;
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_LTDC_Init(void);
static void MX_DMA2D_Init(void);
/* USER CODE BEGIN PFP */
void MPU_Config(void);
static void TransferError(DMA2D_HandleTypeDef* dma2dHandle);
static void TransferComplete(DMA2D_HandleTypeDef* dma2dHandle);
ErrorStatus Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint32_t BufferLength);
/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
 * @brief The application entry point.
 * @retval int
 */
int main(void)
{

 /* USER CODE BEGIN 1 */
	 MPU_Config();
 /* USER CODE END 1 */

 /* Enable the CPU Cache */

 /* Enable I-Cache---------------------------------------------------------*/
 SCB_EnableICache();

 /* Enable D-Cache---------------------------------------------------------*/
 SCB_EnableDCache();

 /* MCU Configuration--------------------------------------------------------*/
 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */
 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_LTDC_Init();
 MX_DMA2D_Init();
 /* USER CODE BEGIN 2 */
 BSP_LED_Init(LED1);
 BSP_LED_Init(LED2);
 /* DMA2D Callbacks Configuration*/
 hdma2d.XferCpltCallback = TransferComplete;
 hdma2d.XferErrorCallback = TransferError;
 /* Start DMA2D transfer*/
 if(HAL_DMA2D_Start_IT(&hdma2d,
 (uint32_t)&aBufferInput, /* Source memory buffer */
 (uint32_t)&aBufferResult, /* Destination memory buffer */
 LAYER_SIZE_X, /* Width of the 2D memory transfer in pixels */
 LAYER_SIZE_Y) /* Height of the 2D memory transfer in lines */
 != HAL_OK)
 {
 /* Initialization Error */
 Error_Handler();
 }

 /* Wait for the end of the transfer*/
 /* Before starting a new transfer, you need to check the current state of
 the peripheral; if it is busy you need to wait for the end of current
 transfer before starting a new one.
 For simplicity reasons, this example is just waiting till the end of the
 transfer, but application may perform other tasks while transfer operation
 is ongoing. */
 while (HAL_DMA2D_GetState(&hdma2d) != HAL_DMA2D_STATE_READY)
 {
 HAL_Delay(100);

 BSP_LED_Off(LED1);

 /* Check transfer correctness*/
 if(Buffercmp(aBufferInput,
 aBufferResult,
 ((LAYER_SIZE_X * LAYER_SIZE_Y * LAYER_NB_BYTES_PER_PIXEL) / 4)) == ERROR)
 {
 /* KO */
 /* Turn LD3 On */
 BSP_LED_On(LED2);
 }
 else
 {
 /* OK */
 /* Turn on LD1 */
 BSP_LED_On(LED1);
 }
 }

 HAL_LTDC_SetAddress(&hltdc, (uint32_t) dolphin_156x129_565, 0);
 /* USER CODE END 2 */

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */
 HAL_Delay(1000);
 HAL_LTDC_ConfigMirror(&hltdc,LTDC_MIRROR_HORIZONTAL, 0);
 HAL_Delay(1000);
 HAL_LTDC_ConfigMirror(&hltdc,LTDC_MIRROR_NONE, 0);

 }
 /* USER CODE END 3 */
}
/* USER CODE BEGIN CLK 1 */

/* The system Clock is configured as follows :
 CPU Clock source = IC1_CK
 System bus Clock source = IC2_IC6_IC11_CK
 CPUCLK (sysa_ck) (Hz) = 600000000
 SYSCLK AXI (sysb_ck) (Hz) = 400000000
 SYSCLK NPU (sysc_ck) (Hz) = 300000000
 SYSCLK AXISRAM3/4/5/6 (sysd_ck) (Hz) = 400000000
 HCLKx(Hz) = 200000000
 PCLKx(Hz) = 200000000
 AHB Prescaler = 2
 APB1 Prescaler = 1
 APB2 Prescaler = 1
 APB4 Prescaler = 1
 APB5 Prescaler = 1
 PLL1 State = ON
 PLL1 clock source = HSI
 PLL1 M = 4
 PLL1 N = 75
 PLL1 P1 = 1
 PLL1 P2 = 1
 PLL1 FRACN = 0
 PLL2 State = BYPASS
 PLL2 clock source = HSI
 PLL3 State = BYPASS
 PLL3 clock source = HSI
 PLL4 State = BYPASS
 PLL4 clock source = HSI
*/
/* USER CODE END CLK 1 */

/**
 * @brief System Clock Configuration
 * @retval None
 */
void SystemClock_Config(void)
{
 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 /** Configure the System Power Supply
 */
 if (HAL_PWREx_ConfigSupply(PWR_EXTERNAL_SOURCE_SUPPLY) != HAL_OK)
 {
 Error_Handler();
 }

 /* Enable HSI */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.PLL1.PLLState = RCC_PLL_NONE;
 RCC_OscInitStruct.PLL2.PLLState = RCC_PLL_NONE;
 RCC_OscInitStruct.PLL3.PLLState = RCC_PLL_NONE;
 RCC_OscInitStruct.PLL4.PLLState = RCC_PLL_NONE;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }

 /** Get current CPU/System buses clocks configuration and if necessary switch
 to intermediate HSI clock to ensure target clock can be set
 */
 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct);
 if ((RCC_ClkInitStruct.CPUCLKSource == RCC_CPUCLKSOURCE_IC1) ||
 (RCC_ClkInitStruct.SYSCLKSource == RCC_SYSCLKSOURCE_IC2_IC6_IC11))
 {
 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_CPUCLK | RCC_CLOCKTYPE_SYSCLK);
 RCC_ClkInitStruct.CPUCLKSource = RCC_CPUCLKSOURCE_HSI;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct) != HAL_OK)
 {
 /* Initialization Error */
 Error_Handler();
 }
 }

 /** Initializes the RCC Oscillators according to the specified parameters
 * in the RCC_OscInitTypeDef structure.
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_NONE;
 RCC_OscInitStruct.PLL1.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL1.PLLSource = RCC_PLLSOURCE_HSI;
 RCC_OscInitStruct.PLL1.PLLM = 4;
 RCC_OscInitStruct.PLL1.PLLN = 75;
 RCC_OscInitStruct.PLL1.PLLFractional = 0;
 RCC_OscInitStruct.PLL1.PLLP1 = 1;
 RCC_OscInitStruct.PLL1.PLLP2 = 1;
 RCC_OscInitStruct.PLL2.PLLState = RCC_PLL_NONE;
 RCC_OscInitStruct.PLL3.PLLState = RCC_PLL_NONE;
 RCC_OscInitStruct.PLL4.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL4.PLLSource = RCC_PLLSOURCE_HSI;
 RCC_OscInitStruct.PLL4.PLLM = 1;
 RCC_OscInitStruct.PLL4.PLLN = 25;
 RCC_OscInitStruct.PLL4.PLLFractional = 0;
 RCC_OscInitStruct.PLL4.PLLP1 = 1;
 RCC_OscInitStruct.PLL4.PLLP2 = 1;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }

 /** Initializes the CPU, AHB and APB buses clocks
 */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_CPUCLK|RCC_CLOCKTYPE_HCLK
 |RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
 |RCC_CLOCKTYPE_PCLK2|RCC_CLOCKTYPE_PCLK5
 |RCC_CLOCKTYPE_PCLK4;
 RCC_ClkInitStruct.CPUCLKSource = RCC_CPUCLKSOURCE_IC1;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_IC2_IC6_IC11;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
 RCC_ClkInitStruct.APB5CLKDivider = RCC_APB5_DIV1;
 RCC_ClkInitStruct.IC1Selection.ClockSelection = RCC_ICCLKSOURCE_PLL1;
 RCC_ClkInitStruct.IC1Selection.ClockDivider = 2;
 RCC_ClkInitStruct.IC2Selection.ClockSelection = RCC_ICCLKSOURCE_PLL1;
 RCC_ClkInitStruct.IC2Selection.ClockDivider = 3;
 RCC_ClkInitStruct.IC6Selection.ClockSelection = RCC_ICCLKSOURCE_PLL1;
 RCC_ClkInitStruct.IC6Selection.ClockDivider = 4;
 RCC_ClkInitStruct.IC11Selection.ClockSelection = RCC_ICCLKSOURCE_PLL1;
 RCC_ClkInitStruct.IC11Selection.ClockDivider = 3;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct) != HAL_OK)
 {
 Error_Handler();
 }
}

/**
 * @brief DMA2D Initialization Function
 * @PAram None
 * @retval None
 */
static void MX_DMA2D_Init(void)
{

 /* USER CODE BEGIN DMA2D_Init 0 */

 /* USER CODE END DMA2D_Init 0 */

 /* USER CODE BEGIN DMA2D_Init 1 */

 /* USER CODE END DMA2D_Init 1 */
 hdma2d.Instance = DMA2D;
 hdma2d.Init.Mode = DMA2D_M2M;
 hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB4444;
 hdma2d.Init.OutputOffset = 0;
 hdma2d.LayerCfg[1].InputOffset = 0;
 hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB4444;
 hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
 hdma2d.LayerCfg[1].InputAlpha = 255;
 if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
 {
 Error_Handler();
 }
 if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN DMA2D_Init 2 */

 /* USER CODE END DMA2D_Init 2 */

}

/**
 * @brief LTDC Initialization Function
 * @PAram None
 * @retval None
 */
static void MX_LTDC_Init(void)
{

 /* USER CODE BEGIN LTDC_Init 0 */

 /* USER CODE END LTDC_Init 0 */

 LTDC_LayerCfgTypeDef pLayerCfg = {0};

 /* USER CODE BEGIN LTDC_Init 1 */

 /* USER CODE END LTDC_Init 1 */
 hltdc.Instance = LTDC;
 hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
 hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
 hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
 hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
 hltdc.Init.HorizontalSync = 4;
 hltdc.Init.VerticalSync = 4;
 hltdc.Init.AccumulatedHBP = 12;
 hltdc.Init.AccumulatedVBP = 12;
 hltdc.Init.AccumulatedActiveW = 812;
 hltdc.Init.AccumulatedActiveH = 492;
 hltdc.Init.TotalWidth = 820;
 hltdc.Init.TotalHeigh = 500;
 hltdc.Init.Backcolor.Blue = 0;
 hltdc.Init.Backcolor.Green = 0;
 hltdc.Init.Backcolor.Red = 0;
 if (HAL_LTDC_Init(&hltdc) != HAL_OK)
 {
 Error_Handler();
 }
 pLayerCfg.WindowX0 = 0;
 pLayerCfg.WindowX1 = 156;
 pLayerCfg.WindowY0 = 0;
 pLayerCfg.WindowY1 = 129;
 pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
 pLayerCfg.Alpha = 255;
 pLayerCfg.Alpha0 = 0;
 pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
 pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
 pLayerCfg.FBStartAdress = 0;
 pLayerCfg.ImageWidth = 156;
 pLayerCfg.ImageHeight = 129;
 pLayerCfg.Backcolor.Blue = 255;
 pLayerCfg.Backcolor.Green = 0;
 pLayerCfg.Backcolor.Red = 0;
 if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN LTDC_Init 2 */
 RIMC_MasterConfig_t RIMC_master = {0};
 RIMC_master.MasterCID = RIF_CID_1;
 RIMC_master.SecPriv = RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV;
 HAL_RIF_RIMC_ConfigMasterAttributes(RIF_MASTER_INDEX_LTDC1 , &RIMC_master);

 HAL_RIF_RISC_SetSlaveSecureAttributes(RIF_RISC_PERIPH_INDEX_LTDCL1 , RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV);
 /* USER CODE END LTDC_Init 2 */

}

/**
 * @brief GPIO Initialization Function
 * @PAram None
 * @retval None
 */
static void MX_GPIO_Init(void)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 /* USER CODE BEGIN MX_GPIO_Init_1 */
 /* USER CODE END MX_GPIO_Init_1 */

 /* GPIO Ports Clock Enable */
 __HAL_RCC_GPIOQ_CLK_ENABLE();
 __HAL_RCC_GPIOH_CLK_ENABLE();
 __HAL_RCC_GPIOB_CLK_ENABLE();
 __HAL_RCC_GPIOE_CLK_ENABLE();
 __HAL_RCC_GPIOD_CLK_ENABLE();
 __HAL_RCC_GPIOG_CLK_ENABLE();
 __HAL_RCC_GPIOA_CLK_ENABLE();

 /*Configure GPIO pin Output Level */
 HAL_GPIO_WritePin(GPIOQ, LCD_BL_CTRL_Pin|LCD_ONOFF_Pin, GPIO_PIN_SET);

 /*Configure GPIO pins : LCD_BL_CTRL_Pin LCD_ONOFF_Pin */
 GPIO_InitStruct.Pin = LCD_BL_CTRL_Pin|LCD_ONOFF_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 HAL_GPIO_Init(GPIOQ, &GPIO_InitStruct);

 /* USER CODE BEGIN MX_GPIO_Init_2 */
 /* USER CODE END MX_GPIO_Init_2 */
}

/* USER CODE BEGIN 4 */
void MPU_Config(void)
{
 MPU_Region_InitTypeDef default_config = {0};
 MPU_Attributes_InitTypeDef attr_config = {0};
 uint32_t primask_bit = __get_PRIMASK();

 /* disable the MPU */
 HAL_MPU_Disable();
 /* create an attribute configuration for the MPU */
 attr_config.Attributes = INNER_OUTER(MPU_NOT_CACHEABLE);
 attr_config.Number = MPU_ATTRIBUTES_NUMBER0;
 HAL_MPU_ConfigMemoryAttributes(&attr_config);
 /* Create a non cacheable region */
 /*Normal memory type, code execution allowed */
 default_config.Enable = MPU_REGION_ENABLE;
 default_config.Number = MPU_REGION_NUMBER0;
 default_config.BaseAddress = __NON_CACHEABLE_SECTION_BEGIN;
 default_config.LimitAddress =__NON_CACHEABLE_SECTION_END;
 default_config.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
 default_config.AccessPermission = MPU_REGION_ALL_RW;
 default_config.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
 default_config.AttributesIndex = MPU_ATTRIBUTES_NUMBER0;
 HAL_MPU_ConfigRegion(&default_config);

 /* enable the MPU */
 HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
 /* Exit critical section to lock the system and avoid any issue around MPU mechanisme */
 __set_PRIMASK(primask_bit);
}

/**
* @brief DMA2D Transfer completed callback
* @PAram hdma2d: DMA2D handle.
* @note This example shows a simple way to report end of DMA2D transfer, and
* you can add your own implementation.
* @retval None
*/
static void TransferComplete(DMA2D_HandleTypeDef *hdma2d)
{
 BSP_LED_On(LED1);
}

/**
* @brief DMA2D error callbacks
* @PAram hdma2d: DMA2D handle
* @note This example shows a simple way to report DMA2D transfer error, and you can
* add your own implementation.
* @retval None
*/
static void TransferError(DMA2D_HandleTypeDef *hdma2d)
{
 /* Turn LED red on On */
 BSP_LED_On(LED2);
}
/**
* @brief Compares two buffers.
* @PAram pBuffer1, pBuffer2: buffers to be compared.
* @PAram BufferLength: buffer's length.
* @retval 0: pBuffer1 identical to pBuffer2
* 1: pBuffer1 differs from pBuffer2
*/
ErrorStatus Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint32_t BufferLength)
{
 while (BufferLength--)
 {
 if (*pBuffer1 != *pBuffer2)
 {
 return ERROR;
 }
 pBuffer1++;
 pBuffer2++;
 }
 return SUCCESS;
}
/* USER CODE END 4 */

/**
 * @brief This function is executed in case of error occurrence.
 * @retval None
 */
void Error_Handler(void)
{
 /* USER CODE BEGIN Error_Handler_Debug */

 /* Turn On the Red Led */
 BSP_LED_On(LED2);

 /* User can add his own implementation to report the HAL error return state */
 __disable_irq();
 while (1)
 {
 }
 /* USER CODE END Error_Handler_Debug */
}

#ifdef USE_FULL_ASSERT
/**
 * @brief Reports the name of the source file and the source line number
 * where the assert_param error has occurred.
 * @PAram file: pointer to the source file name
 * @PAram line: assert_param error line source number
 * @retval None
 */
void assert_failed(uint8_t *file, uint32_t line)
{
 /* USER CODE BEGIN 6 */
 /* User can add his own implementation to report the file name and line number,
 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

 

    This topic has been closed for replies.

    1 reply

    HamadyAuthor
    Visitor II
    March 28, 2025

    Hamady_0-1743185880196.png

    For info here all registers