#define for cortex m4 ?

Status
Not open for further replies.

Frank B

Senior Member
Hi,

i'm searching a define like "#define CORTEX_M4".

I'd like to find out which cpu is used at compile time.

Thanks in advance...!
 
For the Teensy 3.0, __MK20DX128__ is defined. For Teensy 3.1, __MK20DX256__ is defined.

Both __arm__ and CORE_TEENSY are defined for the Teensy 3.x environment.
 
So...

I what case do you use which of the defines ?
Or in other word what defines the different defines ? :confused:
 
I was looking for a more general define that says if a cpu has dsp-functions.

i will use __MK20DX128__ and __MK20DX256__

thanks !
 
So...

I what case do you use which of the defines ?
Or in other word what defines the different defines ? :confused:
The defines are done in the hardware/teensy/boards.txt file and the standard header files provided by the Teensy distribution.

I run my code on several different microprocessors that use the Arduino environment (Teensy 3.0, Uno R3, Trinket, Gemma, Digispark, raw ATtiny85 and eventually Sparkfun Pro Mini and DigiX) to modify the code for different pin assignments, and to remove code on microprocessors that isn't supported (such as all of the serial debug statements in the ATtiny85 environment).

For example, here is part of my Meissner_Config.h file that sets up the various definitions:

Code:
#ifndef MEISSNER_CONFIG_H
#define MEISSNER_CONFIG_H	1

#include <stddef.h>
#include <stdlib.h>
#include <inttypes.h>

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"

#else
#include "WProgram.h"
#include "WConstants.h"
#endif


// Target machine conditionals:
#if defined(__arm__) && defined(CORE_TEENSY)
#define PROCESSOR_TEENSY_3_X	1		// run on Paul Stoffregen's ARM Cortex M4 based teensy 3.0/teensy 3.1

#ifdef __MK20DX128__
#define PROCESSOR_TEENSY_3_0	1
#endif

#ifdef __MK20DX256__
#define PROCESSOR_TEENSY_3_1	1
#endif

#elif defined(__AVR_ATmega328P__)
#define PROCESSOR_UNO_R3	1		// run on an Arduino Uno R3

#elif defined(__SAM3X8E__)
#define PROCESSOR_DUE		1		// run on Digistump's digiX (or Arduino Due)
#define PROCESSOR_DIGIX		1

#elif defined(__AVR_ATtiny85__)
#define PROCESSOR_ATTINY85	1		// run on ATtiny85 devices (trinket, gemma, digispark)
#define PROCESSOR_TRINKET	1
#define PROCESSOR_GEMMA		1
#define PROCESSOR_DIGISPARK	1
#define NO_SERIAL		1
#define NO_SERVO_H		1
#define NO_WIRE_H		1

#else
#define PROCESSOR_UNKNOWN	1		// something else
#endif


// Pins used on the different processors

// On board LED
#if defined(PROCESSOR_ATTINY85)
const uint8_t PIN_LED			= 1;
#else
const uint8_t PIN_LED			= LED_BUILTIN;
#endif

// I2C pins
#if defined(PROCESSOR_ATTINY85)
const uint8_t PIN_SDA			= 0;
const uint8_t PIN_SCL			= 2;

#else
const uint8_t PIN_SDA			= SDA;
const uint8_t PIN_SCL			= SCL;
#endif

// Pin for programming the NeoPixel
// Pin 1 has the bulitin LED on Trinket/Gemma/Digispark, and
// is the only pin that does not interfere i2c on the Gemma
#if defined(PROCESSOR_ATTINY85)
const uint8_t PIN_NEOPIXEL		= 1;

#else
const uint8_t PIN_NEOPIXEL		= 4;
#endif

// Possibly unused analog pin for setting random numbers
#if defined(PROCESSOR_TEENSY_3_X)
const uint8_t PIN_RANDOM		= A13;

#elif defined(PROCESSOR_ATTINY85)
const uint8_t PIN_RANDOM		= 2;

#else
const uint8_t PIN_RANDOM		= A3;
#endif

// Unused pin for the tindie 128x64 OLED display
#if defined(PROCESSOR_TEENY_3_X)
const uint8_t PIN_UNUSED		= 29;

#else
const uint8_t PIN_UNUSED		= PIN_RANDOM;
#endif

// other stuff
#endif /* MEISSNER_CONFIG_H */
 
Ah. Thanks for that!
I have used __MK20DX128__ and others but was not sure for example in what case to use CORE_TEENSY vs __MK20DX128__ .
However, you code makes that very clear! Great stuff!
 
Status
Not open for further replies.
Back
Top