视频讲解
[AG32VF407]国产MCU+FPGA 串口printf调试输出及演示
原理图
测试代码
新建一个platformio工程,复制如下文件到测试工程目录下
E:\tech\AGM-AG32VF\sdk-release\AgRV_pio\platforms\AgRV\boards\agrv2k_407\board.asf
E:\tech\AGM-AG32VF\sdk-release\AgRV_pio\platforms\AgRV\boards\agrv2k_407\board.ve
E:\tech\AGM-AG32VF\sdk-release\AgRV_pio\platforms\AgRV\examples\example\platformio.ini
platformio.ini中增加如下配置,uart调试端口可以查看设备管理器,COM多少,其中速率默认sdk为500000新建src目录,创建uart.c文件,代码如下:
#include "board.h"int main(void)
{board_init();int cnt=0;#define LED_D3_GPIO GPIO4#define LED_D3_GPIO_BITS (1 << 3)SYS_EnableAPBClock(APB_MASK_GPIO4);GPIO_SetOutput(LED_D3_GPIO, LED_D3_GPIO_BITS);GPIO_SetHigh(LED_D3_GPIO, LED_D3_GPIO_BITS);int counter = 0;while (1) {UTIL_IdleMs(500);GPIO_Toggle(LED_D3_GPIO, LED_D3_GPIO_BITS);printf("test %d\r\n", cnt++);}
}
build,upload,然后再点击Serial Monitor,输出如下图
printf实现
E:\tech\AGM-AG32VF\sdk-release\AgRV_pio\packages\framework-agrv_sdk\misc\syscalls.cint printf(const char* fmt, ...)int ret = vprintfmt((void*)putchar, 0, fmt, ap, 0);
E:\tech\AGM-AG32VF\sdk-release\AgRV_pio\packages\framework-agrv_sdk\src\util.cint putchar(int ch)UART_SendCh(UARTx(LOGGER_UART), ch);
E:\tech\AGM-AG32VF\sdk-release\AgRV_pio\platforms\AgRV\boards\agrv2k_407\board.cvoid board_init(void)MSG_UART = UARTx(LOGGER_UART);