Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Stm32Can to support multiple CAN interfaces on ST Micro MCUs that have multiple CAN IFs #816

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

RobertPHeller
Copy link
Contributor

This is a modification to the Stm32Can that allows for multiple CAN IFs running on those ST Micro MCUs that have multiple CAN IFs. When the class is instanciated, the trailing digit in the path name determines which CAN IF this instance is for. If the path ends in '0', CAN1 (or the only) interface is used, if it ends in '1', CAN2 is used (if it exists), and if the path ends in '2', CAN3 is used.

Typical usage:

In HwInit.cxx:

/** CAN 0 CAN driver instance */
static Stm32Can can0("/dev/can0");
/** CAN 1 CAN driver instance */
static Stm32Can can1("/dev/can1");

Later:

   __HAL_RCC_CAN1_CLK_ENABLE();
   __HAL_RCC_CAN2_CLK_ENABLE();

and:

    /* CAN1 pinmux on PB8 and PB9 */
    gpio_init.Mode = GPIO_MODE_AF_PP;
    gpio_init.Pull = GPIO_PULLUP;
    gpio_init.Speed = GPIO_SPEED_FREQ_HIGH;
    gpio_init.Alternate = GPIO_AF9_CAN1;
    gpio_init.Pin = GPIO_PIN_8;
    HAL_GPIO_Init(GPIOB, &gpio_init);
    gpio_init.Pin = GPIO_PIN_9;
    HAL_GPIO_Init(GPIOB, &gpio_init);

    /* CAN2 pinmux on PB12 and PB13 */
    gpio_init.Mode = GPIO_MODE_AF_PP;
    gpio_init.Pull = GPIO_PULLUP;
    gpio_init.Speed = GPIO_SPEED_FREQ_HIGH;
    gpio_init.Alternate = GPIO_AF9_CAN2;
    gpio_init.Pin = GPIO_PIN_12;
    HAL_GPIO_Init(GPIOB, &gpio_init);
    gpio_init.Pin = GPIO_PIN_13;
    HAL_GPIO_Init(GPIOB, &gpio_init);

Then in main.cxx:

    HubDeviceSelect<CanHubFlow> seg1(&can_hub0,"/dev/can0");
    HubDeviceSelect<CanHubFlow> seg2(&can_hub0,"/dev/can1");

I have tested this:

https://github.com/RobertPHeller/RPi-RRCircuits/tree/master/STM32F767ZI_LCC_PNET_Router

@RobertPHeller
Copy link
Contributor Author

RobertPHeller commented Jan 31, 2025 via email

src/freertos_drivers/st/Stm32Can.cxx Outdated Show resolved Hide resolved
src/freertos_drivers/st/Stm32Can.hxx Show resolved Hide resolved
src/freertos_drivers/st/Stm32Can.cxx Outdated Show resolved Hide resolved
src/freertos_drivers/st/Stm32Can.hxx Outdated Show resolved Hide resolved
src/freertos_drivers/st/Stm32Can.hxx Outdated Show resolved Hide resolved
src/freertos_drivers/st/Stm32Can.hxx Outdated Show resolved Hide resolved
src/freertos_drivers/st/Stm32Can.cxx Outdated Show resolved Hide resolved
@RobertPHeller
Copy link
Contributor Author

RobertPHeller commented Feb 3, 2025 via email

…o select the IF, instead of using the pathname.
@RobertPHeller
Copy link
Contributor Author

OK, I made all of the mods Stuart asked for and I just tested on a STM32F7 board and it all works.

…o select the IF, instead of using the pathname.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants