从代码看,提问者似乎是在 non-OS BSP上修改UART驱动,
第1步,开启 UART6的外设时钟(peripheral clock)是对的 (outpw(REG_CLK_PCLKEN0, inpw(REG_CLK_PCLKEN0) | (0x1 << 22)); // Enable UART6 engine clock)
第2步 main 函数里,有两句代码:
outpw(REG_SYS_GPC_MFPL, (inpw(REG_SYS_GPC_MFPL) & 0x000fffff) | 0x77700000); // UART1_RXC6, UART1_TXC5, UART1_RTSC7
outpw(REG_SYS_GPC_MFPH, (inpw(REG_SYS_GPC_MFPH) & 0xfffffff0) | 0x00000007); // UART1_CTSC8
根据TRM 136页 SYS_GPC_MFPL 的描述 (0x77700000 --> 0111 0111 0111 0000 0000 0000 0000 0000)
[31:28] MFP_GPC7 PC.7 multifunc selection (0111) --> TRM page 42 --> UART1_RTS
[27:24] MFP_GPC6 PC.6 multifunc selection (0111) --> TRM page 42 --> UART1_RXD
[23:20] MFP_GPC5 PC.5 multifunc selection (0111) --> TRM page 42 --> UART1_TXD
[19:16] MFP_GPC4 PC.4 multifunc selection
[15:12] MFP_GPC3 PC.3 multifunc selection
[11:08] MFP_GPC2 PC.2 multifunc selection
[07:04] MFP_GPC1 PC.1 multifunc selection
[03:00] MFP_GPC0 PC.0 multifunc selection
根据 TRM 137页对 SYS_GPC_MFPH的描述:(0x00000007 --> 0000 0000 0000 0000 0000 0000 0000 0000 0111)
[31:28] MFP_GPC15 PC.15 multifunc selection
[27:24] MFP_GPC14 PC.14 multifunc selection
[23:20] MFP_GPC13 PC.13 multifunc selection
[19:16] MFP_GPC12 PC.12 multifunc selection
[15:12] MFP_GPC11 PC.11 multifunc selection
[11:08] MFP_GPC10 PC.10 multifunc selection
[07:04] MFP_GPC09 PC.09 multifunc selection
[03:00] MFP_GPC08 PC.08 multifunc selection (0111) ---> TRM page 43 --> UART1_CTS
由此可见,main函数的这两句代码,分别设置的是UART1_RTS, UART1_RXD, UART1_TXD, UART1_CTS
需要配置成 UART6所需要的 RTS/CTS, RXD/TXD
UART6_CTS PA.2 MFP1
PD.8 MFP2
UART6_RTS PA.3 MFP1
PD.9 MFP2
UART6_RXD PA.4 MFP1
PD.11 MFP2
PE.8 MFP5
UART6_TXD PA.5 MFP1
PD.10 MFP2
PE.9 MFP5
为了简单方便,假设CTS PA.2 MFP1, RTS PA.3 MFP1, RXD PA.4 MFP1, TXD PA.5 MFP1,
需要配置 SYS_GPA_MFPL (TRM page 132) 为 0000 0000 0001 0001 0001 0001 0000 0000 即 0x111100
outpw(REG_SYS_GPC_MFPL, (inpw(REG_SYS_GPC_MFPL) & 0xff0000ff) | 0x00111100);
|