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

STM32 can_init_freq() ignores frequency and uses 100000 instead #12104

Closed
bikeNomad opened this issue Dec 13, 2019 · 5 comments
Closed

STM32 can_init_freq() ignores frequency and uses 100000 instead #12104

bikeNomad opened this issue Dec 13, 2019 · 5 comments

Comments

@bikeNomad
Copy link
Contributor

Description of defect

Attempts to create an mbed::CAN object passing in the CAN bit rate don't properly set the frequency. Instead, the CAN port is always opened at 100000 bps.

Target(s) affected by this defect ?

All STM32 parts with CAN peripherals.

Toolchain(s) (name and version) displaying this defect ?

All

What version of Mbed-os are you using (tag or sha) ?

mbed-os-5.15

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

mbed-cli 1.10.1

How is this defect reproduced ?

Create an mbed::CAN object using the three-argument constructor and pass in a frequency argument other than 100000:

CAN myCAN(PIN_CAN_RX, PIN_CAN_TX, 500000);

This is due to mbed-os/targets/TARGET_STM/can_api.c containing this code:

void can_init_freq(can_t *obj, PinName rd, PinName td, int hz)
{
    CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
    CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);
    int peripheral = (int) pinmap_merge(can_rd, can_td);

    int function_rd = (int)pinmap_find_function(rd, PinMap_CAN_RD);
    int function_td = (int)pinmap_find_function(td, PinMap_CAN_TD);

    const can_pinmap_t static_pinmap = {peripheral, rd, function_rd, td, function_td};

    CAN_INIT_FREQ_DIRECT(obj, &static_pinmap, 100000);
}

As you can see, the hz argument is ignored and 100000 is used instead.

@bikeNomad bikeNomad changed the title STM32 can_init_freq() ignores frequency and uses 1000000 instead STM32 can_init_freq() ignores frequency and uses 100000 instead Dec 13, 2019
@ciarmcom
Copy link
Member

Internal Jira reference: https://jira.arm.com/browse/MBOTRIAGE-2473

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 16, 2019

cc @ARMmbed/team-st-mcd

@jeromecoutant
Copy link
Collaborator

jeromecoutant commented Dec 16, 2019

Hi

@mprse

I understand that for CAN, there are 2 API for init:

CAN::CAN(PinName rd, PinName td) :
can_init(&_can, rd, td);
CAN::CAN(PinName rd, PinName td, int hz) :
can_init_freq(&_can, rd, td, hz);

Before #11892, in each target API:

  • can_init_freq is setting CAN with the expected frequency
  • can_init is only calling can_init_freq with the default frequency

Now with #11892

  • can_init is now calling CAN_INIT_DIRECT
  • can_init_freq is now calling CAN_INIT_FREQ_DIRECT
    We miss the frequency setting

@mprse
Copy link
Contributor

mprse commented Dec 16, 2019

@jeromecoutant @bikeNomad Yes, this is a bug.

The fix can be found here: PR #12113.
Please review.

0xc0170 added a commit that referenced this issue Dec 20, 2019
Fix for issue #12104 (STM32 can_init_freq() ignores frequency)
0xc0170 pushed a commit to 0xc0170/mbed-os that referenced this issue Jan 13, 2020
@jeromecoutant
Copy link
Collaborator

As #12113 is merged, we close close this one
Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants