element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • 'Choose another store...'
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs High Throughput SPI traffic part 3a - SPI with DMA
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 27 May 2016 9:46 AM Date Created
  • Views 1304 views
  • Likes 7 likes
  • Comments 3 comments
  • educational_boosterpack
  • lcd
  • spi
  • mibspi
  • hx8353e
  • dma
  • buffered spi
  • hercules
  • launchpad
Related
Recommended

High Throughput SPI traffic part 3a - SPI with DMA

Jan Cumps
Jan Cumps
27 May 2016

We know SPI as a 4*-wire protocol. But it doesn't have to be.

I'm checking high speed SPI data transfer with buffers, DMA and parallel data lines.

 

 

image

 

 

In this blog, I use DMA to hand over data to SPI and let it do its own thing.

 

SPI Performance will NOT Increase

 

In the previous blog, we already achieved maximum SPI performance. We're sending all data via SPI in one shot.

In that example we already achieved the maximum yield possible for our Baudrat The actual traffic speed can't go up by adding DMA.

Why would we use DMA then?

 

DMA to Increase the Troughput and Optimise the Data Channel

 

So the SPI Baud speed doesn't change, does it? Indeed.

The effective 'speed per bit' is at its maximum (for our current physical implementation with one SPI data line)

 

image

 

What changes though, is that we've freed up our microcontroller core during the SPI call.

In the previous Buffered example, the controller ticks were used to move buffer memory to the SPI module.

During that operation, we don't have the exclusive attention of the controller core.

With DMA, the SPI is running all by itself, and gets the data spoon fed by the DMA module.

 

void mibspiDmaConfig(mibspiBASE_t *mibspi,uint32 channel, uint32 txchannel)
{
  uint32 bufid  = 0;
  uint32 icount = 0;


  /* setting transmit and receive channels */
  mibspi->DMACTRL[channel] |= ((txchannel) << 16);


  /* enabling transmit and receive dma */
  mibspi->DMACTRL[channel] |=  0x8000C000; // todo: disable receive


  /* setting Initial Count of DMA transfers and the buffer utilized for DMA transfer */
  mibspi->DMACTRL[channel] |=  (icount << 8) |(bufid<<24);

}

 

void dmaConfigCtrlPacket(uint32 sadd,uint32 dadd,uint32 dsize)
{
   g_dmaCTRLPKT.SADD      = sadd;  /* source address             */
   g_dmaCTRLPKT.DADD      = dadd;  /* destination  address       */
   g_dmaCTRLPKT.CHCTRL    = 0;                 /* channel control            */
   g_dmaCTRLPKT.FRCNT = 1;                 /* frame count                */
   g_dmaCTRLPKT.ELCNT     = dsize;             /* element count              */
   g_dmaCTRLPKT.ELDOFFSET = 4;                 /* element destination offset */
   g_dmaCTRLPKT.ELSOFFSET = 0;          /* element destination offset */
   g_dmaCTRLPKT.FRDOFFSET = 0;          /* frame destination offset   */
   g_dmaCTRLPKT.FRSOFFSET = 0;                 /* frame destination offset   */
   g_dmaCTRLPKT.PORTASGN  = 4;                 /* port b                     */
   g_dmaCTRLPKT.RDSIZE    = 0;  /* read size                  */
   g_dmaCTRLPKT.WRSIZE    = ACCESS_16_BIT;  /* write size                 */
   g_dmaCTRLPKT.TTYPE     = FRAME_TRANSFER ;   /* transfer type              */
   g_dmaCTRLPKT.ADDMODERD = ADDR_INC1;         /* address mode read          */
   g_dmaCTRLPKT.ADDMODEWR = ADDR_OFFSET;       /* address mode write         */
   g_dmaCTRLPKT.AUTOINIT  = AUTOINIT_ON;       /* autoinit                   */
}

 

void _writeData64DMA() {
    gioSetBit(_portDataCommand, _pinDataCommand, 1);
    mibspiTransfer(mibspiREG3, 2 );
    while(!(mibspiIsTransferComplete(mibspiREG3, 2))) {
    }
}

 

If we provide more than one buffer, we can set up a round robin system.

We can fill pixels in one buffer while the SPI is outputting the previous one.

And that allows us to gain time. We don't have to spend time to prepare all data up front to have the buffered speed.

We can prepare just enough, and hand over to SPI and DMA.

Meanwhile, we prepare the next chunk.

 

The Example Program

 

As you can see in the photo at the beginning of the blog, and in the LA output, it has a bug.

The image i corrupted. I don't send the full data.

That doesn't matter for this blog, because it shows the mechanism. But it's not something to be proud of.

Hercules grey beards, please chime in if you know my error.

Part 3b shows the working version.

 

The Series
0 - Buffers and Parallel Data Lines
1a - Buffers and DMA
1b - SPI without Buffers
2 - SPI with Buffers
3a - SPI with DMA
3b - SPI with DMA works
4a - SPI Master with DMA and Parallel Data Lines
Hercules microcontrollers, DMA and Memory Cache
Attachments:
RM46_BOOSTXL-EDUMKII-LCD_BITMAP 20160527.zip
3058.lcd_hx8353e.zip
RM46_BOOSTXL-EDUMKII-LCD_BITMAP_20181009.zip
  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 5 years ago +1
    2 years after the facts I finally have the DMA functionality working. Half a line is now sent to the SPI module without CPU involvement. The SPI module of the Hercules fetches the image data itself (direct…
  • Jan Cumps
    Jan Cumps over 4 years ago +1
    I've attached the latest version, with SPI DMA fully working. It uses DMA to draw a bitmap half a line at a time, instead of pixel per pixel. I've also attached the CCS project for the LCD Driver. It's…
  • Jan Cumps
    Jan Cumps over 4 years ago

    I've attached the latest version, with SPI DMA fully working. It uses DMA to draw a bitmap half a line at a time, instead of pixel per pixel.

    I've also attached the CCS project for the LCD Driver. It's available on GitHub but the attached project is easier to start from.

     

    You don't have permission to edit metadata of this video.
    Edit media
    x
    image
    Upload Preview
    image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago

    2 years after the facts I finally have the DMA functionality working. Half a line is now sent to the SPI module without CPU involvement.

    The SPI module of the Hercules fetches the image data itself (direct memory access) and transmits it to the LCD.

    image

     

    I still need to do some fine-tuning, but glad it works.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fmilburn
    fmilburn over 5 years ago

    Thanks for outlining this and showing some code.  I have used DMA a few times but should look into using it more.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube