Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Used EEPROM addresses #8004

Closed
4 of 6 tasks
HamzaHajeir opened this issue Apr 26, 2021 · 7 comments
Closed
4 of 6 tasks

Used EEPROM addresses #8004

HamzaHajeir opened this issue Apr 26, 2021 · 7 comments

Comments

@HamzaHajeir
Copy link

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-12F
  • Core Version: 2.7.4
  • Development Env: Arduino IDE
  • Operating System: Windows 10

Settings in IDE

  • Module: Nodemcu 1.0
  • Flash Mode: [qio|dio|other]
  • Flash Size: 4MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: nodemcu
  • Flash Frequency: [40Mhz]
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 921600
    image

Problem Description

A different EEPROM start address to what's mentioned in 4m1m ld script
I'm using the flash tool to upload an integer number that's used in an authentication process beside a MAC address, so I've chosen to upload it using esptool.py, However at the moment I'm using ESP Flash Tool to validate it.

image

I'm uploading number 5 (in hexadecimal) to address 0x3FB000.
and number 10 (in hexadecimal) to addresss 0x5FB000

The expected result is that EEPROM.read(0) would return 10, It's returning 5.

The two files are just 4 bytes, little endian, with hex view is:
node_id5.bin: 05 00 00 00
node_id10.bin: 0A 00 00 00

The MCVE contains a function that manually reads the target address's content, I can remove it if it's not helping at all.

What should be the issue? I'm not sure why it's reading another address other than the expected one.

MCVE Sketch

#include <EEPROM.h>

int get_id_in_flash() {
   int* id_read_addr = (int*) 0x405FB000;
   //we can read 4-byte aligned address directly without memcpy
   return *id_read_addr;
}

void initEEPROM()
{
  int value = get_id_in_flash();
  Serial.printf("get_id()=%u\n", value);
  //init, only called once.
  //our EEPROM area is only 4 bytes long.
  //triggers reading flash into internal (4-byte) buffer
  EEPROM.begin(4);

  //read value stored during production at EEPROM index 0
  uint32_t node_id = 0;
  EEPROM.get(0, node_id);
  //use node_id variable..
  Serial.printf("Node_ID=");
  Serial.println(node_id);
  // Serial.printf("Node_ID=%u\n",node_id);
  //optional: we can read the node ID into a RAM variable once and then
  //EEPROM.end();
  //to release the internal 4-byte buffer.
}
void setup()
{
  Serial.begin(115200);
  initEEPROM();
}

void loop() {
  // put your main code here, to run repeatedly:
}

Debug Messages

get_id()=393244
Node_ID=5
@d-a-v
Copy link
Collaborator

d-a-v commented Apr 27, 2021

What about the result of

extern "C" uint32_t _EEPROM_start;
...
    Serial.printf("eeprom start is %p\n", &_EEPROM_start);

The shown result and where EEPROM class is going to read its data depend on the flash configuration used at sketch build time.
There is an ongoing PR (or is it testing, tested?) to make this automatic, depending only on the detected flash size and not on user (mis-)configuration: #6690

@HamzaHajeir
Copy link
Author

What about the result of

extern "C" uint32_t _EEPROM_start;
...
    Serial.printf("eeprom start is %p\n", &_EEPROM_start);

The shown result and where EEPROM class is going to read its data depend on the flash configuration used at sketch build time.
There is an ongoing PR (or is it testing, tested?) to make this automatic, depending only on the detected flash size and not on user (mis-)configuration: #6690

Thanks @d-a-v, I've run the sketch and it gave me a pretty weird result:

eeprom start is 0x405fb000

Where EEPROM.get(0, node_id); reads 5 instead of 10.

@d-a-v
Copy link
Collaborator

d-a-v commented Apr 28, 2021

I'm not the expert. Docs say the flash chip is mapped to address 0x40200000.
We have 0x405fb000 - 0x40200000 = 0x3fb000 which is where you stored 5 in your bin file.

@HamzaHajeir
Copy link
Author

HamzaHajeir commented Apr 28, 2021 via email

@HamzaHajeir
Copy link
Author

HamzaHajeir commented Apr 28, 2021

Closed due to incorrect understanding of memory mapping.

I'm not the expert. Docs say the flash chip is mapped to address 0x40200000.

Thanks @d-a-v, I'd like to have the reference of this information, Couldn't find it.

@d-a-v
Copy link
Collaborator

d-a-v commented Apr 29, 2021

@HamzaHajeir the keywords are "esp8266 memory map"

@HamzaHajeir
Copy link
Author

I've found it, And here's it for reference:
https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants