MCPcopy Create free account
hub / github.com/bitcraze/crazyflie-lib-python / read_flash

Method read_flash

cflib/bootloader/cloader.py:336–361  ·  view source on GitHub ↗

Read back a flash page from the Crazyflie and return it

(self, addr=0xFF, page=0x00)

Source from the content-addressed store, hash-verified

334 self.link.send_packet(pk)
335
336 def read_flash(self, addr=0xFF, page=0x00):
337 """Read back a flash page from the Crazyflie and return it"""
338 buff = bytearray()
339
340 page_size = self.targets[addr].page_size
341
342 for i in range(0, int(math.ceil(page_size / 25.0))):
343 pk = None
344 retry_counter = 5
345 while ((not pk or pk.header != 0xFF or
346 struct.unpack('<BB', pk.data[0:2]) != (addr, 0x1C)) and
347 retry_counter >= 0):
348 pk = CRTPPacket()
349 pk.set_header(0xFF, 0xFF)
350 pk.data = struct.pack('<BBHH', addr, 0x1C, page, (i * 25))
351 self.link.send_packet(pk)
352
353 pk = self.link.receive_packet(1)
354 retry_counter -= 1
355 if (retry_counter < 0):
356 return None
357 else:
358 buff += pk.data[6:]
359
360 # For some reason we get one byte extra here...
361 return buff[0:page_size]
362
363 def write_flash(self, addr, page_buffer, target_page, page_count):
364 """Initiate flashing of data in the buffer to flash."""

Callers 1

read_cf1_configMethod · 0.80

Calls 4

set_headerMethod · 0.95
CRTPPacketClass · 0.90
send_packetMethod · 0.45
receive_packetMethod · 0.45

Tested by

no test coverage detected