| 
									
										
										
										
											2015-02-03 14:24:15 +02:00
										 |  |  | # Copyright (C) Ivan Kravets <me@ikravets.com> | 
					
						
							|  |  |  | # See LICENSE for details. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  |     Builder for STMicroelectronics | 
					
						
							|  |  |  |     STM32 Series ARM microcontrollers. | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from os.path import join | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default, | 
					
						
							|  |  |  |                           DefaultEnvironment) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | env = DefaultEnvironment() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | env.Replace( | 
					
						
							|  |  |  |     AR="arm-none-eabi-ar", | 
					
						
							|  |  |  |     AS="arm-none-eabi-gcc", | 
					
						
							|  |  |  |     CC="arm-none-eabi-gcc", | 
					
						
							|  |  |  |     CXX="arm-none-eabi-g++", | 
					
						
							|  |  |  |     OBJCOPY="arm-none-eabi-objcopy", | 
					
						
							|  |  |  |     RANLIB="arm-none-eabi-ranlib", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ARFLAGS=["rcs"], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASFLAGS=[ | 
					
						
							|  |  |  |         "-c", | 
					
						
							|  |  |  |         "-g",  # include debugging info (so errors include line numbers) | 
					
						
							|  |  |  |         "-x", "assembler-with-cpp", | 
					
						
							|  |  |  |         "-Wall", | 
					
						
							|  |  |  |         "-mthumb", | 
					
						
							|  |  |  |         "-mcpu=${BOARD_OPTIONS['build']['mcu']}" | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CCFLAGS=[ | 
					
						
							|  |  |  |         "-g",   # include debugging info (so errors include line numbers) | 
					
						
							|  |  |  |         "-Os",  # optimize for size | 
					
						
							|  |  |  |         "-ffunction-sections",  # place each function in its own section | 
					
						
							|  |  |  |         "-fdata-sections", | 
					
						
							|  |  |  |         "-Wall", | 
					
						
							|  |  |  |         "-mthumb", | 
					
						
							|  |  |  |         "-mcpu=${BOARD_OPTIONS['build']['mcu']}", | 
					
						
							|  |  |  |         "-MMD"  # output dependancy info | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CXXFLAGS=[ | 
					
						
							|  |  |  |         "-fno-rtti", | 
					
						
							|  |  |  |         "-fno-exceptions" | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | env.Append( | 
					
						
							|  |  |  |     CPPDEFINES=[ | 
					
						
							|  |  |  |         "F_CPU=$BOARD_F_CPU", | 
					
						
							|  |  |  |         "${BOARD_OPTIONS['build']['variant'].upper()}" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | env.Append( | 
					
						
							|  |  |  |     LINKFLAGS=[ | 
					
						
							|  |  |  |         "-Os", | 
					
						
							|  |  |  |         "-nostartfiles", | 
					
						
							|  |  |  |         "-nostdlib", | 
					
						
							|  |  |  |         "-Wl,--gc-sections", | 
					
						
							|  |  |  |         "-mthumb", | 
					
						
							|  |  |  |         "-mcpu=${BOARD_OPTIONS['build']['mcu']}" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-03 14:24:59 +02:00
										 |  |  | if env.get("BOARD_OPTIONS", {}).get("build", {}).get("mcu")[-2:] == "m4": | 
					
						
							| 
									
										
										
										
											2015-02-03 14:24:15 +02:00
										 |  |  |     env.Append( | 
					
						
							|  |  |  |         ASFLAGS=[ | 
					
						
							|  |  |  |             "-mfloat-abi=hard", | 
					
						
							|  |  |  |             "-mfpu=fpv4-sp-d16", | 
					
						
							|  |  |  |             "-fsingle-precision-constant" | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         CCFLAGS=[ | 
					
						
							|  |  |  |             "-mfloat-abi=hard", | 
					
						
							|  |  |  |             "-mfpu=fpv4-sp-d16", | 
					
						
							|  |  |  |             "-fsingle-precision-constant" | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         LINKFLAGS=[ | 
					
						
							|  |  |  |             "-mfloat-abi=hard", | 
					
						
							|  |  |  |             "-mfpu=fpv4-sp-d16", | 
					
						
							|  |  |  |             "-fsingle-precision-constant" | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | env.Append( | 
					
						
							|  |  |  |     BUILDERS=dict( | 
					
						
							|  |  |  |         ElfToBin=Builder( | 
					
						
							|  |  |  |             action=" ".join([ | 
					
						
							|  |  |  |                 "$OBJCOPY", | 
					
						
							|  |  |  |                 "-O", | 
					
						
							|  |  |  |                 "binary", | 
					
						
							|  |  |  |                 "$SOURCES", | 
					
						
							|  |  |  |                 "$TARGET"]), | 
					
						
							|  |  |  |             suffix=".bin" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CORELIBS = env.ProcessGeneral() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Target: Build executable and linkable firmware | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | target_elf = env.BuildFirmware(CORELIBS + ["c", "gcc", "m", "nosys"]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Target: Build the .bin file | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if "uploadlazy" in COMMAND_LINE_TARGETS: | 
					
						
							|  |  |  |     target_bin = join("$BUILD_DIR", "firmware.bin") | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  |     target_bin = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Target: Upload by default .bin file | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | upload = env.Alias(["upload", "uploadlazy"], target_bin, ("$UPLOADCMD")) | 
					
						
							|  |  |  | AlwaysBuild(upload) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Target: Define targets | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Default(target_bin) |