Porting the AN00231 SPDIF Receive to I2S output app onto XK-AUDIO-316-MC-AB development kit

Discussions relating to the XK-EVK-XU316
vladimir593
Member++
Posts: 20
Joined: Tue Dec 12, 2023 11:33 pm

Porting the AN00231 SPDIF Receive to I2S output app onto XK-AUDIO-316-MC-AB development kit

Post by vladimir593 »

Hi everyone,

I am trying to perform SPDIF to I2S conversion with the XK-AUDIO-316-MC-AB development kit.
I found Application Note AN00231 SPDIF Receive to I2S output using Asynchronous Sample Rate Conversion
and tried to compile it for the XU316 dev kit. I am building on Windows 10 with XTC Tools 15.2.

So the first thing that I did was I copied the source code from application notes and made files
with appropriate names as described. Because the app was originally developed for the xCORE-200 Multichannel Audio Platform,
I changed the audio port locations in the main.xc file as described in the xk-audio-316-mc.xn file for the XK-AUDIO-316-MC-AB board.
The second change in main.xc file is a different function name in line 137

case spdif_receive_sample(c_spdif_rx, sample, index):
to
case spdif_rx_sample(c_spdif_rx, sample, index):

because of the new version of spdif_lib (maybe the name was changed with the new release of the spdif library)

Then I added all Build and Used modules to the Makefile as described in the app notes.
I added the xk-audio-316-mc.xn file and set it as TARGET in the Makefile.
All files are located inside one folder without any subfolders.
I am building the app executing the xmake command inside this folder.

While compiling I got the following error
But got the following error:

Compiling main.xc
xcc1: internal compiler error
Failed in ..\FrontEnd\Lowering\lower_combined_pars.cpp, line 183
info->stateObj
For bug reporting instructions, please see:
https://www.xmos.ai/support
xmake[1]: *** [.build_/main.xc.o] Error 1
xmake: *** [bin//AN00231 ASRC SPDIF.xe] Error 2

What could possibly go wrong? Has anyone any ideas?
I attached .zip with my files.

Best regards,
Vladimir
AN00231 ASRC SPDIF.zip
main.xc
Makefile-copy.txt
You do not have the required permissions to view the files attached to this post.
vladimir593
Member++
Posts: 20
Joined: Tue Dec 12, 2023 11:33 pm

Post by vladimir593 »

Update:

Setting XU316-1024-TQ128-C24 as target in the Makefile produces the same issue
User avatar
infiniteimprobability
Verified
XCore Legend
Posts: 1133
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

I have had a quick look and I get the same error. The XC compiler is unhappy about the main par statement. There are issues with portmap for your port to xcore.ai but that is not the cause of what you are seeing. I have isolated it down to the line:

on tile[AUDIO_TILE]: unsafe{ par (int i=0; i<ASRC_N_INSTANCES; i++) asrc(i_serial2block, i_block2serial, i_fs_ratio);}

This is the task declaration for the actual ASRC task and, without this, it doesn't trigger the (unhelpful) compiler error you have seen. I tried:

on tile[AUDIO_TILE]: unsafe {asrc(i_serial2block[0], i_block2serial[0], i_fs_ratio[0]);}
on tile[AUDIO_TILE]: unsafe {asrc(i_serial2block[1], i_block2serial[1], i_fs_ratio[1]);}

which is logically the same thing for ASRC_N_INSTANCES=2 but it triggers the same compiler failure. I'll have another go and see if I can make it play nicely. We have done a LOT of work on lib_src lately (https://github.com/xmos/lib_src/releases) and are working on a new version of this app note which is optimised for xcore.ai and provides much better audio performance. I'll check the status of that.
Engineer at XMOS
vladimir593
Member++
Posts: 20
Joined: Tue Dec 12, 2023 11:33 pm

Post by vladimir593 »

Hi infiniteimprobability,

Many thanks for your answer, I gonna try your solution.
I fixed my port mappings and changed the Makefile to:

TARGET = xk-audio-316-mc
APP_NAME =
USED_MODULES = lib_gpio(>=1.0.0) lib_i2c(>=3.1.0) lib_i2s(>=2.1.0) lib_logging(>=2.0.0) lib_spdif(>=2.0.2) lib_src(>=1.0.0)
XCC_FLAGS = -O2 -g -report -DDEBUG_PRINT_ENABLE=1
XCORE_ARM_PROJECT = 0
VERBOSE = 0
ENABLE_STAGED_BUILD=0
XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common

With these changes, I can build it without issues.
The new app note for xmos.ai would be very helpful,
This is cool I appreciate it.

I will post .zip again after some testing.
Best regards,
Vladimir
User avatar
infiniteimprobability
Verified
XCore Legend
Posts: 1133
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

OK, I took the code from https://github.com/xmos/lib_src/tree/v2 ... DIF_TO_DAC (note AN00231 was removed from version 2.3.0 onwards as it soon to be superseded) and made a few minor changes:

Code: Select all

$ git diff
diff --git a/examples/AN00231_ASRC_SPDIF_TO_DAC/Makefile b/examples/AN00231_ASRC_SPDIF_TO_DAC/Makefile
index f574b39..fc9ff64 100644
--- a/examples/AN00231_ASRC_SPDIF_TO_DAC/Makefile
+++ b/examples/AN00231_ASRC_SPDIF_TO_DAC/Makefile
@@ -1,7 +1,7 @@
 # The TARGET variable determines what target system the application is
 # compiled for. It either refers to an XN file in the source directories
 # or a valid argument for the --target option when compiling
-TARGET = xk-audio-216-mc
+TARGET = xk-audio-316-mc.xn
 
 # The APP_NAME variable determines the name of the final .xe file. It should
 # not include the .xe postfix. If left blank the name will default to
@@ -9,7 +9,7 @@ TARGET = xk-audio-216-mc
 APP_NAME = 
 
 # The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_gpio(>=1.1.0) lib_i2c(>=4.0.0) lib_i2s(>=2.3.0) lib_logging(>=2.1.0) lib_spdif(>=2.0.2) lib_src(>=1.1.0)
+USED_MODULES = lib_gpio(>=1.1.0) lib_i2c(>=4.0.0) lib_i2s(>=2.3.0) lib_logging lib_spdif(>=2.0.2) lib_src
 
 # The flags passed to xcc when building the application
 # You can also set the following to override flags for a particular language:
diff --git a/lib_src/module_build_info b/lib_src/module_build_info
index 073ffa1..f960843 100644
--- a/lib_src/module_build_info
+++ b/lib_src/module_build_info
@@ -1,7 +1,7 @@
 VERSION = 2.2.0
 
-DEPENDENT_MODULES = lib_logging(>=3.0.0) \
-                    lib_xassert(>=4.0.0)
+DEPENDENT_MODULES = lib_logging \
+                    lib_xassert
 
 MODULE_XCC_FLAGS = $(XCC_FLAGS) \
                    -Wno-missing-braces \
Obviously I put xk-audio-316-mc.xn in the /src dir. The good news it compiles successfully without any internal errors targeting xk-audio-316-mc.xn (although I didn't check all of the various port mappings or change the HW setup). So I think it should be able work with the rest of the porting effort. It looks like you copied the source text from the PDF which might have introduces a few weird control characters during that process? That may possibly be upsetting the compiler. Either way it wasn't a very helpful error - sorry about that..
Engineer at XMOS
vladimir593
Member++
Posts: 20
Joined: Tue Dec 12, 2023 11:33 pm

Post by vladimir593 »

Yes, I copied a code from a PDF and then added all tabs and spaces and deleted these weird arrow characters.
It was a little bit of work, but it compiles now :)
vladimir593
Member++
Posts: 20
Joined: Tue Dec 12, 2023 11:33 pm

Post by vladimir593 »

Hi everyone!
I modified the AN00231 app to compile and run on the XC-AUDIO-316-MC-AB dev kit.
But when I am executing xrun --xscope AN00231_ASRC_SPDIF_TO_DAC.xe command,
I am getting a strange output and then the program stops with "ASRC_proc Error code 11"

Has anyone had any experience with this issue?

Changes:
main.xc:
1. I disabled led_matrix interface
2. I changed i2c interface from a single port to 2 1-bit ports
3. I defined all ports as per xc-audio-316.xn

cs4384_5368.xc
1. master clock source is now the onboard Si5351A device
2. added a few functions for it

MCLK frequencies (checked with oscilloscope): 24.576Mhz and 22.5792Mhz
I build with XTC Tools 15.2 and windows 10

xmake output:

Creating AN00231_ASRC_SPDIF_TO_DAC.xe
Constraint check for tile[0]:
Cores available: 8, used: 3 . OKAY
Timers available: 10, used: 3 . OKAY
Chanends available: 32, used: 4 . OKAY
Memory available: 524288, used: 9664 . OKAY
(Stack: 1444, Code: 7230, Data: 990)
Constraints checks PASSED.
Constraint check for tile[1]:
Cores available: 8, used: 5 . OKAY
Timers available: 10, used: 5 . OKAY
Chanends available: 32, used: 15+. MAYBE
Memory available: 524288, used: 59476 . OKAY
(Stack: 12172, Code: 23126, Data: 24178)
Constraints checks PASSED WITH CAVEATS.
Build Complete

xrun --xscope output:

Starting I2S
SR change in lib_audio_codec - 96000
Initializing I2S to 96000Hz and MCLK to 24576000Hz
New rate in SRC in=0, out=3
...
spdif rate ave=0, valid=0, i2s rate=95969, valid=1, i2s_buff=17, fs_ratio=0x759BD67, nom_fs=0x7599999
New rate in SRC in=0, out=3
New rate in SRC in=57005, out=3
ASRC_proc Error code 11
AN00231_ASRC_SPDIF_TO_DAC.zip
Best regards,
Vladimir
You do not have the required permissions to view the files attached to this post.
vladimir593
Member++
Posts: 20
Joined: Tue Dec 12, 2023 11:33 pm

Post by vladimir593 »

Hi everyone!

I have a nice update!
AN00231 SPDIF to I2S app now works on the XK-AUDIO-316-MC-AB board!
It includes the following changes in the source code:

The master clock source is an onboard Si5351A device
New Port Map
No LEDs
some board setup with gpio
minor changes to rate_server function

Tested with
XK-AUDIO-316-MC-AB (coax in)
Android-based HiFi player (coax out)
USB - SPDIF converter (coax out)

works with 16/44.1 16/48 24/44.1 24/48 24/96 coax input

I am going to add TOSLINK support and 24/192 input (got some bugs with 192)

Best regards,
Vladimir
spdif_i2s_xu316mcab.xe
spdif_i2s_xu316_mc_ab.zip
You do not have the required permissions to view the files attached to this post.
User avatar
infiniteimprobability
Verified
XCore Legend
Posts: 1133
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

Hi Vladimir,
that is great news - well done for the successful port!
Engineer at XMOS