各位大佬,我现在开发一个裸跑基于RTX+emwin的项目,其中使用了UART2作为DEBUG接口,UART1作为通讯端口。UART1每次接收接收数据长度会大于150字节,查手册看到fifo只有64字节,不知道能否使用FIFO方式接收。现在想使用串口接收中断方式接收数据,但是不知道如何正确操作,调用了是能中断函数后程序会卡死,注释掉又能正常工作,请教一下大佬们该如何操作。
void sys_uart_init(void)
{
uint32_t addr;
uint32_t val;
/* Config GPIOE1 and GPIOE0 to txd2 and rxd2 */
addr = PIO_REG_BASE+PE_OFFSET+CFG0_OFFSET; //PE7所在寄存器
val = read32(addr);
val &= ~(0xf << ((7 & 0x7) << 2)); //0FFF_FFFF,PE7清零,其他位不变
val |= ((0x3 & 0x7) << ((7 & 0x7) << 2)); //PE7位写入101,复用为TX
write32(addr, val);
addr = PIO_REG_BASE+PE_OFFSET+CFG1_OFFSET; //PE8所在寄存器
val = read32(addr);
val &= ~(0xf << ((0 & 0x7) << 2)); //FFF0,PE8清零,其他位不变
val |= ((0x3 & 0x7) << ((0 & 0x7) << 2));
write32(addr, val);
/* Open the clock gate for uart2 */
addr = 0x01c20068;
val = read32(addr);
val |= 1 << 22;
write32(addr, val);
/* Deassert uart2 reset */
addr = 0x01c202d0; //总线软复位寄存器,Bus Software Reset Register 2
val = read32(addr);
val |= 1 << 22;
write32(addr, val);
/* Config uart2 to 921600-8-1-0 */
addr = 0x01c25800;
write32(addr + 0x04, 0x0);
write32(addr + 0x08, 0xf7);
write32(addr + 0x10, 0x0);
val = read32(addr + 0x0c);
val |= (1 << 7);
write32(addr + 0x0c, val); //选择波特率传感器
write32(addr + 0x00, 0x07 & 0xff); //低八位
write32(addr + 0x04, (0x07 >> 8) & 0xff); //高八位
val = read32(addr + 0x0c); //读传感器
val &= ~(1 << 7); //清零分频寄存器位
write32(addr + 0x0c, val); //锁位
val = read32(addr + 0x0c); //再次读串口寄存器
val &= ~0x1f; //只保留高三位,后五位清零
val |= (0x3 << 0) | (0 << 2) | (0x0 << 3);
write32(addr + 0x0c, val);
/*初始化接控制板串口PA2、PA3*/
addr=PIO_REG_BASE+PA_OFFSET+CFG0_OFFSET;
val = read32(addr); //读PA寄存器值
val &= ~(0Xf<<((3&0x7)<<2)); //与0fff,清除PA3
val &= ~(0Xf<<((2&0x7)<<2)); //与f0ff,清除PA2
val |= ((5 & 0x7)<<((3 & 0x7)<<2)); //PA3位或0x5
val |= ((5 & 0x7)<<((2 & 0x7)<<2)); //PA2位或0x5 目前寄存器,55aa,aa未知
write32(addr,val);
/* 打开UART1时钟树 */
addr=0x01c20000+0x68;
val=read32(addr);
val |= 1<<21 ;
write32(addr,val);
/* 软件复位UART2 */
addr=0x01c20000+0x02d0;
val = read32(addr);
val |= 1<<21;
write32(addr,val);
/* Config uart1 to 921600-8-1-0 */
addr = 0x01c25400;
write32(addr + 0x04, 0x0);
write32(addr + 0x08, 0xf7);
write32(addr + 0x10, 0x0);
val = read32(addr + 0x0c);
val |= (1 << 7);
write32(addr + 0x0c, val); //选择波特率传感器
write32(addr + 0x00, 0x07 & 0xff); //低八位
write32(addr + 0x04, (0x07 >> 8) & 0xff); //高八位
val = read32(addr + 0x0c); //读传感器
val &= ~(1 << 7); //清零分频寄存器位
write32(addr + 0x0c, val); //锁位
val = read32(addr + 0x04); //锁位后读取中断标志位启动接收中断
val |= 0x01;
write32(addr + 0x04,val); //写入数据
val = read32(addr + 0x0c); //再次读串口寄存器
val &= ~0x1f; //只保留高三位,后五位清零
val |= (0x3 << 0) | (0 << 2) | (0x0 << 3);
write32(addr + 0x0c, val);
// f1c100s_intc_set_isr(F1C100S_IRQ_UART1,UART1_Rx_irq); //解除注释程序无法运行
// f1c100s_intc_enable_irq(F1C100S_IRQ_UART1); //解除注释程序无法运行
}
static void UART1_Rx_irq(void)
{
uint8_t data;
uint32_t addr;
if((read32(0x01c25400+0x14)&&0x01))
{
addr=0x01c25400+0x00;
data=(uint8_t)read32(addr);
sysprintf("%c\n",data);
}
}
离线
老铁,目前我也在裸机调串口,加个联系,我们一起讨论一下
离线