Matlab、Simulink、BeagleBone Blue、Counting Steps例子、I2C、C代码错误

Matlab, Simulink, BeagleBone Blue, Counting Steps example, I2C, C code error

我正在尝试 BeagleBone Blue 的示例 Simulink 代码,名为 Counting Steps Using BeagleBone Blue Hardware。 web端是这样的

https://www.mathworks.com/help/supportpkg/beagleboneblue/ref/counting-steps-using-beagleboneblue-hardware-example.html

当我尝试将代码发送到 Beagle 时,出现以下错误。

此外,我想将 I2C 总线与 BeagleBone Blue 一起使用,并使用 Matlab (2019b) 和 Simulink 控制 Beagle。如果我将任何 I2C 块添加到 Simulink 模型并尝试将代码发送到 Beagle,我会得到同样的错误。看起来创建的 C 代码是错误的。有人知道如何解决这个问题吗?

Error executing command "touch -c /home/debian/beagleboneblue_countstep_ert_rtw/*.*;make  -f beagleboneblue_countstep.mk all -C /home/debian/beagleboneblue_countstep_ert_rtw". Details:

STDERR: MW_I2C.c: In function ‘EXT_I2C_writeH’:
MW_I2C.c:140:20: error: storage size of ‘msg’ isn’t known
     struct i2c_msg msg;
                    ^~~
MW_I2C.c: In function ‘EXT_I2C_readH’:
MW_I2C.c:177:20: error: storage size of ‘msg’ isn’t known
     struct i2c_msg msg;
                    ^~~
MW_I2C.c:183:21: error: ‘I2C_M_RD’ undeclared (first use in this function)
         msg.flags = I2C_M_RD;
                     ^~~~~~~~
MW_I2C.c:183:21: note: each undeclared identifier is reported only once for each function it appears in
MW_I2C.c: In function ‘MW_I2C_MasterRead’:
MW_I2C.c:261:28: warning: passing argument 1 of ‘EXT_I2C_readH’ makes integer from pointer without a cast [-Wint-conversion]
     status = EXT_I2C_readH(I2CModuleHandle, SlaveAddress, data, DataLength);
                            ^~~~~~~~~~~~~~~
MW_I2C.c:169:5: note: expected ‘int’ but argument is of type ‘MW_Handle_Type {aka void *}’
 int EXT_I2C_readH(
     ^~~~~~~~~~~~~
MW_I2C.c: In function ‘MW_I2C_MasterWrite’:
MW_I2C.c:273:29: warning: passing argument 1 of ‘EXT_I2C_writeH’ makes integer from pointer without a cast [-Wint-conversion]
     status = EXT_I2C_writeH(I2CModuleHandle, SlaveAddress, data, DataLength);
                             ^~~~~~~~~~~~~~~
MW_I2C.c:132:5: note: expected ‘int’ but argument is of type ‘MW_Handle_Type {aka void *}’
 int EXT_I2C_writeH(
     ^~~~~~~~~~~~~~
MW_I2C.c: In function ‘MW_I2C_Close’:
MW_I2C.c:302:24: warning: passing argument 1 of ‘EXT_I2C_terminateH’ makes integer from pointer without a cast [-Wint-conversion]
     EXT_I2C_terminateH(I2CModuleHandle);
                        ^~~~~~~~~~~~~~~
MW_I2C.c:221:5: note: expected ‘int’ but argument is of type ‘MW_Handle_Type {aka void *}’
 int EXT_I2C_terminateH(int fd)
     ^~~~~~~~~~~~~~~~~~
make: *** [MW_I2C.c.o] Error 1

STDOUT: make: Entering directory '/home/debian/beagleboneblue_countstep_ert_rtw'
gcc -c -MMD -MP -MF"MW_I2C.c.dep" -MT"MW_I2C.c.o" -O0  -D_roboticscape_in_use_ -D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DEXT_MODE=1 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0  -DON_TARGET_WAIT_FOR_START=1 -DTID01EQ=0 -DARM_PROJECT -D_USE_TARGET_UDP_ -D_RUNONTARGETHARDWARE_BUILD_ -DSTACK_SIZE=64 -DRT -DMODEL=beagleboneblue_countstep -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -I./ -o "MW_I2C.c.o" "MW_I2C.c"
beagleboneblue_countstep.mk:446: recipe for target 'MW_I2C.c.o' failed
make: Leaving directory '/home/debian/beagleboneblue_countstep_ert_rtw'

提前致谢

感谢@ryyker 在评论中的回答。

https://itectec.com/matlab/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/

修复 Simulink 中 I2C 模块的错误: 在 MATLAB 提示符下输入以下命令并编辑源代码,如所附屏幕截图所示:

我使用了此修复程序,但用于 BeagleBone Blue。不同之处就在于这个命令。

编辑(完整文件(codertarget.bbblue.internal.getSpPkgRootDir,'src','MW_I2C.c'))

Here is the picture of the I2C fix

文件更改与 Raspi 相同。