diff --git a/drivers/CAN.cpp b/drivers/CAN.cpp index e49b7adfcb..b84d6082ce 100644 --- a/drivers/CAN.cpp +++ b/drivers/CAN.cpp @@ -46,6 +46,11 @@ CAN::CAN(PinName rd, PinName td, int hz) : _can(), _irq() { CAN::~CAN() { // No lock needed in destructor + + // Detaching interrupts releases the sleep lock if it was locked + for (int irq = 0; irq < IrqCnt; irq++) { + attach(NULL, (IrqType)irq); + } can_irq_free(&_can); can_free(&_can); } diff --git a/drivers/SerialBase.cpp b/drivers/SerialBase.cpp index e07a44149d..5ec47ff83a 100644 --- a/drivers/SerialBase.cpp +++ b/drivers/SerialBase.cpp @@ -133,6 +133,16 @@ void SerialBase:: unlock() { // Stub } +SerialBase::~SerialBase() +{ + // No lock needed in destructor + + // Detaching interrupts releases the sleep lock if it was locked + for (int irq = 0; irq < IrqCnt; irq++) { + attach(NULL, (IrqType)irq); + } +} + #if DEVICE_SERIAL_FC void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2) { lock(); diff --git a/drivers/SerialBase.h b/drivers/SerialBase.h index 835e1a33b1..faf29a0699 100644 --- a/drivers/SerialBase.h +++ b/drivers/SerialBase.h @@ -241,8 +241,7 @@ protected: protected: SerialBase(PinName tx, PinName rx, int baud); - virtual ~SerialBase() { - } + virtual ~SerialBase(); int _base_getc(); int _base_putc(int c);