Ok I have an implementation of a circular partition running, really simplistic with a signature and a monotonic block id per logical block in the partition. Quick and very resilient against power breaks.
Since my data chunks are just 8 bytes (bit stuffed values) and they fit very well in the logical blocks, I don't use any crc on them.
The data you are writing is this fixed length or variable and the CRC you are using, is this per chunk of data written? and how much overhead is that?
Can I write directly to flash/partition without fatfs/wear lvl etc drivers?
Re: Can I write directly to flash/partition without fatfs/wear lvl etc drivers?
My base data strutcure is only 36 bytes in size. + 4 bytes for binary framing (sof/eof). Each byte then has the possibility to be delimited. thus my data range is anywhere from 40 - 76 bytes. Though averages around 41 bytes.
I did this because it doesn't matter how corrupt my data gets, whether there is jumps, bad sectors or anything, I can still interpret all remaining data.
An example of what I do:
if I had the following structure (I forget the exact way to write the packed attribute):
I reorded my b1 -> b5 for better alignment, but still need it to be packed.
This was written all by memory, so I dont know what bugs might be in it, but I hope you get the idea
I did this because it doesn't matter how corrupt my data gets, whether there is jumps, bad sectors or anything, I can still interpret all remaining data.
An example of what I do:
if I had the following structure (I forget the exact way to write the packed attribute):
Code: Select all
typedef struct __attribute((packed))__ {
uint16_t len;
uint8_t b1;
uint8_t b2;
uint8_t b3;
uint8_t b4;
uint32_t s1 : 11;
uint32_t s1 : 7;
uint32_t s1 : 5;
uint32_t s1 : 9;
char x[12];
uint8_t b5;
uint8_t crc;
} Example_t;
Example_t example = {24,1,2,3,4,3,3,3,3,"asd",5,0x34};
bool StoreData(void) {
uint8_t * data = &example;
uint32_t len = sizeof(example);
uint8_t * output_buf = (uint8_t *)malloc(len*2+4);
if (output_buf == NULL) {
//something went wrong...
return false;
}
//using index to enumerate through buffer instead of doing (end_ptr - output_buf) is more readable later on for write sizing
int index = 0;
ptr[index++] = 0x02;
ptr[index++] = 0x01;
for (int i = 0; i < len; i++) {
ptr[index++] = data[i];
if (data[i] == 0x02) {
ptr[index++] = 0x02;
}
}
ptr[index++] = 0x02;
ptr[index++] = 0x03;
esp_write_partition(some_partition, some_address, output_buf, index);
free(output_buf);
return true;
}
This was written all by memory, so I dont know what bugs might be in it, but I hope you get the idea
Who is online
Users browsing this forum: jtroncin21 and 119 guests