AnsweredAssumed Answered

SPI and DMA on STM32F2xx

Question asked by Jacobs.Carl.001 on Nov 23, 2011
Latest reply on Nov 23, 2011 by Jacobs.Carl.001
Is there a simple example of this?

I've written some code based on a working non-DMA version of my SPI object. So far I have the following:

void SPI2_StartDMA(u16 NumBytes)
{
     // Disable both DMA channels
     DMA1_Stream3->CR   &= ~1;
     DMA1_Stream4->CR   &= ~1;
     // Disable the SPI port
     SPI2->CR1          &= ~0x40;
     // Clear any outstanding DMA interrupts
     DMA1->LIFCR         = 0x0F400000;
     DMA1->HIFCR         = 0x0000003D;
     // Configure the receiver
     DMA1_Stream3->CR    = (DMA1_Stream3->CR & 0xF0100000) | 0x00012C20;
     DMA1_Stream3->NDTR  = NumBytes;
     DMA1_Stream3->PAR   = (uint32_t)&(SPI2->DR);
     DMA1_Stream3->M0AR  = (uint32_t)&(SPI2RxBuf[0]);
     // Configure the transmitter
     DMA1_Stream4->CR    = (DMA1_Stream4->CR & 0xF0100000) | 0x00012C60;
     DMA1_Stream4->NDTR  = NumBytes;
     DMA1_Stream4->PAR   = (uint32_t)&(SPI2->DR);
     DMA1_Stream4->M0AR  = (uint32_t)&(SPI2TxBuf[0]);
     // Flush the SPI receiver
     (void)SPI2->DR;
     // Enable the DMA mode in the SPI
     SPI2->CR2          |= 3;
     // Enable the DMA devices         
     DMA1_Stream3->CR   |= 1;
     DMA1_Stream4->CR   |= 1;
     // Enable the SPI Port - to start the transfer
     SPI2->CR1          |= 0x40;     
}

I call the previous function with something like:

     SPI2TxBuf[0] = 10;
     SPI2TxBuf[1] = 0;
     SPI2TxBuf[2] = 55;
     SPI2_StartDMA(3);     // Tx/Rx 3 bytes     // Wait for the received response
     printf("Wait.");
while ((DMA1->LISR & 0x0B400000) == 0) ;
     printf("Success.");

I get "Wait.", but no "Success.". It's like the process hasn't started.

Any ideas as to what I might be doing wrong?

Outcomes