Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8041

SDK • Re: RP2040 printf to USB UART gets interrupted by an interrupt

$
0
0
The printf to USB UART stuff is quite complex -- the function has to copy your text elsewhere and queue it up for sending and so on, so it's best to always printf (or call complex functions) in the main code loop.
Close but the critical section is used incorrectly. I want to say there was some guidance about using it liberally. However critical sections are promotion and serialization. Something the preemptive USB design does not support. Critical sections cause FIFO behavior in cooperation. I believe there is a deadlock risk due to order and priority. USB printf is not compatible with this approach.

Using critical section can lead to bad code if not careful. They allow user code to enter kernel mode at will. You would be better off implementing an OS with kernel/user mode enabled in processor. Critical section generally mean well but they come with a style and design which must be understood.

Statistics: Posted by dthacher — Tue Jun 24, 2025 5:13 am



Viewing all articles
Browse latest Browse all 8041

Trending Articles