Re: Freezing / Compiling raw binary data in DFU
Posted: Tue Jul 02, 2019 7:32 am
As mentioned above, you can use frozen scripts to store a bytes object in ROM.
An alternative: to load binary data to some external device (here SPI RAM) then you could simply store that binary data directly on the filesystem as a binary file, then copy it to the external SPI RAM device using a simple loop, eg:
But then the question is how to get the asset file easily to the device, using DFU. There are two ways to do this: 1) to build the filesystem image (I guess FAT FS) on your PC and pack it into a DFU file alongside the main firmware; 2) just pack the binary asset directly into the DFU at a known location in ROM. For the latter you can do:
The deploy asset.dfu as usual (DFU files can contain multiple binary sections, so you could also put the firmware in the same DFU as the assets).
Then use uctypes.bytes_at(0x08080000, asset_len) to access the data directly.
An alternative: to load binary data to some external device (here SPI RAM) then you could simply store that binary data directly on the filesystem as a binary file, then copy it to the external SPI RAM device using a simple loop, eg:
Code: Select all
buf = bytearray(1024)
with open('/assets/data.bin', 'rb') as f:
while True:
n = f.readinto(buf)
if n == 0:
break
spi.write(memoryview(buf)[:n])
Code: Select all
python3 tools/dfu.py -b 0x08080000:asset_data.bin asset.dfu
Then use uctypes.bytes_at(0x08080000, asset_len) to access the data directly.