STM32F4 SPI DMA color not corect

Important: posts that do not use this template will be ignored or closed.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Try to reproduce the issue in a Simulator. If it’s working there then probably it’s not a LittlevGL issue.

Delete this section if you read and applied the mentioned points.

Description

What MCU/Processor/Board and compiler are you using?

STM32F407VE

What do you experience?

Give a detailed description. “It doesn’t work” is not enough information for us to diagnose the issue.

What do you expect?

I am new to lvgl. When I do not use DMA everything is fine but when I use DMA the color display is no longer accurate.

Code to reproduce

Add a code snippet to reproduce the issue in the simulator. It should contain only the relevant code which can be compiled. Bug reports without code snippets or with erroneous code snippets will not be reviewed.

Use the ```c and ``` tags to format your code:

/*You code here*/
lv_disp_drv_t *disp_dma;
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
    /*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
	disp_dma = disp_drv;

    ili9341_setaddress(area->x1, area->y1,area->x2, area->y2);
    LCD_WRX_HIGH();

      /* Reset LCD control line(/CS) and Send data */
    LCD_CS_LOW();
    uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);


    if ( HAL_SPI_Transmit_DMA(&hspi2, (uint8_t *)color_p, size*2) != HAL_OK)    {
   }

}

void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
{
	LCD_CS_HIGH();
	lv_disp_flush_ready(disp_dma);

}``

# when i not use DMA then this worked
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
    /*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
	disp_dma = disp_drv;

    ili9341_setaddress(area->x1, area->y1,area->x2, area->y2);
    LCD_WRX_HIGH();

      /* Reset LCD control line(/CS) and Send data */
    LCD_CS_LOW();
    uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
   if((SPI2->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
	{
		// If disabled, I enable it
		SET_BIT(SPI2->CR1, SPI_CR1_SPE);
	}
    for(uint32_t i=0;i<size;i++) {
////        for(x = area->x1; x <= area->x2; x++) {
////            /* Put a pixel to the display. For example: */
////            /* put_px(x, y, *color_p)*/
       	*((__IO uint8_t *)&hspi2.Instance->DR) = (color_p->full)>>8;
			while(!__HAL_SPI_GET_FLAG(&hspi2, SPI_FLAG_TXE));
			*((__IO uint8_t *)&hspi2.Instance->DR) = (color_p->full);
			while(!__HAL_SPI_GET_FLAG(&hspi2, SPI_FLAG_TXE));
            color_p++;
    }
    CLEAR_BIT(SPI2->CR1, SPI_CR1_SPE);
//    /* IMPORTANT!!!
//     * Inform the graphics library that you are ready with the flushing*/
//    LCD_CS_HIGH();
	lv_disp_flush_ready(disp_drv);
}

Can you fill this point?

Perhaps the bytes are being sent in the wrong order… you could try enabling/disabling LV_COLOR_16_SWAP if you’re using 16bpp.

1 Like

thanks you very much.It worked