Saving data from buffer to spiffs file results in Guru Meditation: Load Prohibited error. How to resolve this?
Posted: 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:
http function which retrieves backend server data in hexdecimal format and calls create_file_app to save data to spiffs file:
Here's the output upon running my program:
Function to open spiffs file and record data:
- void create_file_app(char buffer)
- {
- ESP_LOGI(TAG, "Opening file");
- //ESP_LOGI(TAG, "output buffer to spiffs: %s \n", buffer);
- FILE* f = fopen("/spiffs/hello.png", "a+");
- if (f == NULL) {
- ESP_LOGE(TAG, "Failed to open file for writing");
- return;
- }
- fprintf(f, buffer);
- fclose(f);
- ESP_LOGI(TAG, "File written");
- static void http_native_request(void)
- {
- #define MAX_HTTP_OUTPUT_BUFFER 2048
- char output_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0}; // Buffer to store response of http request
- int content_length = 0;
- int track_length = 0;
- int max_buff = 2048;
- esp_http_client_config_t config = {
- .url = "http://192.168.1.122/api?file=abc",
- };
- esp_http_client_handle_t client = esp_http_client_init(&config);
- // GET Request
- esp_http_client_set_method(client, HTTP_METHOD_GET);
- esp_err_t err = esp_http_client_open(client, 0);
- if (err != ESP_OK) {
- ESP_LOGE(TAG, "Failed to open HTTP connection: %s", esp_err_to_name(err));
- } else {
- content_length = esp_http_client_fetch_headers(client);
- track_length = content_length;
- if (content_length < 0) {
- ESP_LOGE(TAG, "HTTP client fetch headers failed");
- } else {
- //adding new code
- do {
- int data_read = esp_http_client_read_response(client, output_buffer, max_buff);
- if (data_read >= 0) {
- ESP_LOGI(TAG, "HTTP GET Status = %d, content_length = %d",
- esp_http_client_get_status_code(client),
- esp_http_client_get_content_length(client));
- //ESP_LOG_BUFFER_CHAR(TAG, output_buffer, strlen(output_buffer));
- track_length -= data_read;
- if (max_buff > track_length){
- max_buff = track_length;
- }
- create_file_app(output_buffer); //function which opens and records data to spiffs file
- ESP_LOGI(TAG, "max_buff = %d, track_length = %d \n", max_buff, track_length);
- } else {
- ESP_LOGE(TAG, "Failed to read response");
- }
- } while (
- track_length>0
- );
- }
- }
- esp_http_client_close(client);
- }
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.