Page 1 of 1

fdcanV2 wrong assertion in the filtering code

Posted: Wed Nov 27, 2024 4:22 pm
by alex31
Hello,

First, I want to thanks Edoardo for the hdcanv1/v2 refactor, and filtering integration.

I will in the future submit some patches driven by real usager in flying machine.

For now just a simple bug, fdcanv2 will wrongly assert when using filtering on CAND1 :

Code: Select all

void can_lld_set_filters(CANDriver *canp, uint8_t num, const CANFilter *cfp) {

  uint8_t i;
  uint8_t num_std_filter = 0;
  uint8_t num_ext_filter = 0;

  uint32_t can_offset_instance = 0;
  #if STM32_CAN_USE_FDCAN1
  if (&CAND1 == canp) {
    can_offset_instance = CAN1_OFFSET_INSTANCE;
  }
  #endif
  #if STM32_CAN_USE_FDCAN2
  if (&CAND2 == canp) {
    can_offset_instance = CAN2_OFFSET_INSTANCE;
  }
  #endif
  #if STM32_CAN_USE_FDCAN3
  if (&CAND3 == canp) {
    can_offset_instance = CAN3_OFFSET_INSTANCE;
  }
  #endif
  osalDbgAssert(can_offset_instance != 0, "CAN offset instance failed");
 


when using CAND1, CAN1_OFFSET_INSTANCE is 0, so the assert will always fire.

Alexandre

Re: fdcanV2 wrong assertion in the filtering code

Posted: Wed Dec 04, 2024 7:46 pm
by Edoardo1982
alex31 wrote:Hello,

First, I want to thanks Edoardo for the hdcanv1/v2 refactor, and filtering integration.

I will in the future submit some patches driven by real usager in flying machine.

For now just a simple bug, fdcanv2 will wrongly assert when using filtering on CAND1 :

Code: Select all

void can_lld_set_filters(CANDriver *canp, uint8_t num, const CANFilter *cfp) {

  uint8_t i;
  uint8_t num_std_filter = 0;
  uint8_t num_ext_filter = 0;

  uint32_t can_offset_instance = 0;
  #if STM32_CAN_USE_FDCAN1
  if (&CAND1 == canp) {
    can_offset_instance = CAN1_OFFSET_INSTANCE;
  }
  #endif
  #if STM32_CAN_USE_FDCAN2
  if (&CAND2 == canp) {
    can_offset_instance = CAN2_OFFSET_INSTANCE;
  }
  #endif
  #if STM32_CAN_USE_FDCAN3
  if (&CAND3 == canp) {
    can_offset_instance = CAN3_OFFSET_INSTANCE;
  }
  #endif
  osalDbgAssert(can_offset_instance != 0, "CAN offset instance failed");
 


when using CAND1, CAN1_OFFSET_INSTANCE is 0, so the assert will always fire.

Alexandre

Hi Alex,

I believe the code you posted is incorrect, and I’m not sure where it was taken from because it doesn’t seem like something I wrote, there’s no trace of it in the trunk.

In any case, I encourage you to check the latest changes I made to the FDCANv1 and v2 drivers into the trunk.

Edoardo

Re: fdcanV2 wrong assertion in the filtering code

Posted: Wed Dec 04, 2024 9:49 pm
by alex31
My bad, I checked in trunk and there is no trace of this code,

Many apologizes for this.

Alexandre