Skip to content

Update of can_api.c fixing #2987 #2988

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

Merged
merged 2 commits into from
Nov 1, 2016
Merged

Update of can_api.c fixing #2987 #2988

merged 2 commits into from
Nov 1, 2016

Conversation

martinjaeger
Copy link
Contributor

Description

Fix issue #2987

Status

Bug fix is completely implemented for STM32F0 and has been tested on STM32F072 Nucleo board.

Migrations

No APIs are changed, but the behavior of the STM32F0 CAN filter API behaves now as it would be expected.

Todos

  • Check Reference Manuals of other MCUs from STM32 family if register layout is the same as F0 MCU. If yes, same issue will exist for other STM32 targets supporting CAN.

Deploy notes

No changes in build environment.

Steps to test or reproduce

Try to set a CAN message filter with the previous version and wonder why it filters random message IDs, just not the ones you want to be filtered.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 12, 2016

@bcostm @adustm @LMESTM please review

@bcostm
Copy link
Contributor

bcostm commented Oct 13, 2016

LGTM
Just some minor typos.
Thanks for this PR.

@martinjaeger
Copy link
Contributor Author

Should I fix the typos and make a new pull request? Or should I just keep calm and wait for someone to merge it and fix the typos?

@bridadan
Copy link
Contributor

@bcostm Could you be more specifc on the typos so @martinjaeger can fix them? Thanks!

@bcostm
Copy link
Contributor

bcostm commented Oct 27, 2016

It's ok you can merge.

@bridadan
Copy link
Contributor

/morph test

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 960

All builds and test passed!

@0xc0170 0xc0170 removed the needs: CI label Oct 28, 2016
sFilterConfig.FilterMaskIdHigh = mask << 5;
sFilterConfig.FilterMaskIdLow = 0x0; // allows both remote and data frames
}
else if(format == CANExtended){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the formatting, look at the other functions, for instance void can_init(can_t *obj, PinName rd, PinName td)

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 28, 2016

@martinjaeger
Copy link
Contributor Author

Just the mentioned example void can_init(can_t *obj, PinName rd, PinName td) was not consistent regarding formatting of if and while statements. Changed format based on the mbed coding style.

Hope now all typos are fine. If not please explain in a bit more detail what I'm doing wrong. Thanks.

Contributor agreement is signed (mbed user martinj).

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 31, 2016

@mbed-bot: TEST

HOST_OSES=ALL
BUILD_TOOLCHAINS=ALL
TARGETS=ALL

@mbed-bot
Copy link

[Build 1074]
FAILURE: Something went wrong when building and testing.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 31, 2016

@mbed-bot: TEST

HOST_OSES=ALL
BUILD_TOOLCHAINS=ALL
TARGETS=ALL

@mbed-bot
Copy link

[Build 1075]
SUCCESS: Building succeeded and tests were run! Be sure to check the test results

@sg-
Copy link
Contributor

sg- commented Nov 1, 2016

@marhil01 @jupe Can you share feedback about the pr-head CI failure?

@marhil01
Copy link

marhil01 commented Nov 1, 2016

Seems that problem is in test infra/framework

@sg- sg- merged commit 38a9c84 into ARMmbed:master Nov 1, 2016
oter pushed a commit to oter/mbed-os that referenced this pull request Nov 21, 2016
Release mbed OS 5.2.2 and mbed lib v129

Known issues in this release

There is currently a DNS resolution failure in Thread mode with this release. This causes a failure in the
mbed-os-example-client. This will be fixed in a subsequent release. This can be worked around by reverting
to mbed-os-5.2.0

Ports for Upcoming Targets

3011: Add u-blox Sara-N target. ARMmbed#3011
3099: MAX32625 ARMmbed#3099
3151: Add support for FRDM-K82F ARMmbed#3151
3177: New mcu k22512 fixing pr 3136 ARMmbed#3177

Fixes and Changes

2990: [tools] Parallel building of tests ARMmbed#2990
3008: NUCLEO_F072RB: Fix wrong timer channel number on pwm PB_5 pin ARMmbed#3008
3013: STM32xx - Change how the ADC internal pins are checked before pinmap_ ARMmbed#3013
3023: digital_loop tests update for STM32 ARMmbed#3023
3041: [nRF5] - added implementation of API of serial port flow control configuration. ARMmbed#3041
3092: [tools + tests] Adding parallelized build option for iar and uvision exporters ARMmbed#3092
3084: [nrf5] fix in Digital I/O : a gpioe pin was uninitialized badly ARMmbed#3084
3009: TRNG enabled. TRNG APIs implemented. REV A/B/C/D flags removed. Warnings removed ARMmbed#3009
3139: Handle [NOT_SUPPORTED] exception in make.py ARMmbed#3139
3074: Target stm init gcc alignement ARMmbed#3074
3140: [tests] Replacing getchar with RawSerial getc in greentea-client ARMmbed#3140
3158: Added support for 6lowpan PAN ID filter to mbed mesh api configuration ARMmbed#3158
2988: Update of can_api.c fixing ARMmbed#2987 ARMmbed#2988
3175: Updating IAR definition for the NCS36510 for IAR EW v7.8 ARMmbed#3175
3170: [tests] Preventing test from printing before Greentea __sync ARMmbed#3170
3169: [Update of ARMmbed#3014] Usb updates ARMmbed#3169
3143: CFStore fix needed for the Cloud Client ARMmbed#3143
3135: lwip - Fix memory leak in k64f cyclic-buffer overflow ARMmbed#3135
3048: Make update.py test compile examples prior to updating mbed-os version. ARMmbed#3048
3162: lwip/nsapi - Clean up warnings in network code ARMmbed#3162
3161: nsapi - Add better heuristic for the default record of DNS queries ARMmbed#3161
3173: [Exporters] Add a device_name to microbit entry in targets.json ARMmbed#3173
3072: i2c_loop tests update for STM32 ARMmbed#3072
2958: Allowing mbed_app.json files to be discovered for tests. ARMmbed#2958
2969: [nRF52] - switch irq priorities of driver handlers to the lowest level ARMmbed#2969
3078: lwip: Allow several configuration macros to be set externally (bis) ARMmbed#3078
3165: Add address type checks to NanostackInterface ARMmbed#3165
3166: nsapi_dns: Provide 2 IPv6-hosted default servers ARMmbed#3166
3171: [tools] Fixing project.py -S printing problem ARMmbed#3171
3172: [Exporters] New export-build tests ARMmbed#3172
3184: ARMmbed#3183 Compiler warning in trng_api.c with K64F  ARMmbed#3184
3185: Update tests to fix build failures. Also make the code similar to oth ARMmbed#3185
3104: [NuMaker] Support CAN and fix PWM CLK error ARMmbed#3104
3182: Exporter documentation ARMmbed#3182
3186: MultiTech mDot - add back SPI3 pins ARMmbed#3186
3187: [Export-Make] Use internal class variable for resolving templates in makefiles ARMmbed#3187
3195: [Exporters - Make-based] Quote the shell call in mkdir and rmdir ARMmbed#3195
3204: [Export build-test] Directory traversal error ARMmbed#3204
3189: [Exporters - Make-based] Force make exporter to search PATH for compilers ARMmbed#3189
3200: Using Popen for uVision and unifying the structure of the build function ARMmbed#3200
3075: nsapi - Add standardized return types for size and errors ARMmbed#3075
3221: u-blox odin w2 drivers update ARMmbed#3221
@mgiaco
Copy link
Contributor

mgiaco commented Jan 23, 2017

Hello,

So if this is a bug for STM32F0 i think there is also a problem for the other STM32 targets because the bxCAN is the almost the same on every STMF as I know.

@bridadan
Copy link
Contributor

Hi @mgiaco, Are you using CAN on other ST families? If so, can you confirm that your seeing the original issue?

@mgiaco
Copy link
Contributor

mgiaco commented Jan 23, 2017

Hello, no I have not used mbed-os till now. But I will made some tests in the next days with an STM32F4. I will report but first I need a solution for debugging on mbed-os. I tried to export a simple test project with GCC_ARM or with the ST Toolchain everything is broken as i found out. I have no keil toolchain so I have to wait for a fix. After that i will try it.

But I report this because I use STM32F4 am STM32F1 bare metal with CAN and the bxCAN is almost the same so the filter mechanism is also the same as you can see in the hal also.

@bridadan
Copy link
Contributor

Sounds good, looking forward to your results!

@mgiaco
Copy link
Contributor

mgiaco commented Jan 26, 2017

Hello,
Today I made some test on a custom eval board which is based on a NUCLEOF103RB. So now CAN is working but for me there is a issue in PeripheralPins.c. Also the filter is not correct in my opinion.

So the RX pins for CAN should be mode input not mode alternate function push pull. I do not test PA_11 but I think that should be also mode input.

so go with this

const PinMap PinMap_CAN_RD[] = {
    {PA_11, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, 0)},
    {PB_8 , CAN_1, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 10)}, // Remap CAN_RX to PB_8
    {NC,    NC,    0}
};

or this

const PinMap PinMap_CAN_RD[] = {
    {PA_11, CAN_1, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)},
    {PB_8 , CAN_1, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 10)}, // Remap CAN_RX to PB_8
    {NC,    NC,    0}
};

But I can test PA11 in the next days also. I will also made some filter tests later.
I can made a pull request in the next days I think. I will also test the F4 if there is a possability to configure mbed for a stm32F4 discovery board. Is there any way to do that?

@bridadan
Copy link
Contributor

@mgiaco thanks for looking into this, and we look forward to your coming pull request!

I believe most stm32F4 boards are already supported by mbed OS, so I don't think you should have any trouble running tests!

@mgiaco
Copy link
Contributor

mgiaco commented Jan 26, 2017

Yes I know, but till now I use the online compiler - there I add a project. Publish it and after that I am able to clone it with mbed-cli. And now I cannot use STM32F4 discovery so I have to modify something by hand I think - I am right?

By the way is there any other way go get projects from mbed? Is it possible to use git instead of mercurial?
How can I config which target, lib, etc. I am using. I would be really nice if it is possible to clone mbed-os and do anything local.

cheers

@bridadan
Copy link
Contributor

Publish it and after that I am able to clone it with mbed-cli. And now I cannot use STM32F4 discovery so I have to modify something by hand I think - I am right?

If you haven't used any device specific code, you should be able to just recompile the project for the F4 board. Please see the mbed CLI documentation here: https://docs.mbed.com/docs/mbed-os-handbook/en/5.2/getting_started/blinky_cli/

@martinjaeger
Copy link
Contributor Author

I just checked the reference manuals of STM32F0, STM32F1, STM32F2, STM32F3, STM32F4 and STM32F7. All have the same filter configuration, so the bug should be present for all of them. My pull request fixed only STM32F0.

Apart from that, I realized that returning the handle in the fixed function can cause some problems, as the handle number could be 0. This would be interpreted as "not successful" according to CAN.h mbed OS 5 API documentation. So this should be fixed aswell and return 1 in case of successfully set filter.

(BTW: There seem to be some issues with the doxygen output in above page...)

How do we proceed? Should I fix the function for all STM32 versions and make a new pull request or do we need to test it in hardware with all different Nucleo boards? I have only the STM32F072 available.

@mgiaco
Copy link
Contributor

mgiaco commented Feb 6, 2017

What handle do you mean exactly?

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 6, 2017

How do we proceed? Should I fix the function for all STM32 versions and make a new pull request or do we need to test it in hardware with all different Nucleo boards? I have only the STM32F072 available.

Definitely create a bug report, and if fixed, it should be tested on various platforms if the fix applies to them. ST team that I tagged above might be able to help.

@bcostm
Copy link
Contributor

bcostm commented Feb 6, 2017

Hi,
I think it's time to factorize the code and create a single can_api.c file to cover all STM32 devices.

@martinjaeger did you start already to modify the can file for other stm32 ? If not I can start to do it. And we can help for sure to test on different stm32 boards.

By the way, did you develop a test to check the CAN filter ? If yes can you share it ? Thanks.

@mgiaco
Copy link
Contributor

mgiaco commented Feb 6, 2017

@bcostm That is a great idea. Last week I tried mbed can on a nucleo f103rb after the changes I commented above it works for me. But as you can read in this issue #3505 there is really some stuf which is missing in this api. So maybe with this refactoring also some api issues can be fixed.

At work I use this general can api https://github.com/canpie/CANpie for an in house canstack. I also made an example for a stm32f4 discovery board https://github.com/liebherrnenzing/stm32f4_canpie-fd which shows the basic usage of the api. Here https://github.com/liebherrnenzing/canpie-fd_device/blob/bded4dd846454f174104c261ef9534782d089782/stm32/f4/hal/stm32f4xx_canpie-fd.c#L929 you can find the filter implementation which works for me. The nice thing about canpie is that you get the information which buffer send or receive the message. That is what I am missing most in the mbed can implementation.

@martinjaeger
Copy link
Contributor Author

@bcostm no, didn't start coding. A single can_api.c sounds like a great idea.

I had some very simple test code and an additional separate USB2CAN device to inject and read messages to/from the bus.

Code snippet:

#include "mbed.h"

Serial serial(USBTX, USBRX);

DigitalOut led1(LED1);
DigitalOut led2(PA_10);

Ticker tick1;

//CAN can1(PA_11, PA_12);  // RX, TX
CAN can1(PB_8, PB_9);  // RX, TX

int counter = 0;

void send();
void setup();
void receive();

int main()
{
    setup();
    tick1.attach(&send, 0.5);
    can1.attach(&receive);
    can1.mode(CAN::Normal);
    //can1.mode(CAN::LocalTest);  // loop back mode

    can1.filter(0x1, 0xFFFF, CANStandard, 0);

    led1 = 1;

    while(1) {
        serial.printf("loop()\n");
        wait(1);
    }
}

void send() {
    if(can1.write(CANMessage(1337, &counter, 1))) {
        counter++;
        serial.printf("Message sent: %d\n", can1.tderror());
        led1 = !led1;
    }
}

void receive() {
    CANMessage msg;
    if(can1.read(msg)) {
        serial.printf("Message received. id: %d, data: %d\n", msg.id, msg.data[0]);
        led2 = !led2;
    }
}

void setup()
{
    serial.baud(115200);
    serial.printf("\nSerial interface started...\n");
}

aisair pushed a commit to aisair/mbed that referenced this pull request Apr 30, 2024
Ports for Upcoming Targets

3011: Add u-blox Sara-N target. ARMmbed/mbed-os#3011
3099: MAX32625 ARMmbed/mbed-os#3099
3151: Add support for FRDM-K82F ARMmbed/mbed-os#3151
3177: New mcu k22512 fixing pr 3136 ARMmbed/mbed-os#3177

Fixes and Changes

3008: NUCLEO_F072RB: Fix wrong timer channel number on pwm PB_5 pin ARMmbed/mbed-os#3008
3013: STM32xx - Change how the ADC internal pins are checked before pinmap_ ARMmbed/mbed-os#3013
3041: [nRF5] - added implementation of API of serial port flow control configuration. ARMmbed/mbed-os#3041
3084: [nrf5] fix in Digital I/O : a gpioe pin was uninitialized badly ARMmbed/mbed-os#3084
3009: TRNG enabled. TRNG APIs implemented. REV A/B/C/D flags removed. Warnings removed ARMmbed/mbed-os#3009
3074: Target stm init gcc alignement ARMmbed/mbed-os#3074
2988: Update of can_api.c fixing #2987 ARMmbed/mbed-os#2988
3173: [Exporters] Add a device_name to microbit entry in targets.json ARMmbed/mbed-os#3173
2969: [nRF52] - switch irq priorities of driver handlers to the lowest level ARMmbed/mbed-os#2969
3184: #3183 Compiler warning in trng_api.c with K64F  ARMmbed/mbed-os#3184
3104: [NuMaker] Support CAN and fix PWM CLK error ARMmbed/mbed-os#3104
3186: MultiTech mDot - add back SPI3 pins ARMmbed/mbed-os#3186
3075: nsapi - Add standardized return types for size and errors ARMmbed/mbed-os#3075
3221: u-blox odin w2 drivers update ARMmbed/mbed-os#3221
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants