x1000串口配置的失败问题

发布于 2017-05-19 16:00:03
使用的是RT-Thread2.1.0版本,X1000芯片。开了三个串口uart0,uart1,uart2,其中uart2为调试串口。初始化后发现除了调试串口uart2寄存器初始化成功,其余两组初始化失败

[board.h]
#define RT_USING_UART2
#define RT_USING_UART1
#define RT_USING_UART3

[drv_uart.c]
void rt_hw_uart_init(void)
{
struct rt_serial_device *serial;
struct jz_uart_s *uart;
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;

#ifdef RT_USING_UART1
{
static struct rt_serial_device serial1;
static struct jz_uart_s uart1;

serial = &serial1;
uart = &uart1;

serial->ops = &_uart_ops;
serial->config = config;
serial->config.baud_rate = 9600;

uart->hw_base = UART1_BASE;
uart->irqno = IRQ_UART1;
memset(uart->name,0,RT_NAME_MAX);
strcpy(uart->name,"ble");
rt_hw_serial_register(serial,
"uart1",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
}
#endif

#ifdef RT_USING_UART2
{
static struct rt_serial_device serial2;
static struct jz_uart_s uart2;

serial = &serial2;
uart = &uart2;

serial->ops = &_uart_ops;
serial->config = config;
serial->config.baud_rate = 115200;

uart->hw_base = UART2_BASE;
uart->irqno = IRQ_UART2;

rt_hw_serial_register(serial,
"uart2",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
}
#endif

#ifdef RT_USING_UART3
{
static struct rt_serial_device serial3;
static struct jz_uart_s uart3;

serial = &serial3;
uart = &uart3;


serial->ops = &_uart_ops;
serial->config = config;
serial->config.baud_rate = 115200;

uart->hw_base = UART0_BASE;
uart->irqno = IRQ_UART0;
memset(uart->name,0,RT_NAME_MAX);
strcpy(uart->name,"uart0");

rt_hw_serial_register(serial,
"uart0",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
}
#endif
}
static rt_err_t uart_configure (struct rt_serial_device *serial, struct serial_configure *cfg)
{

rt_uint32_t baud_div;
struct jz_uart_s * uart;

RT_ASSERT(serial != RT_NULL);
serial->config = *cfg;

uart = serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
printf("#name:%s hw_base:%x cfg:%d
",uart->name,uart->hw_base,cfg->baud_rate);

/* Init UART Hardware */
UART_IER(uart->hw_base) = 0; /* clear interrupt */
UART_FCR(uart->hw_base) = ~UARTFCR_UUE; /* disable UART unite */

/* Enable UART clock */

/* Set both receiver and transmitter in UART mode (not SIR) */
UART_SIRCR(uart->hw_base) = ~(SIRCR_RSIRE | SIRCR_TSIRE);

/* Set databits, stopbits and parity. (8-bit data, 1 stopbit, no parity) */
UART_LCR(uart->hw_base) = UARTLCR_WLEN_8;
printf("UART_LCR:%x",UART_LCR(uart->hw_base));

/* set baudrate */
#if defined(RT_USING_JZ4750) || defined(RT_USING_JZ4755) || defined(RT_USING_JZ4760)
if(REG_CPM_CPCCR & (1UL << 30))
{
/* CPCCR.ECS = 1: clock source is EXCLK/2 */
baud_div = BOARD_EXTAL_CLK / 2 / 16 / cfg->baud_rate;
}
else
#endif
{
/* CPCCR.ECS = 0: clock source is EXCLK */
baud_div = BOARD_EXTAL_CLK / 16 / cfg->baud_rate;
}

UART_LCR(uart->hw_base) |= UARTLCR_DLAB;
UART_DLHR(uart->hw_base) = (baud_div >> 8) & 0xff;
UART_DLLR(uart->hw_base) = baud_div & 0xff;

UART_LCR(uart->hw_base) &= ~UARTLCR_DLAB;

/* Enable UART unit, enable and clear FIFO */
UART_FCR(uart->hw_base) = UARTFCR_UUE | UARTFCR_FE | UARTFCR_TFLS | UARTFCR_RFLS;


UART_SIRCR(uart->hw_base) = SIRCR_RXPL;//个人添加定义问题用


return (RT_EOK);
}


void put_uart_log(rt_uint32_t base)
{
printf("UART_RDR:(%x+00) UART_RDR:0x%08x
",base,UART_RDR(base));
printf("UART_DLHR:(%x+00) UART_DLLR:0x%08x
",base,UART_DLLR(base));
printf("UART_DLHR:(%x+04) UART_DLHR:0x%08x
",base,UART_DLHR(base));
printf("UART_IER:(%x+04) UART_IER:0x%08x
",base,UART_IER(base));
printf("UART_ISR:(%x+08) UART_ISR:0x%08x
",base,UART_ISR(base));
printf("UART_LCR:(%x+0c) UART_LCR:0x%08x
",base,UART_LCR(base));
printf("UART_MCR:(%x+10) UART_MCR:0x%08x
",base,UART_MCR(base));
printf("UART_LSR:(%x+14) UART_LSR:0x%08x
",base,UART_LSR(base));
printf("UART_MSR:(%x+18) UART_MSR:0x%08x
",base,UART_MSR(base));
printf("UART_SPR:(%x+1C) UART_SPR:0x%08x
",base,UART_SPR(base));
printf("UART_MCR:(%x+10) UART_MCR:0x%08x
",base,UART_MCR(base));
printf("UART_SIRCR:(%x+20) UART_SIRCR:0x%08x
",base,UART_SIRCR(base));
}


[main.c]

int main(int argc, char** argv)
{
rt_device_t device;
rt_err_t result = RT_EOK;
int count = 0;

device = rt_device_find("uart1");
if(device != RT_NULL)
{
printf("find uart1
");
rt_device_set_rx_indicate(device,uart_input);

if(rt_device_open(device,RT_DEVICE_OFLAG_RDWR|RT_DEVICE_FLAG_INT_RX) == RT_EOK)
{
printf("open uart1 ok
");
//rt_size_t size = rt_device_write(device,0,"12345678",8);
//printf("write size:%d
",size);
printf("write size
");
}

}
else
printf("cannot find uart1
");

put_uart_log(UART0_BASE);
printf("##################
");
put_uart_log(UART1_BASE);
printf("##################
");
put_uart_log(UART2_BASE);
printf("##################
");
}


打印信息如下:
UART_RDR:(b0030000+00) UART_RDR:0x00000000
UART_DLHR:(b0030000+00) UART_DLLR:0x00000000
UART_DLHR:(b0030000+04) UART_DLHR:0x00000000
UART_IER:(b0030000+04) UART_IER:0x00000000
UART_ISR:(b0030000+08) UART_ISR:0x00000000
UART_LCR:(b0030000+0c) UART_LCR:0x00000000
UART_MCR:(b0030000+10) UART_MCR:0x00000000
UART_LSR:(b0030000+14) UART_LSR:0x00000000
UART_MSR:(b0030000+18) UART_MSR:0x00000000
UART_SPR:(b0030000+1C) UART_SPR:0x00000000
UART_MCR:(b0030000+10) UART_MCR:0x00000000
UART_SIRCR:(b0030000+20) UART_SIRCR:0x00000000
##################
UART_RDR:(b0031000+00) UART_RDR:0x00000000
UART_DLHR:(b0031000+00) UART_DLLR:0x00000000
UART_DLHR:(b0031000+04) UART_DLHR:0x00000000
UART_IER:(b0031000+04) UART_IER:0x00000000
UART_ISR:(b0031000+08) UART_ISR:0x00000000
UART_LCR:(b0031000+0c) UART_LCR:0x00000000
UART_MCR:(b0031000+10) UART_MCR:0x00000000
UART_LSR:(b0031000+14) UART_LSR:0x00000000
UART_MSR:(b0031000+18) UART_MSR:0x00000000
UART_SPR:(b0031000+1C) UART_SPR:0x00000000
UART_MCR:(b0031000+10) UART_MCR:0x00000000
UART_SIRCR:(b0031000+20) UART_SIRCR:0x00000000
##################
UART_RDR:(b0032000+00) UART_RDR:0x0000000d
UART_DLHR:(b0032000+00) UART_DLLR:0x0000000d
UART_DLHR:(b0032000+04) UART_DLHR:0x00000011
UART_IER:(b0032000+04) UART_IER:0x00000011
UART_ISR:(b0032000+08) UART_ISR:0x000000c1
UART_LCR:(b0032000+0c) UART_LCR:0x00000003
UART_MCR:(b0032000+10) UART_MCR:0x00000000
UART_LSR:(b0032000+14) UART_LSR:0x00000020
UART_MSR:(b0032000+18) UART_MSR:0x00000000
UART_SPR:(b0032000+1C) UART_SPR:0x00000000
UART_MCR:(b0032000+10) UART_MCR:0x00000000
UART_SIRCR:(b0032000+20) UART_SIRCR:0x00000010
##################


有打印信息发现除了调试串口寄存器配置成功,其余两个串口寄存器配置失败,大家有什么好的建议吗?

查看更多

关注者
0
被浏览
1.3k
3 个回答
yytyu
yytyu 2017-11-09
请下问是怎样配置的?

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览