{"id":1489,"date":"2013-01-09T19:57:15","date_gmt":"2013-01-09T22:57:15","guid":{"rendered":"http:\/\/wordpress.matbra.com\/?p=1489"},"modified":"2013-01-09T19:57:15","modified_gmt":"2013-01-09T22:57:15","slug":"compilando-para-teensy-3-0-no-windows-utilizando-makefile","status":"publish","type":"post","link":"https:\/\/wordpress.matbra.com\/en\/2013\/01\/09\/compilando-para-teensy-3-0-no-windows-utilizando-makefile\/","title":{"rendered":"Compile to Teensy 3.0 on Windows using Makefile"},"content":{"rendered":"<p>Good Night,<\/p>\n<p>If you don&#8217;t want to use Arduino IDE (Or Teensy IDE? \ud83d\ude09 to programming and uploading your code to Teensy 3.0 you can use Makefiles.<\/p>\n<p>The last IDE version can be found on  <a href=\"http:\/\/forum.pjrc.com\/forums\/6-Announcements\" target=\"_blank\">PJRC Forum <\/a>. As he said in the Beta 10 version, there is an Makefile example on &#8220;arduino-1.0.3\\hardware\/teensy\/cores\/teensy3&#8221; but to use it you need to add the arm binaries to your system path. To do this, open your command prompt. Start &#8211; execute &#8211; cmd.<\/p>\n<p>And then type:<\/p>\n<blockquote><p>PATH = %PATH%;C:\\CAMINHO_PARA_O_ARDUINO\\arduino-1.0.3\\hardware\\tools\\arm-none-eabi\\bin<\/p><\/blockquote>\n<p><strong>[If you don&#8217;t want to know the modifications that I did, just jump to the end where you can find a resume]<\/strong><\/p>\n<p>To guarantee that I will not screw everything, I did a copy of &#8220;arduino-1.0.3\\hardware\/teensy\/cores\/teensy3&#8221; and did my modifications on it. I executed:<\/p>\n<blockquote><p>cs-make.exe<\/p><\/blockquote>\n<p>Receveid this error message:<\/p>\n<blockquote><p>C:\\CAMINHO_PARA_O_ARDUINO\\arduino-1.0.3\\Projects\\Example_not_working>cs-make.exe<br \/>\nC:\/Users\/X-warrior\/Desktop\/tools\/arm-none-eabi\/bin\/arm-none-eabi-gcc  -Wall -g -Os -mcpu=cortex-m4 -mthumb -nostdlib -MMD -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I.  -c -o analog.o analog.c<br \/>\nprocess_begin: CreateProcess(NULL, C:\/Users\/X-warrior\/Desktop\/tools\/arm-none-eabi\/bin\/arm-none-eabi-gcc -Wall -g -Os -mcpu=cortex-m4 -mthumb -nostdlib -MMD -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I. -c -o analog.o analog.c, &#8230;) failed.<br \/>\nmake (e=2): The system cannot find the file specified.<br \/>\ncs-make.exe: *** [analog.o] Error 2<\/p><\/blockquote>\n<p>Checking the Makefile I decided to change some configs and used FULL PATH for it.<br \/>\nTOOLSPATH = C:\\CAMINHO_PARA_O_ARDUINO\\arduino-1.0.3\\hardware\\tools<br \/>\nCOMPILERPATH  = C:\\CAMINHO_PARA_O_ARDUINO\\arduino-1.0.3\\hardware\\tools\\arm-none-eabi\\bin<\/p>\n<p>The error received was the same, so checking the code again I saw the &#8220;abspath&#8221; and thought that maybe the problem was this, since I changed my folder location. So I removed all &#8220;$(abspath&#8221; remember that it has a parenthesis that closes the command. So for example:<\/p>\n<blockquote><p>$(abspath $(COMPILERPATH)) <strong>will be<\/strong> $(COMPILERPATH)<\/p><\/blockquote>\n<p>Trying to get it working again with cs-make, it started compiling it, but on the end I received this error:<\/p>\n<blockquote><p>\nC:\\Users\\X-warrior\\Desktop\\arduino-1.0.3\\hardware\\tools\\arm-none-eabi\\bin\/arm-none-eabi-objcopy -O ihex -R .eeprom main.elf main.hex<br \/>\nC:\\Users\\X-warrior\\Desktop\\arduino-1.0.3\\hardware\\tools\/teensy_post_compile -file=main -path= -tools=C:\\Users\\X-warrior\\Desktop\\arduino-1.0.3\\hardware\\tools<br \/>\nOpening Teensy Loader&#8230;<br \/>\nTeensy Loader could not find the file main<br \/>\ncs-make.exe: *** [main.hex] Error 1<\/p><\/blockquote>\n<p>Triple checking the Makefile I found &#8220;path=$(shell pwd)&#8221; and I didn&#8217;t remember this pwm command on windows so I tried to execute it and it didn&#8217;t work. So I changed it to &#8220;path=$(shell echo %cd%)&#8221;. Before I start compiling again I decide to clean directory using cs-make clean<\/p>\n<p>I received the following errors:<\/p>\n<blockquote><p>C:\\Users\\X-warrior\\Desktop\\arduino-1.0.3\\Projects\\Example_not_working>cs-make.exe clean<br \/>\nrm -f *.o *.d main.elf main.hex<br \/>\nprocess_begin: CreateProcess(NULL, rm -f *.o *.d main.elf main.hex, &#8230;) failed.<br \/>\nmake (e=2): The system cannot find the file specified.<br \/>\ncs-make.exe: *** [clean] Error 2<\/p><\/blockquote>\n<p>And then I noticed that it was calling rm -f which isn&#8217;t a windows command too. I changed the rm command to:<\/p>\n<blockquote><p>\tdel *.o<br \/>\n\tdel *.d<br \/>\n\tdel $(TARGET).elf<br \/>\n\tdel $(TARGET).hex<\/p><\/blockquote>\n<p>With this I managed to clean the files and tried to compile again, and&#8230; IT WORKS! I did a few tests using main.cpp that was being compiled and uploaded to my Teensy 3. Anyways to work with all that files wasn&#8217;t attractive so I decided to go a little further and do some cleaning. So inside my &#8220;Project&#8221; folder I copied all files excluding Makefile and main.cpp to my new folder inside my project &#8220;teensy\/&#8221;. This way I can compile it without all that files on my working folder. I needed to do a few more changes on Makefile as follow:<\/p>\n<blockquote><p>C_FILES := $(wildcard *.c) \\<br \/>\n\t      $(wildcard $(addprefix teensy\/, *.c)) \\<br \/>\n\t\t  $(wildcard $(addprefix teensy\/util, *.c)) \\<br \/>\n\t\t  $(wildcard $(addprefix teensy\/avr, *.c))<br \/>\nCPP_FILES := $(wildcard *.cpp)  \\<br \/>\n\t\t  $(wildcard $(addprefix teensy\/, *.cpp)) \\<br \/>\n\t\t  $(wildcard $(addprefix teensy\/util, *.cpp)) \\<br \/>\n\t\t  $(wildcard $(addprefix teensy\/avr, *.cpp))<br \/>\nOBJS := $(C_FILES:.c=.o) $(CPP_FILES:.cpp=.o)<\/p><\/blockquote>\n<p>Linker configuration to:<\/p>\n<blockquote><p>LDFLAGS = -Os -Wl,&#8211;gc-sections -mcpu=cortex-m4 -mthumb -Tteensy\/mk20dx128.ld<\/p><\/blockquote>\n<p>And to keep it consistent:<\/p>\n<blockquote><p>$(TARGET).elf: $(OBJS) teensy\/mk20dx128.ld<br \/>\n\t$(CC) $(LDFLAGS) -o $@ $(OBJS)<\/p><\/blockquote>\n<p>And then I found this error:<\/p>\n<blockquote><p>\nteensy\/keylayouts.c:1: fatal error: avr\/pgmspace.h: No such file or directory<br \/>\ncompilation terminated.<br \/>\ncs-make: *** [teensy\/keylayouts.o] Error 1\n<\/p><\/blockquote>\n<p>So I updated the CPPFLAGS to:<\/p>\n<blockquote><p>CPPFLAGS = -Wall -g -Os -mcpu=cortex-m4 -mthumb -nostdlib -MMD $(OPTIONS) -I. -Iteensy\/<\/p><\/blockquote>\n<p>And also remembered that the clean should be updated too.<\/p>\n<blockquote><p>clean:<br \/>\n\tdel *.o<br \/>\n\tdel *.d<br \/>\n\tdel $(TARGET).elf<br \/>\n\tdel $(TARGET).hex<br \/>\n\tdel $(CURRENT_PATH)\\teensy\\*.o<br \/>\n\tdel $(CURRENT_PATH)\\teensy\\*.d<\/p><\/blockquote>\n<p>And add this on the begin of &#8220;Configurations that shouldn&#8217;t be updated&#8221;<\/p>\n<blockquote><p>CURRENT_PATH=$(shell echo %cd%)<\/p><\/blockquote>\n<p>With all this I managed to get the Makefile working on Windows compiling and uploading for Teensy 3.0<\/p>\n<p><strong>Summary:<\/strong><br \/>\nYou must update TOOLSPATH , COMPILERPATH and use your FULL PATH<br \/>\nThen create a folder &#8220;My_Project&#8221;<br \/>\nCreate another folder inside your project called &#8220;teensy&#8221; (My_Project\/teensy\/)<br \/>\nCopy  &#8220;arduino-1.0.3\\hardware\/teensy\/cores\/teensy3\/&#8221;  to &#8220;My_Project\/teensy\/&#8221; (subdir too, but not the Makefile)<br \/>\nAdd the Makefile that you can download on the end of this post inside &#8220;My_Project&#8221;<br \/>\nCopy &#8220;Meu_Projeto\/teensy\/main.cpp&#8221; too &#8220;Meu_Projeto\/main.cpp&#8221;<br \/>\nProgramm inside main.cpp<br \/>\nCompile and upload with cs-make.exe<\/p>\n<p><a href='http:\/\/wordpress.matbra.com\/wp-content\/uploads\/Makefile-Teensy-Windows.rar'>Makefile to Teensy on Windows<\/a><\/p>\n<p>Matheus<\/p>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Good Night, If you don&#8217;t want to use Arduino IDE (Or Teensy IDE? \ud83d\ude09 to programming and uploading your code to Teensy 3.0 you can&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/wordpress.matbra.com\/en\/2013\/01\/09\/compilando-para-teensy-3-0-no-windows-utilizando-makefile\/\">Continue reading<span class=\"screen-reader-text\">Compile to Teensy 3.0 on Windows using Makefile<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[15,163,296,38],"tags":[298,301,300,299,297],"class_list":["post-1489","post","type-post","status-publish","format-standard","hentry","category-c","category-cpp","category-teensy","category-windows","tag-3-0","tag-cs-make","tag-make","tag-makefile","tag-teensy-2","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/psjGE-o1","_links":{"self":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/1489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/comments?post=1489"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/1489\/revisions"}],"predecessor-version":[{"id":1491,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/1489\/revisions\/1491"}],"wp:attachment":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/media?parent=1489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/categories?post=1489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/tags?post=1489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}