#NEWLINE# def program( self , chip_erase = None , progress_cb = None , smart_flash = True , fast_verify = False ) : #NEWLINE# #INDENT# '\n        Determine fastest method of flashing and then run flash programming.\n\n        Data must have already been added with addData\n        ' #NEWLINE# program_start = time ( ) #NEWLINE# if ( progress_cb is None ) : #NEWLINE# #INDENT# progress_cb = _stub_progress #NEWLINE# #UNINDENT# if ( len ( self . flash_operation_list ) == 0 ) : #NEWLINE# #INDENT# logging . warning ( 'No pages were programmed' ) #NEWLINE# return #NEWLINE# #UNINDENT# flash_addr = self . flash_operation_list [ 0 ] . addr #NEWLINE# info = self . flash . getPageInfo ( flash_addr ) #NEWLINE# page_addr = ( flash_addr - ( flash_addr % info . size ) ) #NEWLINE# current_page = flash_page ( page_addr , info . size , [ ] , info . erase_weight , info . program_weight ) #NEWLINE# self . page_list . append ( current_page ) #NEWLINE# for flash_operation in self . flash_operation_list : #NEWLINE# #INDENT# pos = 0 #NEWLINE# while ( pos < len ( flash_operation . data ) ) : #NEWLINE# #INDENT# flash_addr = ( flash_operation . addr + pos ) #NEWLINE# if ( flash_addr >= ( current_page . addr + current_page . size ) ) : #NEWLINE# #INDENT# info = self . flash . getPageInfo ( flash_addr ) #NEWLINE# page_addr = ( flash_addr - ( flash_addr % info . size ) ) #NEWLINE# current_page = flash_page ( page_addr , info . size , [ ] , info . erase_weight , info . program_weight ) #NEWLINE# self . page_list . append ( current_page ) #NEWLINE# #UNINDENT# page_data_end = ( current_page . addr + len ( current_page . data ) ) #NEWLINE# if ( flash_addr != page_data_end ) : #NEWLINE# #INDENT# old_data = self . flash . target . readBlockMemoryUnaligned8 ( page_data_end , ( flash_addr - page_data_end ) ) #NEWLINE# current_page . data . extend ( old_data ) #NEWLINE# #UNINDENT# space_left_in_page = ( info . size - len ( current_page . data ) ) #NEWLINE# space_left_in_data = ( len ( flash_operation . data ) - pos ) #NEWLINE# amount = min ( space_left_in_page , space_left_in_data ) #NEWLINE# current_page . data . extend ( flash_operation . data [ pos : ( page_program_time + amount ) ] ) #NEWLINE# pos += amount #NEWLINE# #UNINDENT# #UNINDENT# if ( not smart_flash ) : #NEWLINE# #INDENT# self . _mark_all_pages_for_programming ( ) #NEWLINE# #UNINDENT# if ( self . page_list [ 0 ] . addr > self . flash_start ) : #NEWLINE# #INDENT# if ( chip_erase is None ) : #NEWLINE# #INDENT# chip_erase = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( chip_erase is True ) : #NEWLINE# #INDENT# logging . warning ( 'Chip erase used when flash address 0x%x is not the same as flash start 0x%x' , self . page_list [ 0 ] . addr , self . flash_start ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . flash . init ( ) #NEWLINE# ( chip_erase_count , chip_erase_program_time ) = self . _compute_chip_erase_pages_and_weight ( ) #NEWLINE# page_erase_min_program_time = self . _compute_page_erase_pages_weight_min ( ) #NEWLINE# if ( ( chip_erase is None ) and ( chip_erase_program_time < page_erase_min_program_time ) ) : #NEWLINE# #INDENT# chip_erase = True #NEWLINE# #UNINDENT# if ( chip_erase != True ) : #NEWLINE# #INDENT# analyze_start = time ( ) #NEWLINE# if self . flash . getFlashInfo ( ) . crc_supported : #NEWLINE# #INDENT# ( sector_erase_count , page_program_time ) = self . _compute_page_erase_pages_and_weight_crc32 ( fast_verify ) #NEWLINE# self . perf . analyze_type = FlashBuilder . FLASH_ANALYSIS_CRC32 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( sector_erase_count , page_program_time ) = self . _compute_page_erase_pages_and_weight_sector_read ( ) #NEWLINE# self . perf . analyze_type = FlashBuilder . FLASH_ANALYSIS_PARTIAL_PAGE_READ #NEWLINE# #UNINDENT# analyze_finish = time ( ) #NEWLINE# self . perf . analyze_time = ( analyze_finish - analyze_start ) #NEWLINE# logging . debug ( ( 'Analyze time: %f' % ( analyze_finish - analyze_start ) ) ) #NEWLINE# #UNINDENT# if ( chip_erase is None ) : #NEWLINE# #INDENT# logging . debug ( ( 'Chip erase count %i, Page erase est count %i' % ( chip_erase_count , sector_erase_count ) ) ) #NEWLINE# logging . debug ( ( 'Chip erase weight %f, Page erase weight %f' % ( chip_erase_program_time , page_program_time ) ) ) #NEWLINE# chip_erase = ( chip_erase_program_time < page_program_time ) #NEWLINE# #UNINDENT# if chip_erase : #NEWLINE# #INDENT# if ( self . flash . isDoubleBufferingSupported ( ) and self . enable_double_buffering ) : #NEWLINE# #INDENT# logging . debug ( 'Using double buffer chip erase program' ) #NEWLINE# flash_operation = self . _chip_erase_program_double_buffer ( progress_cb ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# flash_operation = self . _chip_erase_program ( progress_cb ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . flash . isDoubleBufferingSupported ( ) and self . enable_double_buffering ) : #NEWLINE# #INDENT# logging . debug ( 'Using double buffer page erase program' ) #NEWLINE# flash_operation = self . _page_erase_program_double_buffer ( progress_cb ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# flash_operation = self . _page_erase_program ( progress_cb ) #NEWLINE# #UNINDENT# #UNINDENT# self . flash . target . resetStopOnReset ( ) #NEWLINE# program_finish = time ( ) #NEWLINE# self . perf . program_time = ( program_finish - program_start ) #NEWLINE# self . perf . program_type = flash_operation #NEWLINE# return self . perf