Is there a way to get to the core of printf? I need an USB output as fast as possible, but printf() is very slow, so I want to get rid of all the formatting that is happening inside the function. Where is printf declared? It is most likely in the stdout library, but where can I find it (I´m using visual studio code).
Background (Working on Raspberry Pi Pico with SDK lib - but not relevant for this question):
I want to read 16Bit Hex values from SPI1 and write them within an interrupt to USB in "realtime". So my program kinda looks like this:
Do nothing until SPI Interrupt triggers
Read data from SPI1
Write data to COM19 on PC via USB
The SPI data from the master is coming in at a rate of 4MHz and there is a gap of about 480ns between data words. One data packet is taking about 4,5us (measured from bit1 of word1 to bit1 of word2). Means the maximum time of the interrupt should not be greater than 4,5us. The interrupt function with printf() takes about 9us to process, so thats too slow and some data is not getting caught. Write() is able to process within the time of one cycle and only takes about 2us. The problem with it is, that the data is printed as ASCII on the COM Port (Putty). I disabled a lot of the SDK functions to optimize the runtime and I was wondering can I do the same with printf() ? Must be possible to write directly into the TX register and send it to the PC, but I wasn´t able to find anything about this topic on my research.
Either I need to speed up the printf() function, or find some alternative, because it is clearly slowing down my program.