Skip to main content
Associate
July 27, 2025
Question

Color input format of HAL_DMA2D_Start()

  • July 27, 2025
  • 1 reply
  • 200 views

What should be the color input format for hal_dma2d_start()?
According to the function definition, it seems that only ARGB8888 format colors can be inputted.

static void DMA2D_SetConfig(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width,
 uint32_t Height)
{
 uint32_t tmp;
 uint32_t tmp1;
 uint32_t tmp2;
 uint32_t tmp3;
 uint32_t tmp4;

 /* Configure DMA2D data size */
 MODIFY_REG(hdma2d->Instance->NLR, (DMA2D_NLR_NL | DMA2D_NLR_PL), (Height | (Width << DMA2D_NLR_PL_Pos)));

 /* Configure DMA2D destination address */
 WRITE_REG(hdma2d->Instance->OMAR, DstAddress);

 /* Register to memory DMA2D mode selected */
 if (hdma2d->Init.Mode == DMA2D_R2M)
 {
 tmp1 = pdata & DMA2D_OCOLR_ALPHA_1;
 tmp2 = pdata & DMA2D_OCOLR_RED_1;
 tmp3 = pdata & DMA2D_OCOLR_GREEN_1;
 tmp4 = pdata & DMA2D_OCOLR_BLUE_1;

 /* Prepare the value to be written to the OCOLR register according to the color mode */
 if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_ARGB8888)
 {
 tmp = (tmp3 | tmp2 | tmp1 | tmp4);
 }
 else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_RGB888)
 {
 tmp = (tmp3 | tmp2 | tmp4);
 }
 else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_RGB565)
 {
 tmp2 = (tmp2 >> 19U);
 tmp3 = (tmp3 >> 10U);
 tmp4 = (tmp4 >> 3U);
 tmp = ((tmp3 << 5U) | (tmp2 << 11U) | tmp4);
 }
 else if (hdma2d->Init.ColorMode == DMA2D_OUTPUT_ARGB1555)
 {
 tmp1 = (tmp1 >> 31U);
 tmp2 = (tmp2 >> 19U);
 tmp3 = (tmp3 >> 11U);
 tmp4 = (tmp4 >> 3U);
 tmp = ((tmp3 << 5U) | (tmp2 << 10U) | (tmp1 << 15U) | tmp4);
 }
 else /* Dhdma2d->Init.ColorMode = DMA2D_OUTPUT_ARGB4444 */
 {
 tmp1 = (tmp1 >> 28U);
 tmp2 = (tmp2 >> 20U);
 tmp3 = (tmp3 >> 12U);
 tmp4 = (tmp4 >> 4U);
 tmp = ((tmp3 << 4U) | (tmp2 << 8U) | (tmp1 << 12U) | tmp4);
 }
 /* Write to DMA2D OCOLR register */
 WRITE_REG(hdma2d->Instance->OCOLR, tmp);
 }
 else /* M2M, M2M_PFC or M2M_Blending DMA2D Mode */
 {
 /* Configure DMA2D source address */
 WRITE_REG(hdma2d->Instance->FGMAR, pdata);
 }
}

 But in stm32f429xx.h,  I can see some marco definitions for other colors input format. It seems that the input color format of HAL_DMA2D_Start() can be changed to RGB565 or something else, but there is no such a option in HAL_DMA2D_Start().

/******************** Bit definition for DMA2D_OCOLR register ***************/

/*!<Mode_ARGB8888/RGB888 */

#define DMA2D_OCOLR_BLUE_1 0x000000FFU /*!< BLUE Value */
#define DMA2D_OCOLR_GREEN_1 0x0000FF00U /*!< GREEN Value */
#define DMA2D_OCOLR_RED_1 0x00FF0000U /*!< Red Value */
#define DMA2D_OCOLR_ALPHA_1 0xFF000000U /*!< Alpha Channel Value */

/*!<Mode_RGB565 */
#define DMA2D_OCOLR_BLUE_2 0x0000001FU /*!< BLUE Value */
#define DMA2D_OCOLR_GREEN_2 0x000007E0U /*!< GREEN Value */
#define DMA2D_OCOLR_RED_2 0x0000F800U /*!< Red Value */

/*!<Mode_ARGB1555 */
#define DMA2D_OCOLR_BLUE_3 0x0000001FU /*!< BLUE Value */
#define DMA2D_OCOLR_GREEN_3 0x000003E0U /*!< GREEN Value */
#define DMA2D_OCOLR_RED_3 0x00007C00U /*!< Red Value */
#define DMA2D_OCOLR_ALPHA_3 0x00008000U /*!< Alpha Channel Value */

/*!<Mode_ARGB4444 */
#define DMA2D_OCOLR_BLUE_4 0x0000000FU /*!< BLUE Value */
#define DMA2D_OCOLR_GREEN_4 0x000000F0U /*!< GREEN Value */
#define DMA2D_OCOLR_RED_4 0x00000F00U /*!< Red Value */
#define DMA2D_OCOLR_ALPHA_4 0x0000F000U /*!< Alpha Channel Value */

 

1 reply

TDK
Super User
July 27, 2025

> According to the function definition, it seems that only ARGB8888 format colors can be inputted

Where are you seeing this? Looks configurable to me.

/**
 * @brief Start the DMA2D Transfer.
 * @PAram hdma2d Pointer to a DMA2D_HandleTypeDef structure that contains
 * the configuration information for the DMA2D.
 * @PAram pdata Configure the source memory Buffer address if
 * Memory-to-Memory or Memory-to-Memory with pixel format
 * conversion mode is selected, or configure
 * the color value if Register-to-Memory mode is selected.
 * @PAram DstAddress The destination memory Buffer address.
 * @PAram Width The width of data to be transferred from source
 * to destination (expressed in number of pixels per line).
 * @PAram Height The height of data to be transferred from source to destination (expressed in number of lines).
 * @retval HAL status
 */
HAL_StatusTypeDef HAL_DMA2D_Start(DMA2D_HandleTypeDef *hdma2d, uint32_t pdata, uint32_t DstAddress, uint32_t Width,
 uint32_t Height)
{

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
ShadowLeeAuthor
Associate
July 28, 2025

DMA2D_SetConfig() is called within HAL_DMA2D_Start(). I initialize DMA2D to register-to-memory mode and output RGB565, so pdata should be a color value.But when I input a RGB565 format color value like 0xF800, the screen displays a incorrect color.

tmp1 = pdata & DMA2D_OCOLR_ALPHA_1;
tmp2 = pdata & DMA2D_OCOLR_RED_1;
tmp3 = pdata & DMA2D_OCOLR_GREEN_1;
tmp4 = pdata & DMA2D_OCOLR_BLUE_1;

In DAM2D_SetConfig(), pdata will be separated into tmp1,tmp2,tmp3,tmp4 and then converted into corresponding color format according to hdma2d->Init.ColorMode. But color format conversion can only work properly when pdata is ARGB8888.