using dma with ADC

This forum is for users of Microchip MPUs and who are interested in using Linux OS.

Moderator: nferre

yawimiki
Posts: 9
Joined: Thu Jun 04, 2020 9:26 am

using dma with ADC

Thu Jun 04, 2020 9:55 am

Hi everyone,

I am using at91sam5d27 ek development board. this is the information of linux os which was built using buildroot.
"Linux version 4.19.78-linux4sam-6.2 (root@hawk-B360M-D3H) (gcc version 7.4.0 (Buildroot 2019.05)) #3 Tue Jun 2 16:03:14 AEST 2020"
I followed this (http://ww1.microchip.com/downloads/en/A ... 03250a.pdf) user guide to use ADC interface, I can use adc if I am using small sampling frequency. I cannot use higher sampling frequency because CPU get stopped because I cannot use DMA with ADC. When I echo the watermark,

echo 500 > /sys/bus/iio/devices/iio\:device0/buffer/watermark

According to this (https://www.linux4sam.org/bin/view/Linu ... 2ADCDevice). But I dont get any message from kernel and when I check here,
cat /sys/bus/iio/devices/iio\:device0/buffer/hwfifo_enabled
I get 0.
How can I enable DMA for ADC?

Thank you.
blue_z
Location: USA
Posts: 2154
Joined: Thu Apr 19, 2007 10:15 pm

Re: using dma with ADC

Fri Jun 05, 2020 1:39 am

yawimiki wrote: I am using at91sam5d27 ek development board
There is no Microchip/Atmel board with such a name.

yawimiki wrote: When I echo the watermark...
That's a confusing statement. Do you describe the command 'cat watermark > /tmp/save' as "cat the save file"?

In this case a numeric string is echoed, and the object of the echo command is not the buffer/watermark.
The buffer/watermark is the destination of what is echoed (using redirection).
You're setting the buffer/watermark, and not echoing it.

yawimiki wrote: echo 500 > /sys/bus/iio/devices/iio\:device0/buffer/watermark
Why such a large value, given that it's an order of magnitude larger than the example in the web page?
You don't mention anything about Increasing the buffer size. Did you set a new buffer/length?
Did you inspect the value of buffer/hwfifo_watermark_max ?

yawimiki wrote: According to this (https://www.linux4sam.org/bin/view/Linu ... 2ADCDevice).
...
How can I enable DMA for ADC?
You seem to be using a section of that guide out of context.
You cannot simply expect DMA to be ready without the full initialization of the ADC.
IOW have you set up channels to convert and the trigger?

If you follow all the instructions in that guide (with corrections for its mistakes), then what you might obtain is:
root@sama5d2-xplained:/sys/bus/iio/devices/iio:device0# cat buffer/hwfifo_enabled
1
root@sama5d2-xplained:/sys/bus/iio/devices/iio:device0# cat buffer/hwfifo_watermark
50
root@sama5d2-xplained:/sys/bus/iio/devices/iio:device0# cat buffer/enable
0
root@sama5d2-xplained:/sys/bus/iio/devices/iio:device0# echo 1 > buffer/enable
iio iio:device0: using dma0chan9 for rx DMA transfers

Regards
yawimiki
Posts: 9
Joined: Thu Jun 04, 2020 9:26 am

Re: using dma with ADC

Fri Jun 05, 2020 1:53 am

Hi,
Thank you for reply,

Actually the problem in hwfifo_watermark_max. It is only 128. how can I increase it? of cause the buffer length is larger than watermark size which is 409600.

Thank you.
blue_z
Location: USA
Posts: 2154
Joined: Thu Apr 19, 2007 10:15 pm

Re: using dma with ADC

Fri Jun 05, 2020 11:20 pm

yawimiki wrote: Actually the problem in hwfifo_watermark_max. It is only 128. how can I increase it?
Let's see:
The permissions for that file are strictly read-only.
The name of that file begins with "hw", which typically means "hardware".
The ADC driver hardcodes this value based on a capability implemented in hardware.
So no, you cannot increase this maximum unless you somehow change the silicon.

yawimiki wrote: of cause the buffer length is larger than watermark size which is 409600.
"of cause"?
Do you mean "of course" as in the same sense as "it's obvious"?
Claiming that information is obvious and therefore can be omitted is dubious.
I consider the above answer to be obvious, yet you had to ask the question about it.
What is obvious to you may not be to me (or vice versa), and I choose not to assume too much since I don't know what you are doing.


BTW the IIO documentation is ambiguous and most of the values have no dimensional units assigned, but some values do seem to have a unit of samples.
However the hardware watermark values as used by the Atmel ADC driver seem to have unit of bytes, not samples.
Since the sample size can be larger than one byte, beware of this discrepancy.


Regards
yawimiki
Posts: 9
Joined: Thu Jun 04, 2020 9:26 am

Re: using dma with ADC

Tue Jun 09, 2020 2:38 am

to whom this may concern,

you can change the limits of the hwfifo_watermark_max in adc by changing the iio driver file "at91-sama5d2_adc.c" located at

"/buildroot-at91/output/build/linux-linux4sam_6.2/drivers/iio/adc".
change 128 in this line
#define AT91_HWFIFO_MAX_SIZE 128

Return to “LINUX”

Who is online

Users browsing this forum: Bing [Bot] and 5 guests