Next are the 3 evaluation reports:
(1) https://en.eeworld.com/bbs/thread-1214040-1-1.html
(2) https://en.eeworld.com/bbs/thread-1214570-1-1.html
(3) https://en.eeworld.com/bbs/thread-1215784-1-1.html
It used to be very convenient to use printf in the MDK environment, and there were many reference materials on the Internet. This time, after getting the AT32WB415 evaluation board, I used the official AT32 IDE for development. At first, I naively thought that it was the same as MDK and could be used directly. I added the following code in main:
, compiled it once,
, and then I couldn't wait to download the *.hex file to the evaluation board, opened the serial port debugging tool, and found that the printf "Hello" message was not printed. It suddenly dawned on me that using printf in AT32 IDE is not easy.
The source code was traced back to the location of the stdio.h file of printf
used in the program, while the location of the stdio.h file in the MDK environment was
. MDK could use printf normally, so I had an idea to directly overwrite the stdio.h file called in the AT32 IDE environment with the stdio.h file called in the MDK. But it still didn't work.
So I started searching on Baidu and posted a message for help. After two days of searching, I still couldn't find a suitable solution, so I started my own exploration process.
I checked a lot of information and all of them said that printf redirection is needed. I studied the source code and found that in the
file, the printf function in the C library is retargeted to the USART, as shown in Figure 40.
Figure 40 at32wb415_board.c source code
But through verification, this code is not executed.
Then, I started to consider copying the macros used in the previous GD environment and modifying them according to the macro definition parameters generated when the AT32 IDE creates a new project, for example: USART_TDBE_FLAG. These USART FLAG macros are defined in the USART header file, as shown in Figure 41. Figure 41 FLAG macro definition in the USART header file
USART_TDBE_FLAG: USART send data buffer empty flag.
Finally, you can add
to the main.c file to set how the serial port data should be buffered. If you do not set it, the default situation will be used (after testing, the default situation is definitely not the _IOFBF full buffer mode).
For a detailed introduction to the setvbuf function, please refer to reference [4] C library function - setvbuf.