Page 1 of 1

Read a value from a given memory address

Posted: Thu Nov 21, 2019 7:51 am
by uwe_pg
Hello,
how can I read a value from a given memory address (e.g. 0x02000000) using C?

I tested this
char *ptr = (char *) memory;
printf("Data=%c\n", (char) *ptr);
With memory = 0x20000000 it worked, with memory = 0x02000000 I got:
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:...
At stackoverflow I found: "You get a seg fault if you're trying to read something for which you aren't mapped a page."
Ok, but how can I correct map to the correct page?

I need it for a dump of memory to find some challenges.

Re: Read a value from a given memory address

Posted: Thu Nov 21, 2019 10:35 am
by ESP_Sprite
Where did you get the idea 0x02000000 is valid memory?

Re: Read a value from a given memory address

Posted: Thu Nov 21, 2019 2:32 pm
by uwe_pg
The last value I tested was 0x02000000. Yes, I didn't check it at the manual, this was not a good idea.

First time I started with my address 0x10000.

My partitions are:

Code: Select all

nvs,      data, nvs,     0x9000,  0x4000,
otadata,  data, ota,     0xd000,  0x2000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x010000, 0x150000,
....
I got the same error. I expected the first bytes of my program.

Re: Read a value from a given memory address

Posted: Thu Nov 21, 2019 10:06 pm
by WiFive
Those are flash physical addresses, not mmaped virtual addresses.

https://docs.espressif.com/projects/esp ... ormat.html

Re: Read a value from a given memory address

Posted: Fri Nov 22, 2019 4:35 am
by ESP_Sprite
Agreed. Additionally, because there's a MMU 'in the way', you can't just assume all of flash memory is accessible as RAM in a straightforward way; in order to access it like that, you'd need to mmap portions of it using spi_flash_mmap.

Re: Read a value from a given memory address

Posted: Sat Nov 23, 2019 1:51 pm
by uwe_pg
Thank you for your answers.

In the meantime I have read something about the mapping with the function spi_flash_mmap.It did not seem easy to read the program memory.

Have anyone a good sample which I can use to start.