Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detachInterrupt crashes after using argument in __attachInterruptArg() #6049

Closed
6 tasks done
dok-net opened this issue May 4, 2019 · 4 comments · Fixed by #6048
Closed
6 tasks done

detachInterrupt crashes after using argument in __attachInterruptArg() #6049

dok-net opened this issue May 4, 2019 · 4 comments · Fixed by #6048

Comments

@dok-net
Copy link
Contributor

dok-net commented May 4, 2019

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: WEMOS D1 mini
  • Core Version: 95fd7b5
  • Development Env: Visual Micro IDE
  • Operating System: Windows

Settings in IDE

  • Module: LOLIN(WEMOS) D1 R2 & mini
  • Flash Mode: [qio|dio|other]
  • Flash Size: 4MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: [ck|nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 921600

Problem Description

Using detachInterrupt after __attachInterruptArg with a non-null argument, that's also not incidentally of type ArgStructure (as defined in FunctionalInterrupt.h), leads to a crash.

MCVE Sketch


class Interrupt
{
public:
	void ICACHE_RAM_ATTR isr() {}
	static void ICACHE_RAM_ATTR isr_static(void* self)
	{
		if (self) static_cast<Interrupt*>(self)->isr();
	}
};

Interrupt intr;

void setup()
{
	Serial.begin(9600);
	delay(1000);
	__attachInterruptArg(D6, Interrupt::isr_static, &intr, CHANGE);
	detachInterrupt(D6);
}

// Add the main program code into the continuous loop() function
void loop()
{


}

Debug Messages

Exception (9):
epc1=0x4020328b epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000017 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffdd0 end: 3fffffc0 offset: 01a0
3fffff70:  4010637c 3ffee248 402010f8 3fffefa0  
3fffff80:  401003e4 3ffee2b4 3ffee348 4010043c  
3fffff90:  3fffdad0 00000000 3ffee219 40201061  
3fffffa0:  feefeffe feefeffe feefeffe 402011a0  
3fffffb0:  feefeffe feefeffe 3ffe84f4 40100739  
<<<stack<<<

: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)
0x4020328b std
0x4010637c Interrupt
0x402010f8 esp_yield
0x401003e4 detachInterrupt
0x4010043c detachInterrupt
0x40201061 setup
0x402011a0 loop_wrapper()
0x40100739 cont_wrapper

@devyte
Copy link
Collaborator

devyte commented May 6, 2019

@dok-net the __attachInterruptArg() call is not really exposed and hence not meant to be used by a user in its current form (notice the __ prefix).
That means that strictly speaking this is not a bug.
However, we do want to expose an attachInterruptArg() function that works correctly, and I think you have a PR about that, so I'm keeping this open as an enhancement.

@devyte
Copy link
Collaborator

devyte commented May 6, 2019

BTW, I invited you to our serial gitter channel. Please join so we can better coordinate efforts. If you didn't receive the mention let me know and I'll send it again.

@dok-net
Copy link
Contributor Author

dok-net commented May 9, 2019

@devyte Haven't seen any invite anywhere.

@dok-net
Copy link
Contributor Author

dok-net commented May 12, 2019

This issue is fixed by #6048.
The other PRs with similar concerns make more sense if that PR is accepted first - it fixes a real bug plus adds an API that I am lobbying for because I need/desire for EspSoftwareSerial: the proper Arduino.h-exposed attachInterruptArg().

devyte pushed a commit that referenced this issue Jul 4, 2019
* Properly check for "functional" ISRs and expose C-style attachInterruptArg

* Use RAII idiom

(cherry picked from commit 15c0b5b356aad0c3032b96ed6db0ec70cbf719d3)

# Conflicts:
#	cores/esp8266/core_esp8266_wiring_digital.cpp

* Indentation

* Easier reviewability

* Refactored after review input.

* Finish up insights from review comments.
0hax added a commit to 0hax/esphome that referenced this issue Apr 16, 2020
A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>
0hax added a commit to 0hax/esphome that referenced this issue Apr 16, 2020
A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>
0hax added a commit to 0hax/esphome that referenced this issue Apr 16, 2020
A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>
0hax added a commit to 0hax/esphome that referenced this issue Apr 16, 2020
A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>
0hax added a commit to 0hax/esphome that referenced this issue Apr 17, 2020
A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>
0hax added a commit to 0hax/esphome that referenced this issue Apr 17, 2020
A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>
0hax added a commit to 0hax/esphome that referenced this issue Apr 17, 2020
A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>
0hax added a commit to 0hax/esphome that referenced this issue Apr 25, 2020
A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>
0hax added a commit to 0hax/esphome that referenced this issue Apr 26, 2020
A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>
0hax added a commit to 0hax/esphome that referenced this issue Apr 27, 2020
A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>
0hax added a commit to 0hax/esphome that referenced this issue May 3, 2020
A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049
Same for enabling interrupt, so just reset software serial buffer
indexes.

Signed-off-by: 0hax <0hax@protonmail.com>
0hax added a commit to 0hax/esphome that referenced this issue May 23, 2020
A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>
glmnet added a commit to esphome/esphome that referenced this issue May 24, 2020
* uart: Add support for specifying the number of bits and parity.

ESP8266SwSerial doesn't really check parity but just read the parity bit
and ignore it when receiving data.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: support begin and end methods.

A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>

* esphal: add support for detaching an interrupt.

That's needed when a component needs to enable/disable interrupt on a
gpio.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: rename CONF_NR_BITS to CONF_DATA_BITS_NUMBER.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: use static const uint32_t instead of #define.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: use an enum to handle parity.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: split between esp32 and esp8266.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: check_uart_settings for parity and number of data bits.

Signed-off-by: 0hax <0hax@protonmail.com>

* name param data_bits

* add new params to test

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
sashao pushed a commit to sashao/esphome that referenced this issue Jun 16, 2020
* uart: Add support for specifying the number of bits and parity.

ESP8266SwSerial doesn't really check parity but just read the parity bit
and ignore it when receiving data.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: support begin and end methods.

A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>

* esphal: add support for detaching an interrupt.

That's needed when a component needs to enable/disable interrupt on a
gpio.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: rename CONF_NR_BITS to CONF_DATA_BITS_NUMBER.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: use static const uint32_t instead of #define.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: use an enum to handle parity.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: split between esp32 and esp8266.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: check_uart_settings for parity and number of data bits.

Signed-off-by: 0hax <0hax@protonmail.com>

* name param data_bits

* add new params to test

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
natp13 pushed a commit to natp13/esphome that referenced this issue Jun 17, 2020
* uart: Add support for specifying the number of bits and parity.

ESP8266SwSerial doesn't really check parity but just read the parity bit
and ignore it when receiving data.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: support begin and end methods.

A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>

* esphal: add support for detaching an interrupt.

That's needed when a component needs to enable/disable interrupt on a
gpio.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: rename CONF_NR_BITS to CONF_DATA_BITS_NUMBER.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: use static const uint32_t instead of #define.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: use an enum to handle parity.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: split between esp32 and esp8266.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: check_uart_settings for parity and number of data bits.

Signed-off-by: 0hax <0hax@protonmail.com>

* name param data_bits

* add new params to test

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
SchumyHao pushed a commit to smarthomefans/esphome that referenced this issue Jul 15, 2020
* uart: Add support for specifying the number of bits and parity.

ESP8266SwSerial doesn't really check parity but just read the parity bit
and ignore it when receiving data.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: support begin and end methods.

A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>

* esphal: add support for detaching an interrupt.

That's needed when a component needs to enable/disable interrupt on a
gpio.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: rename CONF_NR_BITS to CONF_DATA_BITS_NUMBER.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: use static const uint32_t instead of #define.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: use an enum to handle parity.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: split between esp32 and esp8266.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: check_uart_settings for parity and number of data bits.

Signed-off-by: 0hax <0hax@protonmail.com>

* name param data_bits

* add new params to test

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
jValdron pushed a commit to jValdron/esphome that referenced this issue Jan 27, 2022
* uart: Add support for specifying the number of bits and parity.

ESP8266SwSerial doesn't really check parity but just read the parity bit
and ignore it when receiving data.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: support begin and end methods.

A component may need to reset uart buffer/status by using begin() and
end() methods. This is useful for example when a component needs to be
sure it is not reading garbage from previously received data over uart.
For end() methods with software serial, disabling interrupt is
currently impossible because of a bug in esp8266 Core:
esp8266/Arduino#6049

Signed-off-by: 0hax <0hax@protonmail.com>

* esphal: add support for detaching an interrupt.

That's needed when a component needs to enable/disable interrupt on a
gpio.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: rename CONF_NR_BITS to CONF_DATA_BITS_NUMBER.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: use static const uint32_t instead of #define.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: use an enum to handle parity.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: split between esp32 and esp8266.

Signed-off-by: 0hax <0hax@protonmail.com>

* uart: check_uart_settings for parity and number of data bits.

Signed-off-by: 0hax <0hax@protonmail.com>

* name param data_bits

* add new params to test

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants