Welcome, Guest

Author Topic: Linux 3.7 ALSA sound support for iMX233?  (Read 41885 times)

ggilles

  • Newbie
  • *
  • Posts: 16
  • Karma: +1/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #45 on: April 07, 2014, 09:28:37 AM »
Hi g.glowacki,

I am using the latest patch from Michall on a 3.13.6 kernel:
patch: https://drive.google.com/file/d/0BxSCLeYUtcwnb3BTZl9TaTJ4UVk/edit?usp=sharing
dts: https://drive.google.com/file/d/0BxSCLeYUtcwnX3dwQklXdE1TN2M/edit?usp=sharing

I don't have the errors you mention. I was not sure if there was a problem after hours of playing, so I ran an experiment. I launched this command-line last friday:
Code: [Select]
aplay -c 2 -f S16_LE -r 22050 /dev/urandomAnd it is still running fine now (2.5 days).

Best

g.glowacki

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #46 on: April 07, 2014, 10:09:14 AM »
I don't have the errors you mention. I was not sure if there was a problem after hours of playing, so I ran an experiment. I launched this command-line last friday:
Code: [Select]
aplay -c 2 -f S16_LE -r 22050 /dev/urandomAnd it is still running fine now (2.5 days).

Best
Hi ggilles,
Thanks for You replay. This error appears when I continuously open and close file, not when infinitely playing. Can You check sth like that:
Code: [Select]
while : ; do aplay -c 2 -f S16_LE -r 22050 <some small random data e.g. /bin/bash> ; done
Thanks a lot:)

GG.

ggilles

  • Newbie
  • *
  • Posts: 16
  • Karma: +1/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #47 on: April 07, 2014, 12:10:52 PM »
This has been running for 1.5 hour now:
Code: [Select]
while true; do aplay -c 2 -f S16_LE -r 22050 -d 1 /dev/urandom; done
And it's still playing.

ggilles

  • Newbie
  • *
  • Posts: 16
  • Karma: +1/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #48 on: April 07, 2014, 02:57:24 PM »
Still playing fine after 4 hours!

g.glowacki

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #49 on: April 14, 2014, 08:14:53 AM »
Thanks a lot ggilles and Grawp,
Thanks to Your suggestions and patch it's working now. After going to kernel 3.13.6 it's been working now for 5 days. I still get many underflows, however DAC doesn't hang up, I've no overflows also.
Maybe You have an idea, why the underflow may appear?

--
GG

scout_3pm

  • Newbie
  • *
  • Posts: 24
  • Karma: +2/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #50 on: May 17, 2014, 12:19:38 AM »
By general an underflow is when the DAC has requested a data output sample, but hasn't got one.

I'm not sure the principle of work of this AUDIO driver now, but if it is not using DMA (Direct Memory Access) or if it is using DMA, but the DMA ISR (Interrupt Service Routine) has low priority or is not optimized enough it can cause this issue.

Again generally a DMA for DAC is used in a ping-pong buffer configuration, where while one buffer is streamed to the DAC another buffer is prepared with data samples. Other more common simpler configuration is a circular buffer, but that requires a little bit more precise work and with more CPU overhead/interference ;-)

Most likely the CPU/MCU/SoC is doing something else, more important (with higher priority) than processing the DMAforDAC ISR and thus postpone the reaction for the next buffer from the audio app.

I can only assume that the DMA is in circular mode with Half Transfer Complete Interrupt which signals when half of the current buffer is transfered so the driver knows when to update the upper half of the buffer and a Full Transfer Complete Interrupt so the driver knows when the buffer will be read from the beginning so the down half can be updated with new data. And as I said this requires more precise timing to handle and if the priority of the DMA ISR is low or the Task Scheduler is switching many tasks it can delay the procedure described above.

Other case is single shot DMA, where the driver continuously is waiting for Transfer complete interrupt of the DMA and when that occurs issues new buffer of single shot DMA transfer with new buffer, in this case is very realistic to have underflows ! But most cases for audio playing in SoC a circular DMA mode is used. I personally prefer ping-pong which is more sophisticated and handy, but not all SoCs or not all SoC's DMA channels support this mode.

You're not able to hear a distinct hang up of the DAC , because at 22kHz sample rate even if you have delayed action from the ISR the last transfered sample to the DAC's output buffer will remain for the next:

T=1/F=1/(22*10^3) ~ 45uS

until the next new sample arrive, if it is missed (underflowed) again it will remain another 45uS as most DACs have autorefresh function which keeps the last transfered sample alive.

This is quite a lot of time for the MCU and I will make this big assumption that you are missing only a few samples, i.e you are having a constant TONE for only a few hundred uS. Even if you lose for example 22 samples which is almost 1 mS you still have the following 22028 samples in that second and it will be very hard to catch that with your ears ;-) Use oscilloscope and you will see how many samples exactly you are missing by looking for how long the value on the DAC output is not changed (where this time is more than 1*T, i.e at least 2*T = 90us or more).

I really got into details, but hope this will help catch the issue:

1.Low ISR priority.
2.Too many processes for the task scheduler.
3.Small DMA buffer (that i forgot to mention, but is also a possibility).

1 and 3 depend on the driver , 2 depends on the system usage. Most likely it is case 1 or 2.

Here is one test you can do :-) :
Try running aplay with 'nice' and with highest possible priority to see if it is the task scheduler ;-)
Check:
man nice
(it is very simple and useful command to set priority of a process in linux)

Good Luck

ps: I'm also going to use the iMX233-OLinuxino-NANO for an audio related project so I will be following the development of the issue.
« Last Edit: May 17, 2014, 12:32:56 AM by scout_3pm »

benbiles

  • Newbie
  • *
  • Posts: 19
  • Karma: +1/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #51 on: October 07, 2014, 01:41:24 PM »
Hi, can anyone confirm if audio has been fixed in 3.x kernel or not?

does this patch work? and how do you use the patch if it does?

Do we have to compile the kernel with the patch? or just patch the installed kernel?

Is there a kernel built with audio IO driver working already? if there is do we have a download link
anywhere?



" Hi g.glowacki,

I am using the latest patch from Michall on a 3.13.6 kernel:
Quote from: Grawp on March 13, 2014, 04:52:09 AM

    patch: https://drive.google.com/file/d/0BxSCLeYUtcwnb3BTZl9TaTJ4UVk/edit?usp=sharing
    dts: https://drive.google.com/file/d/0BxSCLeYUtcwnX3dwQklXdE1TN2M/edit?usp=sharing

"

« Last Edit: October 07, 2014, 01:44:19 PM by benbiles »

g.glowacki

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #52 on: October 07, 2014, 02:24:52 PM »
Hi, can anyone confirm if audio has been fixed in 3.x kernel or not?
Yes it works. I have kernel 3.13.x.

does this patch work? and how do you use the patch if it does?
I've patched the kernel and compiled it.
Do we have to compile the kernel with the patch? or just patch the installed kernel?
Yes. You need to patch kernel with previously mentioned patch.
Is there a kernel built with audio IO driver working already? if there is do we have a download link
anywhere?
I don't know.
Regards.

benbiles

  • Newbie
  • *
  • Posts: 19
  • Karma: +1/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #53 on: October 08, 2014, 06:51:30 AM »
Hi g.glowacki,

Thanks for reply, is there any chance you could post an image of the patched working kernel you built somewhere?

can you explain where you get kernel 3.13.x. from? I have link too https://github.com/koliqi/imx23-olinuxino which is Latest Stable Kernel 3.7.1

and I have cloned https://github.com/ITserve/imx23-audio

trying to build this kernel now with patch..


Also, when you say working audio can you confirm that audio inputs line in L&R stereo and Mic input pin 34 / alsamixer is working cleanly with no random noise and or crashes & buffer under runs ??

Thanks again,

BEN



« Last Edit: October 08, 2014, 08:15:22 AM by benbiles »

ggilles

  • Newbie
  • *
  • Posts: 16
  • Karma: +1/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #54 on: October 08, 2014, 09:10:46 AM »
Also, when you say working audio can you confirm that audio inputs line in L&R stereo and Mic input pin 34 / alsamixer is working cleanly with no random noise and or crashes & buffer under runs ??

No.
Audio outputs work fine, but audio inputs (both mic and line) have a periodic noise in my setup. I could not track the origin of the issue.

Best regards,

-- Gilles

benbiles

  • Newbie
  • *
  • Posts: 19
  • Karma: +1/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #55 on: October 08, 2014, 09:26:09 AM »
Hi Gilles,

So were you using kernel 3.13.x with these patches?

    patch: https://drive.google.com/file/d/0BxSCLeYUtcwnb3BTZl9TaTJ4UVk/edit?usp=sharing
    dts: https://drive.google.com/file/d/0BxSCLeYUtcwnX3dwQklXdE1TN2M/edit?usp=sharing

I am trying to build kernel with https://github.com/ITserve/imx23-audio patch but i'm not sure how to update to 3.13.x kernel

I guess I am waisting my time anyway if audio inputs are broken in both 2.x and 3.x kernels !

Thanks for the update..







ggilles

  • Newbie
  • *
  • Posts: 16
  • Karma: +1/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #56 on: October 08, 2014, 10:22:58 AM »
So were you using kernel 3.13.x with these patches?
I am using kernel 3.13.6.

To update to 3.13.6, here is what I did:
1. clone the imx223-audio repository checkout the imx23-audio branch
2. generate a patch relative to the master branch: with something like
Code: [Select]
git format-patch master --stdout > audio.patch3. clone the stable linux kernel remository, checkout v3.13.6
4. apply the patch of step 2
Code: [Select]
git apply audio.patchyou should probably check that the patch applies cleanly first (with the --check option)

Anyway, if you need audio input this does not work better than the 2.x kernel.

-- gilles

PS: untested instructions!

benbiles

  • Newbie
  • *
  • Posts: 19
  • Karma: +1/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #57 on: October 08, 2014, 11:27:13 AM »
Hi ggiles,

could you explain how I do this step?

3. clone the stable linux kernel repository, checkout v3.13.6

do I clone this with git and then add imx223-audio to the kernel folder and build?

https://kernel.googlesource.com/pub/scm/linux/kernel/git/stable/linux-stable/+/v3.13.6

I think I should build this regardless to learn a bit about patching the kernel etc..
I have built custom kernels in x86 linux but never ARM!







benbiles

  • Newbie
  • *
  • Posts: 19
  • Karma: +1/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #58 on: October 08, 2014, 11:29:21 AM »
I was trying to build using these instructions but can't find the latest kernel for git..


To expand on this a bit more, the instructions I followed are here:

http://www.jann.cc/2012/08/23/building_a_kernel_3_x_for_the_olinuxino_from_sources.html#getting-the-code

I used the https://github.com/koliqi/imx23-olinuxino repository in accordance with above, but instead of using the kernel source from git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git, instead I used https://github.com/ITserve/imx23-audio.

I went through the process of using menuconfig to configure the kernel closely in accordance with the above tutorial. What I did in addition to that was navigate through the sound card options and enabled support for the SOC imx23 audio.

The board now runs with the SD card and I'm able to use networking and so forth, but aplay and linphonec clearly show that no audio devices are present.

macphyter

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: Linux 3.7 ALSA sound support for iMX233?
« Reply #59 on: April 01, 2015, 03:16:01 AM »
I'm trying to get audio working on an Olinuxino, and the patch/dts file mentioned below are no longer available from google drive.  Is there any other place they might be available?  Thanks.

   -Macphyter

---Edit:
Never mind, I found them.  They're in the OpenWRT source tree here if anyone needs them:

https://dev.openwrt.org/browser/trunk/target/linux/imx23/patches?rev=37622

   -Macphyter

Hi Gilles,

So were you using kernel 3.13.x with these patches?

    patch: https://drive.google.com/file/d/0BxSCLeYUtcwnb3BTZl9TaTJ4UVk/edit?usp=sharing
    dts: https://drive.google.com/file/d/0BxSCLeYUtcwnX3dwQklXdE1TN2M/edit?usp=sharing

I am trying to build kernel with https://github.com/ITserve/imx23-audio patch but i'm not sure how to update to 3.13.x kernel

I guess I am waisting my time anyway if audio inputs are broken in both 2.x and 3.x kernels !

Thanks for the update..
« Last Edit: April 01, 2015, 08:14:12 AM by macphyter »