Read a value from a given memory address

uwe_pg
Posts: 11
Joined: Sun Jun 18, 2017 9:07 am

Read a value from a given memory address

Postby uwe_pg » Thu Nov 21, 2019 7:51 am

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.

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

Re: Read a value from a given memory address

Postby ESP_Sprite » Thu Nov 21, 2019 10:35 am

Where did you get the idea 0x02000000 is valid memory?

uwe_pg
Posts: 11
Joined: Sun Jun 18, 2017 9:07 am

Re: Read a value from a given memory address

Postby uwe_pg » Thu Nov 21, 2019 2:32 pm

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.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Read a value from a given memory address

Postby WiFive » Thu Nov 21, 2019 10:06 pm

Those are flash physical addresses, not mmaped virtual addresses.

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

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

Re: Read a value from a given memory address

Postby ESP_Sprite » Fri Nov 22, 2019 4:35 am

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.

uwe_pg
Posts: 11
Joined: Sun Jun 18, 2017 9:07 am

Re: Read a value from a given memory address

Postby uwe_pg » Sat Nov 23, 2019 1:51 pm

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.

Who is online

Users browsing this forum: No registered users and 214 guests