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

While loops in USB ISR #146

Open
ryedwards opened this issue Nov 27, 2022 · 7 comments
Open

While loops in USB ISR #146

ryedwards opened this issue Nov 27, 2022 · 7 comments

Comments

@ryedwards
Copy link
Contributor

While testing code I noted that if the CAN XCVR doesn't have 5V the CAN_MSR_INAK bit will never set. Therefore, the while loop in can.c:

139:	can->MCR &= ~CAN_MCR_INRQ;
140:	while ((can->MSR & CAN_MSR_INAK) != 0);

Will hang while in the USB ISR. We should probably create timeouts for these to prevent a full hang?

Might be a moot point as if the xcvr doesn't have 5V we have bigger problems. The host will still timeout on the "ip link set canX up" command.

@marckleinebudde
Copy link
Contributor

marckleinebudde commented Nov 27, 2022

What should the firmware do, if it detects a timeout? The USB stack doesn't care about the return value, so we can only time out (towards to USB host) at this point and maybe put the LED into some error flashing state...

@ryedwards
Copy link
Contributor Author

Agree. I'm not sure. The firmware can't really do anything about a HW issue in this case. Might only be correctable if the 5V feed is switched (e.g. cannette). It's easy to debug with the ICD attached but for someone with just hardware there would be no indication of what the problem is. I like the idea of LED error indication.

Overall just trying to correct the mortal sin of a while loop in an ISR :)

@marckleinebudde
Copy link
Contributor

marckleinebudde commented Nov 27, 2022

Oh, that's inside the ISR, the timer tick IRQ is probably blocked?

@ryedwards
Copy link
Contributor Author

Yes. You'd need to use a counter in the while loop.

@fenugrec
Copy link
Collaborator

a counter, or read the freerunning SysTick value ? (not via HAL_gettick since that depends on the systick ISR...)

@fenugrec
Copy link
Collaborator

(not a fan of that characteristic of HAL_gettick of requiring an ISR, but that's beside the point here)

@marckleinebudde
Copy link
Contributor

With a normal counter it's not so easy to wait for a certain time (on different µCs). Tickless sounds interesting, I want to have the full timer resolution anyways for the timestamps :)

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

No branches or pull requests

3 participants