STM32F769 CAN3 Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Has thanked: 10 times
Been thanked: 5 times

STM32F769 CAN3

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F769 CAN3

Post by Giovanni »

Hi,

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

Giovanni
neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Has thanked: 10 times
Been thanked: 5 times

Re: STM32F769 CAN3

Post by neums »

Hi,
OK thanks. I will give it a try.
neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Has thanked: 10 times
Been thanked: 5 times

Re: STM32F769 CAN3

Post 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.
Last edited by neums on Fri Nov 04, 2016 11:37 am, edited 1 time in total.
neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Has thanked: 10 times
Been thanked: 5 times

Re: STM32F769 CAN3

Post 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.
Attachments
STM32F7_CAN3_patch.zip
(15.31 KiB) Downloaded 552 times
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F769 CAN3

Post by Giovanni »

Hi,

Thanks, I will look into merging the changes.

Moving this thread in "bug reports".

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F769 CAN3

Post 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
neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Has thanked: 10 times
Been thanked: 5 times

Re: STM32F769 CAN3

Post 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
neums
Posts: 137
Joined: Fri May 08, 2015 1:09 pm
Has thanked: 10 times
Been thanked: 5 times

Re: STM32F769 CAN3

Post by neums »

Hi,
the CAN3 was not added within the 16.1.6 release. Is there any problem with the driver?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F769 CAN3

Post by Giovanni »

Hi,

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

Giovanni
Post Reply