Sunday, 22 September 2013

Success at last :)

Finally. Patches for continuous sampling got accepted in IIO.

All the hard work paid of in the end. Achievement unlocked.

A hiccup n warning here n there mentioned by the autobuild scripts. but no biggy. sending a couple of cleanup patches in a jiffy

Now for rebasing stuff for koen's trees. A long blogpost describing how to get the driver to work from userspace. The trigger stuff on the blog is redundant and misleading now. I'll put a note in the start of those posts pointing to the new one when its done..


  1. Thanks for pushing this through to the end on the IIO group.

    Looking forward to hearing about the new userspace wrap-up!

    1. That could take a while since I'm a bit busy these days.

      In short, its the same as the generic_buffer.c. But remove the trigger checks.

      Similar to the sample application provided at the end of

      Although, the driver now doesn't have those limitations and conforms to IIO spec.

  2. I've been trying with the patch from removing the triggers as well as the previous patch from Craig for the iio_utils.h; however, I am getting a Read Size = 0 and its not recording any data from the buffer.

    My thinking is its not being triggered to write to the buffer somehow but there is no error thrown. I know there are not triggers anymore, so where is it told to write to the buffer?

    1. When you write 1 in the buffer/enable file, the ADC starts sampling..

    2. When I try to do: echo 1 > /sys/bus/iio/devices/iio:device0/buffer/enable
      I get: bash: echo: write error: Invalid argument

      I was able to set a length for the buffer and am sure the tiadc driver is enabled. Also, I thought it might be because a trigger is not active, but the 'new' code does not use triggers I thought.

      I did this anyway: echo 1 > /sys/bus/iio/devices/iio_sysfs_trigger/add_trigger

      and it still returns that invalid argument error, I can write '0' to enable but that does me no good.

      Running: cat /sys/bus/iio/devices/trigger0/name

      I've been trying to troubleshoot using but have had no luck.

    3. Have you enabled the ADC channels?

      Also, which driver/kernel are you using?

    4. I have run: 'echo BB-ADC > /sys/devices/bone_capemgr.*/slots' to enable ADC

      I'm using the 'tiadc' driver.

      Kernel: 'Linux arm 3.8.13-bone28 #1 SMP Mon Sep 16 01:49:45 CDT 2013 armv7l GNU/Linux' its a version of Debian

    5. Sorry for the really long delay in getting back to you.
      My work is mostly for 3.11..
      I didn't down port it to 3.8.

      did you manage to get the ADC working?

    6. This comment has been removed by the author.

    7. Greetings Zubair

      First, thanks for the effort on AM335x_ADC_Driver. As you already realised, it is quite a useful function that you created. It could be an important solution for many people, with much greater impact if you would made an effort to explain how to use it for dummies. May be in a style: "Guide for continuos ADC for dummies". It has been a while since the last time I had to recompile the kernel, may be 10 years, and the only thing I remember it was a lengthy, painful process. Now I need to provide an easy example for students and I suspect this process wont be easy.

      I am creating a simple application for beaglebone black where I need fast sampling from ADC to be able to use it a s PID controller. The physics
      behind are solved, however I am having troubles with sampling rate. The code below gives me no more than 1000 samples per second, at best. Before I deep myself in your world of iio-subsystem and kernel drivers what real sampling frequency could I achieve using continuous ADC reading? Are you still planning to make a guide for mortals who do not recompile kernel often?

      Thank you in advance for the done effort and future advice.


      const char AIN_DEV[] = "/sys/devices/ocp.2/helper.14/AIN0";

      int main() {
      int fd = open(AIN_DEV, O_RDONLY);
      // Get current time from the clock, using microseconds resolution

      time_t end = time(NULL) + 1;
      int i = 0;

      while (time(NULL) < (end + 1))
      char buffer[1024];
      int ret = read(fd, buffer, sizeof(buffer));
      if (ret != -1)
      buffer[ret] = '\0';
      //printf("%d\n", ret);
      //printf("%s\n", buffer);
      lseek(fd, 0, 0);

      std::cout << "have done: " << i <<" reads" << std::endl;
      return 0;

  3. This comment has been removed by the author.

  4. Hi Zubair,

    First of all congratulations for the good work. Could you provide me some info on how to put this new driver to work? As far as I understand I'm going to have to compile a new kernel (which? from your git repository?) and disable the trigger checks in generic_buffer.c, is this correct? Is there any additional step I should be aware of?

    Best regards,

    Tiago C.

    1. Hi Tiago,


      I am a bit out of touch. But if I remember correctly, you should be able to use continuous sampling if you compile this

      And yes. Removing trigger checks in generic_buffer.c is the way to go. Ping me if you get stuck on any issue.


  5. Hi again Zubair,

    Some updates:

    1) Compiled kernel 3.11;
    2) When trying to enable the ADC in slots this was the result:

    root@beaglebone:~# echo BB-ADC > /sys/devices/bone_capemgr.*/slots
    [ 159.910544] of_resolve: Could not find symbol 'ocp'
    [ 159.915789] bone-capemgr bone_capemgr.5: slot #8: Failed to resolve tree
    -sh: echo: write error: Invalid argument
    root@beaglebone:~# dmesg -c
    [ 159.910013] bone-capemgr bone_capemgr.5: part_number 'BB-ADC', version 'N/A'
    [ 159.910093] bone-capemgr bone_capemgr.5: slot #8: generic override
    [ 159.910121] bone-capemgr bone_capemgr.5: bone: Using override eeprom data at slot 8
    [ 159.910151] bone-capemgr bone_capemgr.5: slot #8: 'Override Board Name,00A0,Override Manuf,BB-ADC'
    [ 159.910310] bone-capemgr bone_capemgr.5: slot #8: Requesting part number/version based 'BB-ADC-00A0.dtbo
    [ 159.910341] bone-capemgr bone_capemgr.5: slot #8: Requesting firmware 'BB-ADC-00A0.dtbo' for board-name 'Override Board Name', version '00A0'
    [ 159.910381] bone-capemgr bone_capemgr.5: slot #8: dtbo 'BB-ADC-00A0.dtbo' loaded; converting to live tree
    [ 159.910544] of_resolve: Could not find symbol 'ocp'
    [ 159.915789] bone-capemgr bone_capemgr.5: slot #8: Failed to resolve tree

    To help debugging this, I also include my dtb file (in dts format) here:

    Any clue about this? I think I'm very close now...

    Thank you!


    1. I am not sure if the slots feature was fixed in that kernel. What I would do was directly enable the ADC using the dts file..

    2. Hi Zubair,

      Got it to work. I mean, sort of...I can only get it to work with a maximum of 4 channels. If I try to enable more, the values get all mixed up (i'm testing this with AC signals). Have you ever seen this behaviour?

      Thanks again,


    3. Hi Tiago,

      Glad to know you got it working.

      To be honest, I haven't checked so thoroughly enabling so many channels.

      Can I see the dts code enabling the ADC?


    4. I'd like to reproduce your errors and see if I can debug this. I thought the code was scalable..

    5. Zubair

      Here's the tscadc from am33xx.dtsi:

      tscadc: tscadc@44e0d000 {
      compatible = "ti,am3359-tscadc";
      reg = <0x44e0d000 0x1000>;
      interrupt-parent = <&intc>;
      interrupts = <16>;
      ti,hwmods = "adc_tsc";
      status = "okay";

      tsc {
      compatible = "ti,am3359-tsc";
      am335x_adc: adc {
      #io-channel-cells = <1>;
      compatible = "ti,am3359-adc";
      ti,adc-channels = <0 1 2 3 4 5 6 7>;

    6. By the way...

      Thank you for your great work =)

    7. Hi again Zubair.

      Introductions first, João is a friend of mine, also involved in this work. The credit of enabling the ADC is his.

      What we are doing now is using the ADC to read 6 AC signals. This is done by disabling any reference to the trigger in the file original “generic_buffer.c”. Also applied the changes in “iio_utils.h”. Lets keep in touch with this. Thank you!

      Tiago P.

    8. Nice work. Ping if you need any help. :).

      I didn't find the time to rework genericbuffer.c properly. And used the same method. Just disable trigger. What changes did you make to iio-utils?


  6. Hi Zubair,

    The changes were those described by Craig Markwardt in is comment from 8 October 2013 01:11

    I'm not a member of iio mailing list, nor do I know where iio_utils.h came from other than your sample code. I posted a commit here which resolves the problem:"



    1. Hi All,

      Zubair has sent this upstream to linux-iio which is great. I've applied Craig's patch and attributed the authorship to him. Unfortunately right now I don't have an email address for him.
      If Craig (or anyone else if they think he won't mind!) could send me an email to I'll get that fixed up before sending a pull request to my upstream.

      For reference the patch is:

      and once the 3.13 kernel is out this will go to Greg KH's staging tree and on to Linus as a fix for 3.14-rc1.



    2. Hi Jonathan,

      I've forwarded this message to Craig's original comment on another post. That should send him an email about it..


    3. Hi Zubair,

      I implement a net protocol for linux. What should I do or what's the process to add features to mainline?

      There's a zilion streams and repositories on the net, I just don't know where to start and/or to whom talk to, just to guide me to prepare the code for kernel.


      João Taveira

    4. Hi Joao,

      A good place to start is

      Watch this
      Its a bit old. But still useful and comprehensive.

    5. Unfortunately I didn't see an email. I replied today to Jonathan.

  7. Hi Zubair,

    I have been having difficulty trying to enable ADC subsystem, to use it with PRU, in kernel 3.12. The dmesg returns "could not find symbol ocp". I know I have to change the .dts file, target = <&tscadc> instead, but I am still very confused with it. I got it working on 3.8, however, it would be nice to get it working in 3.12. Could you please help me with it. Thank you.

    Nhan Nguyen

    1. Hi Nhan,

      Check in your kernel folder. If i remember 3.12 doesn't add the tscadc patches by default..

      Hope that helps.

  8. This comment has been removed by the author.

  9. Hi Zubair,
    when i am trying to enable adc i am getting below error. can you please help me to fix this
    -bash: /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage7_en: No such file or directory

    1. Hi,

      This work is quite old now and the file name/location might be different if you are using a modern beaglebone black image.

      try running the following commands

      find /sys | grep iio
      find /sys | grep adc
      find /sys | grep voltage

      They will search for any files names iio/adc/voltage and might show which file to read.

  10. Hello everybody.
    I really like you post.
    I would like to share page collection with you!
    if you want to play game online casino please click on this post comment.Thank you.
    gclub casino
    golden slot casino