Skip to main content
Visitor II
October 10, 2019
Solved

CAN Legacy with STM32F042, STM32Cube Version 5.3.0, FW V1.10.

  • October 10, 2019
  • 8 replies
  • 2988 views

I wanted to use the CAN Legacy Driver like i did it in my old STM32F103 Project (Same Cube Version. latest Firmware) but i failed.

I copied the Legacy CAN-Module to the Driver Source-Path, the Legacy Include's were already included.

But what should i do now? In the old Project i only enabled the Legacy Driver in the HAL_conf.h, but this Fails with the STM32F042.

What is the way to enable it here, or is there anywhere a good example how to ust Interrupt Receive with the new Driver??

    This topic has been closed for replies.
    Best answer by christophkeiner9

    ​Thank you for your Help!

    This is exactly what i did to get it working but i failed.

    Meanwhile i changed to the new Structure because there were too many detail changes to make Legacy work, rewriting was really the better Solution.

    8 replies

    Technical Moderator
    October 11, 2019

    Hello @christophkeiner9​ ,

    The Legacy HAL CAN driver is present in the package release in Driver/STM32F0xx_HAL_Driver/Src/Legacy and Driver/STM32F0xx_HAL_Driver/Inc/Legacy folders for software compatibility reasons. Its usage is not recommended as deprecated.

    It can however be enabled through switch HAL_CAN_LEGACY_MODULE_ENABLED in stm32f0xx_hal_conf.h file.

    Also, check that CAN initialization and configuration are properly done.

    Regards,

    Imen

    christophkeiner9AuthorAnswer
    Visitor II
    October 13, 2019

    ​Thank you for your Help!

    This is exactly what i did to get it working but i failed.

    Meanwhile i changed to the new Structure because there were too many detail changes to make Legacy work, rewriting was really the better Solution.

    Visitor II
    January 31, 2020

    I have the same issu for a F2. In the MCU Package Version 1.8.0 for the STM32F2 it is mentioned, that the old CAN driver is still available. But as you can see in the image, there is no one. And a definition of "HAL_CAN_LEGACY_MODULE_ENABLED" leads to an "Unresolve inclusion error". Is there a workaround? Our customer is running tests for 2 months with the olc CAN API and it is crucial not to repeat these tests with a new CAN API.

    0690X00000BxC8TQAV.jpg

    Visitor II
    February 3, 2020

    Yes, i know, there are a lot of little things to do to get it run, therefore i would not rely on a new software with so many little manual changes.

    I would turn back to the older Cube-Version or use the new CAN Driver and do the testing again.

    Graduate II
    February 3, 2020

    I have a working project on github based off a CANable adapter that uses the STM32F042. I've also made a YouTube tutorial on how to start a STM32CubeIDE project.

    https://github.com/karlyamashita/CANable_USB_CAN

    https://www.youtube.com/watch?v=oe5JmYYAZy0&t=5s

    Visitor II
    February 3, 2020

    ​Thank you Karl, very nice Project. Do you use a crystal for clocking on the PCB, i didn't see it?

    Graduate II
    February 3, 2020

    The whole uC is running with the internal RC at 48mHz. Surprisingly the USB communication works just as well as the CAN controller.

    Visitor II
    February 10, 2020

    Hi Karl, yes i see, the oscillator is synchronized to USB Data Stream, therefore it is sufficient accurate also for higher CAN Datarates. I never used the USB-Device but it's an nice feature.

    Visitor II
    March 20, 2020

    I'm considering the STM32F042 for a new design with a PCB size constraint, I have always used an external crystal when using CAN.

    Is it possible to use this devices internal oscillator ? Anyone had any experience. Max bit rate 125kbs

    Thanks

    Visitor II
    March 20, 2020

    Hi Paul, at 125kbs it may work at room temperature because the HSI has app. +1.5% to -1% accuracy after soldering (Page 65 of the Datasheet).

    A collegue also made a design with internal Oszillator and he found also that 125k is the maximum Baudrate. But if you expect a higher Temperature Range it may fail.

    There are some good application notes if you google for CAN Clock deviation calculating the maximum oscillator tolerance for certain propagation delays and cable length.

    Meanwhile there are a lot of MEMS oscillators which are small and have a very good accuracy.

    Look at the Design of Karl, i think he uses the USB clock Synchronisation so he seem's to need no crystal also at higher Data rates.

    This is a very nice feature, but i have no USB in y Design so i needed a crystal.