Compile and load blink to teensy3.1without ardunio but don't working

Status
Not open for further replies.

mkunal

Member
i compile blink program (main.cpp with make.exe ) without ardunio and load main.hex with teensyloader succesfully.
But teens3.1 don't work or blink . i copy all files to folder C:\blink (except *.c and *.cpp files)
and copy two *.ld files to C:\blinky\teensy folder , main.cpp is in C:\blink .

What can i do ? .

main cpp :

#include "WProgram.h"

extern "C" int main(void)
{
#if !defined(ARDUINO)

// To use Teensy 3.0 without Arduino, simply put your code here.
// For example:

pinMode(13, OUTPUT);
while (1) {
digitalWriteFast(13, HIGH);
delay(500);
digitalWriteFast(13, LOW);
delay(500);
}


#else
// Arduino's main() function just calls setup() and loop()....
setup();
while (1) {
loop();
yield();
}
#endif
}


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

my makefile :



# The name of your project (used to name the compiled .hex file)
TARGET = main

# configurable options
OPTIONS = -DF_CPU=72000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH


#************************************************************************
# Location of Teensyduino utilities, Toolchain, and Arduino Libraries.
# To use this makefile without Arduino, copy the resources from these
# locations and edit the pathnames. The rest of Arduino is not needed.
#************************************************************************

# path location for Teensy Loader, teensy_post_compile and teensy_reboot
#TOOLSPATH = ../../../tools # on Linux
TOOLSPATH = C:\Program Files\Arduino\hardware\tools
# on Mac or Windows

# path location for Arduino libraries (currently not used)
LIBRARYPATH = C:\Program Files\Arduino\libraries

# path location for the arm-none-eabi compiler
COMPILERPATH = C:\Program Files\Arduino\hardware\tools\arm-none-eabi\bin

#************************************************************************
# Settings below this point usually do not need to be edited
#************************************************************************

# CPPFLAGS = compiler options for C and C++
CPPFLAGS = -Wall -g -Os -mcpu=cortex-m4 -mthumb -nostdlib -MMD $(OPTIONS) -I. -Iteensy/

# compiler options for C++ only
CXXFLAGS = -std=gnu++0x -felide-constructors -fno-exceptions -fno-rtti

# compiler options for C only
CFLAGS =

# linker options
LDFLAGS = -Os -Wl,--gc-sections -mcpu=cortex-m4 -mthumb -Tteensy/mk20dx256.ld

# additional libraries to link
LIBS = -lm


# names for the compiler programs
CC = $(COMPILERPATH)/arm-none-eabi-gcc
CXX = $(COMPILERPATH)/arm-none-eabi-g++
OBJCOPY = $(COMPILERPATH)/arm-none-eabi-objcopy
SIZE = $(COMPILERPATH)/arm-none-eabi-size

# automatically create lists of the sources and objects
# TODO: this does not handle Arduino libraries yet...
C_FILES := $(wildcard *.c) \
$(wildcard $(addprefix teensy/, *.c)) \
$(wildcard $(addprefix teensy/util, *.c)) \
$(wildcard $(addprefix teensy/avr, *.c))
CPP_FILES := $(wildcard *.cpp) \
$(wildcard $(addprefix teensy/, *.cpp)) \
$(wildcard $(addprefix teensy/util, *.cpp)) \
$(wildcard $(addprefix teensy/avr, *.cpp))
OBJS := $(C_FILES:.c=.o) $(CPP_FILES:.cpp=.o)


# the actual makefile rules (all .o files built by GNU make's default implicit rules)

all: $(TARGET).hex

$(TARGET).elf: $(OBJS) teensy/mk20dx256.ld
$(CC) $(LDFLAGS) -o $@ $(OBJS)

%.hex: %.elf
$(SIZE) $<
$(OBJCOPY) -O ihex -R .eeprom $< $@
$(TOOLSPATH)/teensy_post_compile -file=$(basename $@) -path=$(shell echo %cd%) -tools=$(TOOLSPATH)
-$(TOOLSPATH)/teensy_reboot


# compiler generated dependency info
-include $(OBJS:.o=.d)

clean:
del *.o
del *.d
del $(TARGET).elf
del $(TARGET).hex
del $(CURRENT_PATH)\teensy\*.o
del $(CURRENT_PATH)\teensy\*.d
 
thanks ;
i install Atmel Studio 6.2 , ArduinoForVisualStudio and write example ADC program .i can compile this program in ardunio 1.0.5 and work but in atmel studio give this error :

Compiling 'adc4' for 'Teensy 3.1'
adc4.ino:In function 'void loop()'
adc4.ino:79:9: error: 'RawHID' was not declared in this scope
:while(RawHID.send(buffer, 0)){
:^
Error compiling

i edit usb_rawhid.h in project directory ( removed the #if defined(USB_RAWHID) and the corresponding #endif. ) and add
#include "usb_rawhid.h" in code but this time error is :

Compiling 'adc4' for 'Teensy 3.1'
adc4.cpp.o:In function `usb_rawhid_class::send(void const*, unsigned short)'
usb_rawhid.h:undefined reference to `usb_rawhid_send'
collect2.exe*:error: ld returned 1 exit status
Error creating .elf

what must i do ? ,
Thanks . .


--------------------------------------------------------------------------------------------------
my program :

int a=0;
byte buffer[64];
byte buton[8];
IntervalTimer myTimer;
const int ledPin = 13;
volatile unsigned long count = 0;
const int numButtons = 8;
int val,v0,v1,v2,v3,v4;
double v,k=(3.3/4096.0);

void setup()
{ buffer[0] = 0xAB;
buffer[1] = 0xCD;
for( int i=2; i<62;i++){
buffer= 0;}
Serial.begin(115200);

analogReadResolution(12);
pinMode(ledPin, OUTPUT);
for (int i=0; i<numButtons; i++) {
buton=0;
pinMode(i, INPUT_PULLUP);}
myTimer.begin(blink, 1000000);
}

void blink(void) {

Serial.print(a);
Serial.print("-->");
Serial.print(count);
count=0;
a++;
Serial.print("->");
Serial.print("V= ");
Serial.print(v0);
Serial.print(" Volt= ");
Serial.print(v,4);
Serial.print(" Data -> ");
Serial.print(buffer[62],BIN);
Serial.print("+");
Serial.print(buffer[63],BIN);
Serial.print(" butons ->");
Serial.print(buffer[61],BIN);
Serial.print(" -");
for(int i=0; i<numButtons; i++){
Serial.print(buton);}
Serial.println("-");

digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(50);

}

void loop()
{

noInterrupts();
v0 = analogRead(2);
buffer[62] = 0x00FF&(v0>>8);
buffer[63] = 0x00FF&v0;
interrupts();
v=k*v0;
v1 = analogRead(1);
v2 = analogRead(2);
v3 = analogRead(3);
v3 = analogRead(4);

buffer[61]=0;
for(int i=0; i<numButtons; i++){
buton=!digitalRead(i);
buffer[61] +=(!buton); }


while(RawHID.send(buffer, 0)){
count++;
break ; }

}
 
Last edited:
if Visual Micro plug-in = Arduino IDE for Microsoft Visual Studio
yes i did and my code starting ":" or :
but again various errors appear . . .
 
if Visual Micro plug-in = Arduino IDE for Microsoft Visual Studio
yes i did and my code starting ":" or :
but again various errors appear . . .
We're not communicating here - language barrier.
You said you do not want to use the Arduino IDE.
I suggested you download and use Atmel Visual Studio. And also download and use the Visual Micro plug-in for Visual Studio, from visualmicro.com

Then begin using some of the examples in the Arduino collection. Or other places. Do not try to write your own code until you understand the examples.
 
View attachment mkunal.ino

I cut/paste your unformatted code from above, into VS/VM. Reformatted it. See enclosure. Only the .ino is enclosed - not the VS/VM project files.
The only compilation error I get is at line 86, where RawHID is not declared.

I added indentation for code blocks per customary format. I moved the open/close braces where they should be.
I commented on the code that there is no use of local variables - all are global. That's OK for a beginner, but not a habit you want to keep.
I commented that you could/should look at eliminating the floating point for the sake of speed and memory space. But that can wait.

I did not pore over the code's algorithm or details for correctness.

Please, you need to comment your code for others and for yourself in the future when you can't make sense of bare naked code.
 
Last edited:
@mkunal,

I am not sure why you want to use a make file to compile code instaed of using the Arduino IDE. It is aimed at beginners. Once your skills have improved and you have a better grasp of things then you can upgrade to a more full fledged IDE as suggested by stevech.

Using a make file is more meant for users that want to program bare metal and know what they are doing. That includes being comfortable with compiler options and general tool chain issues.
 
Last edited:
Agree, makefile is too painful for noobie. And you said for some reason you didn't want Arduino's IDE.

Maybe you are in a self-learning situation but without meeting the prerequisites.

So as said above, you should use Arduino or simple Teensyduino examples to understand fully what the example code does, and how to use the IDE (Arduino or VS/VM or whatever).

Do some reading of tutorial books on C then C++. Study other's code. Ensure you understand the engineering process - which does NOT begin with coding.
 
Status
Not open for further replies.
Back
Top