The memory subsystem allows reading and writing raw binary data to various memories and memory-mapped functionalities in the Crazyflie. In the Crazyflie CLI the mem command is used to access the memory subsystem as raw binary data. Some memories also support decoding of the data by using the display parameter.
Note that all command accept both decimal and hexadecimal (prefix 0x) values for
address, size and data parameters.
For documentation on the memory sub system and the various memory types see this link
Most mem subcommands take a memory reference as the first positional argument.
Three forms are accepted:
- Numeric ID — the ID printed by
mem list, e.g.5or0x05. IDs are an enumeration of the memories currently reported by the Crazyflie and may shift if memories are added or removed, so prefer the type-name form when writing guides or scripts. - Type name — a
MemoryTypevariant, e.g.DeckCtrlDFU. Resolves to that memory if exactly one of the type exists. - Type with instance index —
Type:N, e.g.DeckCtrlDFU:0. Required when multiple memories of the same type are present.
If a type name is given but multiple memories of that type are present and no instance index was supplied, the command errors out and prints the valid range of instance indices.
To list all the available memories in the Crazyflie use the following command:
cfcli mem listThis will show an output similar to the one below showing id, type, size and serial (if available):
ID | Type | Size | Serial
---+--------------+-------------------------+--------------------------
0 | EEPROMConfig | 8191 (0x1fff) |
1 | Trajectory | 4096 (0x1000) |
2 | MemoryTester | 4096 (0x1000) |
3 | DeckCtrl | 2048 (0x800) | 2D0043000550314854363720
4 | DeckMemory | 1342177280 (0x50000000) |
5 | DeckCtrlDFU | 98304 (0x18000) |
For machine-readable output, add the global --csv flag:
cfcli --csv mem listid,type,size_bytes,serial
0,EEPROMConfig,8191,
3,DeckCtrl,2048,2D0043000550314854363720
5,DeckCtrlDFU,98304,
Columns: numeric id, type name, decimal size_bytes, and serial (hex
string, empty when the memory has no serial).
mem read defaults to offset 0 and length 32, so a quick peek at a memory
is just:
cfcli mem read DeckCtrlDFUTo read a specific range, use --offset (-s for "seek") and --length
(-n). Both accept decimal or hex (0x...) values:
cfcli mem read DeckCtrlDFU --offset 0x00 --length 0x20
cfcli mem read DeckCtrlDFU -s 0x00 -n 0x20This will read 0x20 (32) bytes from the DeckCtrlDFU memory starting at
address 0x00. The output will look similar to this:
0000: 30 78 42 43 01 3c 02 00 00 00 00 00 00 00 00 e7 0xBC.<..........
0010: e7 e7 e7 e7 ef ff ff ff ff ff ff ff ff ff ff ff ................
Memories can also be addressed by numeric ID:
cfcli mem read 5 -s 0x00 -n 0x20It's also possible to write the data to a file directly using --output (-o):
cfcli mem read DeckCtrlDFU -s 0x00 -n 0x20 -o memory_dump.binTo write raw binary data to the memory use the following command. This will
write the bytes 1, 1, 2 to the EEPROMConfig memory starting at address 0x20.
cfcli mem write EEPROMConfig -s 0x20 --data 0x01,1,0x02It's also possible to write data from a file using --input (-i):
cfcli mem write EEPROMConfig -s 0x20 -i memory_data.binNote: The Crazyflie will most likely not like writing raw random data to memories, so when using this functionality make sure you know what you are doing!
mem verify takes the same arguments as mem write, but instead of writing it
reads the memory back and compares it against the data you give it. Use it to
confirm that a write landed, or that a memory still holds what you expect.
cfcli mem verify DeckMemory -s 0x10000000 -i color-led.binThe number of bytes read back is the length of the expected data, so the same
--data (-d) and --input (-i) arguments that wrote a region also verify
exactly that region:
cfcli mem verify EEPROMConfig -s 0x20 --data 0x01,1,0x02If everything matches the command prints a confirmation and exits 0:
Read back 32 bytes from memory ID=3 at offset 0x0
Verify OK: 32 bytes at offset 0x0 match
If anything differs, the differing bytes are listed with their absolute offsets and the command exits 1, so a script can act on it:
Read back 32 bytes from memory ID=3 at offset 0x0
Offset | Expected | Actual
-----------+----------+--------
0x00000004 | 0xFF | 0x00
0x00000005 | 0xBD | 0xBC
0x00000014 | 0xEF | 0x6F
Error: Verify FAILED: 3 of 32 bytes differ
At most 16 differing bytes are listed; the rest are summarised as
... and N more, with the total in the final line.
This command is used to interpret and display the content of a memory. Note that not all memories support this functionality.
cfcli mem display EEPROMConfigThis will give an output similar to this:
EEPROM Config:
Radio Channel: 60
Radio Speed: 2 Mbps
Pitch Trim: 0.0000
Roll Trim: 0.0000
Radio Address: [E7, E7, E7, E7, E7]
If no memory is given, an interactive picker is shown.
Below is an example of how to use the raw memory access to bootload the Color
LED deck. Using the DeckMemory type name keeps the commands stable across
firmwares — the numeric ID may differ between Crazyflies (note this only works for one deck
since otherwise there's an offset in the memory address).
# Switch the deck into bootloader mode
cfcli mem write DeckMemory -s 0x1004 --data 0x02
# Write the firmware binary to the deck memory
cfcli mem write DeckMemory -s 0x10000000 -i color-led.bin
# Switch the deck back into application mode
cfcli mem write DeckMemory -s 0x1004 --data 0x01To check that the firmware was written correctly, read it back and compare before leaving bootloader mode:
cfcli mem verify DeckMemory -s 0x10000000 -i color-led.bin