Skip to content

Commit b99ccf6

Browse files
committed
Add timeout also on the 1st while loop
1 parent 9a1d055 commit b99ccf6

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

targets/TARGET_STM/can_api.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,32 @@ int can_frequency(can_t *obj, int f)
202202

203203
if (btr > 0) {
204204
can->MCR |= CAN_MCR_INRQ ;
205-
while ((can->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) {
206-
}
207205
/* Get tick */
208206
tickstart = HAL_GetTick();
209-
can->BTR = btr;
210-
can->MCR &= ~(uint32_t)CAN_MCR_INRQ;
211-
while ((can->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) {
207+
while ((can->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) {
212208
if((HAL_GetTick() - tickstart ) > 2)
213209
{
214210
status = 0;
215211
break;
216212
}
217213
}
218-
if (status ==0) {
219-
error("can ESR 0x%04x.%04x + timeout status %d", (can->ESR&0XFFFF0000)>>16, (can->ESR&0XFFFF), status);
214+
if (status != 0) {
215+
can->BTR = btr;
216+
can->MCR &= ~(uint32_t)CAN_MCR_INRQ;
217+
/* Get tick */
218+
tickstart = HAL_GetTick();
219+
while ((can->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) {
220+
if((HAL_GetTick() - tickstart ) > 2)
221+
{
222+
status = 0;
223+
break;
224+
}
225+
}
226+
if (status ==0) {
227+
error("can ESR 0x%04x.%04x + timeout status %d", (can->ESR&0XFFFF0000)>>16, (can->ESR&0XFFFF), status);
228+
}
229+
} else {
230+
error("can init request timeout\n");
220231
}
221232
} else {
222233
status=0;

0 commit comments

Comments
 (0)