-->
Page 1 of 1

Random crash after removing unused library

PostPosted: Thu Feb 14, 2019 4:22 pm
by gmag11
Hello,

I'm developing a sensor platform using ESP-NOW protocol. I started using WiFiEspNow library but at some point I decided to use plain sdk functions.

Node and gateway code works fine, so I wanted to cleanup code before going on.

When I remove `#include <WiFiEspNow.h>` line I get random crashes both on gateway and sensor node. I've double and triple checked that there is no reference in my code to it, and looked inside library files for anything that can cause this problem. Sincerely I do not understand this issue. It is an X-File for me.

This is one of the crash dumps I get:

Code: Select allException (9):
epc1=0x40204128 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0020453a depc=0x00000000

ctx: sys
sp: 3fffed40 end: 3fffffb0 offset: 01a0

   :Error:9 -> LoadStoreAlignmentCause: Attempt to read/write memory with an unaligned address (for example, trying to read/write a 32-bit word at an address that is not a multiple of 4)
   0x40204128 ESP8266WiFiGenericClass
   :?:::0x40215e2e:hostap_input
   :?:::0x40103125:lmacIsIdle
   :?:::0x4010426a:lmacTxFrame
   :?:::0x40100ab6:ppEnqueueRxq
   :?:::0x40100883:ppProcessTxQ
   :?:::0x401008be:ppProcessTxQ
   :?:::0x40230b7c:wifi_set_status_led_output_level
   : ?? ??:0
   : ?? ??:0
   : ?? ??:0
   :?:::0x40104424:call_user_start_local
   :?:::0x4010442a:call_user_start_local
   :?:::0x4010000d:call_user_start
   :?:::0x40226917:pp_attach
   :?:::0x40226966:pp_attach
   :?:::0x4010106b:ppCalFrameTimes
   :?:::0x4021897a:ieee80211_output_pbuf
   :?:::0x402259d4:ppTxPkt
   :?:::0x40218ae3:ieee80211_output_pbuf
   :?:::0x40104bfd:ets_timer_disarm
   : ?? ??:0
   :?:::0x401049a3:wdt_feed
   :808 (discriminator 2):::0x40206654:Curve25519
   0x40204526 Curve25519
   0x402126b8 etharp_raw
   0x4020b078 __ssputs_r
   0x402071cd _printf_common
   0x40207588 _printf_i
   :?:::0x40103e6f:lmacMSDUAged
   :?:::0x401037de:lmacRecycleMPDU
   :?:::0x40100f22:pp_post
   :?:::0x4010431f:lmacRxDone
   :?:::0x40101c3d:trc_NeedRTS
   :?:::0x40101e0e:trc_NeedRTS
   :?:::0x4010224e:wDev_ProcessFiq
   :?:::0x40101fe8:wDev_ProcessFiq
   : ?? ??:0
   : ?? ??:0
   0x401064d4 millis
   0x402039a9 CryptModule
   :?:::0x40230843:wifi_get_macaddr
   0x402033a8 loop
   0x402059f4 HardwareSerial
   0x402056d9 esp_schedule


I am confused about LoadStoreAlignmentCause. All buffers are accessed as uint8_t pointers and managed with memcpy.

I have my code on Github https://github.com/gmag11/ESP-NOW-sensor/tree/master/espnow_sensor. In order to reproduce this problem only sensor code is needed. Just comment first line on `espnow_sensor.ino`. If that line is active it woks perfectly.

I'm using Visual Micro to compile this project, but Arduino IDE results the same behavior.

I have absolutely no clue about what can be the reason. Any advice will be helpful.

Thank you

Re: Random crash after removing unused library

PostPosted: Sat Feb 23, 2019 8:25 am
by theenggprojects
You have to include the library header line `#include <WiFiEspNow.h>` in order for your code to use these files. There's must be some function, your code is using from that library.

Sometimes, it happens that Library A is dependent on Library B so you are not directly using Library B in your code but in order for Library A to use it you have to include Library B. I hope you understood the concept. Arduino IDE is better option though. https://www.theengineeringprojects.com/ ... tions.html

Re: Random crash after removing unused library

PostPosted: Mon Apr 01, 2019 5:19 am
by gmag11
Finally, I found the problem.

It was related to a debug string whose length was not controlled. This caused accesses out of allocated memory.

Most probably, including that library made that writing into that address was not harmful because its functions were not used.

I've learnt something new :D

Regards