Chat freely about anything...

User avatar
By lucasromeiro
#79025
Pablo2048 wrote:Yeah, right. I'm curious how exactly your google questions looks like that you didn't get any hints ;-) Anyway - beware of that this library has some glitch so it works, but in some cases it fails. If you spare some time to study how exactly this library works and do some _REAL_ research about SDK method used you definitely find where the problem is...


Maybe the language is a problem for my searches. Knowing how to express the problem is difficult sometimes. Thanks for the tip, I'm going to study the library to absorb the method she uses for this leuture. I am facing problem with some strange resets in my esp. I have not yet discovered the cause, but it occurs in the modbus communication process. collecting this information from the field will help me to investigate better and will try to implement other forms of research.
User avatar
By lucasromeiro
#79055 Hello everyone. I was able to do what I wanted.
I adapted some of the codes found in github and managed to save the stack in a txt file.
Here's a rough draft of how it works.
I hope it helps other people.

Thanks:
@Pablo2048
djoele
TheAustrian
Code: Select all
#include <cont.h>

extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack, uint32_t stack_end ){ 
  register uint32_t sp asm("a1");
  cont_t g_cont __attribute__ ((aligned (16)));

  uint32_t cont_stack_start = (uint32_t) &(g_cont.stack);
  uint32_t cont_stack_end = (uint32_t) g_cont.stack_end;
  uint32_t stack_end2 = stack_end;
  uint32_t offset = 0;


  File carregaArquivos = SPIFFS.open("/log.txt","a");
 
  if (rst_info->reason == REASON_SOFT_WDT_RST) {
      offset = 0x1b0;
  }
  else if (rst_info->reason == REASON_EXCEPTION_RST) {
      offset = 0x1a0;
  }
  else if (rst_info->reason == REASON_WDT_RST) {
      offset = 0x10;
  }
  /*
  if (stack > cont_stack_start && stack < cont_stack_end) {
      carregaArquivos.printf(String(timestamp)+";%s", "ctx: cont");
  }
  else {
      carregaArquivos.printf(String(timestamp)+";%s", "ctx: sys");
  }
  */
  carregaArquivos.printf("sp: %08x end: %08x offset: %04x", stack, stack_end, offset);


  carregaArquivos.print(">>>stack>>>");

  for (uint32_t pos = stack; pos < stack_end; pos += 0x10) {
      uint32_t* values = (uint32_t*)(pos);
      //rough indicator: stack frames usually have SP saved as the second word
      bool looksLikeStackFrame = (values[2] == pos + 0x10);
      carregaArquivos.printf("%08x:  %08x %08x %08x %08x %c", pos, values[0], values[1], values[2], values[3], (looksLikeStackFrame)?'<':' ');
  }
  carregaArquivos.print("<<<stack<<< <");
  carregaArquivos.close();
  }
User avatar
By Pablo2048
#79056 Are you sure about your implementation? There are some things that has to be avoided in crash callback function IMHO - for example dynamic memory allocation when crash come from heap problem. So your String(), << operator and SPIFFS object use in callback are definitely no-go...
User avatar
By lucasromeiro
#79057
Pablo2048 wrote:Are you sure about your implementation? There are some things that has to be avoided in crash callback function IMHO - for example dynamic memory allocation when crash come from heap problem. So your String(), << operator and SPIFFS object use in callback are definitely no-go...

Perfect, well remembered. For my use today, I prefer that. Because the problem I want to find is a WDT.
I'll still simulate other scenarios like HEAP quoted by you.
As I said, it is a draft and must be adapted to the reality of each user.
It can be solved by using eeprom with a fixed buffer.