Audio Support Rock Pi S

It was asked as to what users wanted to use with respect to audio inputs and outputs. I bought 2x Rock PI S because it has stereo analog audio out and at least one analog audio input.
EDIT: I’ve yet to try to get them working as I’m doing a few other things with the HW first.
Thanks!

Hi everybody,
I don’t know if this post could help someone out.
Here is how you can set up the I2S and PDM lines of the board so that you can use MEMs digital microphones, either by using I2S or PDM interface.

First of all, I installed on the SD card Radxa official ROM Ubuntu bionic (released on 19 Dec 2019).
Then I did updates and installed required packages for audio and set up

For updates
sudo apt-get update
sudo apt-get upgrade

For audio recording (I use SoX Ubuntu package)
sudo apt-get install libasound2 alsa-utils alsa-oss
sudo apt-get install sox -y

Then, in order to set up I2S/PDM pins on the board, you need to modify the device tree and recompile it. So you need to install the device tree compiler.

sudo apt-get install device-tree-compiler

Then go to /boot/dtbs/your_kernel_version/rockchip and decompile the device tree being used by the bootloader, that is rockpi-s-linux.dtb. To do so, you have to run

dtc -I dtb -O dts -f rockpi-s-linux.dtb -o rockpi-s-linux.dts

Once you have the dts file, open it and go to acodec-sound part

acodec-sound {
	compatible = "rockchip,multicodecs-card";
	rockchip,card-name = "rockchip,rk3308-acodec";
	rockchip,codec-hp-det;
	rockchip,mclk-fs = <0x100>;
	rockchip,cpu = <0xc3>;
	rockchip,codec = <0x8b>;
	phandle = <0x13d>;
};

You will have to change the cpu field. If you want to use up to 8 I2S microphones, you will have to change the value to <0xbe>, which is the phandle of the I2S0 controller (which is exposed on the pinouts layout). Remember you also need to enable the I2S0 interface, so go to i2s@ff300000 and change the status to “okay”.

i2s@ff300000 {
	compatible = "rockchip,rk3308-i2s-tdm";
	reg = <0x0 0xff300000 0x0 0x1000>;
	interrupts = <0x0 0x30 0x4>;
	clocks = <0x2 0x4c 0x2 0x4e 0x2 0xa4 0x2 0x6e 0x2 0x6f 0x2 0x3 0x2 0x4>;
	clock-names = "mclk_tx", "mclk_rx", "hclk", "mclk_tx_src", "mclk_rx_src", "mclk_root0", "mclk_root1";
	dmas = <0x25 0x0 0x25 0x1>;
	dma-names = "tx", "rx";
	resets = <0x2 0x89 0x2 0x8a>;
	reset-names = "tx-m", "rx-m";
	rockchip,cru = <0x2>;
	rockchip,grf = <0x4b>;
	rockchip,mclk-calibrate;
	pinctrl-names = "default";
	pinctrl-0 = <0x4e 0x4f 0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5a>;
	status = "okay";
	phandle = <0xbe>;
};

Once you have done all the changes, re-compile the dts file to get the binary format (dtb).

sudo dtc -I dts -O dtb -f rockpi-s-linux.dts -o rockpi-s-linux.dtb

Then reboot and enjoy!

In case you want to use PDM interface, just change the cpu field in the acodec-sound to <0xc3>, which is the phandle of the PDM controller. Then remember to enable the interface by changing its status to “okay”.

pdm@ff380000 {
	compatible = "rockchip,rk3308-pdm", "rockchip,pdm";
	reg = <0x0 0xff380000 0x0 0x1000>;
	clocks = <0x2 0x4b 0x2 0xa1>;
	clock-names = "pdm_clk", "pdm_hclk";
	dmas = <0x25 0xc>;
	dma-names = "rx";
	resets = <0x2 0x83>;
	reset-names = "pdm-m";
	pinctrl-names = "default";
	pinctrl-0 = <0x5f 0x60 0x61 0x62 0x63>;
	status = "okay";
	phandle = <0xc3>;
};
4 Likes

Hey ash,
check out my last post! Hope it helps.

Hey @baronets, Thanks for that, I am trying to get i2s output for an external DAC, but got a bit sidetracked, and haven’t yet managed. Here is dts I am playing with if your curious! :wink:

Hi @ash. I have checked out your code.
I haven’t tried the armbian image, but if the DAC supports I2S protocol, it should work fine with the configuration I posted. What should change is the clock connection: in my case, I use RX clock. I assume you should only change it. In my case, it does not matter which microphone I am using, as long as both board and the transducer use the same interface.
Currently I am only dealing with multichannel audio recording :slightly_smiling_face:.

Hi @ash. I have checked out your code.
I haven’t tried the armbian image, but if the DAC supports I2S protocol, it should work fine with the configuration I posted. What should change is the clock connection: in my case, I use RX clock. I assume you should only change it. In my case, it does not matter which microphone I am using, as long as both board and the transducer use the same interface.
Currently I am only dealing with multichannel audio recording :slightly_smiling_face:.

Ah, maybe I understood this wrong, is the only way to access i2s via the acodec-sound node?
i.e I can’t define a different codec that directly uses the i2s@ff3x0000 interfaces?

I don’t have a scope right now to confirm if there are any outputs with my overlay, but I don’t see any mapping messages in the boot log such as with acodec-sound:

[1.242] rk3308-acodec ff560000.acodec: rk3308_codec_set_jack_detect: Request detect hp jack once
[1.244] rk-multicodecs acodec-sound: rk3308-hifi <-> ff320000.i2s mapping ok

Eitherway, I don’t think its a DAC/Codec issue, as the PCM5102a is as good as the dummy-codec, and should show up even when not connected.

But I am still a bit confused with the multichannel I2S outputs and mapping.
Looking at the i2s@ff300000 node in rk3308.dtsi

  • Where are the enabled output/input pins defined? Is it pinctrl-0?
    – Are all 8 i2s_8ch_0_sdi and i2s_8ch_0_sdo pins active?

i2s_8ch_0: i2s@ff300000 {
	compatible = "rockchip,rk3308-i2s-tdm";
	reg = <0x0 0xff300000 0x0 0x1000>;
	interrupts = <GIC_SPI 48 IRQ_TYPE_LEVEL_HIGH>;
	clocks = <&cru SCLK_I2S0_8CH_TX>, <&cru SCLK_I2S0_8CH_RX>, <&cru HCLK_I2S0_8CH>,
		 <&cru SCLK_I2S0_8CH_TX_SRC>,
		 <&cru SCLK_I2S0_8CH_RX_SRC>,
		 <&cru PLL_VPLL0>,
		 <&cru PLL_VPLL1>;
	clock-names = "mclk_tx", "mclk_rx", "hclk",
		      "mclk_tx_src", "mclk_rx_src",
		      "mclk_root0", "mclk_root1";
	dmas = <&dmac1 0>, <&dmac1 1>;
	dma-names = "tx", "rx";
	resets = <&cru SRST_I2S0_8CH_TX_M>, <&cru SRST_I2S0_8CH_RX_M>;
	reset-names = "tx-m", "rx-m";
	rockchip,cru = <&cru>;
	rockchip,grf = <&grf>;
	rockchip,mclk-calibrate;
	pinctrl-names = "default";
	pinctrl-0 = <&i2s_8ch_0_sclktx
		     &i2s_8ch_0_sclkrx
		     &i2s_8ch_0_lrcktx
		     &i2s_8ch_0_lrckrx
		     &i2s_8ch_0_sdi0
		     &i2s_8ch_0_sdi1
		     &i2s_8ch_0_sdi2
		     &i2s_8ch_0_sdi3
		     &i2s_8ch_0_sdo0
		     &i2s_8ch_0_sdo1
		     &i2s_8ch_0_sdo2
		     &i2s_8ch_0_sdo3
		     &i2s_8ch_0_mclk>;
	status = "disabled";
};

Hi ash,
yes, pinctrl-0 tells you the pin configuration. I do not think you have to enable them, you only need to enable the i2s which controls them.
I think you could then simply use the acodec-sound, you need it to tell ALSA which audio peripheral to use when recording/playing.
I have not checked on this board, but when I set up in the same way another board (Nano Pi m4v2 by Friendly Elec), as soon as you start recording you have both tx and rx clocks working.
I have no experience with modifying the device tree with overlays, as my previous board was not supporting it :slight_smile:
I am sorry if I am not technically correct, I learned everything by playing around with the board.

hi, i`m trying to get an analog microphone to work.

I connecetd it to pin23 (MICN1) and ground.
But it doesnt work. I`m using the ubuntu image.

I tried: arecord -d 10 -f cd -t wav --device=“hw:1,0” /tmp/test-mic.wav
to thest the microphone , but all i got is an .wav file with continuous buzzing.

Anybody got an analog microphone to work or can help me with that ? Thanks

1 Like

@jack

https://github.com/rockchip-linux/device-custom/tree/master/rk3308/rk3308_2mic_release-0.52-online

This chips benefit is not the number of mics that it can handle as without dsp aec/vad via the codec it becomes much less.
2 Mic would be brilliant as both Google and alexa have settled on this as an optimal cost/performance solution.
The multi mic beamforming setups still suffer vocode bleed degradation from crossover of singular predominant noise.
So in domestic situations where a loud TV or HiFi is playing and your trying to speak across actually they don’t work that great for recognition purpose.
They are amazing in more industrial dispersed noise where actor voice is predominant.

Are there any plans for 2 mic solution, maybe with pixel ring? As if it can use the binary blobs of vad and aec that seem to be already provided in the above repo then this becomes an extremely exciting product.

Currently the alternatives of Pi4 2gb and the Respeaker 4 mic USB comes with Aec. I haven’t actually tried the 4 mic linear for pi and can not work out if the loopback has aec dsp or not.
You can make a home assitant use something like https://mycroft.ai/ and as a singular unit it is exceptionally good, at a cost.

The problem Mycroft has is going back to domestic predominant singular noise sources that it can still suffer from extremely poor recognition if the actor voice isn’t predominant.
Like I say with beamforming you can have a high dispersed noise level and they work great but for domestic situations the same isn’t really true.
Unless the media source can be provided to the aec dsp loopback.
What mycroft and many builders need are low cost AEC/VAD wifi/bluetooth satelite speaker/mics that connect to a central RockPi4 or even X86.

It seems the major selling point of the RK3308 with built in dsp is being overlooked and wondering if you have anything in the pipeline?
Also do you have any working examples of some of the blobs Rockchip provide?

There is a big interest in opensource private non cloud AI where the load will likely be too high for the RK3308 but wow its a great low cost dsp audio networked satelite system to connect to a singular central unit (home ai cloud).

I have the same problem!
The schematics tell that MIC1 and MIC2 are loopback, so I thought I needed to use another MIC Channel. Tried MIC5, but when recording with the following command:

arecord -D plughw:1,0 -d 5 -f S16_LE -c 1 -r 48000 -t wav /tmp/mic-test.wav

The MIC 0 Left and MIC 0 Right channels are set to “Work” in Alsamixer automatically. Using 6 channels gave some sound on channel 5, but very small in amplitude and with lots of buzzing.
Hope someone has got an analog microphone to work on the Rock Pi S!

Is it something to do with the mic bias presume its programmable how though?

8.3.2 Analog Interface
Fig. 8-7 Microphone Input
There are two microphone input pin, MICP and MICN. They can be configured as differential
inputs by the microphone PGA (MIC).
The signal of microphone output should be input to Audio Codec through DC-blocking
capacitor, as shown in following figure.
Fig. 8-8 Input DC-blocking capacitor
The capacitance and input resistance from a high pass filter. For example, when the gain of
the MIC module is 20dB, the input resistance is 45kΩ and 0.1uF DC-blocking capacitor is
used, the lower cut-off frequency is:
3 6
1 1 35.4
2 2 45 10 0.1 10
f Hz
  RC 
  
   
The capacitance of the DC-blocking capacitor should be determined by the minimum input
impedance and application requirements. If the output of microphone is single-ended, the
audio ADC input should be connected as following figure.
RK3308 TRM-Part1
Copyright 2018 © FuZhou Rockchip Electronics Co., Ltd. 149
Fig. 8-9 Input single-ended DC-blocking capacitor
Microphone PGA has two gains to amplify the input signal, that is 0dB and +20dB.
Automatic Level Control (ALC) function is included to adjust the signal level, which is input
into ADC. ALC will measure the signal magnitude and compare it to defined threshold. Then
it will adjust the ALC controlled gain (ALC_L and ALC_R) according to the comparison result.
When the AGC function is off, the gain (ALC_L and ALC_R) is directly controlled by register,
and the programmable gain range is from -18dB to +28.5dB, and the tuning step is 1.5dB.
Audio Codec supports two line output and two headphone out configurations. The DAC
output can drive load through DC-blocking capacitor.
In the configuration using DC-blocking capacitor, shown in the following figure, the
headphone ground is connected to the real ground. The capacitance and the load resistance
determine the lower cut-off frequency. For instance, if 600Ω load and 4.7uF DC-blocking
capacitor are used, the lower cut-off frequency is:
6
1 1 56.5
2 2 600 4.7 10
f Hz
  RC 
  
  
The DC-blocking capacitor can be increased to lower the cut-off frequency for better bass
response.
CODEC DAC
VOUTL
VOUTR
AGND Fig. 8-10 Output DC-blocking capacitor
The headphone-out driver has a gain range from -39dB to +6dB with a tuning step of 1.5dB.
The line out driver has a gain range from -16.5dB to +6dB with a tuning step of 1.5dB.

Also needs dc blocking caps.

According to the post mine turns up today.

I found this out in the wild if its any use to anyone?
Reference Schematic For RK3308

@baronets

I tried the dts change with the latest updates and don’t seem to be able to get it working.
I know these I2S mics work on a Pi.
Just got a stereo pair just for a test.
I2S0_8CH_SCLK_TX I am presuming is the clock
I2S0_8CH_LRCK_TX L/R hi/low word clock
I2S0_8CH_SDI0 Data input
3.3v and gnd connected and then your DTS edit.

arecord -Dplughw:rockchiprk3308a -c8 -fS16_LE -r16000 rec.wav

Nothing though all channels totally flat and empty.
Has anything changed since you write up or do you think its the likely that I am doing something dumb?

Would be so good to get this added to the wiki also.

1 Like

Hi @stuartiannaylor ,
I2S0_8CH_SCLK_TX and I2S0_8CH_LRCK_TX L/R refer to transmission, that means output mode not input mode. Those pins have to be used when you connect speakers not microphones.
If you want to connect microphones then you need to use I2S0_8CH_SCLK_RX and I2S0_8CH_LRCK_RX (pins 19 and 20).
Be careful that whenever you upgrade the linux kernel, it overwrites the device tree changes you made. To overcome this problem you could use device tree overlays instead of changing the device tree directly but I do not know if the Rock Pi S supports that.
I hope I solved your issue.

Yeah doh seems like I had one of those days.
I was thinking in terms of clock direction rather than data and also because I had a red wire also stuck it on 5v from examination.

Think I have killed it as grabbed a fresh I2S mic and still no go.
I just need to try back on the Pi and see if I have a working Mic and then see if it works on the RockpiS but looking like might have to get another just to eliminate that damage could of been done.

My fault really as was just on a bored day and not paying true attention as interested in voiceAI but still waiting for a KWS.
There is this one version that is 100% opensource and has a model generator and just waiting for them to smoothe off some rough edges, so no major rush.

https://linto.ai/

I am recapping from a long time since I read the tech manual from rockchip but the VAR and Wake from sleep did you ever tinker with the DTS and get those running?

@jack I have been hassling jack for some time about mic connections as yeah it supports overlays but slightly bemused why Radxa hasn’t provided as like said and overlay would stop ony overwrites.

I guess I could of prob setup without a KWS and just used snapcast to RTP via WiFi and used as a speaker/mic.

EC work quite on the RockPi if you use ec - Echo Canceller but would be great if it had USB audio gadget drivers not that I have done much research on what is required.

So Doh and thanks for the great info and I will get back to if I ended up getting a replacement or not.
Dunno why radxa haven’t done more in the wiki or overlays with audio?

@jack the 512mb bt/wifi do you know when those are back in stock as its not much more for POE but it isn’t needed but think of getting x4 to make a wireless wide array room mic quad sound system.

Hi @stuartiannaylor,
Unfortunately I never changed the device trwe to use the VAR.
I only used a button as wakeup source from standby but that is different.
I am using a custom kernel on my Rock Pi S so I do not mind not using overlays as I never do the upgrade.

I will prob at one stage get round to checking the VAD dunno why I called it VAR must be a bit SAD (Speech activity Detection) after it still not working.

I lost interest as got sidetracked by some other things, trying to find a really good KWS but actually thinking a Wifi/USB conference speaker might even be a project.

@jack it just bemuses why Radxa doesn’t add and focus on its audio capability in terms of documentation and overlays as its heavily invested that way by rockchip and for that its an absolute awesome Pi killer as approx Pi3 perf with stereo output and x8 mic inputs just add a 3.5mm barrel and prob 4x I2S mics you can not touch it at that price.

Maybe it didn’t sell which actually bemuses me as the paradox is if it did have some simple info maybe if the usb audio gadget and mic interfacing got some love it would as for price its freaking awesome.

[EDIT]

@baronets

Haven’t tried but think that setting is in alsamixer.

ACODEC_DAC_ANA_CON12
Address: Operational Base + offset (0x0470)
Bit Attr Reset Value Description
31:8 RO 0x0 reserved
7:6 RW 0x0
The select signal of HPMIX module in the right DAC channel.
DAC_R_HPMIX_SEL [1] is reserved, it should be 1'b0.
DAC_R_HPMIX_SEL[0],Select input from I2S
1'b0: Don't select
1'b1: Select
5:4 RW 0x2
DAC_R_HPMIX_GAIN
The gain signal of HPMIX module in the right DAC channel.
2'b01: -6dB
2'b10: 0dB
others: reserved
3:2 RW 0x0
DAC_L_HPMIX_SEL
The select signal of HPMIX module in the left DAC channel.
DAC_L_HPMIX_SEL [1] is reserved, it should be 1'b0.
DAC_L_HPMIX_SEL[0],Select input from I2S
1'b0: Don't select
1'b1: Select 

Maybe I2S will work with the DAC but will have to set back up to try?

PS didn’t kill it with 5v your dts has a different naming to the standard which I never checked.
Copy over to the right filename as with the official setup and all works fine.

But guess now my audio out isn’t on LINEOUT_R pin 25, LINEOUT_L pin 26 as only returns when I revert back to the original dtb.

Anyone know how to get audio out and I2S mics working?

Just thought sod it and connected a analogue mic module without dc blocking caps.

3.3 -> Module VCC, GND -> Module GND
Out -> Mic-P, GND -> Mic-N

Works fine the mems is a bit quiet and the electret with the MAX9814 is mighty as it usually is.

There was DC buzz but far less than my lazy approach expected as thought it would be horrendous but ok just to test.
I will get some .1uf ceramics on Mic-N & Mic-P and see how its goes.

Also while I am at it a 4.7uF DC blockers on the stereo out is prob worth a try also, so will come back on that.

[edit]

I would say these are definitely the best to go for as even though electret rather than mems the Max9814 gives far more amplification.

There is a level of dc buzz that I think is endemic to the Soc board as on high gain with the codec you just amplify this base buzz with you signal.
So the higher the input signal the less you need to amplify.

Yeah blocking caps help a little but going to play with values a little bit more as its guess work to the impedance of the mic module.
Also because I had one I put an audio cap 12000uF across 5v & gnd which did clean the line a little but minimal.
Prob smaller :slight_smile: might help and not lessen the effect but debatable if worth the hassle or space.

The mems analogue modules due to the large codec gain needed produce quite a lot of noise. Its still completely fine for recognition but for voice recording you wouldn’t be happy.
In fact even the max9814 you probably wouldn’t be happy but in comparison to the mems the low level of background noise is only a problem if you where thinking of creating a wifi mic or something and expecting studio quality.

My application of a voiceAI then more than happy with the sensitivity of the max9814 you need to put 3.3v on the gain pin as the top gain by leaving it floating as usual with these modules is noisy.
Dunno why they are that way as the top gain is pure over optimism whilst -10db makes a world of difference.
The low gain by applying gnd to the gain pin doesn’t seem to be much different but the lower signal it produces means more codec amplification and the board noise starts to creep in.

You can listen here to the electret with a codec gain of 13.5db with a single mic

https://drive.google.com/file/d/1f4IUcTLdSJDCfdRAsQuA4JSWxw39670t/view?usp=sharing

Also my computer is pretty noisy so here is a recording where through the recording it goes to sleep and you can hear in a much quieter room a truer reflection of quality.

https://drive.google.com/file/d/1goGPNXlUE8P-R2T3tHrhjXFQwtWENz0h/view?usp=sharing

1 Like

Hi
I am using a DAC that needs master clock AK4495 and when I am following your instructions here I am not getting any output on the master clock pin. It should be on pin 7 (GPIO2_A4) right?
SCLK, LRCLK, and SDO working fine.
My question is do you know if something is wrong in the dts file or is it the driver?