Hi,
I have been banging my head over the following.
I have setup some functions to read and write to Flash which seem to work fine. But when I try to check the values of a global variable in flash compared to another global variable in RAM I have a problem. Before I even set the flash variable it is already updated.
In detail. The following code is run at boot once.
Global variables are set
uint8_t Test2;
uint8_t gg;
The result is this. Which is ok since Test2 has a value of 48 in flash from before.
Now if I remove the comment on //Test2=gg;
I get the this. Test2 has become =gg=50 without even reaching at this part of the code yet !! It's like it has been updated by magic! This happens all the time whatever value gg has, Test2 has already been updated with it !
Flash write/read issue
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: Flash write/read issue
Could it be that your code is running without you seeing it? Could be that between flashing and opening the monitor (which resets the processor), the CPU gets to execute code for a little bit.
Re: Flash write/read issue
No, the code executes once before the main loop.
I realized I have this problem only in the first flash of the ESP. If I reset it works ok.
The following is between resets. This is repeating which is ok
Ofc this is not solving my problem cause it's the first flash that I'm trying to catch by reading flash if it's initialized or not
I realized I have this problem only in the first flash of the ESP. If I reset it works ok.
The following is between resets. This is repeating which is ok
Ofc this is not solving my problem cause it's the first flash that I'm trying to catch by reading flash if it's initialized or not
-
- Posts: 52
- Joined: Thu Jun 22, 2023 12:50 pm
Re: Flash write/read issue
Hello.
Could you please try to declare those variables as volatile?
Or try to use something like `vTaskDelay(pdMS_TO_TICKS(1000));` from `freertos/FreeRTOS.h` to delay the start.
Could you please try to declare those variables as volatile?
Code: Select all
volatile uint8_t Test2;
volatile uint8_t gg;
Re: Flash write/read issue
Thanks ESP_adokitkat.
It worked with a delay 900ms not less ! The volatile didn't do anything.
There's clearly something very wrong here. I don't suppose I need to wait 900ms before I call my function!
It worked with a delay 900ms not less ! The volatile didn't do anything.
There's clearly something very wrong here. I don't suppose I need to wait 900ms before I call my function!
Re: Flash write/read issue
ok found the problem.
I was trying to use the nvs functions too fast before they had time to initialize (facepalm), so I set the same delay right after them
Thanks a lot!
I was trying to use the nvs functions too fast before they had time to initialize (facepalm), so I set the same delay right after them
Thanks a lot!
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: Flash write/read issue
That cannot be it; nvs initialization is not asynchroneous so nvs is available when the initialization routine finishes. My bet is still that your program runs for a small while (less than 900ms, seemingly) between the flashing being done and your serial monitor starting. Flashing resets the chip after it's done, monitor takes a few hundred ms to start and also resets the chip. So between the flashing and the first time you see text output, your program already ran once.
(Also, there's no need to make those variables volatile; all nvs calls are by definition sequence points, so there's no chance those variables will do something undefined. More generally, you're not doing interrupt or multithreading work here and the variables are in RAM and not hardware addresses, so 'volatile' is entirely unneeded.)
(Also, there's no need to make those variables volatile; all nvs calls are by definition sequence points, so there's no chance those variables will do something undefined. More generally, you're not doing interrupt or multithreading work here and the variables are in RAM and not hardware addresses, so 'volatile' is entirely unneeded.)
Who is online
Users browsing this forum: Baidu [Spider] and 156 guests