Serial read for Arduino Due in S-function

2 次查看(过去 30 天)
Hey there,
I'm trying to send two different data sets from Matlab to the Arduino Due over the Serial Port. The reason I'm not using the external mode is because it's slowing the Arduino down to a speed, where it's not able to run in realtime anymore. I've tried to implement the code similar to an example on the Arduino HP ( ReadASCIIString), but it seems that Matlab isn't properly including the Serial library. I was following the Device Driver tutorial to create the S-function, but as soon as I use the Serial.begin function, I get the following error when building the code:
The call to realtime_make_rtw_hook, during the after_make hook generated the following error:
The build failed with the following message: "D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc" -I"D:/Documents/MATLAB/untitled_rtt" -I"D:/Documents/MATLAB" -I"D:/Programme/MATLAB/R2014a/extern/include" -I"D:/Programme/MATLAB/R2014a/simulink/include" -I"D:/Programme/MATLAB/R2014a/rtw/c/src" -I"D:/Programme/MATLAB/R2014a/rtw/c/src/ext_mode/common" -I"D:/Programme/MATLAB/R2014a/rtw/c/ert" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/arduino/sam/system/libsam" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/arduino/sam/system/CMSIS/CMSIS/Include" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/arduino/sam/system/CMSIS/Device/ATMEL" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/arduino/sam/cores/arduino" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/arduino/sam/cores/arduino/USB" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/arduino/sam/variants/arduino_due_x" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino/include" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/libraries/Servo/src" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/libraries/Servo/arch/sam" -c -g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -mcpu=cortex-m3 -mthumb -I. -D"MODEL=untitled" -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"ALLOCATIONFCN=0" -D"TID01EQ=0" -D"printf=iprintf" -D"F_CPU=84000000" -D"_RUNONTARGETHARDWARE_BUILD_=" -D"_ROTH_DUE_=" -D"ARDUINO=154" -D"ARDUINO_SAM_DUE=" -D"ARDUINO_ARCH_SAM=" -D"__SAM3X8E__=" -D"USB_PID=0x003e" -D"USB_VID=0x2341" -D"USBCON=" -D"_RTT_NUMSERVOS_=0" ./serial_20140629_1_wrapper.c ./ert_main.c ./untitled.c ./untitled_data.c ./IPAddress.cpp ./Print.cpp ./Reset.cpp ./RingBuffer.cpp ./Stream.cpp ./UARTClass.cpp ./USARTClass.cpp ./CDC.cpp ./HID.cpp ./USBCore.cpp ./WInterrupts.c ./WMath.cpp ./WString.cpp ./cortex_handlers.c ./cxxabi-compat.cpp ./hooks.c ./iar_calls_sam3.c ./itoa.c ./syscalls_sam3.c ./wiring.c ./wiring_analog.c ./wiring_digital.c ./wiring_pulse.cpp ./wiring_shift.c ./variant.cpp ./io_wrappers.cpp
./serial_20140629_1_wrapper.c: In function 'serial_20140629_1_Outputs_wrapper':
./serial_20140629_1_wrapper.c:42: error: 'Serial' undeclared (first use in this function)
./serial_20140629_1_wrapper.c:42: error: (Each undeclared identifier is reported only once
./serial_20140629_1_wrapper.c:42: error: for each function it appears in.)
./serial_20140629_1_wrapper.c: In function 'serial_20140629_1_Update_wrapper':
./serial_20140629_1_wrapper.c:62: error: 'Serial' undeclared (first use in this function)
cs-make: *** [serial_20140629_1_wrapper.o] Error 1
The build process will terminate as a result.
The build failed with the following message: "D:/Programme/MATLAB/SupportPackages/R2014a/arduino- 1.5.4/hardware/tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc" - I"D:/Documents/MATLAB/untitled_rtt" -I"D:/Documents/MATLAB" - I"D:/Programme/MATLAB/R2014a/extern/include" -I"D:/Programme/MATLAB/R2014a/simulink/include" - I"D:/Programme/MATLAB/R2014a/rtw/c/src" -I"D:/Programme/MATLAB/R2014a/rtw/c/src/ext_mode/common" -I"D:/Programme/MATLAB/R2014a/rtw/c/ert" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/arduino/sam/system/libsam" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/arduino/sam/system/CMSIS/CMSIS/Include" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/arduino/sam/system/CMSIS/Device/ATMEL" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/arduino/sam/cores/arduino" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/arduino/sam/cores/arduino/USB" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/hardware/arduino/sam/variants/arduino_due_x" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino/include" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/libraries/Servo/src" -I"D:/Programme/MATLAB/SupportPackages/R2014a/arduino-1.5.4/libraries/Servo/arch/sam" -c -g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -mcpu=cortex-m3 -mthumb -I. -D"MODEL=untitled" -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"ALLOCATIONFCN=0" -D"TID01EQ=0" -D"printf=iprintf" -D"F_CPU=84000000" -D"_RUNONTARGETHARDWARE_BUILD_=" -D"_ROTH_DUE_=" -D"ARDUINO=154" -D"ARDUINO_SAM_DUE=" -D"ARDUINO_ARCH_SAM=" -D"__SAM3X8E__=" -D"USB_PID=0x003e" -D"USB_VID=0x2341" -D"USBCON=" -D"_RTT_NUMSERVOS_=0" ./serial_20140629_1_wrapper.c ./ert_main.c ./untitled.c ./untitled_data.c ./IPAddress.cpp ./Print.cpp ./Reset.cpp ./RingBuffer.cpp ./Stream.cpp ./UARTClass.cpp ./USARTClass.cpp ./CDC.cpp ./HID.cpp ./USBCore.cpp ./WInterrupts.c ./WMath.cpp ./WString.cpp ./cortex_handlers.c ./cxxabi-compat.cpp ./hooks.c ./iar_calls_sam3.c ./itoa.c ./syscalls_sam3.c ./wiring.c ./wiring_analog.c ./wiring_digital.c ./wiring_pulse.cpp ./wiring_shift.c ./variant.cpp ./io_wrappers.cpp
./serial_20140629_1_wrapper.c: In function 'serial_20140629_1_Outputs_wrapper':
./serial_20140629_1_wrapper.c:42: error: 'Serial' undeclared (first use in this function)
./serial_20140629_1_wrapper.c:42: error: (Each undeclared identifier is reported only once
./serial_20140629_1_wrapper.c:42: error: for each function it appears in.)
./serial_20140629_1_wrapper.c: In function 'serial_20140629_1_Update_wrapper':
./serial_20140629_1_wrapper.c:62: error: 'Serial' undeclared (first use in this function)
cs-make: *** [serial_20140629_1_wrapper.o] Error 1
Despite the fact I included the Arduino.h Simulink apparently doesn't know what to do with the Serial command. Does anyone know how to solve this problem?

回答(5 个)

Sreeram
Sreeram 2014-7-22
Hi Paul,
Could you please post in the files that you are using if you could share and it would be helpful in debugging this further?
Thanks, Sreeram Mohan

Paul
Paul 2014-7-22
Hey Sreeram, thank you for your answer!
I attached a .zip file with the .slx which includes an s-function-builder. I tried to use an Arduino turorial where the Arduino reads three serial messages from the buffer and assign the values to different PWM pins.
I hope you can find a solution!
Thanks, Paul

YL
YL 2014-7-29
Hi Paul,
I'm also having this problem, but I was sending data through DUE. Have you figured out the solution?
Thanks,

YL
YL 2014-7-29
I included the "Arduino.h" in the s-function builder, then it could be compiled but the port was not transmitting anything.

Philipp Schaefer
Philipp Schaefer 2016-2-20
编辑:Philipp Schaefer 2016-2-20
Take a look at this file Device Driver Guide.
In the PDF navigate to page 23 and read the chapter. You will find a tool renc2cpp included with it.
After pressing build in the s Function builder run renc2cpp('yourSfcnName') in the matlab command line.
I made the following changes to these files (as already sent to the support team)
1)
C:\MATLAB\SupportPackages\R2015b\arduino\toolbox\target\supportpackages\arduinotarget\registry\Arduino_arm.m
On line 175 I added the cCompilerOpts = {'-std=gnu99'}; for the compiler options, to make it more similar to the Arduino IDE. This is however not mandatory.
After the change, run saveToolchainInfoToMATFiles.m in the same folder.
2) IMPORTANT
C:\MATLAB\SupportPackages\R2015b\arduino\toolbox\target\supportpackages\arduinotarget\src\MW_ArduinoHWInit.cpp
This is the main initialization file. Compared to the Arduino main.cpp (C:\MATLAB\SupportPackages\R2015b\arduino-1.6.1\hardware\arduino\sam\cores\arduino\main.cpp) there is a line missing for the USB device. I added this one:
//USB DEVICE
#if (defined(_ROTH_DUE_) && defined(USBCON))
USBDevice.attach();
#endif
3) MOST IMPORTANT
The file C:\MATLAB\SupportPackages\R2015b\arduino\toolbox\target\supportpackages\arduinotarget\registry\attributes\ArduinoDue_attributes.xml, which sets the compile and link files, doesnt do it in correct order. The Arduino Due seems to be very picky about this as found in a forum thread (http://forum.arduino.cc/index.php?topic=162959.0). I essentially swapped the order of include files, but didn’t add anything.
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/avr/dtostrf.c</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/new.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/wiring_shift.c</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/wiring_analog.c</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/itoa.c</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/cortex_handlers.c</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/hooks.c</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/wiring.c</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/WInterrupts.c</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/syscalls_sam3.c</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/iar_calls_sam3.c</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/wiring_digital.c</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/Print.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/USARTClass.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/WString.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/USB/CDC.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/USB/HID.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/wiring_pulse.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/UARTClass.cpp</sourcefile>
<sourcefile>$(TARGET_ROOT)/src/MW_ArduinoHWInit.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/abi.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/Stream.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/RingBuffer.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/IPAddress.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/Reset.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/cores/arduino/WMath.cpp</sourcefile>
<sourcefile>$(ARDUINO_ROOT)/hardware/arduino/sam/variants/arduino_due_x/variant.cpp</sourcefile>
<sourcefile>$(ARDUINO_BASE_ROOT_DIR)/src/io_wrappers.cpp</sourcefile>
It seems to be very important to link USBCore.cpp before linking CDC.cpp and HID.cpp. Same applies for other files.

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by