MATLAB Answers

1

Get ERROR when trying to upload 'Custom Simulink Block aka: S-Function Builder' to Arduino UNO

D P 님이 질문을 제출함. 19 Apr 2013
최근 활동 Robert Noble 님이 편집함. 21 Oct 2015
MATLAB/Simulink Version: 2012b
I have been trying to create a custom Simulink Block using the User-Defined Functions(S-Function Builder) that can controls 3 stepper motors.
The code to initialize/control the motors uses an external library called 'AccelStepper Library'. The custom simulink block for the stepper motor control 'builds' and 'simulates' without any errors. But when I try to 'upload' this simulink model onto the Arduino UNO Target it goes through 70% and displays the following error message:
The call to realtime_make_rtw_hook, during the after_make hook generated the following error: The build failed with the following message: "C:/MATLAB/Targets/R2012b/arduino-1.0/hardware/tools/avr/bin/avr-gcc" -I"C:/Users/Alpha/Documents/MATLAB/AStepper_rtt" -I"C:/Users/Alpha/Documents/MATLAB" -I"C:/Program Files/MATLAB/R2012b/extern/include" -I"C:/Program Files/MATLAB/R2012b/simulink/include" -I"C:/Program Files/MATLAB/R2012b/rtw/c/src" -I"C:/Program Files/MATLAB/R2012b/rtw/c/src/ext_mode/common" -I"C:/Program Files/MATLAB/R2012b/rtw/c/ert" -I"C:/MATLAB/Targets/R2012b/arduino-1.0/hardware/arduino/cores/arduino" -I"C:/MATLAB/Targets/R2012b/arduino-1.0/hardware/arduino/variants/standard" -I"C:/MATLAB/Targets/R2012b/arduino/include" -I"C:/MATLAB/Targets/R2012b/arduino-1.0/libraries/Servo" -mmcu=atmega328p -std=gnu99 -Wall -Wstrict-prototypes -gstabs -Os -D"MODEL=AStepper" -D"NUMST=1" -D"NCSTATES=0" -D"HAVESTDIO=" -D"ONESTEPFCN=0" -D"TERMFCN=1" -D"MAT_FILE=0" -D"MULTI_INSTANCE_CODE=0" -D"INTEGER_CODE=0" -D"MT=0" -D"CLASSIC_INTERFACE=0" -D"TID01EQ=0" -D"F_CPU=16000000" -D"_RUNONTARGETHARDWARE_BUILD_=" -D"_RTT_NUMSERVOS_=0" -c -x none ./HardwareSerial.cpp ./Print.cpp ./WInterrupts.c ./WMath.cpp ./WString.cpp ./new.cpp ./wiring.c ./wiring_analog.c ./wiring_digital.c ./io_wrappers.cpp ./AStepper.c ./AStepper_data.c ./ert_main.c ./StepperControl_slsp_wrapper.cpp ./l_slsp_wrapper.cpp cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
In file included from ./AStepper.c:18: ./AStepper_private.h:48: warning: function declaration isn't a prototype
In file included from ./AStepper_data.c:18: ./AStepper_private.h:48: warning: function declaration isn't a prototype
In file included from ./ert_main.c:18: C:/MATLAB/Targets/R2012b/arduino-1.0/hardware/arduino/cores/arduino/Arduino.h:24:1: warning: "true" redefined
In file included from ./AStepper.h:23, from ./ert_main.c:17: ./rtwtypes.h:158:1: warning: this is the location of the previous definition
In file included from ./ert_main.c:18: C:/MATLAB/Targets/R2012b/arduino-1.0/hardware/arduino/cores/arduino/Arduino.h:25:1: warning: "false" redefined
In file included from ./AStepper.h:23, from ./ert_main.c:17: ./rtwtypes.h:154:1: warning: this is the location of the previous definition
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
In file included from ./StepperControl_slsp_wrapper.cpp:40: C:/Users/Alpha/Documents/MATLAB/AccelStepper.h:150:22: error: WProgram.h: No such file or directory
C:/Users/Alpha/Documents/MATLAB/AccelStepper.h:151:20: error: wiring.h: No such file or directory
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
make: * [HardwareSerial.o] Error 1
The build process will terminate as a result.
--> Does ANYONE have a clue what this error message can be related to?? ANY help will be greatly appreciated!!

  댓글 수: 3

I have the same issue creating my LCD driver block... i am following the drivers guide by Campas. Please let me know if you have found a solution.
Thx - phil
I'm running into the same problem and I think others in another environment have indicated that it is a compiler flag that is causing the problem. see here: http://stackoverflow.com/questions/11002866/eclipse-arduino-make-error-1
Post if you find a solution, thanks
I've finally came back to give a bit of insight on this. I found out that where variables are defined is important. Some variables need to be defined in the libraries tab in the External function declarations section. This section makes the definitions accessible the entire S-Function whereas defining variables in other sections make those variables accessible only to code locally. For example, variable defined in the Discrete Update tab which is where the "setup()" code from arduino would go are not visible to code in the Outputs tab of the S-Function Builder. This makes sense to me now as the "Discrete Update" and the "Outputs" code get put into a function.
Again the "Libraries" tab is probably the better place to put global variables as well as other functions that you may be calling from other parts of the code. If you do write functions there then these functions will also need the extern "C" appended before "void" in the cpp wrapper file. If this last bit does not make sense then there are some other topics that need to be understood before trying to fix this problem.
I hope this helps.

로그인 to comment.

답변 수: 3

phil 님의 답변 19 Apr 2013

here is my very similar error:
The build failed with the following message: "C:/MATLAB/Targets/R2012b/arduino-1.0/hardware/tools/avr/bin/avr-gcc" -
I"C:/Users/Philipp Protschka/Dropbox/Projects/Mercuino/DisplayDriverv1/DisplayDriverv1_rtt" -I"C:/Users/Philipp
Protschka/Dropbox/Projects/Mercuino/DisplayDriverv1" -I"C:/Program Files/MATLAB/R2012b/extern/include" -I"C:/Program
Files/MATLAB/R2012b/simulink/include" -I"C:/Program Files/MATLAB/R2012b/rtw/c/src" -I"C:/Program
Files/MATLAB/R2012b/rtw/c/src/ext_mode/common" -I"C:/Program Files/MATLAB/R2012b/rtw/c/ert" -
I"C:/MATLAB/Targets/R2012b/arduino-1.0/hardware/arduino/cores/arduino" -I"C:/MATLAB/Targets/R2012b/arduino-
1.0/hardware/arduino/variants/mega" -I"C:/MATLAB/Targets/R2012b/arduino/include" -I"C:/MATLAB/Targets/R2012b/arduino-
1.0/libraries/Servo" -mmcu=atmega2560 -std=gnu99 -Wall -Wstrict-prototypes -gstabs -Os -D"MODEL=DisplayDriverv1" -D"NUMST=1"
-D"NCSTATES=0" -D"HAVESTDIO=" -D"ONESTEPFCN=0" -D"TERMFCN=1" -D"MAT_FILE=0" -D"MULTI_INSTANCE_CODE=0" -D"INTEGER_CODE=0" -
D"MT=0" -D"CLASSIC_INTERFACE=0" -D"TID01EQ=0" -D"F_CPU=16000000" -D"_RUNONTARGETHARDWARE_BUILD_=" -D"_ROTH_MEGA2560_=" -
D"_RTT_NUMSERVOS_=0" -c -x none ./HardwareSerial.cpp ./Print.cpp ./WInterrupts.c ./WMath.cpp ./WString.cpp ./new.cpp
./wiring.c ./wiring_analog.c ./wiring_digital.c ./io_wrappers.cpp ./DDvers1_wrapper.cpp ./DisplayDriverv1.c
./DisplayDriverv1_data.c ./ert_main.c cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++ cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++ cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++ cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++ cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++ cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++ ./io_wrappers.cpp: In function 'void Serial_read(int, int, uint8_t*, int*)': ./io_wrappers.cpp:40: warning: 'libFcnOutput' may be used uninitialized in this function cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++ cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++ ./DDvers1_wrapper.cpp: In function 'void DDvers1_Outputs_wrapper(const boolean_T*, const real_T*, const real_T*, int_T)': ./DDvers1_wrapper.cpp:73: error: 'lcd' was not declared in this scope ./DDvers1_wrapper.cpp:77: error: 'lcd' was not declared in this scope In file included from ./ert_main.c:18: C:/MATLAB/Targets/R2012b/arduino-1.0/hardware/arduino/cores/arduino/Arduino.h:24:1: warning: "true" redefined In file included from ./DisplayDriverv1.h:23, from ./ert_main.c:17: ./rtwtypes.h:158:1: warning: this is the location of the previous definition In file included from ./ert_main.c:18: C:/MATLAB/Targets/R2012b/arduino-1.0/hardware/arduino/cores/arduino/Arduino.h:25:1: warning: "false" redefined In file included from ./DisplayDriverv1.h:23, from ./ert_main.c:17: ./rtwtypes.h:154:1: warning: this is the location of the previous definition

  댓글 수: 1

Hey Phil, sorry for the late response, I just came back to this!
I never got it to work. I think the issue was that I was trying to use an external library "AccelStepper" inside the custom block and matlab/simulink didn't like that..
DP

로그인 to comment.


masroor 님의 답변 2 Feb 2015

add library file ( .h and .c) file into your current working directory where s function is located

  댓글 수: 0

로그인 to comment.


Robert Noble 님의 답변 21 Oct 2015
Robert Noble 님이 편집함. 21 Oct 2015

Hi, I know this is now an old thread but I had a very similar error message while working on a custom LCD screen block. I have now resolved the problem, with a very simple fix and thought it would be good to share as I couldn't find any decent answers. The problem I had was that the LiquidCrystal.cpp and LiquidCrystal.h files I had placed in my working directory were from a different version of the Arduino IDE that the MATLAB support package automatically installs. To resolve the problem I simply deleted the .h and .cpp files for the LiquidCrystal library that I had placed in my working directory and replaced them with the .h and .cpp files from the MATLAB installed Arduino IDE folder; C:\MATLAB\SupportPackages\R2013a\arduino-1.0\libraries\LiquidCrystal
This fixed the problem instantly.
Hopefully this will help someone in the future.
Rob

  댓글 수: 0

로그인 to comment.



Translated by