| 
									
										
										
										
											2015-02-03 14:24:15 +02:00
										 |  |  | # Copyright (C) Ivan Kravets <me@ikravets.com> | 
					
						
							|  |  |  | # See LICENSE for details. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							| 
									
										
										
										
											2015-03-09 12:18:46 +02:00
										 |  |  |     Builder for ST STM32 Series ARM microcontrollers. | 
					
						
							| 
									
										
										
										
											2015-02-03 14:24:15 +02:00
										 |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 13:19:00 +02:00
										 |  |  | import platform | 
					
						
							| 
									
										
										
										
											2015-02-03 14:24:15 +02:00
										 |  |  | 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-03 14:24:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | env = DefaultEnvironment() | 
					
						
							| 
									
										
										
										
											2015-02-23 21:02:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py"))) | 
					
						
							| 
									
										
										
										
											2015-02-03 14:24:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | env.Replace( | 
					
						
							| 
									
										
										
										
											2015-02-04 20:23:50 +02:00
										 |  |  |     UPLOADER=join("$PIOPACKAGES_DIR", "tool-stlink", "st-flash"), | 
					
						
							|  |  |  |     UPLOADERFLAGS=[ | 
					
						
							|  |  |  |         "write",        # write in flash | 
					
						
							|  |  |  |         "$SOURCES",     # firmware path to flash | 
					
						
							|  |  |  |         "0x08000000"    # flash start adress | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     UPLOADCMD="$UPLOADER $UPLOADERFLAGS" | 
					
						
							| 
									
										
										
										
											2015-02-03 14:24:15 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | env.Append( | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  |     CPPDEFINES=[ | 
					
						
							|  |  |  |         "${BOARD_OPTIONS['build']['variant'].upper()}" | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     LINKFLAGS=[ | 
					
						
							|  |  |  |         "-nostartfiles", | 
					
						
							|  |  |  |         "-nostdlib" | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2015-02-03 14:24:15 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Target: Build executable and linkable firmware | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-09 12:18:46 +02:00
										 |  |  | target_elf = env.BuildFirmware() | 
					
						
							| 
									
										
										
										
											2015-02-03 14:24:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Target: Build the .bin file | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if "uploadlazy" in COMMAND_LINE_TARGETS: | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  |     target_firm = join("$BUILD_DIR", "firmware.bin") | 
					
						
							| 
									
										
										
										
											2015-02-03 14:24:15 +02:00
										 |  |  | else: | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  |     target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) | 
					
						
							| 
									
										
										
										
											2015-02-03 14:24:15 +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-03 14:24:15 +02:00
										 |  |  | # | 
					
						
							|  |  |  | # Target: Upload by default .bin file | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 13:19:00 +02:00
										 |  |  | disable_msd = (platform.system() == "Darwin" and | 
					
						
							|  |  |  |                platform.release().startswith("14.")) | 
					
						
							|  |  |  | if "mbed" in env.subst("$FRAMEWORK") and not disable_msd: | 
					
						
							| 
									
										
										
										
											2015-03-13 00:02:31 +02:00
										 |  |  |     upload = env.Alias(["upload", "uploadlazy"], | 
					
						
							|  |  |  |                        target_firm, env.UploadToDisk) | 
					
						
							| 
									
										
										
										
											2015-03-09 12:18:46 +02:00
										 |  |  | else: | 
					
						
							|  |  |  |     upload = env.Alias(["upload", "uploadlazy"], target_firm, "$UPLOADCMD") | 
					
						
							| 
									
										
										
										
											2015-02-03 14:24:15 +02:00
										 |  |  | AlwaysBuild(upload) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Target: Define targets | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-18 20:11:52 +02:00
										 |  |  | Default([target_firm, target_size]) |