Now I wanna pre-allocate contiguous block of memory for this DMA audio buffer, cause I think this random can be in slow buffer pushing. I think so, cause of it no underruns on ALSA level, I already debugged it.
Posts made by Mark Nagaev
-
RE: Problem with i2s driver and ALSA, underrun
-
RE: Problem with i2s driver and ALSA, underrun
Ok I add some fixes, now it works better, but not perfect on 192/24.
First, I increased period_bytes_max, it can be 65535 bytes cause it limmited only by dma transfer.
Second, buffer_bytes_max and prealloc_buffer_size, I increased them too, now it ~4MB.
Third, dma_data->maxburst = 4, cause it can be transferred 16 bytes, after threshold reached.Now it's randomly can be ~100 underruns while playing, but most od the time it's clear
root@OpenWrt:/# aplay /root/1kHz(24x192)cut.wav
Playing WAVE '/root/1kHz(24x192)cut.wav' : Signed 24 bit Little Endian in 3bytes, Rate 192000 Hz, Stereo
[ 3262.796745] underrun 4
root@OpenWrt:/# aplay /root/1kHz(24x192)cut.wav
Playing WAVE '/root/1kHz(24x192)cut.wav' : Signed 24 bit Little Endian in 3bytes, Rate 192000 Hz, Stereo
[ 3278.822202] underrun 69
root@OpenWrt:/# aplay /root/1kHz(24x192)cut.wav
Playing WAVE '/root/1kHz(24x192)cut.wav' : Signed 24 bit Little Endian in 3bytes, Rate 192000 Hz, Stereo
[ 3291.029872] underrun 19
root@OpenWrt:/# aplay /root/1kHz(24x192)cut.wav
Playing WAVE '/root/1kHz(24x192)cut.wav' : Signed 24 bit Little Endian in 3bytes, Rate 192000 Hz, Stereo
[ 3303.158453] underrun 3
root@OpenWrt:/# aplay /root/1kHz(24x192)cut.wav
Playing WAVE '/root/1kHz(24x192)cut.wav' : Signed 24 bit Little Endian in 3bytes, Rate 192000 Hz, Stereo
[ 3316.406874] underrun 1
root@OpenWrt:/# aplay /root/1kHz(24x192)cut.wav
Playing WAVE '/root/1kHz(24x192)cut.wav' : Signed 24 bit Little Endian in 3bytes, Rate 192000 Hz, Stereo
[ 3328.456432] underrun 1
root@OpenWrt:/# aplay /root/1kHz(24x192)cut.wav
Playing WAVE '/root/1kHz(24x192)cut.wav' : Signed 24 bit Little Endian in 3bytes, Rate 192000 Hz, Stereo
[ 3341.206080] underrun 100
root@OpenWrt:/# aplay /root/1kHz(24x192)cut.wav
Playing WAVE '/root/1kHz(24x192)cut.wav' : Signed 24 bit Little Endian in 3bytes, Rate 192000 Hz, Stereo
[ 3352.909575] underrun 1
root@OpenWrt:/# aplay /root/1kHz(24x192)cut.wav
Playing WAVE '/root/1kHz(24x192)cut.wav' : Signed 24 bit Little Endian in 3bytes, Rate 192000 Hz, Stereo
[ 3365.469447] underrun 0
root@OpenWrt:/# aplay /root/1kHz(24x192)cut.wav
Playing WAVE '/root/1kHz(24x192)cut.wav' : Signed 24 bit Little Endian in 3bytes, Rate 192000 Hz, Stereo
[ 3388.133126] underrun 1 -
RE: Contiguous Memory Allocator in kernel
@Modest-Polykarpovich not my own, but I'm still trying to improve existin driver, here my post, I add some of my fixes, It works better with them, but not perfect with rates higher than 96kHz, I really wanna play bit-perfect 192/24 on i2s Omega2
-
RE: Contiguous Memory Allocator in kernel
@Modest-Polykarpovich 16 MB just for experiment, but I need about 4 MB of contiguous memory for my DMA audio buffer, of course it works in kernel-mode. If it's interesting for u, u can read this article
-
Contiguous Memory Allocator in kernel
Hi, I'm trying to pre-allocate contiguos block of memory.
In kernel_menuconfig I'm selecting cma enabled in Kernel type submenu, and in Device drivers->Generic driver option I'm selecting DMA Contiguous Memory Allocator, trying to apply 16 MB size zone with max page order 6 (I have 16 kB kernel page size). Building image and downloadin in Omega2p.
When it starts i have message in terminal:[ 0.000000] Determined physical RAM map:
[ 0.000000] memory: 08000000 @ 00000000 (usable)
[ 0.000000] cma: Failed to reserve 128 MiBand after :
[ 0.000000] Memory: 124736K/131072K available (4117K kernel code, 226K rwdata, 944K rodata, 208K init, 245K bss, 6336K reserved, 0K cma-reserved)
Idk why it trying reserve 128 MiB, I added in device-tree of Omega2p this block to reserve 64 MB of memory:
memory@0 { device_type = "memory"; reg = <0x0 0x8000000>; }; reserved-memory { #address-cells = <1>; #size-cells = <1>; ranges; /* global autoconfigured region for contiguous allocations */ linux,cma { compatible = "shared-dma-pool"; reusable; reg = <0x4000000 0x4000000>; alignment = <0x2000>; linux,cma-default; }; };
It still failing to reserve, if turn on debug messages:
[ 0.000000] Determined physical RAM map:
[ 0.000000] memory: 08000000 @ 00000000 (usable)
[ 0.000000] cma: dma_contiguous_reserve(limit 08000000)
[ 0.000000] cma: dma_contiguous_reserve: reserving 16 MiB for global area
[ 0.000000] cma: cma_declare_contiguous(size 0x01000000, base 0x00000000, limit 0x08000000 alignment 0x00000000)
[ 0.000000] cma: Failed to reserve 128 MiBAnyway, mb someone successed with contiguous allocation for DMA buffers?
-
RE: Network configuration
@Douglas-Kryder oh, u mean it's apsta mode? Yeah it's really poor speed, u can connect it by eth and use only ap mode it'll be 40-50mbps for each device. But in my situation, I don't wanna be connected to internet on omega, it must be endpoint with audio server.
-
RE: Network configuration
@Douglas-Kryder yeah, but I wanna use omega like an access point wifi, it's eazier to connect several phones to it and stream from each of them, u don't need to reconfigure wifi of omega. It's simply for usability
-
RE: Network configuration
@Lucas-Gozalvez yeah, the same, it's all in OS of smartphones, can't do anything with it, i think
-
RE: Network configuration
I wanna use shairport synch for streaming airplay music over wifi and cellular connection for all applications on my iphone for example
-
Network configuration
I need to connect my phone to a wifi omega2 that is not connected to the internet. Is there a way to connect to omega2 with Wifi, yet continue to the the cellular connection for internet data?
Mb any network configuration to say to phone stay connected by wifi but use 4g for internet? -
RE: How to get the firmware with function of I2S and I2C?
https://docs.onion.io/omega2-docs/cross-compiling.html
Download a build system, configure it, build your own firmware. This functions will work on openwrt branch-kernel 4.14. -
Problem with i2s driver and ALSA, underrun
My hardware i2s driver's params:
static struct snd_pcm_hardware ralink_pcm_hardware = {
.info = SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER,
.formats = SNDRV_PCM_FMTBIT_S16_LE |
SNDRV_PCM_FMTBIT_S24_LE,
.channels_min = 2,
.channels_max = 2,
.period_bytes_min = PAGE_SIZE, \ 512
.period_bytes_max = PAGE_SIZE * 2, actually not max, it can be PAGE_SIZE * 8
.periods_min = 2, actually idk what this param means
.periods_max = 128, should I enlarge it?
.buffer_bytes_max = 128 * PAGE_SIZE * 2, should I enlarge it too?
.fifo_size = RALINK_I2S_FIFO_SIZE, it's 32
}
static const struct snd_dmaengine_pcm_config ralink_dmaengine_pcm_config = {
.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
.pcm_hardware = &ralink_pcm_hardware,
.prealloc_buffer_size = 256 * PAGE_SIZE, And enlarge it?
};I have underruns when just aplay 96/24 and 192/24 audio, it s clear with 48/24
root@OpenWrt:~# aplay 24x192.wav -v
Playing WAVE '24x192.wav' : Signed 24 bit Little Endian in 3bytes, Rate 192000 Hz, Stereo
Plug PCM: Linear conversion PCM (S24_LE)
Its setup is:
stream : PLAYBACK
access : RW_INTERLEAVED
format : S24_3LE
subformat : STD
channels : 2
rate : 192000
exact rate : 192000 (192000/1)
msbits : 24
buffer_size : 96256
period_size : 1024
period_time : 5333
tstamp_mode : NONE
tstamp_type : MONOTONIC
period_step : 1
avail_min : 1024
period_event : 0
start_threshold : 96256
stop_threshold : 96256
silence_threshold: 0
silence_size : 0
boundary : 1577058304
Slave: Hardware PCM card 0 'ad1938' device 0 subdevice 0
Its setup is:
stream : PLAYBACK
access : MMAP_INTERLEAVED
format : S24_LE
subformat : STD
channels : 2
rate : 192000
exact rate : 192000 (192000/1)
msbits : 32
buffer_size : 96256
period_size : 1024
period_time : 5333
tstamp_mode : NONE
tstamp_type : MONOTONIC
period_step : 1
avail_min : 1024
period_event : 0
start_threshold : 96256
stop_threshold : 96256
silence_threshold: 0
silence_size : 0
boundary : 1577058304
appl_ptr : 0
hw_ptr : 0
root@OpenWrt:~# cat /sys/kernel/debug/10000a00.i2s/stats
tx stats
below threshold 2276321
under run 94
over run 0
dma fault 0Mb I need to change something in my hardware i2s driver?
-
RE: [Resolved] Attaching PCM5102 to Omega2 (I2S)
Anyway, someone successed with plaing something with aplay on i2s(Lede 17.01 branch)?
-
RE: Kernel panic with pulseaudio
@Lazar-Demin Hello, i'm trying to solve this problem too, can you explain more specifically where the root of the problem is and what modules it affects?
I debugged and find in arch/mips/mm/dma-default.c struct dma_map_ops what consist NULL, do u fix it? -
RE: SPI add devices/GPIO CS/shared MISO MOSI
@Rogier-Lodewijks no, u don't need patch spidev, only spi-mt7621.c source file and it's in kernel yea. After this u can add cs-gpios in device tree, and spi device in node. Spi device can be spidev if u developing spi driver and u need its API. Thank you)
-
RE: SPI add devices/GPIO CS/shared MISO MOSI
Okay, I solved this, now i have workin SPI with cs lines on gpio.
This final spi driver spi-mt7621In Device tree(Omega2.dtsi) in node spi u need to add cs-gpios like this:
&spi0 { status = "okay"; pinctrl-names = "default"; pinctrl-0 = <&spi_pins>, <&spi_cs1_pins>; cs-gpios = <0>, <0>, <&gpio0 17 1>; m25p80@0 { #address-cells = <1>; #size-cells = <1>; compatible = "jedec,spi-nor";
and u need to add spi-device node like this :
spidev@1 { #address-cells = <1>; #size-cells = <1>; compatible = "linux,spidev"; spi-max-frequency = <3125000>; reg = <1>; }; ad193x: ad193x@2 { #address-cells = <1>; #size-cells = <1>; compatible = "adi,ad193x"; spi-max-frequency = <3125000>; reg = <2>; #sound-dai-cells = <0>; };
It must be work fine.
-
RE: SPI add devices/GPIO CS/shared MISO MOSI
Ok, i understand why it was 49, i was using wrong gpio bank, but anyway now it's look like that
root@Omega-6D86:/# cat /sys/kernel/debug/gpio GPIOs 0-31, platform/10000600.gpio, 10000600.gpio: gpio-17 ( |spi-mt7621 ) out hi GPIOs 32-63, platform/10000600.gpio, 10000600.gpio: gpio-38 ( |reset ) in lo GPIOs 64-95, platform/10000600.gpio, 10000600.gpio:
gpio 17 really registred like cs, but when i'm tryin to make a transaction:
root@Omega-6D86:~# python writebytes2.py Traceback (most recent call last): File "writebytes2.py", line 16, in <module> time.sleep(0.0004) IOError: [Errno 16] Resource busy
and what i have, when tryin to export this pin:
root@Omega-6D86:/sys/class/gpio# echo 17 > export -ash: write error: Resource busy
Any ideas?
-
SPI add devices/GPIO CS/shared MISO MOSI
Hello, I'm trying to add some devices on spi. Here i found the way to do it.
This my spi section in device tree:pinctrl-names = "default"; pinctrl-0 = <&spi_pins>, <&spi_cs1_pins>; cs-gpios = <0>, <0>, <&gpio1 17 0>; m25p80@0 { #address-cells = <1>; #size-cells = <1>; compatible = "jedec,spi-nor"; reg = <0>; spi-max-frequency = <40000000>; m25p,chunked-io = <31>; partition@0 { label = "u-boot"; reg = <0x0 0x30000>; read-only; }; partition@30000 { label = "u-boot-env"; reg = <0x30000 0x10000>; read-only; }; factory: partition@40000 { label = "factory"; reg = <0x40000 0x10000>; read-only; }; firmware: partition@50000 { label = "firmware"; }; }; spidev@1 { compatible = "linux,spidev"; reg = <1>; spi-max-frequency = <40000000>; }; spidev@2 { compatible = "linux,spidev"; reg = <2>; spi-max-frequency = <40000000>; };
current driver : https://github.com/wdu/mt7688
my code, using python :
import onionSpi, onionGpio, time busNumber = 2 deviceId = 32766 rst = onionGpio.OnionGpio(15) rst.setOutputDirection(0) codec = onionSpi.OnionSpi(busNumber, deviceId) codec.sck = 7 codec.mosi = 8 codec.miso = 9 codec.cs = 17 codec.mode = 3 codec.speed = 3125000 # check the device if codec.checkDevice() is 0: mapped = "the device adapter is already mapped." else: mapped = "the device adapter is NOT mapped." print("Registered: {}".format(mapped)) # register the device if codec.registerDevice() is 0: success = "Device with the specified bus number and device ID is already registered OR successfully registered SPI device adapter." else: success = "Unable to register device." print("Registering.. : {}".format(success)) # initialize the device parameters if codec.setupDevice() is 0: success = "Setup successful." else: success = "Setup failed." print("Setting up spi device: {}".format(success)) # check the device again if codec.checkDevice() is 0: mapped = "the device adapter is already mapped." else: mapped = "the device adapter is NOT mapped." print("Registered: {}".format(mapped)) rst.setOutputDirection(1) time.sleep(0.0001) rst.setOutputDirection(0) ret = codec.writeBytes(0x04, [0x1A]) print(ret)
it's returned:
Registered: the device adapter is already mapped.
SPI device already available
Registering.. : Device with the specified bus number and device ID is already registered OR successfully registered SPI device adapter.
Initializing SPI parameters...
Set SPI mode: 0x500
Set bits per word: 0
Set max speed: 3125000 Hz (3125 KHz)
ERROR: Cannot set SPI mode 0x500
Setting up spi device: Setup failed.
Registered: the device adapter is already mapped.
ERROR: SPI transfer failed
Traceback (most recent call last):
File "/root/kek.py", line 56, in <module>
ret = codec.writeBytes(0x04, [0x1A])
IOError: SPI transaction failed.spidev is returned :
[ 2084.178830] spidev spi32766.2: setup: ignoring unsupported mode bits 500 [ 2084.185747] spidev spi32766.2: failed to request gpio cs 49
WHY GPIO 49??
GPIO 17 always HIGH. Any Ideas?