I want to build and simulate a C++ project for Cortex-M4, using the g++ arm compiler, in Arm Dev Studio.
Which example would be suitable as a template please?
Hello David,
Is the issue specifically that printfs are not working? Have you enabled semihosting in your code? The below article (not written by Arm) may be useful:
https://interrupt.memfault.com/blog/arm-semihosting
Hi Ronan,
Thanks for your reply. To be honest, I'm not sure that the problem is as simple as enabling semi-hosting, there is the issue of C++ startup to consider.
I'm new to ARM and am rather to surprised to find that there appear to be no examples in ARM Dev Studio of developing with C++; everything seems to be for 'C'. I've tried selecting C++ in the new project wizard but that seems to generate very simple 'Hello world' examples with no C++ startup code.
Do you have any suggestions for a starting point please?Best regards
David
Hi David,
I'm not overly familiar with g++, but using armclang, there is little difference between using C and C++. The initialization code should take care of everything.
Note that C++ has a significantly larger init code, which may be an issue if using a contrained MCU, which is why C is used more often than C++, but that is a side issue.
Looking again at the history above, I note that you have '#if 0'd out the code to enable the FPU, though your code may assume it is enabled. Set a breakpoint on your code for _fp_init and single step through that function. Is that what is causing the error?
Looking at the structure of the example you are using to build from, copying this $Sub#_lib_rt_init code into the scs.c file should bring that in. Alternatively, disable FP by compiling with:
-mcpu=cortex-m4 -mfpu=none -mfloat-abi=soft
Stephen suggested the use of CMSIS. This contains all the necessary init code, including device specific code if working with an MCU. I created a simple example (attached), that builds and runs a C++ example I found online on the supplied FVP.
CMSIS_cpp.zip
Hi Ronan and StephenThanks very much for your answer Ronan. In line with your suggestion, I am now trying to use CMSIS and thought it best to try to run the CMSIS-RTOS2 Blinky example that Stephen suggested.
I have successfully imported it and built it. Please will you explain how I can run it in ARM Dev Studio?
Best regards
I assume you imported the uVision Simulator version of the Blinky example. This is configured by default for Cortex-M3. If you wish to change it for Cortex-M4, open the .rteconfig file. and go to the Device Tab, and click Change, and select ARMCM4(_FP) (if floating point desired). The example I attached yesterday may be easier to consume.To run, select Fiile > New > Model Connection, and give it a meaningful name. Also recommend associating with the project for ease of file management. In next pane, select MPS2_Cortex-M4 from the FVPs (Fixed Virtual Platforms) installed with Arm DS. Finally, in the Files tab, navigate to the .axf built in the Workspace, and in Debugger tab, Debug from main (or entry point), Click debug, and the model will launch and load the code (to repeat, you will be able to just double click on this connection in the Debug Connections pane).
Thanks, I have successfully built the Blinky example and created a debug connection for it. Please will you remind me what I need to do to see the printf output in the Target Console?
If you have time, I would be grateful for steps to add C++ source file.Best regards
This one had me scratching my head for a moment...
I found the default build setting is to send printf (stdout) to Event Recorder, which is a Keil MDK feature for instrumentation.
Open the .rteconfig file, and disable this setting in Compiler > I/O, to use the default (semihosting) stdout.
Rebuilt, and I do indeed see the output in the Target Console:
Iris server started listening to port 7100 telnetterminal0: Listening for serial connection on port 5000 telnetterminal1: Listening for serial connection on port 5001 telnetterminal2: Listening for serial connection on port 5002 Iris server is reported on port 7100 LED On: #0 LED On: #1 LED Off: #0 LED On: #2 LED Off: #1 ...
To add a C++ file, this is not straight forward in this case. I don't think there is an option to change a C project to a C/C++ project. If you are just adding a single C++ source file, you can right click on that file, and in Properties > Tool Chain Editor, select the C++ compiler. You then need to go to Settings and enter compatible build options for the C builds. This will only apply to this source file, so isn't very scalable :(
The easiest solution (sorry) is to create a New > Project > C/C++ > C++ Project > CMSIS C/C++ Project, and then copy over the Blinky.c source file. You will need to setup the generated .rteconfig file the same way as it was for the previous project, but that is fairly straight forward from the GUI (and is likely do-once operation).