如何在imx6q中启用UART中断?

时间:2016-10-25 05:48:57

标签: interrupt uart imx6

我正在使用I.MX6Q Sabre SD板。我正在尝试使用自己的启动脚本和ld脚本构建自定义映像。该图像将加载u-boot。我正在尝试为UART1启用UART接收中断。但它不会进入中断服务程序。我可以通过轮询发送和接收数据。启用uart中断的基本初始化步骤是什么?我已按如下方式对uart进行了初始化,

void UART1_init(void)
{
int tmp;
//*********** UART1 IOMUX****************//
* R32 (IOMUXC_BASE_ADDR+0x280) = 0x00000003; // ALT3 CSI0_DAT10 TxD
* R32 (IOMUXC_BASE_ADDR+0x284) = 0x00000003; // ALT3 CSI0_DAT11 RxD
* R32 (IOMUXC_BASE_ADDR+0x920) = 0x00000001; //UART1_UART_RX_DATA_SELECT_INPUT
tmp=(* R32 (CCM_BASE_ADDR+0x24)) & 0x0000003F ; //CSCDR1 uart_podf div by 1
* R32 (CCM_BASE_ADDR+0x24) = tmp; // UART refclk = 80MHz

// Enable UART1
// enable uart1, ignore RTS, wordsize 8bits, 1 stop bit, no parity
*(unsigned int*)(UART1_UCR2_1) = 0x01; // reset UART state machines 
*(unsigned int*)(UART1_UCR2_1) = 0x2006; // UCR2 = CTSC,TXEN,RXEN=1,reset
*(unsigned int*)(UART1_UCR1_1) = 0x0001; // UARTEN = 1,enable the clock
*(unsigned int*)(UART1_UCR2_1) |= IGNORE_RTS<<14; // configure IRTS bit
*(unsigned int*)(UART1_UCR2_1) |= WORD8<<5;
*(unsigned int*)(UART1_UCR2_1) |= STOP1<<6;
*(unsigned int*)(UART1_UCR3_1) |= 0x00000004; // set RXD_MUX_SEL bit
*(unsigned int*)(UART1_UCR1_1) |= 0x0201; // recieve ready interput enable
// disable parity
*(unsigned int*)(UART1_UCR2_1) &= ~(0x00000100);
//SetRFDIV_to_div_by_1_UART1(); 
tmp = *(unsigned int*)(UART1_UFCR_1); // save UFCR to default value
*(unsigned int*)(UART1_UFCR_1) = 5<<7; // set RFDIV to div-by-1 or b101 
*(unsigned int*)(UART1_UFCR_1) |= tmp; // set other UFCR bits back to default
*(unsigned int*)(UART1_UBIR_1) = 0x4;
*(unsigned int*)(UART1_UBMR_1) = 0xD8;
*(unsigned int*)(UART1_UCR3_1) |= 0x00000040; 
*(unsigned int*)(UART1_UCR4_1) |= 0x00000081; 

/* RxTl =1 */
tmp = *(unsigned int*)(UART1_UFCR_1);
tmp = tmp & 0xffffffc0;
tmp = tmp | 0x00000001;
*(unsigned int*)(UART1_UFCR_1) = tmp;

/* Rf div */
tmp = *(unsigned int*)(UART1_UCR1_1);
tmp = tmp & 0xfffffcff;
tmp = tmp | 0x00000200;
*(unsigned int*)(UART1_UCR1_1) = tmp;
}

我是否缺少uart接收中断的一些初始化步骤?

1 个答案:

答案 0 :(得分:0)

我发现了问题。它不是在UART初始化中。我忘了设置VBAR寄存器(向量基地址寄存器),其复位值为0x00000000。我已将我的矢量表链接到0x0093ff80。正确设置VBAR寄存器后,UART中断在上述初始化时工作正常。这就是我设置VBAR的方式,

ldr r6,=__ram_vectors_start
MCR p15,0,r6,c12,c0,0
MCR p15,0,r6,c12,c0,1