Storing data constants in flash at fixed location

dinesh4761
Posts: 1
Joined: Wed Feb 21, 2018 11:28 am

Storing data constants in flash at fixed location

Postby dinesh4761 » Wed Feb 21, 2018 11:37 am

Hi,

Recently I have decided to migrate to ESP32 from Microchip PIC32MZ2048EFG064 + ATWINC1500 WiFi and experiencing bit interesting to work.
However I came across 1 point for which I am not able to find a solution. Can someone please help me out?

The point to which I need solution is as below
In PIC32, I can declare an WORD constant array at some specified fixed location of say 1024 in length, which can be placed into PIC32 internal flash and can be directly accessed run-time using "<array_name>" e.g. WORD arrayVal = test_array[333];
Here in ESP32 I am not able get a way to do so. Also please note that I have to declare such 5-6 different types of arrays.

Please suggest me a nice solution to this.

Thanks in advance

Regards,
Dinesh

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: Storing data constants in flash at fixed location

Postby ESP_Sprite » Thu Feb 22, 2018 1:15 am

In the ESP32, anything declared as const will end up in the rodata segment, which then will go into flash and is read directly from that. So for your example, you would declare test_array as e.g.

Code: Select all

const uint16_t test_array[1024]={10, 9, 8, 3, 4, 5, 6, ...,};
(assuming that the non-C-standard WORD type is equivalent to an uint16).

Who is online

Users browsing this forum: Bing [Bot] and 112 guests