Class-D Audio Amplifier - SAMA5D27-SOM1

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

Moderator: nferre

CleberPeter
Location: Brazil
Posts: 20
Joined: Tue May 14, 2019 7:57 pm

Class-D Audio Amplifier - SAMA5D27-SOM1

Thu Mar 26, 2020 7:29 pm

I'm trying to work with a Class-D Audio Amplifier on SAMA5D27-SOM1 in Single-ended mode and enabling Non-overlapping.
For tests i'm using the SAMA5D27-SOM1-EK and ROOTFS generated with Yocto Thud branch.

To enable the peripheral i make this configuration on device tree:

at91-sama5d27_som1_ek.dts:

Code: Select all

#include "at91-sama5d27_som1.dtsi"
...
apb {
               ...
               pinctrl@fc038000 {
				pinctrl_classd_default: classd_default {
					pinmux = <PIN_PB1__CLASSD_R0>,
						          <PIN_PB2__CLASSD_R1>;
					bias-pull-up;
				};
                ...
                }

                classd: classd@fc048000 {
	                        pinctrl-names = "default";
	                        pinctrl-0 = <&pinctrl_classd_default>;
	                        atmel,pwm-type = "single";
	                        atmel,non-overlap-time = <10>;
	                        status = "okay";
               };
               ...
}

And this other configuration already existed on sama5d2 device tree. wich is imported by at91-sama5d27_som1_ek.dts.

sama5d2.dtsi:

Code: Select all

apb{
	...
	classd: classd@fc048000 {
		compatible = "atmel,sama5d2-classd";
		reg = <0xfc048000 0x100>;
		interrupts = <59 IRQ_TYPE_LEVEL_HIGH 7>;
		dmas = <&dma0
				(AT91_XDMAC_DT_MEM_IF(0) | AT91_XDMAC_DT_PER_IF(1) |
				AT91_XDMAC_DT_PERID(47))>;
		dma-names = "tx";
		clocks = <&classd_clk>, <&classd_gclk>;
		clock-names = "pclk", "gclk";
		status = "disabled";
	};
	...
}

To compile the driver atmel-classd.c i used the file default file sama5_defconfig when compiling the kernel. This file enable the driver with option:

Code: Select all

CONFIG_SND_ATMEL_SOC_CLASSD=y

During the kernel boot the audio card is detected by the Alsa, this can be vericated on boot log message:

Code: Select all

[1.550000] ALSA device list:
		   	#0: CLASSD

And finally go to the problem, when i execute the command on linux terminal:

Code: Select all

speaker-test -f1000 -t sine -c2

This code performs a 1kHz sine tone with a sample rate of 48kHz on both audio channels.

The PB1 and PB2 pins have a PWM signal without modulation, as if a mute audio file was playing. The image linked show signals from pins during command executation . (https://drive.google.com/open?id=1DMgxR ... FR4hPatRtY)

The PWM switching frequency displayed on the pins is close to 760kHz which matches the information in the document "Getting Started with the SAMA5D2 Audio Subsystem" for a sample rate of 48kHz.

I put printk's on every function of atmel-classd.c, i don't see any error on driver execution. Below follow the sequence of calling funcion by SO.

Initialization kernel:

Code: Select all

atmel_classd_dt_init
atmel_classd_codec_get_remap
atmel_classd_asoc_card_init
atmel_classd_codec_probe
Start playing audio:

Code: Select all

atmel_classd_cpu_dai_startup
atmel_classd_codec_dai_startup
atmel_classd_codec_dai_hw_params
atmel_classd_platform_configure_dma
atmel_classd_dai_prepare
atmel_classd_codec_dai_digital_mute - passing parameter 0
atmel_classd_dai_trigger- passing parameter (SNDRV_PCM_TRIGGER_START/SNDRV_PCM_TRIGGER_RESUME/SNDRV_PCM_TRIGGER_PAUSE_RELEASE)
Stop playing audio:

Code: Select all

atmel_classd_dai_trigger- passing parameter (SNDRV_PCM_TRIGGER_STOP/SNDRV_PCM_TRIGGER_SUSPEND/SNDRV_PCM_TRIGGER_PAUSE_PUSH)
atmel_classd_codec_dai_digital_mute - passing parameter 1
atmel_classd_shutdown

How i get the PWM signal modulated by audio file ?
Anyone do this work ?
This can be problem with DMA configurarion ?

I appreciate any suggestion.
CleberPeter
Location: Brazil
Posts: 20
Joined: Tue May 14, 2019 7:57 pm

Re: Class-D Audio Amplifier - SAMA5D27-SOM1

Fri Mar 27, 2020 5:19 pm

This problem was solved.

The sound controlling devices are muted by default. You need to unmute them explicitly.

Using this command:

Code: Select all

amixer set 'Mono' 70 unmute
as this page explains:

https://www.linux4sam.org/bin/view/Linux4SAM/AudioFAQ
uvijay
Posts: 5
Joined: Thu Jul 09, 2020 4:50 pm

Re: Class-D Audio Amplifier - SAMA5D27-SOM1

Fri Nov 27, 2020 6:06 pm

I am working on SAMA5D27-WLSOM board i have enabled CLASS D kernel configuration as mention in the post. After that i could able to list the device from aplay -l

root@sama5d27-wlsom1-ek-sd:~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: CLASSD [CLASSD], device 0: CLASSD PCM atmel-classd-hifi-0 [CLASSD PCM atmel-classd-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0

in boot log also CLASSD is listing
ALSA device list:
#0: CLASSD
When i try to play wav file using aplay not getting the sound output.

Also tried below command
#amixer set 'Mono' 70 unmute
Simple mixer control 'Mono',0
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [on]

Anyone suggest on how to get sound?
CleberPeter
Location: Brazil
Posts: 20
Joined: Tue May 14, 2019 7:57 pm

Re: Class-D Audio Amplifier - SAMA5D27-SOM1

Sat Nov 28, 2020 12:15 am

What is the volume obtained in the alsamixer ?

Try to test with this command:

Code: Select all

 speaker-test -f1000 -t sine -c2 
uvijay
Posts: 5
Joined: Thu Jul 09, 2020 4:50 pm

Re: Class-D Audio Amplifier - SAMA5D27-SOM1

Mon Nov 30, 2020 7:45 am

Getting below response
speaker-test -f1000 -t sine -c2

speaker-test 1.1.8

Playback device is default
Stream parameters are 48000Hz, S16_LE, 2 channels
Sine wave rate is 1000.0000Hz
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 128 to 16384
Period size range from 64 to 8192
Using max buffer size 16384
Periods = 4
was set period_size = 4096
was set buffer_size = 16384
0 - Front Left
1 - Front Right
Time per period = 5.646523
0 - Front Left
1 - Front Right
Time per period = 5.973220
0 - Front Left
1 - Front Right
Time per period = 5.973176
0 - Front Left
....
....
...
....

Return to “LINUX”

Who is online

Users browsing this forum: No registered users and 2 guests