Skip to content

Fix for #3863: STM Check can sync error #4329

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 6 commits into from
May 30, 2017
Merged

Conversation

adustm
Copy link
Member

@adustm adustm commented May 16, 2017

Description

Can init function needs 11 bits at the same level to synchronize to the CAN bus.
In some cases this cannot occur (refer to #3863 where the object is initialized at a lower frequency than the bus and the bus is very busy). We thus need a timeout mechanism to exit the init function.
in TARGET_STM/can_api.c:

        /* Get tick */
        tickstart = HAL_GetTick();
        can->BTR = btr;
        can->MCR &= ~(uint32_t)CAN_MCR_INRQ;
        while ((can->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) {
            if((HAL_GetTick() - tickstart ) > 2)
            {
                status = 0;
                break;
            }
        }
        if (status ==0) {
            error("can ESR  0x%04x.%04x + timeout status %d", (can->ESR&0XFFFF0000)>>16, (can->ESR&0XFFFF), status);
        }

Status

READY

Migrations

NO

Steps to test or reproduce

refer to #3863 : need a 1st device that overloads the CAN bus with a high frequency. Then try to initialize the 2nd device with a low frequency (or the default one at 100kHz).
The CAN object of the 2nd device will not output of the init function because the HW synchronization cannot occur
With this PR, you will be notified that the initialization could not occur.

cc @bperry730 @ohagendorf

@ohagendorf
Copy link
Contributor

I would implement the timeout handling in both while loops, i.e. also after line 200.

@adustm
Copy link
Member Author

adustm commented May 16, 2017

I would implement the timeout handling in both while loops, i.e. also after line 200.

@ohagendorf I have added that for safety check, but the HW synchronization occurs only when going from init_mode to normal_mode. That's why I had put the timeout only on the 2nd while loop.

Copy link
Contributor

@Ingramz Ingramz left a comment

Choose a reason for hiding this comment

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

I found some code style inconsistencies, it would be nice if you could fix those please.

can_frequency(obj, 100000);
if (can_frequency(obj, 100000) != 1) {
error("Can frequency could not be set\n");
};
Copy link
Contributor

Choose a reason for hiding this comment

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

; is redundant

while ((can->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) {
if((HAL_GetTick() - tickstart ) > 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Whitespace missing between if and (, also there's a redundant whitespace after tickstart.

while ((can->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) {
if((HAL_GetTick() - tickstart ) > 2)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Opening bracket should be on the same line with if

/* Get tick */
tickstart = HAL_GetTick();
while ((can->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) {
if((HAL_GetTick() - tickstart ) > 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same issues as above.

break;
}
}
if (status ==0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

One space is missing.

}
}
if (status ==0) {
error("can ESR 0x%04x.%04x + timeout status %d", (can->ESR&0XFFFF0000)>>16, (can->ESR&0XFFFF), status);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would add spaces around & and >>, also use lowercase 0x prefix instead of 0X.

} else {
return 0;
status=0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing spaces.

@Ingramz
Copy link
Contributor

Ingramz commented May 22, 2017

Very good! There's still a redundant space on those lines: if ((HAL_GetTick() - tickstart ) > 2) {, change them to if ((HAL_GetTick() - tickstart) > 2) { and it will be perfect.

@adbridge
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: 342

All builds and test passed!

@sg-
Copy link
Contributor

sg- commented May 26, 2017

@adustm This needs a conflict resolved.

@adustm
Copy link
Member Author

adustm commented May 29, 2017

@sg- Rebase done. Thanks

@adustm
Copy link
Member Author

adustm commented May 30, 2017

Hello, Is it ok now ?

@0xc0170
Copy link
Contributor

0xc0170 commented May 30, 2017

/morph test

@mbed-bot
Copy link

Result: SUCCESS

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

/morph test

Output

mbed Build Number: 368

All builds and test passed!

@adbridge adbridge merged commit 45b4d41 into ARMmbed:master May 30, 2017
@adbridge
Copy link
Contributor

adbridge commented Jun 5, 2017

Seems this is reliant on #4165 which had an API change and was thus targeted for 5.5.0

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.

7 participants