PROGMEM

MrSupe
Thu Jan 07, 2016 9:30 pm
Could somebody tell me if it is possible to use PROGMEM known from esp8266 project (esp8266WebServer)?

const char PAGE_NetworkConfiguration[] PROGMEM = R”=====(
<!DOCTYPE html>
<html>
<head>

</head>
<body>
hello!
</body>

</html>
)=====”;


martinayotte
Thu Jan 07, 2016 10:47 pm
Yes, if you mean on ESP8266, but you need to send it using proper functions, send_P() or sendContent_P(), not the variants without the _P, because PROGMEM need to be handled properly.
For STM32, I’ve never try it.

mrburnette
Fri Jan 08, 2016 12:40 am
martinayotte wrote:Yes, if you mean on ESP8266, but you need to send it using proper functions, send_P() or sendContent_P(), not the variants without the _P, because PROGMEM need to be handled properly.

For STM32, I’ve never try it.


stevech
Fri Jan 08, 2016 3:00 am
Today’s ARM GCC, and probably the variant for the ESP8266′ non-ARM cpu, and with AVRs, you can do portable C code

instead of
char* msg1[] PROGMEM = {"~Maple Mini~> Serial Mon> SD Check ~> I2C Scan ` Press AnyKey"


martinayotte
Fri Jan 08, 2016 3:03 am
@Ray, probably you’re not aware of what send_P() and sendContent_P() is doing to transmit huge PROGMEM strings over TCP using ESP8266WebServer …
The main issue is RAM ! If you have a PROGMEM which is, lets say, an JPG with 64K size. You don’t want to have to all those bytes copied to RAM to do a TCP transmit (either HTTP or something else). It need to be transmit by chunks, such as ESP MTU 1640 packet size, but directly from Flash.
So, when I said “For STM32, I’ve never try it.”, it is because I’ve never have to do such thing, especially that ESP8266WebServer never been ported to STM32 ;) . Although that can be a good idea for new project … :)

MrSupe
Fri Jan 08, 2016 9:35 am
The construction below is different from Arduino standard PROGMEM because content could be written without string quotes.
const char PAGE_NetworkConfiguration[] PROGMEM = R”=====(
<!DOCTYPE html>
<html>
<head>

</head>
<body class=”bodyclass”>
hello!
</body>

</html>
)=====”;

this is standard Arduino construction (content have to be wrapped in quotes):

const char PAGE_NetworkConfiguration[] PROGMEM = {“
<!DOCTYPE html>
<html>
<head>

</head>
<body class=\”bodyclass\”>
hello!
</body>

</html>
“};

So question is, if it is possible to make similar PROGMEM construction like in esp8266: long string without quotes.


mrburnette
Fri Jan 08, 2016 1:09 pm
MrSupe wrote:The construction below is different from Arduino standard PROGMEM because content could be written without string quotes.
const char PAGE_NetworkConfiguration[] PROGMEM = R”=====(

)=====“;

So question is, if it is possible to make similar PROGMEM construction like in esp8266: long string without quotes.


MrSupe
Fri Jan 08, 2016 1:57 pm
I talking about this construction in ArduinoIDE. I am using ArduinoIDE with esp8266…

RogerClark
Fri Jan 08, 2016 7:58 pm
Silly question… But how does this relate to the STM32.

If this is an ESP8266 question, you would probably be better off posting to a forum for the ESP8266

In general I no longer use the PROGMEM or F directives/ macros, as I hardly ever use AVR devices any more.

In fact I find on the ESP8266 that I get strange issues when using the F macro when sending data via TCP, so when recently porting some AVR code to ESP8266 I had remove all the F macros.


MrSupe
Fri Jan 08, 2016 8:19 pm
this is general question…
I am trying to port esp8266WebServer to ST32. I would like to be as much as compatible as possible.
Moreover I thing it is great idea to have PROGMEM working as above (no need to use string quotation).

One more question: what big chunks I can use to transfer strings over TCP with ST32?


martinayotte
Fri Jan 08, 2016 9:49 pm
I’m not a network expert, but the 1460 magic number I’ve wrote above is not related to any CPU, but is a quite standard value on any platforms.

stevech
Sat Jan 09, 2016 12:47 am
MrSupe wrote:this is general question…
I am trying to port esp8266WebServer to ST32. I would like to be as much as compatible as possible.
Moreover I thing it is great idea to have PROGMEM working as above (no need to use string quotation).

One more question: what big chunks I can use to transfer strings over TCP with ST32?


RogerClark
Sat Jan 09, 2016 2:44 am
stevech wrote:But PROGMEM is n/a for the ESP8266 and the STM32. It’s applicable only to Harvard architectureslike the AVR.

martinayotte
Sat Jan 09, 2016 2:16 pm
Simple search with PROGMEM doesn’t reveal all the thing under the hood.
I don’t know all the mechanics in details, but it all about using Flash directly without bringing it into RAM cache, which is helpful in case of huge data.
Since the Flash is an external SPI on ESP8266, there are functions such as memcpy_P(), strcpy_P(), strlen_P, etc. to access bytes, words, etc. thru macros pgm_read_byte(), pgm_read_word(), etc. which takes care of addressing alignments.

Of course, on STM32, all that mechanics can be removed, but maybe it is a good idea to keep some of the macros just to have compatible application code.


stevech
Sat Jan 09, 2016 7:05 pm
On the ARM-based Teensy, the GCC compiler command line and .h files and so on cause the f(x) macro to be a NOP, and all the xxx_P() are also coded to n/a.The ESP8266 and STM32F could/should do the same.

Of course, to avoid having constants in flash copied to RAM as initialized variables, you have to declare such variables with the “const” attribute, rather than PROGMEM. The current Arduino for AVR will work as well, with this change.


mrburnette
Sun Jan 10, 2016 7:19 pm
stevech wrote:
<…>
The current Arduino for AVR will work as well, with this change.

stevech
Mon Jan 11, 2016 8:54 pm
search this page for mention of the F() macro. https://www.pjrc.com/teensy/arduino_contrib.html

For the ARMs and other conventional single-address-space MCUs and CPUS, it’s not needed but for ARM is is “NOP” macro like
#define F(x) x

So that compiling for ARM targets can ignore the F() macro

That web page half-incorrectly says “…because the compiler defaults to allocating strings in RAM …”
More correctly, an initialized variable that is not declared as const (or the same using PROGMEM or F() macro for strings), is stored in flash and copied to RAM by the C startup code.

On Harvard architecture MCUs like the AVR (and PIC) the flash and RAM are separate address spaces and special code is needed to read data within flash.


Leave a Reply

Your email address will not be published. Required fields are marked *