2 Replies Latest reply on Feb 8, 2012 10:13 PM by ki.leung

    Using DMA to transfer a Struct variable

    pasquale.de.sando

      Hi everyone,

         

      I need to transfer a struct variable composed of two fields (uint8,uint16) towards an SPI interface.

         

      I tried to use a DMA channel and only one TD, configured to transfer 1 byte per burst with increment of the source address.

         

      With this configuration, if I set the struct variable as: (0x0F,0xFFFF) I see on the oscilloscope: 0x0F,0X00FF.

         

      Even using 3 byte per burst the result is the same.

         

      Is it needed to use a dedicate TD for each field of the Struct variable or I need to configure the DMA channel and the TD in a different way ?

         

       

         

      Thanks in advance

        • 1. Re: Using DMA to transfer a Struct variable
          user_1377889

          A struct in C can be seen as a sequence of bytes (uint8). When you handle it just like that and use the sizeof(struct MyStructure) macro to calculate the number of bytes to transfer nothing can go wrong.

             

          The SPI interface may go wrong when you send data faster than they are clocked out of the interface. I do not know how you are checking the FIFO in your DMA-process. I doubt that the supplied interrupt routines wotk together with DMA.

             

          I would suggest to set the TX-Buffer-size to a sufficient value and send the structure as a whole (array of bytes) to the SPI and let it be handled by the internal interrupts.

             

          Bob 

          • 2. Re: Using DMA to transfer a Struct variable
            ki.leung

             I think the GCC compiler paded with extra bytes inside structures.  

               

            You can verify this checking the address of the first and the second element of the structure.

               

            I can't remember if you have to use the attribute "align" or "pack". you can find it in the GCC help manual.