cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F767 SPI DMA and images stored on flash get stuck on transmission

EasyNet
Associate III

Hello!

I'm working on a project to use some bar-displays 284x76 pixels using ST7789 driver and I'm struggling for about 2 weeks to solve this issue. 
Everything is perfect using SPI DMA HAL_SPI_Transmit_DMA() if the buffer is in RAM.

But if I define a struct like this in file image.h:

typedef const struct {
	const uint32_t width;
    const uint32_t height;
    const uint32_t bytes_per_pixel;
    const uint16_t pixel_data[]; // Array flexibil (C99)
} ImageRGB565_16bit;

 

Then in FCU.h I have:

#include "images.h"

extern ImageRGB565_16bit FCU01;
extern ImageRGB565_16bit FCU02;
extern ImageRGB565_16bit FCU03;
extern ImageRGB565_16bit FCU04;
extern ImageRGB565_16bit FCU05;

 

And loading images like this FCU.c:

ImageRGB565_16bit FCU01 = {
  284, 76, 2,
  {
		  0x0000, 0x0000, 0x0000,
..
  }
};


When I run the code I'm getting this result on Serial port:

FCU Background with alpha 0.2
FCU            = 0x80313a4
FCU.pixel_data = 0x80313b0

Which looks like the struct resides in FLASH memory.


But the HAL_SPI_Transmit_DMA() stuck at this function:

  /* Enable the Tx DMA Stream/Channel */
  if (HAL_OK != HAL_DMA_Start_IT(hspi->hdmatx, (uint32_t)hspi->pTxBuffPtr, (uint32_t)&hspi->Instance->DR,
                                 hspi->TxXferCount))
  {
    /* Update SPI error code */
    SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_DMA);
    /* Process Unlocked */
    __HAL_UNLOCK(hspi);
    return HAL_ERROR;
  }

every time and I couldn't find a way to go further. The only solution worked was in Debug line-by-line! Which also was very weird for me!

If I'm changing the typedef like this:

typedef struct {
	const uint32_t width;
    const uint32_t height;
    const uint32_t bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
    const uint16_t pixel_data[]; // Array flexibil (C99)
} ImageRGB565_16bit;

 

Then the result is this:

FCU Background with alpha 0.2
FCU            = 0x2000000c
FCU.pixel_data = 0x20000018

which looks like the pointer is in SRAM and is working!

So, my questions are:
1. Why HAL_SPI_Transmit_DMA() get stuck when the pointer is in FLASH, BUT is working if I'm using Debug line-by-line?
So: when runs directly it get stuck, but in debug mode line-by-line is working.

2. The second version looks like the pointer is in SRAM. In this case all images are loaded in SRAM or is just temporary copied from FLASH to SRAM?

3. There is any solutions to transfer correctly images from FLASH via DMA without blocking completely HAL_SPI_Transmit_DMA() ?

4. Which is the besy approach to get around this limitation? Can I use MEM2MEM DMA to copy from this struct the image to a buffer in MCU then to use the buffer to send it via SPI?


0 REPLIES 0