问题 : 使用printf串口1没有任何输出
已经在RTE_device.h中启用USART功能
已经添加Compiler(I/O:STDOUT)
已经调用stdout_init初始化
附代码
串口初始化代码:
[mw_shl_code=c,true]
#include "Driver_USART.h"
#include "stdout_usart.h"
#include "stdio.h"
//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
// <h>STDOUT USART Interface
// <o>Connect to hardware via Driver_USART# <0-255>
// <i>Select driver control block for USART interface
#define USART_DRV_NUM 1
// <o>Baudrate
#define USART_BAUDRATE 115200
// </h>
#define _USART_Driver_(n) Driver_USART##n
#define USART_Driver_(n) _USART_Driver_(n)
extern ARM_DRIVER_USART USART_Driver_(USART_DRV_NUM);
#define ptrUSART (&USART_Driver_(USART_DRV_NUM))
/**
Initialize stdout
eturn 0 on success, or -1 on error.
*/
int stdout_init (void) {
int32_t status;
status = ptrUSART->Initialize(NULL);
if (status != ARM_DRIVER_OK) return (-1);
status = ptrUSART->PowerControl(ARM_POWER_FULL);
if (status != ARM_DRIVER_OK) return (-1);
status = ptrUSART->Control(ARM_USART_MODE_ASYNCHRONOUS |
ARM_USART_DATA_BITS_8 |
ARM_USART_PARITY_NONE |
ARM_USART_STOP_BITS_1 |
ARM_USART_FLOW_CONTROL_NONE,
USART_BAUDRATE);
if (status != ARM_DRIVER_OK) return (-1);
status = ptrUSART->Control(ARM_USART_CONTROL_TX, 1);
if (status != ARM_DRIVER_OK) return (-1);
return (0);
}
/**
Put a character to the stdout
param[in] ch Character to output
eturn The character written, or -1 on write error.
*/
int stdout_putchar (int ch) {
uint8_t buf[1];
buf[0] = ch;
if (ptrUSART->Send(buf, 1) != ARM_DRIVER_OK) {
return (-1);
}
while (ptrUSART->GetTxCount() != 1);
return (ch);
}
[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>