I'm getting started with the XK-EVK-XU316 and I'm already stuck on the simplest task :-D
I started from the unmodified app_usb_aud_xk_evk_xu316, which I compiled, ran, and tested. Everything works fine!
XTC version is 15.2.1, sw_usb_audio version is 8.0.0,
What I need to do is setting some GPIO pins based on some input stream properties (PCM or DSD input and sampling rate).
For example, I'd like to turn on LED 2 when the sampling frequency is a multiple of 44.1kHz, and turn it off when it's a multiple of 48kHz.
After looking at how LEDs are turned on/off for the XK-316-MC board, and finding the correct LED port in the XK-EVK-XU316 xcore.ai Evaluation Kit Manual (it's port 4C), I did the following modifications to "src/extensions/audiohw.xc".
At the top, I added the port definition:
Code: Select all
on tile[0]: out port p_leds = XS1_PORT_4C;
Then, I added these the lines "p_leds <: 0x2;" and "p_leds <: 0x0;" inside "void AudioHwConfig" to turn on/off LED 2, respectively:
Code: Select all
void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode,
unsigned sampRes_DAC, unsigned sampRes_ADC)
{
assert(samFreq >= 22050);
// Set the AppPLL up to output MCLK.
if ((samFreq % 22050) == 0)
{
// Disable the PLL
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, (APP_PLL_CTL_441 & 0xF7FFFFFF));
// Enable the PLL to invoke a reset on the appPLL.
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, APP_PLL_CTL_441);
// Must write the CTL register twice so that the F and R divider values are captured using a running clock.
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, APP_PLL_CTL_441);
// Now disable and re-enable the PLL so we get the full 5us reset time with the correct F and R values.
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, (APP_PLL_CTL_441 & 0xF7FFFFFF));
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, APP_PLL_CTL_441);
// Set the fractional divider if used
write_node_config_reg(tile[0], XS1_SSWITCH_SS_APP_PLL_FRAC_N_DIVIDER_NUM, APP_PLL_FRAC_44);
// Turn on LED 2 (samFreq multiple of 44100)
p_leds <: 0x2;
}
else if ((samFreq % 24000) == 0)
{
// Disable the PLL
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, (APP_PLL_CTL_48 & 0xF7FFFFFF));
// Enable the PLL to invoke a reset on the appPLL.
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, APP_PLL_CTL_48);
// Must write the CTL register twice so that the F and R divider values are captured using a running clock.
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, APP_PLL_CTL_48);
// Now disable and re-enable the PLL so we get the full 5us reset time with the correct F and R values.
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, (APP_PLL_CTL_48 & 0xF7FFFFFF));
write_node_config_reg(tile[1], XS1_SSWITCH_SS_APP_PLL_CTL_NUM, APP_PLL_CTL_48);
// Set the fractional divider if used
write_node_config_reg(tile[0], XS1_SSWITCH_SS_APP_PLL_FRAC_N_DIVIDER_NUM, APP_PLL_FRAC_48);
// Turn off LED 2 (samFreq multiple of 48000)
p_leds <: 0x0;
}
// Wait for PLL output frequency to stabilise due to fractional divider enable
delay_microseconds(100);
// Turn on the clock output
write_node_config_reg(tile[0], XS1_SSWITCH_SS_APP_CLK_DIVIDER_NUM, APP_PLL_DIV);
}
The code compiles without errors, but when I launch the executable with xrun, my computer isn't able to use the board as an audio device anymore.
These are the related kernel logs from my Linux machine:
Code: Select all
apr 23 12:33:56 michele-xps9700 kernel: usb 1-2.4: new full-speed USB device number 43 using xhci_hcd
apr 23 12:33:57 michele-xps9700 kernel: usb 1-2.4: new full-speed USB device number 44 using xhci_hcd
apr 23 12:33:57 michele-xps9700 kernel: usb 1-2.4: New USB device found, idVendor=20b1, idProduct=0019, bcdDevice= 7.31
apr 23 12:33:57 michele-xps9700 kernel: usb 1-2.4: New USB device strings: Mfr=1, Product=3, SerialNumber=2
apr 23 12:33:57 michele-xps9700 kernel: usb 1-2.4: Product: XMOS xCORE (UAC1.0)
apr 23 12:33:57 michele-xps9700 kernel: usb 1-2.4: Manufacturer: XMOS
apr 23 12:33:59 michele-xps9700 pipewire[1080]: spa.alsa: hw:sofsoundwire,2p: (375 suppressed) snd_pcm_avail after recover: Broken pipe
apr 23 12:34:02 michele-xps9700 pipewire[1080]: spa.alsa: hw:sofsoundwire,2p: (375 suppressed) snd_pcm_avail after recover: Broken pipe
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 1:1: cannot set freq 48000 to ep 0x1
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 2:1: cannot set freq 48000 to ep 0x82
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: failed to get current value for ch 1 (-22)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: failed to get current value for ch 2 (-22)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: cannot get min/max values for control 2 (id 10)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 11:0: failed to get current value for ch 1 (-22)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 11:0: failed to get current value for ch 2 (-22)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 11:0: cannot get min/max values for control 2 (id 11)
apr 23 12:34:02 michele-xps9700 mtp-probe[18275]: checking bus 1, device 44: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4"
apr 23 12:34:02 michele-xps9700 mtp-probe[18275]: bus: 1, device: 44 was not an MTP device
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: cannot get min/max values for control 2 (id 10)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: cannot get min/max values for control 2 (id 10)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: cannot get min/max values for control 2 (id 10)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: cannot get min/max values for control 2 (id 10)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: cannot get min/max values for control 2 (id 10)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: cannot get min/max values for control 2 (id 10)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: cannot get min/max values for control 2 (id 10)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: cannot get min/max values for control 2 (id 10)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: cannot get min/max values for control 2 (id 10)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: cannot get min/max values for control 2 (id 10)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 10:0: cannot get min/max values for control 2 (id 10)
apr 23 12:34:02 michele-xps9700 mtp-probe[18297]: checking bus 1, device 44: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4"
apr 23 12:34:02 michele-xps9700 mtp-probe[18297]: bus: 1, device: 44 was not an MTP device
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 2:1: usb_set_interface failed (-32)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 2:1: usb_set_interface failed (-32)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 2:1: usb_set_interface failed (-32)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 2:1: usb_set_interface failed (-32)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 2:1: usb_set_interface failed (-32)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 2:1: usb_set_interface failed (-32)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 2:1: usb_set_interface failed (-32)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 2:1: usb_set_interface failed (-32)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 2:1: usb_set_interface failed (-32)
apr 23 12:34:02 michele-xps9700 kernel: usb 1-2.4: 2:1: usb_set_interface failed (-32)
EDIT: I'm also attaching the output of xgdb below.
Code: Select all
Program received signal ET_ILLEGAL_RESOURCE, Resource exception.
[Switching to tile[1] core[0]]
AudioHwConfig (samFreq=<value optimized out>, mClk=<value optimized out>, dsdMode=<value optimized out>, sampRes_DAC=<value optimized out>, sampRes_ADC=24)
at ../src/extensions/audiohw.xc:316
316 p_leds <: 0x2;
Many thanks in advance for your help.
Michele