Jump to content
Sign in to follow this  
sportq

One sketch multiple architectures

Recommended Posts

This is probably an FAQ but I can't find the answer anywhere - sorry.

 

I have several Launchpads, an MSP430, TM4C123 and a TM4C129. I have the same sketch that I'd like to target at each of them but since the pin names are different for each of them I need to edit the sketch repeatedly or have three different copies (well two really for the MSP/ARM types).

 

I'm guessing there's already macro defined somewhere so I could do something like:

 

#ifdef MSP430

int pin=P1_0;

#endif

 

#ifdef TM4C123 || TM4C129

int pin=PB_5;

#endif

 

....and choosing the correct board from the drop down menu in energia will set the appropriate macro.

 

Do these exist and if so where are they documented? Apologies if the answer is obvious.

 

Peter

Share this post


Link to post
Share on other sites

Here's a reasonable set of #ifdef's to try.

 

#ifdef __MSP430_HEADER_VERSION__

// MSP430 definitions

#endif

 

#ifdef TARGET_IS_BLIZZARD_RB1

// Tiva-C TM4C123 and/or Stellaris LaunchPad definitions go here

#endif

 

#ifdef TARGET_IS_SNOWFLAKE_RA0

// Tiva-C TM4C129 Connected LaunchPad definitions go here

#endif

Share this post


Link to post
Share on other sites

I personally go with using the numeric value instead, you will have to change the numbers for each board anyway as the capabilities are not the same on all boards. I have run the same sketch between an MSP430, stellaris launchpad and an arduino mega quite a few times but each time have had to change which pins are used for different functions. I personally put all pin declarations at the top of my sketch where they are easily accessible.

Share this post


Link to post
Share on other sites

What do you intend to do? You can use pin numbers instead of port mappings, but not all devices share the same capabilities on the same numbered pins.

 

I can live with completely different pin numbers between launchpads, I just don't want to have change the file or maintain different copies for different target platforms.

 

Even pin numbers are good way forward as I would #define them into meaningful names at the top of the sketch.

 

Thanks all!

 

Peter

Share this post


Link to post
Share on other sites

Here's a reasonable set of #ifdef's to try.

 

#ifdef __MSP430_HEADER_VERSION__

// MSP430 definitions

#endif

 

#ifdef TARGET_IS_BLIZZARD_RB1

// Tiva-C TM4C123 and/or Stellaris LaunchPad definitions go here

#endif

 

#ifdef TARGET_IS_SNOWFLAKE_RA0

// Tiva-C TM4C129 Connected LaunchPad definitions go here

#endif

 

The MSP430 macro works, but the two Tiva-C ones don't. Are these targets listed in a header file somewhere?

 

Peter

Share this post


Link to post
Share on other sites

The MSP430 macro works, but the two Tiva-C ones don't. Are these targets listed in a header file somewhere?

 

Peter

From Energia.h... odd. You had the right board selected?

 

Sent from my Galaxy Note II with Tapatalk 4

Share this post


Link to post
Share on other sites

I had a similar question, to which I have found only partial solution.
http://forum.stellarisiti.com/topic/1965-architecture-for-conditional-compilation-in-energia/
 
In addition to the macros mentioned above in this thread, there are:
ENERGIA - Defined by the environment
__MSP430_CPU__ - Another way of detecting MSP430
__arm__ - Should be true for any ARM processor (e.g. Tiva, Stellaris, CC3200, SAM, STM32, Freescale, ... )
__AVR__ - Atmel AVR processors (original Arduino, etc.)
 
Processor specific macros, such as:
__LM4F120H5QR__
 
Problem with the TARGET_IS_SNOWFLAKE_RA0 style of macros is they refer to particular versions of the silicon.
So when they come out with production versions, will have to add extra macros.
(Similar problem to using the processor specific macros, just a little more esoteric.  People are more likely to notice
if they are using a different processor than the one specified, vs. using a different silicon revision.)
 
Anybody know of a complete catalog of macros for identifying the environment and processor in various Arduino ports?
This covers several environments
http://embedxcode.weebly.com/manage-code-for-multiple-platforms.html
 
but does not cover TeensyDuino, Arduino Galileo (Intel).
 
How do you identify CC2000 in Energia?
 
Would be nice if Energia defined a macro to distinguish, say Tiva processors, without having to do a list of all of them.  Likewise for CC3200.
Likewise would be nice if there were an easy way to distinguish Atmel SAM/Atmel Software Framework, STM32, etc. (as groups, rather than individual processors).
 
I have been using this snippet in a library that runs on AVR or Tiva.  It defines __TIVA__, so I can use that in conditionals throughout the code.
 

#if defined(ENERGIA)

#if defined(__arm__)

#ifndef __TIVA__

#if defined(__TM4C129XNCZAD__) || defined(__TM4C1294NCPDT__) || defined(__LM4F120H5QR__) || defined(__TM4C123GH6PM__)

#define __TIVA__

#else

#error "**** Unrecognized ARM processor ****"

#endif

#endif //__TIVA__

#endif

#endif // ENERGIA

 
 
Still looking for,
One macro to rule them all, One macro to find them; One macro to bring them all and in the darkness bind them.

Share this post


Link to post
Share on other sites

FTFY,

 

One macro to rule them all, One macro to find them; One macro to bring them all and in the compiler bind them.

Share this post


Link to post
Share on other sites

From Energia.h... odd. You had the right board selected?

 

Yep, switched the boards back and forth several times. MSP always works, the Tiva boards aren't detected.

 

Peter

Share this post


Link to post
Share on other sites

Yep, switched the boards back and forth several times. MSP always works, the Tiva boards aren't detected.

 

Peter

 

Strange, I tried the following sketch in Energia 0101E0012 for Windows.

#include <Energia.h>

#ifdef TARGET_IS_SNOWFLAKE_RA0
#warning Let it snow!
#elif defined(TARGET_IS_BLIZZARD_RB1)
#warning Lots of snow.
#endif

When I set the board to Launchpad (Stellaris) or Launchpad (Tiva C) or,

Launchpad (Tiva C) with 1294, in Energia, and then compiled - it gave the expected message.

 

Energia.h also defines macros like PART_TM4C1294NCPDT - you might check to see if they are getting defined.

Share this post


Link to post
Share on other sites

 

Strange, I tried the following sketch in Energia 0101E0012 for Windows.

#include <Energia.h>

#ifdef TARGET_IS_SNOWFLAKE_RA0
#warning Let it snow!
#elif defined(TARGET_IS_BLIZZARD_RB1)
#warning Lots of snow.
#endif

When I set the board to Launchpad (Stellaris) or Launchpad (Tiva C) or,

Launchpad (Tiva C) with 1294, in Energia, and then compiled - it gave the expected message.

 

Energia.h also defines macros like PART_TM4C1294NCPDT - you might check to see if they are getting defined.

 

Tested the above code, also on Windows 7, and I get nothing with the board set tm4c123 or tm4c129 in the drop down list.

 

I tried adding an unconditional #warning and still got nothing from in the output from the compilation though!

 

Peter

Share this post


Link to post
Share on other sites

Update - I found incantation for checking for TeensyDuino.

 

#if defined(CORE_TEENSY)

You can differentiate teensies further by testing for __AVR__ vs. __arm__ (Teensy 3+)

 

 

--

 

@@sportq You might try replacing the #warnings with #errors.

Some of the platforms seem to suppress gcc's warning messages.  (e.g. Arduino will not display warnings).

Share this post


Link to post
Share on other sites

Just stumbled across yet another variant - this appears to be for the future (from Arduino IDE 1.5: Library specification 

https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification which is still in beta)

 

ARDUINO_ARCH_XXX

where XXX specifies the architecture

 

The draft only mentions architectures AVR and SAM (Atmel ARM), does not say what name they give to the Galileo architecture

ARDUINO_ARCH_AVR

ARDUINO_ARCH_SAM

Share this post


Link to post
Share on other sites

Galileo/Intel x86 architecture:

__ARDUINO_X86__

 

In Arduino 1.5.7 Beta also defining board identifiers

ARDUINO_SAM_DUE - Arduino Due

ARDUINO_AVR_YUN - Arduino Yun
etc. - Similar for a bunch of the AVR based Arduinos.
 
I am not sure if the first part is always Arduino, or if it is intended to depend on the company behind the board (or the environment).
 
Looks like CC3200 has the macro __CC3200R1M1RGC__ for the individual chip.
Does Energia define anything for the entire CC3200 family (in case they ever release updated/related chips)?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...