Saving data from buffer to spiffs file results in Guru Meditation: Load Prohibited error. How to resolve this?

karunt
Posts: 94
Joined: Sat Apr 03, 2021 7:58 am

Saving data from buffer to spiffs file results in Guru Meditation: Load Prohibited error. How to resolve this?

Postby karunt » Fri May 14, 2021 1:43 pm

I'm using the following code to retrieve hexadecimal data pertaining to an image from a backend node.js server which gets stored in "output_buffer" each time esp_http_client_read_response is called in a while loop. When I pass output_buffer to another function to store the data in a spiffs file, I get a Load Prohibited error. Ultimately, I'm trying to save an image to a spiffs file. I read about enabling gdbstub, so I did that. I understand that there's some issue with the address listed next to EXCVADDR, which is 0x00000060. But besides this, I have no clue how to investigate or resolve this issue. Any help would be appreciated. Here's my code:

Function to open spiffs file and record data:
  1. void create_file_app(char buffer)
  2. {
  3.     ESP_LOGI(TAG, "Opening file");
  4.     //ESP_LOGI(TAG, "output buffer to spiffs: %s \n", buffer);
  5.     FILE* f = fopen("/spiffs/hello.png", "a+");
  6.     if (f == NULL) {
  7.         ESP_LOGE(TAG, "Failed to open file for writing");
  8.         return;
  9.     }
  10.     fprintf(f, buffer);
  11.     fclose(f);
  12.     ESP_LOGI(TAG, "File written");
http function which retrieves backend server data in hexdecimal format and calls create_file_app to save data to spiffs file:
  1. static void http_native_request(void)
  2. {
  3.     #define MAX_HTTP_OUTPUT_BUFFER 2048
  4.     char output_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0};   // Buffer to store response of http request
  5.     int content_length = 0;
  6.     int track_length = 0;
  7.     int max_buff = 2048;
  8.     esp_http_client_config_t config = {
  9.         .url = "http://192.168.1.122/api?file=abc",
  10.     };
  11.     esp_http_client_handle_t client = esp_http_client_init(&config);
  12.  
  13.     // GET Request
  14.     esp_http_client_set_method(client, HTTP_METHOD_GET);
  15.     esp_err_t err = esp_http_client_open(client, 0);
  16.     if (err != ESP_OK) {
  17.         ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
  18.     } else {
  19.         content_length = esp_http_client_fetch_headers(client);
  20.         track_length = content_length;
  21.         if (content_length < 0) {
  22.             ESP_LOGE(TAG, "HTTP client fetch headers failed");
  23.         } else {
  24.             //adding new code
  25.             do {
  26.             int data_read = esp_http_client_read_response(client, output_buffer, max_buff);
  27.             if (data_read >= 0) {
  28.                 ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d",
  29.                 esp_http_client_get_status_code(client),
  30.                 esp_http_client_get_content_length(client));
  31.                 //ESP_LOG_BUFFER_CHAR(TAG, output_buffer, strlen(output_buffer));
  32.                 track_length -= data_read;
  33.                 if (max_buff > track_length){
  34.                     max_buff = track_length;
  35.                 }
  36.                 create_file_app(output_buffer); //function which opens and records data to spiffs file
  37.                 ESP_LOGI(TAG, "max_buff = %d, track_length = %d \n", max_buff, track_length);
  38.             } else {
  39.                 ESP_LOGE(TAG, "Failed to read response");
  40.             }
  41.             } while (
  42.                 track_length>0
  43.             );
  44.         }
  45.     }
  46.     esp_http_client_close(client);
  47. }
Here's the output upon running my program:

Code: Select all

I (5721) HTTP_CLIENT: HTTP GET Status = 200, content_length = 9035
I (5721) spiffs: Opening file
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x40156ef2  PS      : 0x00060430  A0      : 0x80150378  A1      : 0x3ffc81d0
0x40156ef2: _vfprintf_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:918

A2      : 0x00000000  A3      : 0x00000060  A4      : 0x00000000  A5      : 0x00000000
A6      : 0x3ffc84f0  A7      : 0x00000008  A8      : 0x3ffae9f0  A9      : 0x3ffc81b0
A10     : 0x00000000  A11     : 0x3ffc81e0  A12     : 0x3ffba198  A13     : 0x0000ff00
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x0000001c  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000060  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff

Backtrace:0x40156eef:0x3ffc81d0 0x40150375:0x3ffc84e0 0x400d59e6:0x3ffc8530 0x400d5922:0x3ffc8550 0x400d5963:0x3ffc8de0 0x40087839:0x3ffc8e00
0x40156eef: _vfprintf_r at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:918

0x40150375: fprintf at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/fprintf.c:54

0x400d59e6: create_file_app at c:\users\karun\epuzzle\epuzzle2020\ground0\epuzz\build/../main/spiffs.c:22

0x400d5922: http_native_request at c:\users\karun\epuzzle\epuzzle2020\ground0\epuzz\build/../main/http.c:88

0x400d5963: http_test_task at c:\users\karun\epuzzle\epuzzle2020\ground0\epuzz\build/../main/http.c:103

0x40087839: vPortTaskWrapper at C:/Users/Karun/ESP/esp-idf/components/freertos/xtensa/port.c:143

ELF file SHA256: 2a1ea04526d56e2d

Entering gdb stub now.
$T0b#e6GNU gdb (crosstool-NG esp-2020r3) 8.1.0.20180627-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-host_w64-mingw32 --target=xtensa-esp32-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from c:\users\karun\epuzzle\epuzzle2020\ground0\epuzz\build\epuzz.elf...done.
Remote debugging using \\.\COM3
warning: unrecognized item "T0b" in "qSupported" response
_vfprintf_r (data=<optimized out>, fp=<optimized out>, fmt0=<optimized out>, ap=...)
    at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:918
918     /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c: No such file or directory.

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

Re: Saving data from buffer to spiffs file results in Guru Meditation: Load Prohibited error. How to resolve this?

Postby ESP_Sprite » Mon May 17, 2021 1:59 am

Pay attention to your compiler warnings. Your error is in this line:

Code: Select all

void create_file_app(char buffer)

Who is online

Users browsing this forum: No registered users and 63 guests