1630 views|0 replies

43

Posts

0

Resources
The OP
 

[Atria AT32WB415 Review] 4. Implementation of printf under AT32 IDE (printf redirection) [Copy link]

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.

雅特力AT32WB415开发板-评测报告-施连敏-20220806-0901.pdf (2.76 MB, downloads: 3)
newlib_stubs.c (6.21 KB, downloads: 6)

image-20220902110546-4.png (6.11 KB, downloads: 0)

image-20220902110546-4.png

image-20220902110546-8.png (4.28 KB, downloads: 0)

image-20220902110546-8.png

image-20220902110546-9.png (7.98 KB, downloads: 0)

image-20220902110546-9.png

image-20220902110546-10.png (14.01 KB, downloads: 0)

image-20220902110546-10.png

image-20220902110546-11.png (65.89 KB, downloads: 0)

image-20220902110546-11.png

image-20220902110546-12.png (128.73 KB, downloads: 0)

image-20220902110546-12.png
This post is from RF/Wirelessly
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

快速回复 返回顶部 Return list