Servo code causing Exception 9

Using ESP12E 8266 with Servo Library. Have used successfully many times but now I am consistently getting an Exception 9. The Exception Decoder tool consistently shows a Servo routine StartWaveForm at the top of the stack. I have tried aligned the Ints used to write to the servos. I have changed a char * routine to strcpy into a buffer. I've moved code around (just in case there was something to be gained). I've worked on this issue for many hours. I've also taken out the Servo code and the Exception disappears, only to return when I put the Servo code back in (natch). So I am sure it has something to do with the library. I also downgraded from 1.1.8 to 1.1.6 with no change. Following is the stack as reported by the decoder tool.

Exception 9: LoadStoreAlignmentCause: Load or store to an unaligned address PC: 0x40105e64 EXCVADDR: 0x00000003 Decoding stack results 0x4020ccb0:
startWaveform(uint8_t, uint32_t, uint32_t, uint32_t, int8_t, uint32_t, bool) at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266*core_esp8266_waveform_pwm.cpp* line 411 0x4020a484: Servo::writeMicroseconds(int) at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\Servo\src*Servo.cpp* line 120 0x4020ce94: __delay(unsigned long) at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266*core_esp8266_wiring.cpp* line 49 0x4020a4d6: Servo::write(int) at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\Servo\src*Servo.cpp* line 109 0x402012ba: goExecute(int, int) at C:\ArduinoWork\Sketches\Rovers\WifiFighter\WifiFighter_RT/Helper.ino line 37 0x40201517: handleWebSocketMessage(void, unsigned char, unsigned int)** at C:\ArduinoWork\Sketches\Rovers\WifiFighter\WifiFighter_RT/WifiFighter_RT.ino line 159 0x4020a810: HardwareSerial::write(unsigned char const, unsigned int)* at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/HardwareSerial.h line 193 0x4020a804: HardwareSerial::write(unsigned char const, unsigned int)* at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/HardwareSerial.h line 193 0x4020ad24: Print::write(char const)* at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/Print.h line 59 0x4020aed0: Print::println() at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/Print.h line 57 0x402016c0: onEvent(AsyncWebSocket, AsyncWebSocketClient, AwsEventType, void*, unsigned char*, unsigned int)** at C:\ArduinoWork\Sketches\Rovers\WifiFighter\WifiFighter_RT/WifiFighter_RT.ino line 204 0x40219a68: operator delete(void)* at /workdir/repo/gcc-gnu/libstdc++-v3/libsupc++/ line 49 0x4020f1be: std::_Function_handler::_M_invoke(std::_Any_data const&, AsyncWebSocket&&, AsyncWebSocketClient&&, AwsEventType&&, void*&&, unsigned char*&&, unsigned int&&)** at c:\users\wdcas\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\bits/std_function.h line 289 0x4020f490: AsyncWebSocket::_handleEvent(AsyncWebSocketClient, AwsEventType, void, unsigned char*, unsigned int)** at c:\users\wdcas\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\3.0.4-gcc10.3-1757bed\xtensa-lx106-elf\include\c++\10.3.0\bits/std_function.h line 617 0x4010084d: millis() at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266*core_esp8266_wiring.cpp* line 193 0x40204120: AsyncWebSocketClient::_onData(void, unsigned int)* at C:\ArduinoWork\Sketches\libraries\ESPAsyncWebServer-master\src*AsyncWebSocket.cpp* line 693 0x4010084d: millis() at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266*core_esp8266_wiring.cpp* line 193 0x4020414c: std::_Function_handler >::_M_invoke(const std::_Any_data &, void &&, AsyncClient &&, void &&, unsigned int &&) at C:\ArduinoWork\Sketches\libraries\ESPAsyncWebServer-master\src*AsyncWebSocket.cpp line 483 0x4020279c: AsyncClient::_recv(std::shared_ptr&, tcp_pcb, pbuf, long) at C:\ArduinoWork\Sketches\libraries\ESPAsyncTCP-master\src/ESPAsyncTCP.h line 103 0x40202804: AsyncClient::_s_recv(void, tcp_pcb, pbuf*, long)** at C:\ArduinoWork\Sketches\libraries\ESPAsyncTCP-master\src*ESPAsyncTCP.cpp* line 737 0x40224289: tcp_input at core/tcp_in.c line 501 0x40221a11: ip4_input at core/ipv4/ip4.c line 1467 0x40100d6b: umm_free_core(umm_heap_context_t, void)** at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\umm_malloc*umm_malloc.cpp* line 549 0x4021a715: ethernet_input_LWIP2 at netif/ethernet.c line 188 0x4021a514: esp2glue_ethernet_input at glue-lwip/lwip-git.c line 116 0x40242e2d: ethernet_input at glue-esp/lwip-esp.c line 365 0x40242e3f: ethernet_input at glue-esp/lwip-esp.c line 373 0x40100f24: umm_init() at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\umm_malloc*umm_malloc.cpp* line 476 0x401000ac: app_entry_redefinable() at C:\Users\wdcas\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266*core_esp8266_main.cpp* line 325

PLEASE NOTE: the goExecute function comes from my code.

Any ideas or input is welcomed.


David C

Post your code.

From these version numbers, I assume you are talking about the standard official Servo library:

However, the ESP8266 boards platform comes with its own Servo library, which will always be used when you are compiling for an ESP8266 board:

So the version of the standard library you have installed makes no difference.

You can learn which libraries are in use by opening File > Preferences in the Arduino IDE, compiling your sketch, and then checking the contents of the black output pane at the bottom of the Arduino IDE window. There you will see something like this:

Multiple libraries were found for "Servo.h"
 Used: C:\Users\asdf\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\Servo
 Not used: E:\arduino\ide\arduino-1.8.19\libraries\Servo
 Not used: C:\Users\asdf\Documents\Arduino\libraries\Servo
Using library Servo at version 1.0.2 in folder: C:\Users\asdf\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\Servo

Thanks for the replies. I learned that the 8266 board's own Servo library is being used (verbose compiler warnings turned on). I also found that this is a known problem with 8266. Re: Memory alignment on ESP8266 - Exception(9) — Read Modify Write
While I've been unable to fix the issue with the aligned attribute on the values I'm passing to the servo.write() function, I have found a good work around. Not as elegant as I'd like, but it works.

Thanks again for the replies and suggestions.

You are welcome. Thanks for taking the time to post an update with your findings.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.