-
Notifications
You must be signed in to change notification settings - Fork 3k
fix #3863 Add an mbed API that allows the init of the CAN at the bus frequency #4165
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
Conversation
Getting a linking error when building with armcc at least for NUMAKER_PFM_NUC472 and UBLOX_EVK_ODIN_W2 targets.
|
Thanks @tommikas . @adustm Adding new HAL function introduces a requirement for all targets that support CAN to have this function implemented. Therefore to make this addition, we should implement it for all targets that support CAN. There are not that many. We can create a devel branch here for this. |
Unfortunately, I think the solution will not solve the problem in every case. We found the problem the first time in a test application, one sending mcu and one receiving mcu. Each second a single CAN message was send with a CAN bus frequency of 1MHz. We just call the constructor without a following call of can.frequency so the default 1MHz were used. From time to time the receiving mcu didn’t start – it stopped in the constructor in can_init during the execution of can_frequency(obj, 100000) in the second while ((can->MSR & CAN_MSR_INAK) == CAN_MSR_INAK). The other application was an automotive RADAR sensor connected over CAN with an STM Nucleo. The sensor starts with an init message with a maximal message rate until it gets its config from another CAN node. In this scenario the bus will never be idle long enough to set the frequency to the requested 500kHz. The same functionality realised only with Cube HAL function works without problems since a couple of days. We just used a CAN example from an eval board from the Cube library and adapted it to our hardware. |
Thanks @0xc0170 and @tommikas for your comments. I agree for the separate development branch if needed. At the moment, it seems we still have another issue. I will need to fix it before we go for the devel branch. Hello @ohagendorf
Did you have a chance to check the differences between mbed and Cube settings wrt CAN HW registers or clocks or RCC registers ? |
Hello @adustm |
Hi @ohagendorf
I've seen differences between Cube code and mbed-os code: the above parameters + a timeout exit. Could you also provide me with the rate of the CANbus at boot time ? Kind regards |
bump @adustm @ohagendorf What's the status on this? |
Hello @theotherjimmy I don't have any news on the fact that it does not solve the issue from @ohagendorf but I am thinking about handling this in a separate PR (at least by detecting a timeout and by sending an error code) |
Hello, I think I've added every can_init_freq for every CAN platforms.
Kind regards |
@cyliangtw @TomoYamanaka @mmahadevan108 please review, as this PR touches your platforms as well. What do you think about CAN init freq proposal? |
This PR is fine to our platforms, it could support backward compatibility. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your changing.
In TARGET_RZ_A1H and TARGET_VK_RZ_A1H.
if you keep this change, f
of CAN::CAN(PinName rd, PinName td, int f)
will not be referenced anywhere.
Therefore, please let me suggest to add two changinges.
First changing:
I would like to add can_frequency(obj, hz);
in the below.
https://github.com/ARMmbed/mbed-os/pull/4165/files#diff-d349510c34424b620ac131c682689558L576
https://github.com/ARMmbed/mbed-os/pull/4165/files#diff-cab74c93ed52cd8f693385e5f4885084L593
Second changing:
I would like to change can_init_freq(obj, rd, td, 0);
to can_init_freq(obj, rd, td, 100000);
in the below.
https://github.com/ARMmbed/mbed-os/pull/4165/files#diff-d349510c34424b620ac131c682689558R579
https://github.com/ARMmbed/mbed-os/pull/4165/files#diff-cab74c93ed52cd8f693385e5f4885084R596
please update can_api.c file in TARGET_LPC408X/TARGET_LPC4088_DM |
Thank you all for your remarks @TomoYamanaka san, Hello @mmahadevan108 and I have rebased the pull request Kind regards |
@adustm. Thank you, changes look fine to me. |
Hi @0xc0170 |
restart uvisor |
It's failing due to periodic issues with the Uvisor CI and the parallel threads that the compiler uses leaking data. I will restart it again! |
retest uvisor |
@TomoYamanaka @cyliangtw Could you please confirm you are also happy with the updates and sign off the review so that we can get this merged in ? Thanks |
Thanks of this modification. The change is fine to me after review code. |
/morph test-nightly |
retest uvisor |
Result: FAILUREYour command has finished executing! Here's what you wrote!
OutputTest failed! |
/morph test-nightly |
retest uvisor |
/morph test-nightly |
retest uvisor |
Result: FAILUREYour command has finished executing! Here's what you wrote!
OutputTest failed! |
We had a K64F that was behind on firmware updates and was showing failures. It has been updated now. /morph test-nightly |
Result: FAILUREYour command has finished executing! Here's what you wrote!
OutputTest failed! |
Hello @bridadan @adbridge , the K64F is in TIMEOUT-ERROR.
I guess there is an issue in your testbench somewhere. Could you try and solve it, please ? |
/morph test-nightly |
retest uvisor |
@adustm I've restarted the jobs, if they fail again we may have a broken device in the CI @studavekar |
Result: ABORTEDYour command has finished executing! Here's what you wrote!
OutputTest failed! |
Apologies have aborted few of the jobs which failed and on one of device. CI seems to unstable now with the devices. Will re-trigger the tests after checking few jobs. |
/morph test-nightly |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
@Looks good although the can_init looks useless at this point so should be considered for deprecation. Second note is that HAL setting the default frequency seems wrong, although was the way it was apparently. Shall we remove can_init in another PR and use the constructor to set a default frequency across all CAN object using |
@sg- for sure the old can_init is not usefull anymore |
Description
If the bus is using a much higher frequency than the default value chosen in the init function, the device cannot synchronize and is blocked (see #3863 for details). The device needs an IDLE frame on the CAN bus to synchronize, but if the device is not set with the correct frequency, the IDLE frame may never be detected.
for instance: initialize CAN at 100kbps. It needs an idle frame on the CAN bus to synchronize (ie: 110us to have 11 consecutive recessive bits). If the bus is at 500kbs and highly busy due to another device, 110us of consecutive recessive bits does not occur. I have only 58us in my use case.
Adding the frequency parameter to the CAN class (same as done in serial api for baud rates) allows us to initialize and synchronize the CAN device even if the bus is often busy.
Status
READY
Steps to test or reproduce
Have a 1st device with high bus occupation with the following code:
Have the current device trying to initialize. Without the PR, NUCLEO_F767ZI cannot exit from the init function (because HW cannot syncrhonize). With the PR, it can synchronize if the init function is modifying the frequency (we can see the printf "created can") with the following code:
cc @bperry730 @ohagendorf