打印

本人开发WinCE时有关UART的小结, CPU是PXA270

[复制链接]
3320|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
cmqiu1969|  楼主 | 2009-6-22 13:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
一、    硬件
PXA270公有3个串口,分别是FFUART,BTUART和SUART。FFUART可以控制Modem, BTUART可以进行蓝牙通讯,SUART就只能进行一般的RS232通讯。
二、    软件
1 Eboot下的Debug口的实现
    在PLATFORM\Mtct_smt_2700g\Src\Common\Dbgserial\ Dbgserial.c中修改如下:
    VOID InitDebugSerial(UINT32 DbgSerPhysAddr) 
{
    UINT32 logMask = 0;
    volatile BULVERDE_GPIO_REG *pGPIO_REGS = NULL;
    volatile BULVERDE_CLKMGR_REG *pCLKMGR_REGS = NULL;
    
    volatile i,j;

    // At this moment we must suppress logging.
    //
    logMask = g_oalLogMask;
    g_oalLogMask = 0;

    g_pDebugUARTPort = (volatile BULVERDE_UART_REG *) OALPAtoVA(DbgSerPhysAddr, FALSE);
    pGPIO_REGS       = (volatile BULVERDE_GPIO_REG *) OALPAtoVA(BULVERDE_BASE_REG_PA_GPIO, FALSE);
    pCLKMGR_REGS     = (volatile BULVERDE_CLKMGR_REG *) OALPAtoVA(BULVERDE_BASE_REG_PA_CLKMGR, FALSE);

    // Ensure that UART interrupts are turned off.
    //
    g_pDebugUARTPort->lcr     = 0x0;    // Clear DLAB.
    g_pDebugUARTPort->ier_dlh = 0x0;    // IER_DLH = 0x0.

    // Set the Baud Rate (Divisor low = DEBUG_BAUD_38400).
    // The divisor latches are at offsets 0 and 1, which are 
    // receive/transmit data and ier registers.
    //
    g_pDebugUARTPort->lcr         = 0x80;                // Access Divisor.
    g_pDebugUARTPort->thr_rbr_dll = DEBUG_BAUD_115200;    // Low byte divisor.
    g_pDebugUARTPort->ier_dlh     = 0x00;                // High byte divisor.
    g_pDebugUARTPort->lcr         = 0x0;                 // Clear DLAB.

    //Setting UART properties to 8N1 
    //
    g_pDebugUARTPort->lcr         = 0x3;     // 8 bits, 1 stop, no parity. Also LCR DLAB bit = 0.

    g_pDebugUARTPort->iir_fcr     = 0x01;    // Enable the FIFO.
    g_pDebugUARTPort->iir_fcr     = 0x07;    // Clear Rx,Tx FIFOs.

    // Don't enable UART interrupts - we'll poll for the data.
    //
    g_pDebugUARTPort->ier_dlh     = 0x0;  

    // Ensure loop-back test mode is off even though MCR reset value is 0x0. 
    //
    g_pDebugUARTPort->mcr         = 0x0;    // UART is in normal mode.

    // Configure GPIO pins for FFUART
    //
//    if (DbgSerPhysAddr == BULVERDE_BASE_REG_PA_FFUART)
//   {
//#define SMT
//        // Initialize GPIO pins.
//#ifdef    SMT
//        GPIO99    FFTXD    OUT        3
//        GPIO102    FFRXD    IN        3
//        GPIO82    FFDTR    OUT        3
//        GPIO44    BTCTS    IN        1
//        GPIO41    FFRTS    OUT        2
//        GPIO37    FFDSR    IN        1
//        GPIO10    FFDCD    IN        1
//        GPIO89    FFRI    IN        3



        // Write 0 on GPIO pins 41, 82 and 99 before configuring them as outputs.
        //

        pGPIO_REGS->GPCR1 = 0x1u<<(41-32);
        pGPIO_REGS->GPCR2 = 0x1u<<(82-64);
        pGPIO_REGS->GPCR3 = 0x1u<<(99-96);    

        // Configure direction of GPIO pins 10, 37, 44, 89 and 102 as input 
        //  and GPIO pins 41, 82 and 99 as output
        //

        pGPIO_REGS->GPDR0 &= ~(0x1u<<(10-0));
        pGPIO_REGS->GPDR1 &= ~(0x1u<<(37-32));
        pGPIO_REGS->GPDR1 &= ~(0x1u<<(44-32));
        pGPIO_REGS->GPDR2 &= ~(0x1u<<(89-64));
        pGPIO_REGS->GPDR3 &= ~(0x1u<<(102-96));
               
        
        pGPIO_REGS->GPDR1 |= (0x1u<<(41-32));
        pGPIO_REGS->GPDR2 |= (0x1u<<(82-64));
        pGPIO_REGS->GPDR3 |= (0x1u<<(99-96));

        //     Configure GPIO pins 10, 37 and 44 for Alt_fn1. 
        //    And pin 41 for Alt_fn2
        //    And pins 82,89,99 and 102 for Alt_fn3.
        //

        pGPIO_REGS->GAFR0_L &=~ (0x1u<<20);//(0x1u<<10)<<2;
        pGPIO_REGS->GAFR1_L &=~ (0x1u<<10);//(0x1u<<(37-32))<<2;
        pGPIO_REGS->GAFR1_L &=~ (0x1u<<24);//(0x1u<<(44-32))<<2;
        pGPIO_REGS->GAFR1_L &=~ (0x2u<<18);//(0x2u<<(41-32))<<2;
        pGPIO_REGS->GAFR2_U &=~ (0x3u<<4);//(0x3u<<(82-64-16))<<2;
        pGPIO_REGS->GAFR2_U &=~ (0x3u<<18);//(0x3u<<(89-64-16))<<2;
        pGPIO_REGS->GAFR3_L &=~ (0x3u<<6);//(0x3u<<(99-96))<<2;
        pGPIO_REGS->GAFR3_L &=~ (0x3u<<12);//(0x3u<<(102-96))<<2;

        pGPIO_REGS->GAFR0_L |= (0x1u<<20);//(0x1u<<10)<<2;
        pGPIO_REGS->GAFR1_L |= (0x1u<<10);//(0x1u<<(37-32))<<2;
        pGPIO_REGS->GAFR1_L |= (0x1u<<24);//(0x1u<<(44-32))<<2;
        pGPIO_REGS->GAFR1_L |= (0x2u<<18);//(0x2u<<(41-32))<<2;
        pGPIO_REGS->GAFR2_U |= (0x3u<<4);//(0x3u<<(82-64-16))<<2;
        pGPIO_REGS->GAFR2_U |= (0x3u<<18);//(0x3u<<(89-64-16))<<2;
        pGPIO_REGS->GAFR3_L |= (0x3u<<6);//(0x3u<<(99-96))<<2;
        pGPIO_REGS->GAFR3_L |= (0x3u<<12);//(0x3u<<(102-96))<<2;
        

        // Enable the FFUART clock.
        //
        pCLKMGR_REGS->cken |= XLLP_CLKEN_FFUART ;

    // Enable the UART.
    //
    g_pDebugUARTPort->ier_dlh = 0x40;

    // Restore the logging mask.
    //
    g_oalLogMask = logMask;
}
2 WinCE下调试口的实现
    在PLATFORM\Mtct_smt_2700g\Src\Drivers\Serial\ms2_serial.cpp中修改
    class CBulPdd16550FUART : public CBulPdd16550 {
public:
    CBulPdd16550FUART (LPTSTR lpActivePath, PVOID pMdd, PHWOBJ pHwObj) 
        : CBulPdd16550 (lpActivePath,pMdd, pHwObj) {  };
    virtual BOOL Init() {
        if (CBulPdd16550::Init() ) {
            ConfigurePinout();
            //Enable FFUART clock
            m_pDCCLKReg->cken |= XLLP_CLKEN_FFUART ;
            return TRUE;
        }
        else
            return FALSE;
    }
    virtual void    SerialRegisterRestore() {
        ConfigurePinout();
        CBulPdd16550::SerialRegisterRestore();
    }
private:
    BOOL ConfigurePinout(){
        //Initialize GPIO pins 
//2009-3-5 9:38
//modified by Bruce
//        //Write 0 on GPIO pins 39, 40 and 41 before configuring them as outputs.
//        m_pGPIOReg->GPCR1 = ( XLLP_GPIO_BIT_FFDTR | XLLP_GPIO_BIT_FFTXD | XLLP_GPIO_BIT_FFRTS );
//        
//        //Configure direction of GPIO pins 34, 35, 36, 37 and 38 as input 
//        //and GPIO pins 39, 40 and 41 as output
//        m_pGPIOReg->GPDR1 &= ~( XLLP_GPIO_BIT_FFRXD | XLLP_GPIO_BIT_FFCTS | 
//                                XLLP_GPIO_BIT_FFDCD | XLLP_GPIO_BIT_FFDSR | 
//                                XLLP_GPIO_BIT_FFRI );
//        m_pGPIOReg->GPDR1 |= (  XLLP_GPIO_BIT_FFTXD |  XLLP_GPIO_BIT_FFDTR |  XLLP_GPIO_BIT_FFRTS );
//        
//        //Configure GPIO pins 34, 35, 36, 37 and 38 for Alt_fn1. And pins 39, 40 and 41 for Alt_fn2.
//        m_pGPIOReg->GAFR1_L |= (XLLP_GPIO_AF_BIT_FFRXD | XLLP_GPIO_AF_BIT_FFCTS | 
//                                XLLP_GPIO_AF_BIT_FFDCD | XLLP_GPIO_AF_BIT_FFDSR | 
//                                XLLP_GPIO_AF_BIT_FFRI  | XLLP_GPIO_AF_BIT_FFTXD | 
//                                XLLP_GPIO_AF_BIT_FFDTR | XLLP_GPIO_AF_BIT_FFRTS );

        // Write 0 on GPIO pins 41, 82 and 99 before configuring them as outputs.
        //

        m_pGPIOReg->GPCR1 = 0x1u<<(41-32);
        m_pGPIOReg->GPCR2 = 0x1u<<(82-64);
        m_pGPIOReg->GPCR3 = 0x1u<<(99-96);    

        // Configure direction of GPIO pins 10, 37, 44, 89 and 102 as input 
        //  and GPIO pins 41, 82 and 99 as output
        //

        m_pGPIOReg->GPDR0 &= ~(0x1u<<(10-0));
        m_pGPIOReg->GPDR1 &= ~(0x1u<<(37-32));
        m_pGPIOReg->GPDR1 &= ~(0x1u<<(44-32));
        m_pGPIOReg->GPDR2 &= ~(0x1u<<(89-64));
        m_pGPIOReg->GPDR3 &= ~(0x1u<<(102-96));
               
        
        m_pGPIOReg->GPDR1 |= (0x1u<<(41-32));
        m_pGPIOReg->GPDR2 |= (0x1u<<(82-64));
        m_pGPIOReg->GPDR3 |= (0x1u<<(99-96));

        //     Configure GPIO pins 10, 37 and 44 for Alt_fn1. 
        //    And pin 41 for Alt_fn2
        //    And pins 82,89,99 and 102 for Alt_fn3.
        //
//        pGPIO_REGS->GAFR0_L    =0;
//        pGPIO_REGS->GAFR1_L    =0;
//        pGPIO_REGS->GAFR2_L    =0;
//        pGPIO_REGS->GAFR3_L    =0;
//        pGPIO_REGS->GAFR0_U    =0;
//        pGPIO_REGS->GAFR1_U    =0;
//        pGPIO_REGS->GAFR2_U    =0;
//        pGPIO_REGS->GAFR3_U    =0;

        m_pGPIOReg->GAFR0_L &=~ (0x1u<<20);//(0x1u<<10)<<2;
        m_pGPIOReg->GAFR1_L &=~ (0x1u<<10);//(0x1u<<(37-32))<<2;
        m_pGPIOReg->GAFR1_L &=~ (0x1u<<24);//(0x1u<<(44-32))<<2;
        m_pGPIOReg->GAFR1_L &=~ (0x2u<<18);//(0x2u<<(41-32))<<2;
        m_pGPIOReg->GAFR2_U &=~ (0x3u<<4);//(0x3u<<(82-64-16))<<2;
        m_pGPIOReg->GAFR2_U &=~ (0x3u<<18);//(0x3u<<(89-64-16))<<2;
        m_pGPIOReg->GAFR3_L &=~ (0x3u<<6);//(0x3u<<(99-96))<<2;
        m_pGPIOReg->GAFR3_L &=~ (0x3u<<12);//(0x3u<<(102-96))<<2;

        m_pGPIOReg->GAFR0_L |= (0x1u<<20);//(0x1u<<10)<<2;
        m_pGPIOReg->GAFR1_L |= (0x1u<<10);//(0x1u<<(37-32))<<2;
        m_pGPIOReg->GAFR1_L |= (0x1u<<24);//(0x1u<<(44-32))<<2;
        m_pGPIOReg->GAFR1_L |= (0x2u<<18);//(0x2u<<(41-32))<<2;
        m_pGPIOReg->GAFR2_U |= (0x3u<<4);//(0x3u<<(82-64-16))<<2;
        m_pGPIOReg->GAFR2_U |= (0x3u<<18);//(0x3u<<(89-64-16))<<2;
        m_pGPIOReg->GAFR3_L |= (0x3u<<6);//(0x3u<<(99-96))<<2;
        m_pGPIOReg->GAFR3_L |= (0x3u<<12);//(0x3u<<(102-96))<<2;

        return TRUE;
    }
}

3 WinCE下调试口转为可以被应用程序使用的普通串口
    在PLATFORM\Mtct_smt_2700g\Src\Kernel\Oal\init.c中修改如下:
    VOID OEMInitDebugSerial(void)
{
UINT32 *pDbgSerPhysAddr = (UINT32*) OALArgsQuery(BSP_ARGS_QUERY_DBGSERIAL);
    return;
    if (pDbgSerPhysAddr)
    {
        InitDebugSerial(*pDbgSerPhysAddr);
    }
}
在platform.reg中修改为:
; -----------------------------------------------------------------------------
; @CESYSGEN IF CE_MODULES_SERIAL
IF BSP_NOSERIAL !
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SerialBT]
   "Irq"=dword:15        ; 21 IRQ_BTUART
   "SysIntr"=dword:1c           ; 28 SYSINTR_BTUART
   "MemBase"=dword:40200000    ; BTUART Register 
   "MemLen"=dword:40
   "DeviceArrayIndex"=dword:81  ; BTUART object
   "Prefix"="COM"
   "IClass"="{CC5195AC-BA49-48a0-BE17-DF6D1B0173DD}"
   "Dll"="ms2_serial.dll"
   "Index"=dword:3        ;cqz
   "Order"=dword:0

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SerialBT\Unimodem]
   "Tsp"="Unimodem.dll"
   "DeviceType"=dword:0
   "FriendlyName"="COM3:";Serial Cable on COM1:
   "DevConfig"=hex: 10,00, 00,00, 05,00,00,00, 10,01,00,00, 00,4B,00,00, 00,00, 08, 00, 00, 00,00,00,00

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SerialST]
    "Dll"="ms2_serial.dll"
    "Irq"=dword:15               ; 20 IRQ_STUART
    "SysIntr"=dword:1d           ; 29 SYSINTR_SFUART
    "MemBase"=dword:40700000     ; STUART Register
    "MemLen"=dword:40
    "Prefix"="COM"
    "Index"=dword:2        ;cqz 4
    "Order"=dword:1
    "DeviceArrayIndex"=dword:82  ; STUART object
    "IClass"="{CC5195AC-BA49-48a0-BE17-DF6D1B0173DD}"
    
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Serial\Unimodem]
   "Tsp"="Unimodem.dll"
   "DeviceType"=dword:0
    "FriendlyName"="COM2:" ;Serial Cable on COM4:
   "DevConfig"=hex: 10,00, 00,00, 05,00,00,00, 10,01,00,00, 00,4B,00,00, 00,00, 08, 00, 00, 00,00,00,00

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\SerialFT]
   "Irq"=dword:15                ; 21 IRQ_FFUART
   "SysIntr"=dword:1b           ; 29 SYSINTR_FFUART
   "MemBase"=dword:40100000        ; FFUART Register 
   "MemLen"=dword:40
   "DeviceArrayIndex"=dword:80  ; FTUART object
   "Prefix"="COM"
   "IClass"="{CC5195AC-BA49-48a0-BE17-DF6D1B0173DD}"
   "Dll"="ms2_serial.dll"
   "Index"=dword:5
   "Order"=dword:2

ENDIF BSP_NOSERIAL !

相关帖子

沙发
cmqiu1969|  楼主 | 2009-6-22 14:00 | 只看该作者

有关USB的小结

使用特权

评论回复
板凳
cmqiu1969|  楼主 | 2009-6-22 14:01 | 只看该作者

UART的PDF

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

14

帖子

0

粉丝