Issue with Embedded Coder Target for Arduino - matlab

I am following this MathWorks File Exchange Link. I am having problem while running the myarduino_blink.slx demo.
My MATLAB version is R2015a, and I am using an Arduino Uno. I ran the file setup_custom_target_arduino.m after changing the relevant directory listing and the arduino version in the m file, and I got the output of Arduino on COM 3, which was correct.
After this, I checked the Simulink Library Browser and I had the Custom C/C++ Target Arduino Library will all its modules. Now when I simulate the model, I get the following error:
Error in S-function 'myarduino_blink/Digital Output':
S-Function 'sfunar_digitalOutput' does not exist
Kindly help me out, what could I have done wrong?
Update 1
Ok, I solved the "does not exist" problem. Apparently, no MEX compiler was installed. So I installed the Windows SDK, then re-ran the m file and now I am able to generate the .mex64 files. Now I run into another problem, when I build the simulink model, it gives this error:
Build procedure for model: 'myarduino_blink' aborted due to an error
How to solve this?

setup_custom_target_arduino.m calls build_all_sfunctions.m which should compile all of the S-Functions in the blocks directory. It looks as if that hasn't occurred for some reason. Check in the blocks directory that each of the S-Functions has a .c, .tlc (both of which come with the package) and a .mex64 (which is the compiled version of the .c generated by build_all_sfunctions.m) file.
If they are not there then the setup hasn't executed correctly, and you'll need to compile all of the S-Functions.
If they are there then you most likely have some sort of path issue (although since you say you can see the library in the library browser this seems unlikely).

Related

Why is VS Code throwing this error (ARDUINO)?

Okay, so I'm trying to code & upload to an Arduino with VS Code (Visual Studio Code). When I try to upload or verify my Arduino code, this error pops up:
If you cannot see that, it says:
[Starting] Verify sketch - ir_remote\ir_remote.ino [Warning] Output path is not specified. Unable to reuse previously compiled files. Verify could be slow. See README. Arduino: This application was configured to use a bundled Java Runtime Environment but the runtime is missing or corrupted. [Error] Exit with code=1
Help will be greatly appreciated. I started messing around with the Arduino a few weeks ago, and I've been using VS Code for a long time.
ALSO:
Code works completely fine on Arduino IDE, I want to be able to code and upload to an Arduino with VS Code.
I also tried posting this on the Arduino Forum, and no one replied.
I was able to solve the issue sharing here to help,
I installed Arduino from MS App Store, and i got exactly same error, i uninstalled the Arduino and downloaded installer from Arduino web site, i installed Arduino set the path by pointing to in VS Code settings > extensions > Arduino Configurations > Arduino Path, paste here path to installation folder. And it was all good.
Under project files .vscode folder be sure arduino.json has path set to
"output": "../ArduinoOutput",
Remember that you have to select Development board, Programmer and Serial Port as well in VS Code IDE.
Please View
https://maker.pro/arduino/tutorial/how-to-use-visual-studio-code-for-arduino
Abolfazl Danayi 5 months ago
Salaam
I had the same problem and after following the very nice instructions of the author and what Jack said, I found this:
Add "output": "./build" (or wherever you want) to your ".vscode/arduino.json" file, just as Jack mentioned.
Delete ".vscode/c_cpp_properties.json" file. (If you don't do this, the intellisense won't work).
Build the project again (via verification or upload buttons).
Enjoy (And hope the bests for me in the case your problem is done following this routine!)

Where are the files defining NVIC for STM32 in PlatformIO when using CubeMX?

I've recently switched to using PlatformIO for developing for STM32 using the following workflow:
Create a .ioc file using the CubeMX utility
Generate source code and the PlatformIO configuration from that .ioc file from the stm32pio command line utility
Edit, build, and debug using the PlatformIO plug-in for VSCode (Mac)
Overall, this works very well. However, I was previously using the CubeMX code generation in ST's CubeMX IDE, which placed a .s file in the source directory that (as I understand it) defined the NVIC, as well as the default function that was used for exceptions/interrupts that are not explicitly defined (i.e., those handled by their default weak implementations.) I don't see where this is defined in the new workflow. Is this generated dynamically as part of the build process?
The reason I'm asking is (beside wanting a better understanding of the process overall), I'd like to write an interrupt handler for EXTI0, but trigger it as a software interrupt, and not assign a pin to it. If that is not possible, then perhaps the entire point is moot.
I was able to find the answer. These steps might be useful to somebody else who comes across this question. This was done on MacOS, but should be similar to the process for other operating systems.
During the build process, the filename can be seen. It will be prefaced with startup_, followed by the name of the particular chip you're developing for. In my case, the line is
Compiling .pio/build/disco_f072rb/FrameworkCMSISDevice/gcc/startup_stm32f072xb.o
Searching in the .platformio folder of my user directory, I found the matching .s file, which in my case was .platformio/packages/framework-stm32cube/f0/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc/startup_stm32f072xb.s
The structure of the path leading to the file indicates the particulars of the hardware and frameworks I'm using: STM32Cube framework, a F0 series chip, and the GCC compiler. The easiest way to find this file, and how I was able to find it, is using the find command from the terminal to search the PlatformIO directory.
Reading this file gives the lines I was looking for, defining the names of the functions to be used for exception and interrupt handling, such as the following:
.weak EXTI0_1_IRQHandler
.thumb_set EXTI0_1_IRQHandler,Default_Handler
It seems like, while I am using the CubeMX HAL for some drivers, the basic startup code is done using CMSIS, so it should be the same for HAL, LL, or CMSIS based builds.

Error: register 'sp' unsuitable for global register variables on this target

I am playing around with a project for a STM32 µC. I use the SW4STM32 workbench and CubeMX on a Mac OSX system. My project itself is fine, everything compiles accordingly and behaves on the device as expected.
For a further learning purpose, I would like to implement unit tests using the CppuUTest framework. I have set up everything, got my test directories and a makefile to configure the MakefileWorker variables in place.
However, when executing the Makefile, I keep getting the error:
error:
register 'sp' unsuitable for global register variables on this target
This error originates from the file syscalls.c (which is a file generated by CubeMX). The line causing the error is:
register char * stack_ptr asm("sp");
After doing my research, it seems like there is no easy workaround to solve the issue. The source code is generated by Cube and works fine when compiling with the sw4stm32 toolchain (which is using a mcu gcc compiler).
However, the CppUTest toolchain is using clang, which cannot cope with global register variables (as the error says aswell).
My question here ist:
Has anyone of you had the same error yet or more experience in setting up CppUTest for a sw4stm32 project on an OSx system? Does anyone have an idea how to solve this problem?
If you need more information / code snippets from me, I will gladly share it.
Thank you very much guys! Any help would be highly appreciated :-)
Cheers,
Tobi

Why cannot Simulink find/run precompiled mexw64 files of the toolboxes?

I want to run a Simulink model in real time. So I need the Real time sync block in "Simulink desktop real time" (sldrt) toolbox working. It seems to be correctly installed, also in path. But I always get the error:
Error in S-function 'real_time_test/Real-Time Synchronization': Unable to acquire handle to MATLAB function 'sldrtsync'
Component:Simulink | Category:Blockerror
This error occurs also with the Desktop real time example _sldrtex_vdp_ also see my minimal example that I cannot get working..
In the sldrt directory there are two files:
sldrtsync.mexw64
sldrtsync.tlc
This path is also included in Matlab Path.
API: Win7 64bit
Matlab R2016b
Windows SDK 7.1
Where to look for the solution?

Publish Procedure Failed - Simulink code generation with TwinCAT Target file

I would like to develop an application in Matlab/Simulink which will be integrated in TwinCAT by TcCOM modules (code generation with TwinCAT.tlc target file).
I have some problems in the PUBLISH PROCEDURE!!!
First of all, I have to mention that I passed through all the steps mentioned in the TwiCAT – Simulink Handbook (see on page 9: https://download.beckhoff.com/download/document/automation/twincat3/TwinCAT_3_Matlab_Simulink_EN.pdf ). The next steps are accomplished:
Matlab R2015b is installed;
TwinCAT 3 is installed and embedded in Visual Studio 2013;
Microsoft Windows Driver Kit is installed (WinDDK 7600.16385.1)
Twincat 3 Target for Matlab/Simulink (TE1400) is installed and embedded in Matlab;
The necessary licenses are activated;
The application is very basic, it has an INPUT and an OUTPUT block, a SUM and a CONSTANT block.
The Simulink model have been configured as:
Solver: Fixed Step solver (ode3) with 0.005 fixed-step size;
Code Generation: TwinCAT.tlc System target file;
Code Generation -> Tc Build: Publish Module CHECKED
When I try to Build Model, Simulink returns the next error message:
‘Publish Procedure Failed – MGFcn:43’
and
'error MSB3231: Unable to remove directory'
If you need, I can attach the .txt file with the errors.
If I leave the Publish Module UNCHECKED, Simulink generates C++ code without errors. But, I need to have TcCOM modules.
I hope that I delivered all the necessary information.