Hi, I am trying to get MIDI working on XK-AUDIO-316-MC-AB (the pair of DIN5 connectors on the board) with no success so far.
I don't really need USB MIDI (though the USB MIDI part of the reference sw_usb_audio didn't seem to work too), I want to be able to receive/send MIDI commands from my firmware via those pair of DIN5 connectors. So, I've found app_midi_simple.xc from lib_xua tests, adjusted its CMakeLists.txt to set target like set(APP_HW_TARGET xk-audio-316-mc.xn) and set ports to PORT_MIDI_OUT and PORT_MIDI_IN. Then I have adjusted the transmit function to just send one command midi_send_data(c_midi, byterev(tx_packet)). When I monitor what's being sent on the other side — I get some garbage, regardless of what I am trying to send.
What am I missing? How to properly send/receive MIDI data via the built-in DIN5 connectors? Are they supposed to work?
Thanks.
Problem with XK-AUDIO-316-MC-AB and its MIDI
-
hohoho
- Member
- Posts: 14
- Joined: Tue Jun 02, 2020 3:40 pm
-
infiniteimprobability
Verified - XCore Legend
- Posts: 1185
- Joined: Thu May 27, 2010 10:08 am
Hi,
the DIN connectors on the board do work and MIDI is both simulator tested in XUA and HW regression tested in sw_usb_audio on the XU316 MC board (and previous XU216 too).
If you just want MIDI (without USB) then app_midi_simple.xc is a great place to start. You could do MIDI with lib_uart instead but the USB audio (lib_xua) MIDI (aka UART) implementation is specialised for MIDI being fixed at 31,250 baud and also only using one thread (Tx and Rx optimised into single task) so is more efficient with resources.
What you are doing should work - would you be able to expand on what you mean by garbage? Could you possibly append a capture of what you see?
It is worth probing on the test points of J41 so you see the full 3v3 signal rather than on the MIDI side.
the DIN connectors on the board do work and MIDI is both simulator tested in XUA and HW regression tested in sw_usb_audio on the XU316 MC board (and previous XU216 too).
If you just want MIDI (without USB) then app_midi_simple.xc is a great place to start. You could do MIDI with lib_uart instead but the USB audio (lib_xua) MIDI (aka UART) implementation is specialised for MIDI being fixed at 31,250 baud and also only using one thread (Tx and Rx optimised into single task) so is more efficient with resources.
What you are doing should work - would you be able to expand on what you mean by garbage? Could you possibly append a capture of what you see?
It is worth probing on the test points of J41 so you see the full 3v3 signal rather than on the MIDI side.
Engineer at XMOS
-
hohoho
- Member
- Posts: 14
- Joined: Tue Jun 02, 2020 3:40 pm
My test program looks like this:
when I do
I get:
And it seems like on the receiving side I get things like, 00 00 F7, or FF, or 00 00 — a few times in different combinations. And that actually seems to be a part of the board initialization. Because after the input above, it doesn't seem to react on MIDI commands sent to it.
What am I missing?
Code: Select all
#include <xs1.h>
#include <platform.h>
#include <xclib.h>
#include "xk_audio_316_mc_ab/board.h"
#include "xua.h"
#include "xud_device.h"
#include "uac_hwresources.h"
#include "midiinparse.h"
#include "midioutparse.h"
static const xk_audio_316_mc_ab_config_t hw_config = {
CLK_FIXED, // clk_mode. Drive a fixed MCLK output
0, // 1 = dac_is_clock_master
MCLK_48,
0, // pll_sync_freq (unused when driving fixed clock)
AUD_316_PCM_FORMAT_I2S,
32, // data bits
2 // channels per frame
};
on tile[1] : port p_midi_tx = PORT_MIDI_OUT;
on tile[1] : buffered in port:1 p_midi_rx = PORT_MIDI_IN;
on tile[1] : clock clk_midi = CLKBLK_MIDI;
unsigned midi_in_parse_helper(unsigned midi[3], struct midi_in_parse_state &m_state){
unsigned valid = 0;
unsigned packed = 0;
for(int i = 0; i < 3; i++){
// printf("Packing byte %d 0x%x\n", i, midi[i]);
{valid, packed} = midi_in_parse(m_state, 0, midi[i]);
if(valid){
return packed;
}
}
return 0;
}
void test(chanend c_midi){
int is_ack;
unsigned rx_packet;
struct midi_in_parse_state m_state;
reset_midi_state(m_state);
while (1) {
select{
case midi_get_ack_or_data(c_midi, is_ack, rx_packet):
if (is_ack){
printf("ACK from Tx\n");
} else {
unsigned midi_data[3] = {0};
unsigned byte_count = 0;
{midi_data[0], midi_data[1], midi_data[2], byte_count} = midi_out_parse(byterev(rx_packet));
printf("Got packet from MIDI: 0x%8x\n", rx_packet);
printf("dut_midi_rx: %u %u %u\n", midi_data[0], midi_data[1], midi_data[2]);
midi_send_ack(c_midi);
unsigned midi[] = {144, 60, 81};
unsigned tx_packet = midi_in_parse_helper(midi, m_state);
midi_send_data(c_midi, byterev(tx_packet));
printf("Sent packet to midi: %u %u %u (0x%8x)\n", midi[0], midi[1], midi[2], tx_packet);
}
break;
}
}
}
int main(void)
{
chan c_midi;
par
{
on tile[1]: test(c_midi);
on tile[1]: usb_midi(p_midi_rx, p_midi_tx, clk_midi, c_midi, 0);
on tile[0]: {
xk_audio_316_mc_ab_board_setup(hw_config);
}
}
return 0;
}Code: Select all
xrun --io bin/app_miditest.xeCode: Select all
Got packet from MIDI: 0x fe0f
dut_midi_rx: 254 0 0
Sent packet to midi: 144 60 81 (0x 9903c51)
ACK from TxWhat am I missing?
-
hohoho
- Member
- Posts: 14
- Joined: Tue Jun 02, 2020 3:40 pm
Interesting, when I power the board on, I get full 3.3v. But when I start my app, it drops to nearly zero. And it briefly goes back to 3.3v and back to 0.01 every time I restart the app (and that is when I get those garbage packets).infiniteimprobability wrote: Wed Nov 12, 2025 10:51 am It is worth probing on the test points of J41 so you see the full 3v3 signal rather than on the MIDI side.
I am measuring between (3v3 and GND pins).
