Page 1 of 2

STM32F769 CAN3

Posted: Wed Nov 02, 2016 4:26 pm
by neums
Hi,
is there anybody who's implementing CAN3 for the STM32F7 or is this work in the pipe?

If not, what are the steps to do this?

I saw that the CAN3 has to be added to the stm32_registry.h file.
CAN3 has its own filter banks.

Thanks.

Re: STM32F769 CAN3

Posted: Wed Nov 02, 2016 5:14 pm
by Giovanni
Hi,

It is not scheduled yet, it should not be complex to do following the driver patterns.

Giovanni

Re: STM32F769 CAN3

Posted: Thu Nov 03, 2016 8:36 am
by neums
Hi,
OK thanks. I will give it a try.

Re: STM32F769 CAN3

Posted: Fri Nov 04, 2016 10:20 am
by neums
Hi,
here is my initial version. You were right. Is was not very complex to implement CAN3 following the driver patterns.
Just one thing is not that easy. The function can_lld_set_filters is written to have just CAN1 and CAN2 were CAN2 is the slave of CAN1. But CAN3 is a master CAN with its own receive filter banks. Therefore i added the driver handle pointer to the input paramter of can_lld_set_filters and canSTM32SetFilters.

I had also to modify the stm32_registry.h because of the interrupt vectors of CAN3 and stm32_rcc.h because of rccResetCAN3, rccEnableCAN3 and rccDisableCAN3.

Thanks for feedback.

Re: STM32F769 CAN3

Posted: Fri Nov 04, 2016 11:37 am
by neums
There was also a bug when configuring the rx filters of CAN2 in can_lld_set_filters(). Modified it in hal_can_lld.c from:

Code: Select all

#if STM32_CAN_USE_CAN1
  if(canp == &CAND1) {
    rccEnableCAN1(FALSE);
    /* Filters initialization.*/
    canp->can->FMR = (canp->can->FMR & 0xFFFF0000) | (can2sb << 8) | CAN_FMR_FINIT;
  }
#endif

to

Code: Select all

#if STM32_CAN_USE_CAN1
  if(canp == &CAND1) {
    rccEnableCAN1(FALSE);
    /* Filters initialization.*/
    canp->can->FMR = (canp->can->FMR & 0xFFFF0000) | CAN_FMR_FINIT;
    canp->can->FMR = (canp->can->FMR & 0xFFFF0000) | (can2sb << 8) | CAN_FMR_FINIT;
  }
#endif

CAN_FMR_FINIT has to be set before writing can2sb to the register.

Another change in hal_can_lld.c - canSTM32SetFilters() from:

Code: Select all

#if STM32_CAN_USE_CAN2
  osalDbgCheck((can2sb >= 1) && (can2sb < STM32_CAN_MAX_FILTERS) &&
               (num <= STM32_CAN_MAX_FILTERS));
#endif

to

Code: Select all

#if STM32_CAN_USE_CAN2
  osalDbgCheck((can2sb >= 0) && (can2sb <= STM32_CAN_MAX_FILTERS) &&
               (num <= STM32_CAN_MAX_FILTERS));
#endif


I set the check of can2sb to 0 and to STM32_CAN_MAX_FILTERS because due to the reference manual RM0090 (STM32F4 chapter 32.9.4 CAN filter registers - CAN filter master register (CAN_FMR)) these values are valid.

In the reference manual of the STM32F769 (RM0410) it is not stated as valid but it work also. I asked for that fact in the STM forum:
STM32F769 CAN2

Please consider the new patch.

Re: STM32F769 CAN3

Posted: Fri Nov 04, 2016 12:06 pm
by Giovanni
Hi,

Thanks, I will look into merging the changes.

Moving this thread in "bug reports".

Giovanni

Re: STM32F769 CAN3

Posted: Mon Nov 21, 2016 2:55 pm
by Giovanni
Hi,

I merged the patch but had to make some changes, there were problems. The driver didn't compile on other STM32s and there were other things to be added.

Please verify if it works for you.

Giovanni

Re: STM32F769 CAN3

Posted: Tue Nov 22, 2016 8:01 am
by neums
Hi,
thanks for merging. Yes, i see the bug where i called CAND3 directly and not by pointer. Thanks for finding. The driver is fine for me now.

Thanks

Re: STM32F769 CAN3

Posted: Tue Jan 03, 2017 9:38 am
by neums
Hi,
the CAN3 was not added within the 16.1.6 release. Is there any problem with the driver?

Re: STM32F769 CAN3

Posted: Tue Jan 03, 2017 10:12 am
by Giovanni
Hi,

It has been added to the trunk code, it will be present in the next release, 17.2.0 likely.

Giovanni