I2C for Multiple Clients Modification - XCORE 200 MC

Technical discussions related to any XMOS development kit or reference design. Eg XK-1A, sliceKIT, etc.
wizard1238
New User
Posts: 3
Joined: Wed Feb 01, 2017 2:51 pm

Post by wizard1238 »

For the default setting, I found i2c_share is used in the usb audio firmware, why is it needed? as the compiler will complain and avoid multi use of i2c in different thread, swlock seems useless, it will also hunt performance unnecessary.


RitchRock
XCore Addict
Posts: 186
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

wizard1238 wrote:For the default setting, I found i2c_share is used in the usb audio firmware, why is it needed? as the compiler will complain and avoid multi use of i2c in different thread, swlock seems useless, it will also hunt performance unnecessary.
I had this question also. Performance really doesn't seem to be affected at all now that I've moved to lib_i2c.
avrobot
Member++
Posts: 17
Joined: Mon Jun 04, 2018 4:26 am

Post by avrobot »

I'm having compile errors when trying to add lib_i2c to "app_usb_aud_xk_216_mc".
Sadly Xmos support are not assisting so hoping someone has some suggestion... here is the process I am following...

1>Import the mc ref design from the zip file and then I clean/compile with default moudles_i2c_xx included to make sure the ref design builds correctly with no errors.

2> next I delete the 3x module_i2c_xx folders from the xtimecomposer project and from file system, comment out any calls to i2c functions and comment out any existing i2c #includes then clean/recompile to make sure no errors.

3> next I add lib_i2c by adding from "libraries" tab in xtimecomposer ( also tried to add from lib_i2c direct from archive zip file - same result). Also update lib_logging and lib_xassert ( lib_i2c requires these to be updated).

4> make sure lib_i2c AND module_locks are added to Make file and remove the two unused module_i2c_xx entries from makefile.

5> manually add lib_i2c folders to "paths and symbols" to ensure I can resolve #include "i2c.h" in main .xc file.

6> clean/compile and always get the errors below: (Note: no code using lib_i2c is added to my project at this stage - yet and the errors occur)

D:/xxx/lib_i2c/src/i2c_master_single_port.xc:21:45: error: parse error before numeric constant
unsigned SCL_HIGH,
^
<command line>:4:18: note: expanded from here
#define SCL_HIGH 1
^
D:/xxx/lib_i2c/src/i2c_master_single_port.xc:28:14: error: use of undeclared identifer `p_i2c'
val = peek(p_i2c);
^~~~~
*** Many More errors ***
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Hi. Can you post your full project so it can be imported for testing?

Also you can review an appnote with i2c:

https://www.xmos.com/support/appnotes/AN00181

Does that build for you ok?
avrobot
Member++
Posts: 17
Joined: Mon Jun 04, 2018 4:26 am

Post by avrobot »

Thanks. Please find test project attached.
Errors appear in CDT console on Clean and build.
I have not tried AN00181 but have successfully tried AN00156 - so the issue seems to be something related to importing into the existing "app_usb_aud_xk_216_mc" project.
Attachments
TestProject_LIB_I2C_v1.rar
(1.95 MiB) Downloaded 405 times
TestProject_LIB_I2C_v1.rar
(1.95 MiB) Downloaded 405 times
RitchRock
XCore Addict
Posts: 186
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

Hi,

Please delete lib_i2c files "I2c_master_async.xc, I2c_slave.xc so that your project explorer now displays:
lib_i2c.JPG
lib_i2c.JPG (24.1 KiB) Viewed 7827 times
lib_i2c.JPG
lib_i2c.JPG (24.1 KiB) Viewed 7827 times
Next, in your Makefile add lib_xassert along with lib_i2c.

Doing this, I was able to build without errors.
avrobot
Member++
Posts: 17
Joined: Mon Jun 04, 2018 4:26 am

Post by avrobot »

Thanks for that however it still shows the same errors for me even after doing your suggested steps... on clean I check CDT Console for the errors that appear around half way into the console output log.
May I ask what version of xtimecomponser are you using and is it PC version? I wonder if you get the chance to share your successfully building project here so I can verify?
RitchRock
XCore Addict
Posts: 186
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

Strange. Replace the contents of the Makefile with this one. When I run it with the Makefile as-is in your project, I do get the compile errors. When I use this one, it builds. Maybe you can figure out the difference. Interested to know if this works for you.

Code: Select all

# 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.xn
APP_NAME = 

# The flags passed to xcc when building the application
BUILD_FLAGS     = -DFLASH_MAX_UPGRADE_SIZE=64*1024 -fcomment-asm -Xmapper --map -Xmapper MAPFILE -Wall -O3 -report -lquadflash -fsubword-select -save-temps -g -fxscope -DXSCOPE -DXUD_SERIES_SUPPORT=4 -march=xs2a -DUSB_TILE=tile[1] -DADAT_TX_USE_SHARED_BUFF=1 -DQUAD_SPI_FLASH=1

# The USED_MODULES variable lists other module used by the application. These
# modules will extend the SOURCE_DIRS, INCLUDE_DIRS and LIB_DIRS variables. 
# Modules are expected to be in the directory above the BASE_DIR directory.
USED_MODULES = lib_xassert lib_i2c(>=4.0.0) module_usb_shared module_xud module_usb_audio module_spdif_tx module_spdif_rx module_usb_midi module_dfu module_usb_device module_locks module_adat_tx module_adat_rx

# Build config naming scheme:

# Audio Class:  1 or 2
# Input 	enabled: i (channelcount)
# Output 	enabled: o (channelcount)
# MIDI 		enabled: m, disabled: x
# SPDIF out	enabled: s, disabled: x
# SPDIF in 	enabled: s, disabled: x
# ADAT out	enabled: a, disabled: x
# ADAT in	enabled: a, disabled: x
# DSD out	enabled: d, disabled: x
# e.g. 2i10o10xsxxx: Audio class 2.0, input and output enabled (10 channels each), SPDIF output, no SPDIF input, no ADAT

TEST_DFU_1 ?= 0
ifeq ($(TEST_DFU_1),1)
BUILD_FLAGS += -DBCD_DEVICE=0x9901
endif
TEST_DFU_2 ?= 0
ifeq ($(TEST_DFU_2),1)
BUILD_FLAGS += -DBCD_DEVICE=0x9902
endif

MFI ?= 0

ifeq ($(MFI), 0)

# Test build configs (Note these make use of the defaults in customdefines.h)

# Audio Class 2, Input (8), Output (8), No MIDI, No SPDIF i/o, No ADAT i/o, TDM mode
XCC_FLAGS_2i8o8xxxxx_tdm8  = $(BUILD_FLAGS) -DI2S_CHANS_DAC=8 -DI2S_CHANS_ADC=8 -DNUM_USB_CHAN_OUT=8 -DNUM_USB_CHAN_IN=8 \
								-DMIDI=0 -DSPDIF_TX=0 -DSPDIF_RX=0 -DADAT_TX=0 -DADAT_RX=0 -DDSD_CHANS_DAC=0 \
								-DI2S_MODE_TDM=1 -DMAX_FREQ=96000 
INCLUDE_ONLY_IN_2i8o8xxxxx_tdm8 =

# Audio Class 2, Input (8), Output (8), No MIDI, No SPDIF i/o, No ADAT i/o, TDM slave mode
XCC_FLAGS_2i8o8xxxxx_tdm8_slave  = $(BUILD_FLAGS) -DI2S_CHANS_DAC=8 -DI2S_CHANS_ADC=8 -DNUM_USB_CHAN_OUT=8 -DNUM_USB_CHAN_IN=8 \
								-DMIDI=0 -DSPDIF_TX=0 -DSPDIF_RX=0 -DADAT_TX=0 -DADAT_RX=0 -DDSD_CHANS_DAC=0 \
								-DI2S_MODE_TDM=1 -DMAX_FREQ=96000 -DMIXER=0 -DCODEC_MASTER=1
INCLUDE_ONLY_IN_2i8o8xxxxx_tdm8_slave =


# Audio Class 2, Input (0), Output (8), No MIDI, No SPDIF i/o, No ADAT i/o, TDM slave mode
XCC_FLAGS_2i0o8xxxxx_tdm8_slave  = $(BUILD_FLAGS) -DI2S_CHANS_DAC=8 -DI2S_CHANS_ADC=0 -DNUM_USB_CHAN_OUT=8 -DNUM_USB_CHAN_IN=0 \
								-DMIDI=0 -DSPDIF_TX=0 -DSPDIF_RX=0 -DADAT_TX=0 -DADAT_RX=0 -DDSD_CHANS_DAC=0 \
								-DI2S_MODE_TDM=1 -DMAX_FREQ=96000 -DMIXER=0 -DCODEC_MASTER=1
INCLUDE_ONLY_IN_2i0o8xxxxx_tdm8_slave =



# Audio Class 2, Input (16), Output (16), No MIDI, No SPDIF i/o, No ADAT i/o, No DSD, TDM mode
# Note: sample rate restricted to 96K to fit in USB bandwidth
XCC_FLAGS_2i16o16xxxxx_tdm8  = $(BUILD_FLAGS) -DI2S_CHANS_DAC=16 -DI2S_CHANS_ADC=16 -DNUM_USB_CHAN_OUT=16 -DNUM_USB_CHAN_IN=16 \
								-DMIDI=0 -DSPDIF_TX=0 -DSPDIF_RX=0 -DADAT_TX=0 -DADAT_RX=0 -DDSD_CHANS_DAC=0 \
								-DI2S_MODE_TDM=1 -DMAX_FREQ=96000
INCLUDE_ONLY_IN_2i16o16xxxxx_tdm8  =

# Audio Class 2, Input, Output, No MIDI, No SPDIF Tx, TDM (32in/32out)
XCC_FLAGS_2i32o32xxxxx_tdm8  = $(BUILD_FLAGS) -DSPDIF_TX=0 -DI2S_MODE_TDM=1 -DI2S_CHANS_ADC=32 -DMAX_FREQ=48000 -DI2S_CHANS_DAC=32 -DNUM_USB_CHAN_OUT=32 -DNUM_USB_CHAN_IN=32
INCLUDE_ONLY_IN_2i32o32xxxxx_tdm8 =

# Audio Class 2, Input, Output, No MIDI, SPDIF, TDM (32in/32out)
XCC_FLAGS_2i32o32xsxxx_tdm8 = $(BUILD_FLAGS) -DSPDIF_TX=1 -DI2S_MODE_TDM=1 -DI2S_CHANS_ADC=32 -DMAX_FREQ=48000 -DI2S_CHANS_DAC=32 -DNUM_USB_CHAN_OUT=32 -DNUM_USB_CHAN_IN=32
INCLUDE_ONLY_IN_2i32o32xsxxx_tdm8  =

# Audio Class 2, Input, Output, MIDI, SPDIF
XCC_FLAGS_2i10o10msxxxx = $(BUILD_FLAGS) -DMIDI=1 -DSPDIF_TX=1
INCLUDE_ONLY_IN_2i10o10msxxxx = 

# Audio Class 2, Input, Output, MIDI, SPDIF, DSD
XCC_FLAGS_2i10o10xxxxxd = $(BUILD_FLAGS) -DMIDI=0 -DSPDIF_TX=0 -DDSD_CHANS_DAC=2
INCLUDE_ONLY_IN_2i10o10xxxxxd = 

# Audio Class 2, Input, Output, no MIDI, no SPDIF
XCC_FLAGS_2i10o10xxxxxx = $(BUILD_FLAGS) -DMIDI=0 -DSPDIF_TX=0
INCLUDE_ONLY_IN_2i10o10xxxxxx = 

# Audio Class 2, Input, Output, no MIDI, no SPDIF
XCC_FLAGS_2i10o10xxxxxx_slave = $(BUILD_FLAGS) -DMIDI=0 -DSPDIF_TX=0 -DCODEC_MASTER=1
INCLUDE_ONLY_IN_2i10o10xxxxxx_slave = 

# Audio Class 2, Input, Output, no MIDI, SPDIF
XCC_FLAGS_2i10o10xsxxxx = $(BUILD_FLAGS) -DMIDI=0 -DSPDIF_TX=1
INCLUDE_ONLY_IN_2i10o10xsxxxx = 

# Audio Class 2, Input, Output, no MIDI, SPDIF
XCC_FLAGS_2i10o10xsxxxx_mix8 = $(BUILD_FLAGS) -DMIDI=0 -DSPDIF_TX=1 -DMAX_MIX_COUNT=8
INCLUDE_ONLY_IN_2i10o10xsxxxx_mix8 = 

# Audio Class 2, Input, Output, No Midi, SPDIF, DSD
XCC_FLAGS_2i10o10xsxxxd = $(BUILD_FLAGS) -DSPDIF_TX=1 -DDSD_CHANS_DAC=2
INCLUDE_ONLY_IN_2i10o10xsxxxd = 

# Audio Class 2, 10 Input, 16 Output, no MIDI, no SPDIF tx, no SPDIF Rx, ADAT tx, no ADAT rx, no DSD
XCC_FLAGS_2i10o16xxxaxx = $(BUILD_FLAGS) -DSPDIF_TX=0 -DMIDI=0 -DADAT_TX=1 -DMAX_FREQ=96000 -DNUM_USB_CHAN_OUT=16
INCLUDE_ONLY_IN_2i10o16xxxaxx = 

# Audio Class 2, 16 Input, 10 Output, no MIDI, no SPDIF tx, no SPDIF Rx, ADAT tx, ADAT rx, no DSD
# Sample rate restriced to 96kHz fit in USB bandwidth
XCC_FLAGS_2i16o16xxxaax = $(BUILD_FLAGS) -DSPDIF_TX=0 -DMIDI=0 -DADAT_RX=1 -DADAT_TX=1 -DMAX_FREQ=96000 -DNUM_USB_CHAN_OUT=16 -DNUM_USB_CHAN_IN=16
INCLUDE_ONLY_IN_2i16o16xxxaax = 

# Audio Class 2, Input, Output, No MIDI, SPDIF out, SPDIF in
XCC_FLAGS_2i10o10xssxxx = $(BUILD_FLAGS) -DSPDIF_RX=1
INCLUDE_ONLY_IN_2i10o10xssxxx = 

# Audio Class 1, 2 channels Input, 2 channels Output, no MIDI, no SPDIF
XCC_FLAGS_1i2o2xxxxxx = $(BUILD_FLAGS) -DAUDIO_CLASS=1
INCLUDE_ONLY_IN_1i2o2xxxxxx =

# Audio Class 1, 8 channels Input, 2 channels Output, no MIDI, no SPDIF
XCC_FLAGS_1i8o2xxxxxx = $(BUILD_FLAGS) -DAUDIO_CLASS=1 -DNUM_USB_CHAN_IN_FS=6 -DMAX_FREQ_FS=44100 -DSTREAM_FORMAT_INPUT_1_RESOLUTION_BITS=16
INCLUDE_ONLY_IN_1i8o2xxxxxx =

ifeq ($(TEST_CONFIGS),1)
XCC_FLAGS_upgrade1 = $(BUILD_FLAGS) -DBCD_DEVICE_J=0x99 -DBCD_DEVICE_M=0x0 -DBCD_DEVICE_N=0x1
XCC_FLAGS_upgrade2 = $(BUILD_FLAGS) -DBCD_DEVICE_J=0x99 -DBCD_DEVICE_M=0x0 -DBCD_DEVICE_N=0x2
endif

else

# MFi test build configs - iAP support enabled
	
# # Audio Class 2, iAP enabled, Input, Output, No MIDI, SPDIF Tx
XCC_FLAGS_2i10o10xsxxxx_mfi = $(BUILD_FLAGS) -DIAP=1 -DSPDIF_TX=1 -DMIDI=0
INCLUDE_ONLY_IN_2i10o10xsxxxx_mfi = 

# # Audio Class 2, iAP enabled, No Input, Output, No MIDI, SPDIF Tx, DSD
XCC_FLAGS_20i10oxsxxxxd_mfi = $(BUILD_FLAGS) -DIAP=1 -DSPDIF_TX=1 -DMIDI=0 -DDSD_CHANS_DAC=2
INCLUDE_ONLY_IN_20i10oxsxxxxd_mfi = 

#Audio Class 2, iAP enabled, EA Protocol (Native Transport), Input, Output, No MIDI, No SPDIF Tx. i
# Hid controls disabled (buttons used for EA)
# XCC_FLAGS_210i10oxxxxx_mfi_n = $(BUILD_FLAGS) -DIAP=1 -DIAP_EA_NATIVE_TRANS=1 -DMIDI=0 -DSPDIF_TX=0 -DHID_CONTROLS=0
# INCLUDE_ONLY_IN_210i10oxxxxx_mfi_n =

#Audio Class 2, iAP enabled, Input, Output, No,  No SPDIF Tx. Select USB A port. Ignore VBUS.
#Note, this is the config used for Apple role-switch
XCC_FLAGS_2ioxx_usba_mfi = $(BUILD_FLAGS) -DIAP=1 -DMIDI=0 -DSPDIF_TX=0 -DUSB_SEL_A=1 -DXUD_PWR_CFG=0
INCLUDE_ONLY_IN_2ioxx_usba_mfi = 

include mfi.mk

endif


MODULE_LIBRARIES = xud_x200

#=============================================================================
# The following part of the Makefile includes the common build infrastructure
# for compiling XMOS applications. You should not need to edit below here.

XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
avrobot
Member++
Posts: 17
Joined: Mon Jun 04, 2018 4:26 am

Post by avrobot »

Thanks but unfortunately same errors occur. Did your compilation successfully generate the bin file? Interesting that your make file did not include the defines for SCL_HIGH in SDA_HIGH in build flags. Definitely an odd one.. also tried from command line xmake and same issue.

[Update] I found that manually enabling the Project Reference properties for each lib and module now allows build without errors. Thanks!
RitchRock
XCore Addict
Posts: 186
Joined: Tue Jan 17, 2017 9:25 pm

Post by RitchRock »

Do you mean this screen?
ProjectReferences.JPG
(81.92 KiB) Not downloaded yet
ProjectReferences.JPG
(81.92 KiB) Not downloaded yet
Interesting that I did not need to enable anything here. Glad you finally got it working.
Post Reply