cancel
Showing results for 
Search instead for 
Did you mean: 

32F429IDISCOVERY SPI over DMA driven LCD

mchalapetr
Associate II
Posted on March 15, 2015 at 17:52

The original post was too long to process during our migration. Please click on the attachment to read the original post.
7 REPLIES 7
jjmz
Associate II
Posted on March 15, 2015 at 20:57

Could it be because max DMA transfer size is 64k elements ?

(240x320 => 76800, truncated to 11264 on a 16bit register)

mchalapetr
Associate II
Posted on March 15, 2015 at 22:28

This is the first time that I hear about some kind of DMA stream restriction...

Why then the DCMI and DMA works....you mean that the DCMI->DR transfers when is full...bacically 38400 x....and with SPI and DMA I want 153600 transfers?
Posted on March 16, 2015 at 01:28

DMA_InitStructure.DMA_BufferSize  is 16-bits, ie 0..65535 bytes, half-words or word

38400 fits, 153600 clearly does not.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
mchalapetr
Associate II
Posted on March 16, 2015 at 19:35

Wow I really didnt know that... So is there a way how to use SPI over DMA with QVGA image? I cant think of anything....Probably redefing the DMA over and over...

Thats stupid right? Problem is that I have to send the data as bytes...That means that I would had to redefine the DMA 4 times for one frame....

EDIT: Actually I made it work...It's not elegant but it works...
mchalapetr
Associate II
Posted on March 16, 2015 at 23:11

OK, so I get that DMA buffer has a limit but I totally dont get how is the transfer driven...The code below is from two diferent versions of the SW...It's not together but I think it's a good example so I just want to explanation how is the DMA behaving...

When I want to copy data from DCMI (32 bit register) to some kind of frame buffer (16 bit array uint16_t frame_buffer[320*240]) then buffer size 38400 is enough and it works well. Then I woud say, yeah the increment is driven by the DCMI register that is 32bit.

DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) (&DCMI->DR);

  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t) frame_buffer;

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;

  DMA_InitStructure.DMA_BufferSize = 320*240*2/4; 

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

But when I want to for example copy data from SDRAM to SPI for transfer. Now if I follow the same logic because the source is 32 bit than 38400 sould also be enough. But it's not... buffer size 38400 makes only 1/4 od the image...why is now the transfer driven  by individual bytes therefore I would need 4*38400= 153600??

DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t) p_img;

    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) &(ILI9341_SPI->DR);

    DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;

    DMA_InitStructure.DMA_BufferSize = 320*240*2/4;

    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;

    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
stm322399
Senior
Posted on March 17, 2015 at 10:17

The explanation is *very* simple: when peripheral and memory data width are different, the number of transfers refers to the width on the peripheral bus. DCMI has word size transfers, so buffersize is 320*200*2/4. Good. SPI has byte size transfers, so buffersize muste be 320*200*2=128000, which is obviously not possible because of the size of NDT register. RTFM 10.3.10 ''Programmable data width''.

To solve you case, you must deal with multiple DMA transfers. Two 64000 transfers should be enough.

mchalapetr
Associate II
Posted on March 17, 2015 at 11:52

Thanks Gonzalez...So basically peripheral memory width is always the one that determines the number of transfers...

The multiple DMA transfers are a solution and it works well...I just wanted to know what is the system behind it...For me it's not 320x200x2 but 320x240x2=153600 so I need three DMA transfers in total...

Anyway thanks for your help...