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 3b - SPI with DMA works
  • 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: 10 Jun 2018 8:21 PM Date Created
  • Views 663 views
  • Likes 8 likes
  • Comments 2 comments
Related
Recommended

High Throughput SPI traffic part 3b - SPI with DMA works

Jan Cumps
Jan Cumps
10 Jun 2018

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 finally got DMA working.

 

Attention: there's pre-knowledge required. For this blog it's expected that you have decent Hercules skills and that you can successfully replicate the mibSPI DMA example from HALCoGen RM57Lx Help.

Don't start with this project if that example isn't fully familiar to you. It would be a sure path to frustration.

 

Configuration of the SPI module in HALCoGen

 

This is exactly identical as for buffered SPI. So all settings of the part 2 - SPI with Buffers.

I'm using transfer group 3, a 16 bit 64 position buffer. Baud rate is 27 MHz.

There's a number of activities to be done with the memory settings and the linker file to give our RAM the right behaviour for DMA (shared mode).

These are documented in the mibSPI DMA example from HALCoGen RM57Lx Help (and this blog: https://www.hackster.io/jancumps/hercules-configure-memory-cache-for-dma-0945cd ).

 

/* buffer memory in special location for DMA / MibSPI */
#define D_SIZE      128

#pragma SET_DATA_SECTION(".sharedRAM")
#pragma DATA_ALIGN(TXDATA, 8); /* Note: It is very important to keep the data alignment on 64-bit for the DMA */
uint16_t TXDATA[D_SIZE/2];         /* transmit buffer in sys ram */
#pragma SET_DATA_SECTION()

 

To make DMA work with the SPI module 3 of the launchpad, you need to know the request line to be used with this device.

The info can be found in the controller's technical reference document. We're ussing DMA channel 0, so the request line is 15.

image

 

void initDMA() {
       dmaReqAssign(0, 15 );

 

Next is to configure the DMA control structure. Here are a few highlights that are different than the HALCoGen example:

 

      g_dmaCTRLPKT.ELCNT     = dsize;             /* element count              */
      g_dmaCTRLPKT.ELDOFFSET = 4;                 /* element destination offset */
      g_dmaCTRLPKT.WRSIZE    = ACCESS_16_BIT;     /* write size                 */
      g_dmaCTRLPKT.ADDMODEWR = ADDR_OFFSET;       /* address mode write         */

 

dsize is the size of the block we're transferring. In this case 64 16 bit variables -> 128 8 bit values.

eldoffset is 4 because we already have transfer group 1 and 2 defined. They consume the start of SPI3's buffer.

 

We pass the structure in the DMA registers and prime the system:

 

       /* - setting dma control packets */
       dmaSetCtrlPacket(DMA_CH0,g_dmaCTRLPKT);


       /* - setting the dma channel to trigger on h/w request */
       dmaSetChEnable(DMA_CH0, DMA_HW);


       /* - configuring the mibspi dma , channel 0 , tx line -0 , rxline -1     */
       /* - refer to the device data sheet dma request source for mibspi tx/rx  */
       mibspiDmaConfig(mibspiREG3,0,0);


       // first set the read mode
       TXDATA[0] = 0x03;
       // - enabling dma module
       dmaEnable();

 

Then our program prepares the memory and hands things over to the SPI / DMA tandem:

 

void flashBitmapLineDMA(bitmap_t *bmp, uint32_t line) {


    _setWindow(0, line, bmp->width/2, line );
    loadBitmapInDMABuffer(bmp, line, 0);
    initDMA();
    _writeData64DMA();


    _setWindow(bmp->width/2, line, bmp->width, line );
    loadBitmapInDMABuffer(bmp, line, D_SIZE / 2);
    initDMA();
    _writeData64DMA();


}

 

The function that handles the notification to the SPI module is simple:

 

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

 

You'll see that the function waits for the DMA is complete. That's to make things easy for my program but it also takes away a possible advantage: doing something else while the transfer happens.

So there's still room for improvement.

All in all, it's fast already:

 

image

 

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:
5852.RM46_BOOSTXL-EDUMKII-LCD.zip
lcd_hx8353e.zip
  • Sign in to reply

Top Comments

  • genebren
    genebren over 5 years ago +2
    Very nice update on your project. Advanced peripherals (DMA) are very useful in speeding up data flow in processors. Good work! Gene
  • Jan Cumps
    Jan Cumps over 4 years ago

    If you don't like to download the LCD driver code from github (https://github.com/jancumps/hercules_libraries/tree/master/lcd_hx8353e ): I've attached the CCS project.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 5 years ago

    Very nice update on your project.  Advanced peripherals (DMA) are very useful in speeding up data flow in processors.

    Good work!

    Gene

    • Cancel
    • Vote Up +2 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