Arduino Shared Cross-Platform Code And Library Development

by Visual Micro 16. January 2017 14:09

news: april 2017 - this functionality is free and in all version from vs2015+

related: shared single code files between projects

Visual Micro makes special use of Visual Studio C++ Shared Projects for both project and library development. C++ shared projects were released in Visual Studio 2015 and are improved in the soon to be released Visual Studio 2017.

Use "File>New>Project>C++>Arduino Library Project" to create a new library project or the "Add Library" menu to create from existing library code. When creating a project from existing library code, the code remains unchanged and compatible with the Arduino IDE. 

There are two types of shared projects that Visual Micro supports. It is important to understand the difference. Shared "library" projects that contain an Arduino format library.properties text file in the project root are compiled as Arduino Libraries. Shared "code" projects do not contain a library.properties text file. During compilation of shared code projects, the code is merged with the main project code in the temp build folder. In this case the code can be accessed as if it was within the folder structure of the main project.

Multiple main projects can use the same shared project(s). Intellisense in shared projects is powered by the current "Startup Project". A shared project can not be compiled directly, can not be a Startup Project and does not have a fixed platform.

tip: Adding a new library project to an official Arduino library folder will automatically make the library available for use in the Arduino IDE.

Shared projects can be created using the standard Visual Studio new project wizard.

Visual Micro also provides a simple way to create a shared project for an existing Arduino library.

Shared projects that contain an Arduino library.properties in the root folder are considered to be Arduino Libraries. If the library.properties file does not exist the shared project is considered part of the main project.

The "References" node of a Visual Studio project enables shared projects to be referenced by a master project.

Some of the magic of shared projects is that they do not have a specific architecture. Instead the architecture (intellisense etc) is taken from the "Startup project" of the current Visual Studio solution.

This enables us to develop cross-platform code whilst benefiting from intellisense for a specifc architecture. in fact VS2017RC takes this a step further but that's for another blog.

Using a shared library project is no different to using normal Arduino libraries. In fact they are normal arduino libraries except they also have a .vcxitems file in the library root which simply allows Visual Studio to show the source code during development (in a solution).

Shared library projects must be #included in the code in the same way as a normal Arduino library. The fact that we are using a shared project for development has no bearing on the compilation. The compliation works as normal and compiles the library as it does for all other libraries.

A useful difference between a shared library project and a normal library is that Visual Micro can find the library in any location, not just the published known Arduino library locations. This has many benefits for source control and also versioning.

It is possible to create a shared library project and add it to a solution with a single click.

All users must add a reference to the shared project to the master project(s). Right click the "References" node of a master project in the solution explorer to add the reference to the Shared Project (library). This ensure the intellisense of the shared project will know the correct architecture.

Below are the images of the steps for paid Visual Micro users:-

1) Paid users should switch on "Create a project when adding libraries

 

2) Add a library to a project in the usual manner.

If the project already uses the library it will not cause an issue. If the lib headers are not required in the .ino file you can remove them.

3) After adding a library, the headers will be inserted into the .ino code as usual. In addition, a new project (with the same name of the library) will be added to the currently open solution (if the library project does not already exists in the solution)

So that intellisense can detect the correct platform, a reference is added to all master projects in the solution that use the library.

Right click the References node of a master project and then click "Add Reference"

4) When the Add Reference window opens, cick the "Shared Projects" tab and put a check mark against the library project(s) you want to use in the current master project.

 

Arduino Defines - Configuration/Project Now Supports {build.properties}

by Visual Micro 21. September 2014 09:39
These project properties can now include merge field expressions that make use of any of the build properties.

This example makes the upload COM port available to the code as a #define called myport

myport {serial.port}

tip: All build properties can be viewed during compilation by switch on "tools>options>visual micro>compiler>show build properties"

 

Maple Leaflabs and STM32 for Visual Studio

by Visual Micro 27. August 2013 14:30

Warning: Our impression of the Maple Ide is that it is not yet as mature as some of the other solutions and the usb drivers stop working frequently. Maple has been added to the free plugin and the debugger by user request. Our personal option is that Maple is not very easy to use or support and might lead to fustration for less experienced users.

14th Jan 2013: Apparently build and upload now fully supported for maple REV6 boards (thanks Yuri). Debug trace/break is supported. Other maple ide boards have not been tested. We would appreciate feed back to the forum from experienced users. 

Our Personal Maple Observations and Tips

When working with Maple SerialUSB in your code and also using the debugger please read these important tips

On windows 7 64 bit we found that the leaflabs serial port would periodically stop working. We have not tested other versions of windows

On windows 8 the Maple usb can completely disappear.

Maple authors have announced reduced support for windows

The Maple IDE can be downloaded from here

To install the usb drivers from the maple ide folder, win8 users will need to switch to allowing unsigned usb driver installation

 

Stm32 Usb Debug - Trace Mode

To use Leaflabs compatible hardware with Visual Micro please download the Maple Ide

Known Debugger Issue on Stm32 (will be resolved asap)

The Hit Count >= settings can be used at the moment with Stm32 because it does not initialize variables correctly when in the Global space.


For example:

unsigned long myLong1 = 0L;
bool myBool = 0;

void setup() {
}

The example above will result in garbage in all bits except the first

unsigned long myLong1;
bool myBool;

void setup() {
myLong1 = 0L;
myBool = 0;
}

The example above would result in all bits being cleared and correct values of zero

Energia IDE for Visual Studio

by Visual Micro 2. August 2013 16:33

August 2016 - Energia 1.6 Release w/ Board Manager and Library Manager

Important Installation Bullets

  • This documention is in the process of being rewritten and updated. Energia is support in Visual Studio 2-12 to the latest v15. Gdb debug is currently only supported in Visual Studio 2015 although might work in the new version v15
  • note: Microsoft have shortened the Visual Studio version number and aligned with their internal version numbers. This is why the latest version is called 15, when the previous version was called 2015. It's going to be a bit confusing for a year or so.
  • Install Tip: Visual Studio 2015 and above, the C++ compiler is optional during installation. Energia and Arduino use C++ so you need to make sure C++ is installed. If you didn't install c+ when VS was installed then update via "control panel>add or remove programs>visual studio>change>custom". And while you doing that install the Android Tools for Visual Studio so you can try the GDB debugger.
  • Download the Energia IDE - Arduino Compatible. Texas Instruments Quality.

Review of Tiva C Series 123G

I don't sell hardware at visualmicro.com and don't benefit from recommending hardware. I just post about the things that we have personally found impressive which is rare :)

The Tiva C Series is certainly the best workhorse I have seen for years. Flexible, fast, accurate, well designed, well packaged and at a fraction of the cost of significantly inferior boards.

I paid $15 USD for my board from a retailer! I have never seen a program build and upload so quicky. Impressive. Never seen GDB debugging launch so quickly.

Code Sample - Change the LED color

//RED

analogWrite(PF_1, 700);

//GREEN

analogWrite(PF_2, 250);

//BLUE

analogWrite(PF_3, 50);

 

Example Features

The ARM Cortex-M4F Based MCU TM4C123G LaunchPad Evaluation Kit (EK-TM4C123GXL) offers these features:

  • High Performance TM4C123GH6PM MCU:
    • 80MHz 32-bit ARM Cortex-M4F CPU
    • 256KB Flash, 32KB SRAM, 2KB EEPROM
    • Two Controller Area Network (CAN) modules
    • USB 2.0 Host/Device/OTG + PHY
    • Dual 12-bit 2MSPS ADCs, motion control PWMs
    • 8 UART, 6 I2C, 4 SPI
    • Ultra Bright RGB LED (Analog Pins: PF_1, PF_2, PF_3)
    • 2 x User Buttons SW1/SW2
  • On-board In-Circuit Debug Interface (ICDI)
  • USB Micro-B plug to USB-A plug cable
  • Preloaded RGB quick-start application
  • ReadMe First quick-start guide

You can try the debug for the 123 and 129 boards in the cureent release of Visual Micro. In the next release the following settings are automatically applied based on selected board but here is how to manually configure.

If you are using the paid/pro version add one of these properties to the local project board.txt. Make sure the Andoid Tools for Visual Studio are installed which means you have a gdb debugger installed. then press "F5" or "Debug>Start Debugging".


#LaunchPad (Tiva C) w/ tm4c123 (80MHz)
build.openocdscript=board/ek-tm4c123gxl.cfg

OR (depending on your board model)

#LaunchPad (Tiva C) w/ tm4c129 (120MHz)
build.openocdscript=board/ek-tm4c1294xl.cfg

note to existing users. visual micro .vcxproj project files created prior to 22 of July 2016 will show an error when attempting to start gdb. A simple fix adding two lines into older vcxproj files is described in the draft GDB Debugging release notes (alternatively the project can be deleted and the sketch re-opened which recreates the project file backup the project before deleting).

  • Tiva™ C Series TM4C123G LaunchPad

 

 

msp430 (LaunchPad)

The Energia installation guide provides most of the information that you require. It can be found here

If upload fails after install we can view "windows device manager" to determine if you have unknown devices showing (after connecting your board). LaunchPad 430 usb drivers are available via the getting started link above but can also be found here

Stellaris (StellarPad)

When we plugged a StellarPad into a windows 7 64 machine we found that in device manager there were 3 "debug" drivers showing with yellow exclaimation marks.

Attempts to upload a program to the board failed with this error:-

Error claiming interface -12

Failed!

The solution was to update the driver for each of the 3 entries using the TI drivers available here

Options: Visual Micro + USB or GDB Debugging