def check_memory(self, args): board = self.e.board_model(args.board_model) boardVariant = args.cpu if ('cpu' in args) else None flash_max = sram_max = 0 try: flash_max = int( BoardModels.getValueForVariant(board, boardVariant, 'upload', 'maximum_size')) except KeyError: pass try: sram_max = int( BoardModels.getValueForVariant(board, boardVariant, 'upload', 'maximum_data_size')) except KeyError: pass firmware = os.path.join(self.e.build_dir, "firmware.elf") output = subprocess.Popen([self.e.memsize, "--format=sysv", firmware], stdout=subprocess.PIPE).communicate()[0] text_size = int(re.search('\.text\s+(\d+)', output).group(1)) data_size = int(re.search('\.data\s+(\d+)', output).group(1)) bss_size = int(re.search('\.bss\s+(\d+)', output).group(1)) flash_size = text_size + data_size sram_size = data_size + bss_size flash_pct = flash_size * 100 / flash_max if flash_max > 0 else 0 sram_pct = sram_size * 100 / sram_max if sram_max > 0 else 0 if flash_max > 0: print "Sketch uses {:,d} bytes ({:d}%) of " \ "program storage space.\nMaxiumum is {:,d} bytes.".format( flash_size, flash_pct, flash_max ) else: print "Sketch uses {:,d} bytes of program storage space.\n" \ "Maxiumum is unknown.".format( flash_size ) if sram_max > 0: print "Global variables use {:,d} bytes ({:d}%) of dynamic " \ "memory,\nleaving {:,d} bytes for local variables. " \ "Maxiumum is {:,d} bytes.".format( sram_size, sram_pct, sram_max - sram_size, sram_max ) else: print "Global variables use {:,d} bytes of dynamic memory.\n" \ "Maxiumum is unknown.".format( sram_size ) if flash_pct > 99: print "\033[91mSketch too big; see " \ "http://www.arduino.cc/en/Guide/Troubleshooting#size\nfor tips " \ "on reducing it.\033[0m" if sram_pct >= 75: print "\033[91mLow memory available, stability problems may " \ "occur.\033[0m"
def check_memory(self, args): board = self.e.board_model(args.board_model) boardVariant = args.cpu if ('cpu' in args) else None; flash_max = sram_max = 0 try: flash_max = int(BoardModels.getValueForVariant(board, boardVariant, 'upload', 'maximum_size')) except KeyError: pass try: sram_max = int(BoardModels.getValueForVariant(board, boardVariant, 'upload', 'maximum_data_size')) except KeyError: pass firmware = os.path.join(self.e.build_dir, "firmware.elf") output = subprocess.Popen( [self.e.memsize, "--format=sysv", firmware], stdout=subprocess.PIPE).communicate()[0] text_size = int(re.search('\.text\s+(\d+)', output).group(1)) data_size = int(re.search('\.data\s+(\d+)', output).group(1)) bss_size = int(re.search('\.bss\s+(\d+)', output).group(1)) flash_size = text_size + data_size sram_size = data_size + bss_size flash_pct = flash_size * 100 / flash_max if flash_max > 0 else 0 sram_pct = sram_size * 100 / sram_max if sram_max > 0 else 0 if flash_max > 0: print "Sketch uses {:,d} bytes ({:d}%) of " \ "program storage space.\nMaxiumum is {:,d} bytes.".format( flash_size, flash_pct, flash_max ) else: print "Sketch uses {:,d} bytes of program storage space.\n" \ "Maxiumum is unknown.".format( flash_size ) if sram_max > 0: print "Global variables use {:,d} bytes ({:d}%) of dynamic " \ "memory,\nleaving {:,d} bytes for local variables. " \ "Maxiumum is {:,d} bytes.".format( sram_size, sram_pct, sram_max - sram_size, sram_max ) else: print "Global variables use {:,d} bytes of dynamic memory.\n" \ "Maxiumum is unknown.".format( sram_size ) if flash_pct > 99: print "\033[91mSketch too big; see " \ "http://www.arduino.cc/en/Guide/Troubleshooting#size\nfor tips " \ "on reducing it.\033[0m" if sram_pct >= 75: print "\033[91mLow memory available, stability problems may " \ "occur.\033[0m"
def setup_flags(self, args): board = self.e.board_model(args.board_model) boardVariant = args.cpu if ('cpu' in args) else None mcu = '-mmcu=' + BoardModels.getValueForVariant( board, boardVariant, 'build', 'mcu') # Hard-code the flags that are essential to building the sketch self.e['cppflags'] = SpaceList([ mcu, '-DF_CPU=' + BoardModels.getValueForVariant( board, boardVariant, 'build', 'f_cpu'), '-DARDUINO=' + str(self.e.arduino_lib_version.as_int()), '-DARDUINO_ARCH_' + args.arch.upper(), '-I' + self.e['arduino_core_dir'], ]) # Add additional flags as specified self.e['cppflags'] += SpaceList(shlex.split(args.cppflags)) try: self.e['cppflags'].append('-DUSB_VID=%s' % BoardModels.getValueForVariant( board, boardVariant, 'build', 'vid')) except KeyError: None try: self.e['cppflags'].append('-DUSB_PID=%s' % BoardModels.getValueForVariant( board, boardVariant, 'build', 'pid')) except KeyError: None if self.e.arduino_lib_version.major: variant_dir = os.path.join(self.e.arduino_variants_dir, board['build']['variant']) self.e.cppflags.append('-I' + variant_dir) self.e['cflags'] = SpaceList(shlex.split(args.cflags)) self.e['cxxflags'] = SpaceList(shlex.split(args.cxxflags)) self.e['asmflags'] = SpaceList(shlex.split(args.asmflags)) # Again, hard-code the flags that are essential to building the sketch self.e['ldflags'] = SpaceList([mcu]) self.e['ldflags'] += SpaceList( ['-Wl,' + flag for flag in shlex.split(args.ldflags)]) self.e['names'] = { 'obj': '%s.o', 'lib': 'lib%s.a', 'cpp': '%s.cpp', 'asm': '%s.S', 'deps': '%s.d', }
def setup_flags(self, args): board = self.e.board_model(args.board_model) boardVariant = args.cpu if ('cpu' in args) else None; mcu = '-mmcu=' + BoardModels.getValueForVariant(board, boardVariant, 'build', 'mcu') # Hard-code the flags that are essential to building the sketch self.e['cppflags'] = SpaceList([ mcu, '-DF_CPU=' + BoardModels.getValueForVariant(board, boardVariant, 'build', 'f_cpu'), '-DARDUINO=' + str(self.e.arduino_lib_version.as_int()), '-DARDUINO_ARCH_' + args.arch.upper(), '-I' + self.e['arduino_core_dir'], ]) # Add additional flags as specified self.e['cppflags'] += SpaceList(shlex.split(args.cppflags)) try: self.e['cppflags'].append('-DUSB_VID=%s' % BoardModels.getValueForVariant(board, boardVariant, 'build', 'vid')) except KeyError: None try: self.e['cppflags'].append('-DUSB_PID=%s' % BoardModels.getValueForVariant(board, boardVariant, 'build', 'pid')) except KeyError: None if self.e.arduino_lib_version.major: variant_dir = os.path.join(self.e.arduino_variants_dir, board['build']['variant']) self.e.cppflags.append('-I' + variant_dir) self.e['cflags'] = SpaceList(shlex.split(args.cflags)) self.e['cxxflags'] = SpaceList(shlex.split(args.cxxflags)) self.e['asmflags'] = SpaceList(shlex.split(args.asmflags)) # Again, hard-code the flags that are essential to building the sketch self.e['ldflags'] = SpaceList([mcu]) self.e['ldflags'] += SpaceList([ '-Wl,' + flag for flag in shlex.split(args.ldflags) ]) self.e['names'] = { 'obj': '%s.o', 'lib': 'lib%s.a', 'cpp': '%s.cpp', 'asm': '%s.S', 'deps': '%s.d', }
def run(self, args): self.discover() port = args.serial_port or self.e.guess_serial_port() boardVariant = args.cpu if ('cpu' in args) else None; board = self.e.board_model(args.board_model) protocol = BoardModels.getValueForVariant(board, boardVariant, 'upload', 'protocol') if protocol == 'stk500': # if v1 is not specifid explicitly avrdude will # try v2 first and fail protocol = 'stk500v1' if not os.path.exists(port): raise Abort("%s doesn't exist. Is Arduino connected?" % port) # send a hangup signal when the last process closes the tty file_switch = '-f' if platform.system() == 'Darwin' else '-F' ret = subprocess.call([self.e['stty'], file_switch, port, 'hupcl']) if ret: raise Abort("stty failed") # pulse on DTR try: s = Serial(port, 115200) except SerialException as e: raise Abort(str(e)) s.setDTR(False) sleep(0.1) s.setDTR(True) s.close() # Need to do a little dance for Leonardo and derivatives: # open then close the port at the magic baudrate (usually 1200 bps) first # to signal to the sketch that it should reset into bootloader. after doing # this wait a moment for the bootloader to enumerate. On Windows, also must # deal with the fact that the COM port number changes from bootloader to # sketch. touch_port = \ board['upload'].get('use_1200bps_touch') == 'true' or \ protocol == 'avr109' if touch_port: new_port = None before = self.e.list_serial_ports() if port in before: ser = Serial() ser.port = port ser.baudrate = 1200 ser.open() ser.close() # Scanning for available ports seems to open the port or # otherwise assert DTR, which would cancel the WDT reset if # it happened within 250 ms. So we wait until the reset should # have already occured before we start scanning. if platform.system() != 'Darwin': sleep(0.3) elapsed = 0 enum_delay = 0.25 while elapsed < 10: now = self.e.list_serial_ports() diff = list(set(now) - set(before)) if diff: new_port = diff[0] break before = now sleep(enum_delay) elapsed += enum_delay if not new_port: raise Abort("Couldn’t find a board on the selected port. " "Check that you have the correct port selected. " "If it is correct, try pressing the board's reset " "button after initiating the upload.") port = new_port # call avrdude to upload .hex subprocess.call([ self.e['avrdude'], '-C', self.e['avrdude.conf'], '-p', BoardModels.getValueForVariant(board, boardVariant, 'build', 'mcu'), '-P', port, '-c', protocol, '-b', BoardModels.getValueForVariant(board, boardVariant, 'upload', 'speed'), '-D', '-U', 'flash:w:%s:i' % self.e['hex_path'], ])