Page 1 of 1

esp_flash_read/esp_flash_write problem

Posted: Sat Aug 10, 2024 6:19 pm
by gailu96
Hi Experts,

I am using ESP32 version 3.0.4 in Arduino. I have dedicated 1MB for user data in my partition table and using esp_flash_read()/esp_flash_write() to read and write data. It seems that either in write or in read only one byte length is taken and length argument is ignored. I built the code in Arduino. Here is the code. Can someone please tell me why only first byte is read?

Code: Select all

/*
   SPIFlash
*/

extern "C"{
    // Platform Includes
    #include <esp_flash.h>
    #include <esp_err.h>
}

#include <Arduino.h>


// the setup function runs once when you press reset or power the board
void setup() {
  esp_err_t ret;

  Serial.begin(115200);

  ret = esp_flash_init(esp_flash_default_chip);

  Serial.printf("esp_flash_init() returned: %s\r\n", esp_err_to_name(ret));
  
}

// the loop function runs over and over again forever
void loop() {
  esp_err_t ret;
  const char buffer[] = "Hello World";
  char value[16];

  delay(1000);
  ret = esp_flash_write(esp_flash_default_chip, buffer, 0x100000, strlen(buffer)+1);
  Serial.printf("esp_flash_write() returned: %s length written: %d\r\n", esp_err_to_name(ret), strlen(buffer)+1);

  delay(1000);
  ret = esp_flash_read(esp_flash_default_chip, value, 0x100000, 16);
  Serial.printf("esp_flash_read() returned: %s Original Value: %s Retrieved Value: %s\r\n", esp_err_to_name(ret), buffer, value);  

  delay(5000);

}
And here is the output

Code: Select all

esp_flash_write() returned: ESP_OK length written: 12
esp_flash_read() returned: ESP_OK Original Value: Hello World Retrieved Value: H
esp_flash_write() returned: ESP_OK length written: 12
esp_flash_read() returned: ESP_OK Original Value: Hello World Retrieved Value: H

Re: esp_flash_read/esp_flash_write problem

Posted: Mon Aug 12, 2024 7:54 am
by pacucha42
This seems to answered here, right?
https://esp32.com/viewtopic.php?f=2&t=4 ... edce257e0c