MATLAB: Using “Raspbian Buster” OS, why do I get build errors related to I2C when creating a RASPI object, or building a model with I2C blocks

MATLABraspbian-bustersimulink

I try to create a RASPI object in MATLAB, using the command "r = raspi()", why does this result in build errors related to I2C.c?
I obeserve similar build errors when I use the I2C block from Simulink and try to build the model.
>> r = raspi()
### Updating Raspberry Pi I/O server...
### Connecting to board...
### Connected to 172.29.43.43...
### Creating server folder...
### Transferring source files...
### Building MATLAB I/O server...
Error executing command "make -C /opt/MATLAB/server_v19.1.0 -f Makefile". Details:
STDERR: handler.c: In function ‘updateSourceInfoâ€:
handler.c:435:41: warning: ‘,0†directive writing 2 bytes into a region of size
between 0 and 2 [-Wformat-overflow=]
sprintf(pData->audioCard, "plughw:%d,0", cardType);
^~
handler.c:435:5: note: ‘sprintf†output between 11 and 13 bytes into a
destination of size 10
sprintf(pData->audioCard, "plughw:%d,0", cardType);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I2C.c: In function ‘I2C_openâ€:
I2C.c:29:23: warning: unused variable ‘i2c_funcs†[-Wunused-variable]
unsigned long i2c_funcs = 0;
^~~~~~~~~
I2C.c: In function ‘EXT_I2C_readRegisterâ€:
I2C.c:74:24: error: array type has incomplete element type ‘struct i2c_msgâ€
struct i2c_msg msg[2];
^~~
I2C.c:83:24: error: ‘I2C_M_RD†undeclared (first use in this function); did you
mean ‘I2C_open�
msg[1].flags = I2C_M_RD | I2C_M_NOSTART; // Read
^~~~~~~~
I2C_open
I2C.c:83:24: note: each undeclared identifier is reported only once for each
function it appears in
I2C.c:83:35: error: ‘I2C_M_NOSTART†undeclared (first use in this function)
msg[1].flags = I2C_M_RD | I2C_M_NOSTART; // Read
^~~~~~~~~~~~~
I2C.c:74:24: warning: unused variable ‘msg†[-Wunused-variable]
struct i2c_msg msg[2];
^~~
I2C.c: In function ‘EXT_I2C_writeRegisterâ€:
I2C.c:110:24: error: array type has incomplete element type ‘struct i2c_msgâ€
struct i2c_msg msg[2];
^~~
I2C.c:122:24: error: ‘I2C_M_NOSTART†undeclared (first use in this function)
msg[1].flags = I2C_M_NOSTART; // Write
^~~~~~~~~~~~~
I2C.c:110:24: warning: unused variable ‘msg†[-Wunused-variable]
struct i2c_msg msg[2];
^~~
I2C.c: In function ‘EXT_I2C_writeâ€:
I2C.c:148:24: error: storage size of ‘msg†isnâ€t known
struct i2c_msg msg;
^~~
I2C.c:148:24: warning: unused variable ‘msg†[-Wunused-variable]
I2C.c: In function ‘EXT_I2C_readâ€:
I2C.c:178:24: error: storage size of ‘msg†isnâ€t known
struct i2c_msg msg;
^~~
I2C.c:182:21: error: ‘I2C_M_RD†undeclared (first use in this function); did
you mean ‘I2C_open�
msg.flags = I2C_M_RD;
^~~~~~~~
I2C_open
I2C.c:178:24: warning: unused variable ‘msg†[-Wunused-variable]
struct i2c_msg msg;
^~~
make: *** [Makefile:56: obj/I2C.o] Error 1

Best Answer

With the new version of Raspbian OS, “Raspbian Buster”, some header files of “i2c-dev” library got re-organized and our I2C source code is not compatible with the same. MATLAB IO server needs to be updated to fix this issue.
As a result, users working with this newer OS image and running OS customization from our Raspberry Pi Support Package during Hardware Setup will meet this build error while trying to run the command “r=raspi()”, or when using the I2C block from Simulink and trying to build the model.
MATLAB releases R2017b, R2018a, R2018b, and R2019a will be affected by this error as OS Customization support has been available from R2017b.
1) To fix error for MATLAB command “r = raspi()”:
Enter below command at the MATLAB prompt and edit the source code as shown in the attached screenshot:
>> edit(fullfile(raspi.internal.getRaspiRoot,'server','I2C.c'))
2) To fix the error in Simulink for I2C blocks:
Enter below command at the MATLAB prompt and edit the source code as shown in attached screenshot:
>>edit(fullfile(codertarget.raspi.internal.getSpPkgRootDir,'src','MW_I2C.c'))
Related Question