| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  | # Copyright (C) Ivan Kravets <me@ikravets.com> | 
					
						
							|  |  |  | # See LICENSE for details. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  |     Builder for Atmel SAM series of microcontrollers | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from os.path import join | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  | from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default, | 
					
						
							|  |  |  |                           DefaultEnvironment, SConscript) | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | from platformio.util import get_serialports | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | env = DefaultEnvironment() | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  | env = SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py")), | 
					
						
							|  |  |  |                  exports="env") | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | env.Replace( | 
					
						
							| 
									
										
										
										
											2015-02-06 18:12:56 +02:00
										 |  |  |     UPLOADER=join("$PIOPACKAGES_DIR", "$PIOPACKAGE_UPLOADER", "bossac"), | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  |     UPLOADERFLAGS=[ | 
					
						
							| 
									
										
										
										
											2015-02-06 18:12:56 +02:00
										 |  |  |         "--info", | 
					
						
							|  |  |  |         "--debug", | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  |         "--port", "$UPLOAD_PORT", | 
					
						
							| 
									
										
										
										
											2015-02-06 18:12:56 +02:00
										 |  |  |         "--erase", | 
					
						
							|  |  |  |         "--write", | 
					
						
							|  |  |  |         "--verify", | 
					
						
							| 
									
										
										
										
											2015-02-23 16:49:01 +02:00
										 |  |  |         "--boot", | 
					
						
							|  |  |  |         "--reset" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  |     ], | 
					
						
							| 
									
										
										
										
											2015-02-06 18:12:56 +02:00
										 |  |  |     UPLOADBINCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCES' | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | env.Append( | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  |     CPPDEFINES=[ | 
					
						
							|  |  |  |         "printf=iprintf" | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     LINKFLAGS=[ | 
					
						
							|  |  |  |         "-Wl,--entry=Reset_Handler", | 
					
						
							|  |  |  |         "-Wl,--start-group" | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CORELIBS = env.ProcessGeneral() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Target: Build executable and linkable firmware | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  | target_elf = env.BuildFirmware(["m", "gcc"] + CORELIBS) | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Target: Build the .bin file | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if "uploadlazy" in COMMAND_LINE_TARGETS: | 
					
						
							| 
									
										
										
										
											2015-02-18 20:21:20 +02:00
										 |  |  |     target_firm = join("$BUILD_DIR", "firmware.bin") | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  | else: | 
					
						
							| 
									
										
										
										
											2015-02-18 20:21:20 +02:00
										 |  |  |     target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-09 19:57:39 +02:00
										 |  |  | # | 
					
						
							|  |  |  | # Target: Print binary size | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD") | 
					
						
							|  |  |  | AlwaysBuild(target_size) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  | # | 
					
						
							|  |  |  | # Target: Upload by default .bin file | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  | upload = env.Alias( | 
					
						
							| 
									
										
										
										
											2015-02-18 20:21:20 +02:00
										 |  |  |     ["upload", "uploadlazy"], target_firm, ("$UPLOADBINCMD")) | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  | AlwaysBuild(upload) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Check for $UPLOAD_PORT variable | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-06 18:12:56 +02:00
										 |  |  | is_uptarget = (set(["upload", "uploadlazy"]) & set(COMMAND_LINE_TARGETS)) | 
					
						
							| 
									
										
										
										
											2015-02-05 15:58:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | if is_uptarget: | 
					
						
							|  |  |  |     # try autodetect upload port | 
					
						
							|  |  |  |     if "UPLOAD_PORT" not in env: | 
					
						
							|  |  |  |         for item in get_serialports(): | 
					
						
							|  |  |  |             if "VID:PID" in item['hwid']: | 
					
						
							|  |  |  |                 print "Auto-detected UPLOAD_PORT: %s" % item['port'] | 
					
						
							|  |  |  |                 env.Replace(UPLOAD_PORT=item['port']) | 
					
						
							|  |  |  |                 break | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if "UPLOAD_PORT" not in env: | 
					
						
							|  |  |  |         print("WARNING!!! Please specify environment 'upload_port' or use " | 
					
						
							|  |  |  |               "global --upload-port option.\n") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Setup default targets | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 20:21:20 +02:00
										 |  |  | Default([target_firm, target_size]) |