Question:
When I use STDIO functions, such as printf, the process is slow and incoming data is missed. Why?
---------------------------------------------
Answer:
The slow stdio operations which you are seeing are due to the manner in which STDIO operations are performed. A typical example is printf(), which performs three operations when it is used: It first does an open, then a read, then a close.
At each of these events, the DSP is halted by a hidden breakpoint (at the __primio label), the requested operation is performed, then the DSP is run again. When the DSP is halted, the emulator or debug agent gets a context switch request and, in the case of an Emulator, the context is transferred via JTAG, over USB to the host. Then memory operations are then performed as necessary. When the host is done, context is switched back to the DSP which requires USB traffic again, and the debug agent is set running. Multiply this by 3 times for the three operations (open, read, close) that a printf() does, and this takes time.
The context-switches between the DSP and the Host (PC) are performed whenever any STDIO is used, and consume quite a lot of time due to the data transfers necessary to do this. Although the HPUSB-ICE, USB-ICE and the ICE-100B (or EZ-KIT Debug Agent) perform the same switches, it should be quicker using the HPUSB-ICE as the HPUSB-ICE has higher bandwidth availability, and so can perform the context switches much faster.
If you are using an emulator and are unhappy with the speed, then you may simply need to scale down the amount of data you are trying to log via printf. Unfortunately, due to the way stdio operations are performed via JTAG, it is slower, and can disrupt the real-time metrics of your application due to the number of halt/run commands.
The best way to improve the STDIO performance, though, is to eradicate the context switches by taking the Emulator/Debug agent out of the process, which can be done by redirecting STDIO to a local peripheral, for example UART or USB, which would allow you to pipe data to a terminal application (such as HyperTerminal) via the Serial Port on your PC. You can find detailed information on how to do this in the System Runtime Documentation within CCES Help (Help->Contents->CrossCore Embedded Studio 2.x.x->System Runtime Documentation->STDIO PrimIO). You can also find information within the System Services and Device Drivers User Guide (Help->Contents->CrossCore Embedded Studio 2.x.x->System Runtime Documentation->System Services and Device Drivers->ADSP-BF609 API Reference->Modules->STDIO Service).