Lib XUA - AN246 Behavioural Queries

Technical questions regarding the XTC tools and programming with XMOS.
Jcvc
Member
Posts: 13
Joined: Wed May 07, 2025 11:13 pm

Lib XUA - AN246 Behavioural Queries

Post by Jcvc »

Hi,

As I'm going through the various example applications on the different libraries and applications, I've now bumped into example application AN246 which can be found on <dir>\lib_xua\examples\AN00246_xua_example and whilst playing with it, I've found some strange behaviours and would please appreciate some guidance on the observed behaviour and what may I be doing incorrectly.

Below are the different observations to which I would very much appreciate some input please :)
1- If I run the application without making any modification, I can see the enumeration on the device manager just fine and the device shows up as a sound card. However, on the TUSBAudio control panel (I have the Thesycon usb driver installed) it does not detect any device. Note that I can get the I2S clocks out, so it currently works even without being being detected on the TUSBaudio control panel.
Is there any specific define that I should be enabling in order for the image that is being built to include any specific usb enumeration that is specific to Thesycon?

2- I modify the configuration of the code slightly so that the device also enumerates as a microphone (along with the speaker). The code modifications are as below: (nothing else was modified)

Code: Select all

#define NUM_USB_CHAN_OUT      2     /* Number of channels from host to device */
#define NUM_USB_CHAN_IN       2     /* Number of channels from device to host */
#define I2S_CHANS_DAC         2     /* Number of I2S channels out of xCORE */
#define I2S_CHANS_ADC         2     /* Number of I2S channels in to xCORE */
Now this is where I get even further lost (please do bear in mind that I'm a beginner). Once I flash the device, the device seems to fall through when making a call to ConfigAudioPortsWrapper() within XUA_AudioHub() which was found through using several printfs. The line 882 corresponds to the printf that happens right before the call to ConfigAudioPortsWrapper().

I've added a bunch of prints and through the xscope I'm reading the following:

Code: Select all

C:\xmos\lib_xua\examples\AN00246_xua_example>xrun --xscope C:\xmos\lib_xua\examples\AN00246_xua_example\bin\app_xua_simple.xe
AudioHwInit
mClk:-1, curSamFreq:48000
mClk:24576000, curSamFreq:48000, numBits:64
Divide:8
divide > 0
!remainder
!divider_is_odd
ConfigAudioPortsWrapper
p_i2s_dac:539896, I2S_WIRES_DAC:1, p_i2s_adc:0, I2S_WIRES_ADC:1
p_lrclk:65536, p_bclk:65792, p_mclk_in:66304, clk_audio_bclk:1030, divide:8, curSamFreq:48000
xrun: Program received signal ET_ECALL, Application exception.
      0x0008093c in XUA_AudioHub (clk_audio_mclk=<optimized out>, clk_audio_bclk=1030, p_mclk_in=66304, c_aud=<optimized out>, p_lrclk=<optimized out>, p_bclk=<optimized out>, p_i2s_dac=..., p_i2s_adc=...) at C:/xmos/lib_xua/lib_xua/src/core/audiohub/xua_audiohub.xc:882
Backtrace below:

Code: Select all

(gdb) backtrace
#0  0x000800c4 in _DoException ()
#1  0x0008093c in XUA_AudioHub (clk_audio_mclk=<optimized out>, clk_audio_bclk=1030, p_mclk_in=66304, c_aud=<optimized out>,
    p_lrclk=<optimized out>, p_bclk=<optimized out>, p_i2s_dac=..., p_i2s_adc=...)
    at C:/xmos/lib_xua/lib_xua/src/core/audiohub/xua_audiohub.xc:882
#2  0x0008034c in __main__main_tile_1 (formal.c_aud9=65792, formal.i2c10=<optimized out>) at <synthesized>:118
#3  0x0008168c in main ()
I've also added a few printfs straight upon the call to ConfigAudioPortsWrapper(), but doesn't even get to print them (I'm not sure if some parallel task is conflicting with it?).
When I run stereo usb IN/OUT (along with the respective I2S channels) on the usb audio reference application, I don't have this problem and it enumerates just fine and I can get the clocks and audio out. I've compared the code between the two on the main of the lib_xua and it's mainly doing the same (just avoiding all the defines from SPDIF, adat & etc).

Any idea why it would be different here? Any suggestion on what I could/should be looking in to?

Thank you!
User avatar
upav
Verified
Member++
Posts: 29
Joined: Wed May 22, 2024 3:30 pm

Post by upav »

I'm not an xua expert myself but something to keep in mind here:

I wouldn't add a lot of printfs to an xua source code as printfs take a lot of cycles
xua being very time-critical is likely to start missing timings and misbehaving (so might start seeing different issues when you add printfs)
If you need to have prints, I would recommend not using a lot of them and using printint/printhex/printstr from print.h as they are more light-weight

ET_ECALL exception means that the assert has happened
Briefly looking at the code, I found 3 assert statements just before the ConfigAudioPortsWrapper call, https://github.com/xmos/lib_xua/blob/de ... ub.xc#L846
if one of those statements is false you'll get a runtime exception (ET_ECALL in this case)

Hope it helps :)
Pavel
xmos software engineer
Jcvc
Member
Posts: 13
Joined: Wed May 07, 2025 11:13 pm

Post by Jcvc »

Hi Pavel,

Appreciated for the information regarding the lighter-weight printfs' alternative, I'll have to start getting used to them as I improve on the platform :)

Regarding the asserts, I've added printfs specifically after each assert to ensure that they were passing fine, which translates into the 3 different printfs:

Code: Select all

divide > 0
!remainder
!divider_is_odd
Since they're being printed out, it means that it passes all the 3 asserts. Then, the next printf on that same file that I had added was "ConfigAudioPortsWrapper" which happens right before the call to ConfigAudioPortsWrapper(), which means it gets here. However, that's where it then fails. I then have some printfs inside ConfigAudioPortsWrapper & ConfigAudioPorts, but none of them are printing out when I have USB_IN=2, whereas they print if I have USB_IN=0.