@@ -217,7 +217,7 @@ def write_flash_page(self, linear_address, input_data, erase_page=True):
217217 # should only be included in the routine when the erase_page_1 = 1.
218218 # The pseudo-code does not refer to this parameter!
219219 routine_part1 = [
220- 0x75 , 0xAD , ((linear_address >> 8 ) // FLASH_WORD_SIZE ) & 0x7E , # MOV FADDRH, #imm
220+ 0x75 , 0xAD , ((linear_address >> 8 ) // FLASH_WORD_SIZE ) & 0x7E , # MOV FADDRH, #imm
221221 0x75 , 0xAC , 0x00 , # MOV FADDRL, #00
222222 ]
223223 routine_erase = [
@@ -253,7 +253,7 @@ def write_flash_page(self, linear_address, input_data, erase_page=True):
253253 else :
254254 routine = routine_part1 + routine_part2
255255
256- self .write_xdata_memory (0xF000 , input_data )
256+ self .write_xdata_memory (0xF000 , input_data [: FLASH_PAGE_SIZE ] )
257257 self .write_xdata_memory (0xF000 + FLASH_PAGE_SIZE , routine )
258258 self .run_instruction (0x75 , 0xC7 , 0x51 ) # MOV MEMCRT, (bank * 16) + 1
259259 self .set_pc (0xF000 + FLASH_PAGE_SIZE )
@@ -276,12 +276,12 @@ def read_flash_page(self, linear_address):
276276 return self .read_code_memory (linear_address & 0xFFFF , FLASH_PAGE_SIZE )
277277
278278
279- def read_flash (self , * , start_address = 0 , length = 0 ):
279+ def read_flash (self , * , start_address = 0 , length ):
280280 """ Read a chunk of flash memory.
281281
282282 Parameters:
283- length -- The length (in bytes) of the amount of flash memory that you want to read.
284283 start_address -- The address in flash memory you want to begin reading data from.
284+ length -- The length (in bytes) of the amount of flash memory that you want to read.
285285 """
286286 flash_data = bytearray ()
287287 for i in range (start_address , length , FLASH_PAGE_SIZE ):
@@ -308,23 +308,24 @@ def program_flash(self, image_array, *, erase=True, verify=True, start=0):
308308 Parameters:
309309 image_array -- The data to be written to the flash.
310310 erase -- Used to specify whether or not the flash needs to be erased before programming.
311- verify - Used to specify whether or not the data was flashed correctly.
311+ verify -- Used to specify whether or not the data was flashed correctly.
312312 start -- The address to begin writing data to the flash.
313313 """
314314
315315 if erase :
316316 self .mass_erase_flash ()
317317
318318 data = bytearray (image_array )
319- address = 0
319+ address = start
320+
320321 while data :
321322 time .sleep (0.1 )
322323 # Grab a page...
323324 page = data [:FLASH_PAGE_SIZE ]
324325 del data [:FLASH_PAGE_SIZE ]
325326
326327 # ... and write it to flash.
327- self .write_flash_page (address , page , False )
328+ self .write_flash_page (address - start , page , False )
328329 address += FLASH_PAGE_SIZE
329330
330331 time .sleep (0.1 )
0 commit comments