This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

McASP on Linux (BeagleBone)

Other Parts Discussed in Thread: AM3358

I seem to be having trouble with McASP and / or ALSA. At first I had no output on serializers at all, the EDMA buffer would get filled but never flushed so I figured that the transmit DMA event (AXEVT) was not getting caught. To that end I modified devices.c in arch/arm/mach-omap2:

static const s16 am33xx_dma_rsv_chans[][2] = {
/* (offset, number) */
{0, 2},
{8, 2}, // Added McASP channels 8 and 9
{14, 2},
{26, 6},
{48, 4},
{56, 8},
{-1, -1}
};

With this the buffer gets flushed and I get valid I2S data on the serializer (along with correct clock and fsync). Problem is that this sounds wrong on the loudspeaker (via a discrete codec) and I get regular buffer underruns. This is how it looks in userspace:

root@beaglebone:~# aplay_off 48khz_test.wav -vvv
Playing WAVE '48khz_test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
Plug PCM: Route conversion PCM (sformat=S16_LE)
Transformation table:
0 <- 0
1 <- 0
Its setup is:
stream : PLAYBACK
access : RW_INTERLEAVED
format : S16_LE
subformat : STD
channels : 1
rate : 48000
exact rate : 48000 (48000/1)
msbits : 16
buffer_size : 32768
period_size : 2048
period_time : 42666
tstamp_mode : NONE
period_step : 1
avail_min : 2048
period_event : 0
start_threshold : 32768
stop_threshold : 32768
silence_threshold: 0
silence_size : 0
boundary : 1073741824
Slave: Hardware PCM card 0 'AM335X EVM' device 0 subdevice 0
Its setup is:
stream : PLAYBACK
access : MMAP_INTERLEAVED
format : S16_LE
subformat : STD
channels : 2
rate : 48000
exact rate : 48000 (48000/1)
msbits : 16
buffer_size : 32768
period_size : 2048
period_time : 42666
tstamp_mode : NONE
period_step : 1
avail_min : 2048
period_event : 0
start_threshold : 32768
stop_threshold : 32768
silence_threshold: 0
silence_size : 0
boundary : 1073741824
appl_ptr : 0
hw_ptr : 0
Max peak (2048 samples): 0x00000000 # 0%
Max peak (2048 samples): 0x00000001 # 0%
Max peak (2048 samples): 0x0000009c # 0%
Max peak (2048 samples): 0x00000072 # 0%
Max peak (2048 samples): 0x00000083 # 0%
Max peak (2048 samples): 0x0000008f # 0%
Max peak (2048 samples): 0x0000006c # 0%  
Max peak (2048 samples): 0x00000060 # 0%
Max peak (2048 samples): 0x00000061 # 0%
Max peak (2048 samples): 0x00000076 # 0%
Max peak (2048 samples): 0x0000007a # 0%
Max peak (2048 samples): 0x00000856 ## 6%
Max peak (2048 samples): 0x0000208c ###### 25%
Max peak (2048 samples): 0x00002a48 ####### 33%
Max peak (2048 samples): 0x0000329c ######## 39%
Max peak (2048 samples): 0x00003349 ######### 40%  // underrun only happens after 16 samples, amouting to buffer size
underrun!!! (at least 17.528 ms long)
Status:
state : XRUN
trigger_time: 1339159976.367665902
tstamp : 1339159976.385137250
delay : 0
avail : 32768
avail_max : 32768
Max peak (2048 samples): 0x000032cc ######## 39%
Max peak (2048 samples): 0x00003178 ######## 38%
Max peak (2048 samples): 0x00002e25 ######## 36%
Max peak (2048 samples): 0x000030de ######## 38%
Max peak (2048 samples): 0x00002c32 ####### 34%
Max peak (2048 samples): 0x000029b0 ####### 32%
Max peak (2048 samples): 0x00002800 ####### 31%
Max peak (2048 samples): 0x000025d1 ###### 29%
Max peak (2048 samples): 0x00002402 ###### 28%
Max peak (2048 samples): 0x00002311 ###### 27%
Max peak (2048 samples): 0x00002224 ###### 26%
Max peak (2048 samples): 0x00004094 ########### 50%
Max peak (2048 samples): 0x000028df ####### 31%
Max peak (2048 samples): 0x000021b5 ###### 26%
Max peak (2048 samples): 0x0000213b ###### 25%
Max peak (2048 samples): 0x00002072 ###### 25%
underrun!!! (at least 14.801 ms long)
Status:
state : XRUN
trigger_time: 1339159980.79336308
tstamp : 1339159980.94129538
delay : 0
avail : 32768
avail_max : 32768
Max peak (2048 samples): 0x00001edd ##### 24%
// periods amounting to buffer size cut for brevity
Max peak (2048 samples): 0x000013d4 #### 15%
underrun!!! (at least 370.801 ms long)
Status:
state : XRUN
trigger_time: 1339159983.319245731
tstamp : 1339159983.690038716
delay : 0
avail : 32768
avail_max : 32768
Max peak (2048 samples): 0x0000136a #### 15%
// periods amounting to buffer size cut for brevity
Max peak (2048 samples): 0x00001055 ### 12%

....

Investigating further into this I see that once the CPU-side buffer gets completely emptied I get an buffer underrun error and so on. Even though it gets plenty events from the McASP (I can see that davinci_pcm_dma_irq gets called, which is registered as channel 8 event callback with EDMA) the CPU only transfers once buffer is emptied and ALSA reports an underrun. I suppose a transfer should be initiated on every AXEVT? Am I wrong in modifying devices.c to reserve slots 8 and 9 for McASP? Before I was getting absolutely nothing on the serializer. The write FIFO is set to generate AXEVT every 32-bit word. Would someone please advise on this?

Thanks in advance!