KurtE
Senior Member+
Supposed we have a constant table of items that also contain strings, that we would like to keep out of the ITCM or DTCM memory how best to do it?
Example:
If I remember correctly the known_chips array will stay in flash, but those strings will not....
I thought one solution to this was using the F() were setup to do this...
like:
This leads to a compiler error saying, it can not convert a (const __FlashStringHelper *) to a (const char *)
You can fix this error by casting...
However this still does not appear to leave the string in flash...
At least if I run the sketch:
Output:
Note: if I add
So is the only way to do the table with keeping strings out of memory to either
a) define the strings as individual strings like I mentioned and reference them
b) or maybe instead of structure having (const char *) instead have const char[10] where the 10 is size of largest one
Am I missing something obvious?
Edit, should mention this run was using MMOD
Example:
Code:
PROGMEM static const struct chipinfo {
uint8_t id[3];
uint8_t addrbits; // number of address bits, 24 or 32
uint16_t progsize; // page size for programming, in bytes
uint32_t erasesize; // sector size for erasing, in bytes
uint8_t erasecmd; // command to use for sector erase
uint32_t chipsize; // total number of bytes in the chip
uint32_t progtime; // maximum microseconds to wait for page programming
uint32_t erasetime; // maximum microseconds to wait for sector erase
const char *pn; //flash name
} known_chips[] = {
//NAND
//{{0xEF, 0xAA, 0x21}, 24, 2048, 131072, 134217728, 2000, 15000}, //Winbond W25N01G
//Upper 24 blocks * 128KB/block will be used for bad block replacement area
//so reducing total chip size: 134217728 - 24*131072
{{0xEF, 0xAA, 0x21}, 24, 2048, 131072, 0, 131596288, 2000, 15000, "W25N01GVZEIG"}, //Winbond W25N01G
//{{0xEF, 0xAA, 0x22}, 24, 2048, 131072, 134217728*2, 2000, 15000}, //Winbond W25N02G
{{0xEF, 0xAA, 0x22}, 24, 2048, 131072, 0, 265289728, 2000, 15000, "W25N02KVZEIR"}, //Winbond W25N02G
{{0xEF, 0xBB, 0x21}, 24, 2048, 131072, 0, 265289728, 2000, 15000, "W25M02"}, //Winbond W25M02
};
I thought one solution to this was using the F() were setup to do this...
like:
Code:
{{0xEF, 0xAA, 0x22}, 24, 2048, 131072, 0, 265289728, 2000, 15000, F("W25N02KVZEIR")}, //Winbond W25N02G
This leads to a compiler error saying, it can not convert a (const __FlashStringHelper *) to a (const char *)
You can fix this error by casting...
However this still does not appear to leave the string in flash...
At least if I run the sketch:
Code:
void setup()
{
while (!Serial) ;
Serial.begin(115200);
const char *p;
p = "abcd";
Serial.printf("%p - %s\n", (uint32_t)p, p);
p = (const char *)F("efgh");
Serial.printf("%p - %s\n", (uint32_t)p, p);
const __FlashStringHelper *pf = F("ijkl");
Serial.printf("%p - %s\n", (uint32_t)pf, pf);
}
void loop() { }
Output:
Code:
0x200004b8 - abcd
0x200004cc - efgh
0x200004d4 - ijkl
Note: if I add
Code:
const char PROGMEM name1[] = "In Flash";
...
p = name1;
Serial.printf("%p - %s\n", (uint32_t)p, p);
Code:
0x200004b8 - abcd
0x200004cc - efgh
0x200004d4 - ijkl
0x60001aa4 - In Flash
a) define the strings as individual strings like I mentioned and reference them
b) or maybe instead of structure having (const char *) instead have const char[10] where the 10 is size of largest one
Am I missing something obvious?
Edit, should mention this run was using MMOD