Simple DMA Example on LPC2368

Import programDMA_LPC2368

A really simple example of initialising the DMA controller and starting a transfer. The example is designed to be as transparent as possible using a bare minimum of macros for clarity.

Motivation

I bought the LPC2368 a very long time ago and never really found a use for it. So I decided to dust it off and try and use it in a project with a camera. I thought I'd use DMA to stream data from the camera into memory and do a little bit of processing on it.

That's when I found that the LPC2368 had been left a very long way behind and everyone was using the LPC1768.

There are plenty of libraries that try and wrap the DMA channels in classes and abstract the hardware away but that's not what I wanted.

There are plenty of libraries and examples that use fancy lookup tables and arrays of pointers to hardware that just seem to clutter what should be a relatively simple process and, again, was not what I wanted.

Being stuborn, really wanting to understand the ARM architecture and wanting to use the board for something other than collecting dust, I decided to delve into the user manual.

What the code does

The example just performs a memory to memory DMA using just the bare registers and some very simple macros.

It flashes LED1 so you know the CPU is doing something.

It lights LEDs 2, 3 and 4 to give an indication that the transfer is in progress.

LED2 lights up when the first byte of the source and destination buffer match. This indicates the transfer at least started.

LED3 lights up when the 4th byte of the source and destination buffer match. This indicates that at least 1 word of data was transfered.

LED4 lights up when the whole buffer has been copied.

Conclusion

It turns out that the LPC2368 GPDMA unit isn't quite so 'General Purpose'.

The only memory it can transfer to / from is the USB RAM located at 0x7FD00000.

I learned that the hard way by not reading the manual fully, trawling the web for hours only to find a single post hinting at what the problem might be and then stumbling across a small paragraph in the user manual showing that it wasn't able to transfer to the memory locations I was using and that the GPDMA unit is actually a bit rubbish.

Future work

I'll update the example with.

1) Interrupt on completion.

2) Scatter/gather.

3) Checking the status of channels.

4) DMAing data to / from a peripheral.

5) DMAing data to / from GPIO.


Please log in to post comments.