Browse Source

uc_stm32h7_can:Correct initalization of the mumber of interfaces

H7 Only supports 2 not 3 CAN interfaces.

   CanInitHelper passes in in the run time configuration of
   the number of interfaces. The code was ignoring these!
main
David Sidrane 3 years ago committed by Daniel Agar
parent
commit
dd6d7e9979
  1. 2
      src/drivers/uavcan/uavcan_drivers/stm32h7/driver/include/uavcan_stm32h7/can.hpp
  2. 8
      src/drivers/uavcan/uavcan_drivers/stm32h7/driver/src/uc_stm32h7_can.cpp

2
src/drivers/uavcan/uavcan_drivers/stm32h7/driver/include/uavcan_stm32h7/can.hpp

@ -261,7 +261,7 @@ public:
#else #else
, num_ifaces_(1) , num_ifaces_(1)
#endif #endif
, enabledInterfaces_(0x7) , enabledInterfaces_(0x3)
{ {
uavcan::StaticAssert < (RxQueueCapacity <= CanIface::MaxRxQueueCapacity) >::check(); uavcan::StaticAssert < (RxQueueCapacity <= CanIface::MaxRxQueueCapacity) >::check();
} }

8
src/drivers/uavcan/uavcan_drivers/stm32h7/driver/src/uc_stm32h7_can.cpp

@ -1032,6 +1032,8 @@ int CanDriver::init(const uavcan::uint32_t bitrate, const CanIface::OperatingMod
{ {
int res = 0; int res = 0;
enabledInterfaces_ = enabledInterfaces;
UAVCAN_STM32H7_LOG("Bitrate %lu mode %d", static_cast<unsigned long>(bitrate), static_cast<int>(mode)); UAVCAN_STM32H7_LOG("Bitrate %lu mode %d", static_cast<unsigned long>(bitrate), static_cast<int>(mode));
static bool initialized_once = false; static bool initialized_once = false;
@ -1045,7 +1047,8 @@ int CanDriver::init(const uavcan::uint32_t bitrate, const CanIface::OperatingMod
/* /*
* FDCAN1 * FDCAN1
*/ */
if (enabledInterfaces & 1) { if (enabledInterfaces_ & 1) {
num_ifaces_ = 1;
UAVCAN_STM32H7_LOG("Initing iface 0..."); UAVCAN_STM32H7_LOG("Initing iface 0...");
ifaces[0] = &if0_; // This link must be initialized first, ifaces[0] = &if0_; // This link must be initialized first,
res = if0_.init(bitrate, mode); // otherwise an IRQ may fire while the interface is not linked yet; res = if0_.init(bitrate, mode); // otherwise an IRQ may fire while the interface is not linked yet;
@ -1062,7 +1065,8 @@ int CanDriver::init(const uavcan::uint32_t bitrate, const CanIface::OperatingMod
*/ */
#if UAVCAN_STM32H7_NUM_IFACES > 1 #if UAVCAN_STM32H7_NUM_IFACES > 1
if (enabledInterfaces & 2) { if (enabledInterfaces_ & 2) {
num_ifaces_ = 2;
UAVCAN_STM32H7_LOG("Initing iface 1..."); UAVCAN_STM32H7_LOG("Initing iface 1...");
ifaces[1] = &if1_; // Same thing here. ifaces[1] = &if1_; // Same thing here.
res = if1_.init(bitrate, mode); res = if1_.init(bitrate, mode);

Loading…
Cancel
Save