plieningerweb / esp8266-software-uart

Software UART / Software Serial / SoftUart for ESP8266 to connect more than one UART
MIT License
124 stars 42 forks source link

Fatal exception (28) thrown on SoftUART Init #4

Closed krzychb closed 8 years ago

krzychb commented 9 years ago

After doing stress testing of SoftUWART I have stumbled across the following fault scenario:

If data stream is present at RX of SoftUWART during ESP8266 power up, the following exception is thrown:

SOFTUART initialize gpio
SOFTUART bit_time is 17
SOFTUART RX INIT DONE
Fatal exception (28):
epc1=0x401010a3, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
ets Jan  8 2013,rst cause:2, boot mode:(3,6)

For the same set up but with no data present on RX, initialization is completed correctly as follows:

SOFTUART initialize gpio
SOFTUART bit_time is 17
SOFTUART RX INIT DONE
SOFTUART TX INIT DONE
SOFTUART INIT DONE

Going back to fault scenario (data present at RX on power up), I believe the following happens:

Interrupts on RX are enabled:

SOFTUART RX INIT DONE

An interrupt is triggered by data on RX but not properly serviced since the following two initialization steps still need to be complete:

SOFTUART TX INIT DONE
SOFTUART INIT DONE

To fix this issue I have reversed order of initialization of RX and TX:

SOFTUART initialize gpio
SOFTUART bit_time is 17
SOFTUART TX INIT DONE
SOFTUART RX INIT DONE
SOFTUART INIT DONE

This way interrupts on RX are initialized in the last step and are followed immediately by procedures hidden under “SOFTUART INIT DONE”. Now my set up of SoftUART is working correctly for any power up :ok_hand:

Thank you for adding good comments to the code and diagnostics messages like above that were instrumental to fixing this issue. :thumbsup: If you believe my analysis is correct I am ready to embark on doing my first pull request :boom:

plieningerweb commented 9 years ago

Thank you for fixing the issue.

A pull request would be perfect, then I could merge the fix back into the master :+1:

krzychb commented 8 years ago

Thanks!