diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/can.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/can.hpp index 4e16d33f8..6cd61280e 100644 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/can.hpp +++ b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/can.hpp @@ -180,7 +180,7 @@ class CanIface : public uavcan::ICanIface, uavcan::Noncopyable * * Should be called from RX ISR, TX ISR, and select(); interrupts must be enabled. */ - void pollErrorFlags(); + void pollErrorFlagsFromISR(); void discardTimedOutTxMailboxes(uavcan::MonotonicTime current_time); diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp index d552345aa..40a588872 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp @@ -616,7 +616,7 @@ void CanIface::handleTxInterrupt(const uavcan::uint64_t utc_usec) } update_event_.signalFromInterrupt(); - pollErrorFlags(); + pollErrorFlagsFromISR(); } void CanIface::handleRxInterrupt(uavcan::uint8_t fifo_index, uavcan::uint64_t utc_usec) @@ -679,16 +679,14 @@ void CanIface::handleRxInterrupt(uavcan::uint8_t fifo_index, uavcan::uint64_t ut had_activity_ = true; update_event_.signalFromInterrupt(); - pollErrorFlags(); + pollErrorFlagsFromISR(); } -void CanIface::pollErrorFlags() +void CanIface::pollErrorFlagsFromISR() { const uavcan::uint8_t lec = uavcan::uint8_t((can_->ESR & bxcan::ESR_LEC_MASK) >> bxcan::ESR_LEC_SHIFT); if (lec != 0) { - CriticalSectionLocker cs_locker; - can_->ESR = 0; error_cnt_++; @@ -837,11 +835,17 @@ uavcan::int16_t CanDriver::select(uavcan::CanSelectMasks& inout_masks, const uavcan::MonotonicTime time = clock::getMonotonic(); if0_.discardTimedOutTxMailboxes(time); // Check TX timeouts - this may release some TX slots - if0_.pollErrorFlags(); + { + CriticalSectionLocker cs_locker; + if0_.pollErrorFlagsFromISR(); + } #if UAVCAN_STM32_NUM_IFACES > 1 if1_.discardTimedOutTxMailboxes(time); - if1_.pollErrorFlags(); + { + CriticalSectionLocker cs_locker; + if1_.pollErrorFlagsFromISR(); + } #endif inout_masks = makeSelectMasks(pending_tx); // Check if we already have some of the requested events