一个项目上用到CC2530的P0_4 P0_5作为串口,但是默认的zha协议栈里只支持串口0备用位置1和串口2备用位置2,这就坑爹了。经过一番代码搜索发现是可以修改代码以支持串口2备用位置1的。
首先增加预定义(不修改也行,直接根据已有的定义修改)
ZTOOL_P3
#if HAL_DMA
#if (defined ZAPP_P2) || (defined ZTOOL_P2)
#define HAL_UART_DMA 2
#elif (defined ZTOOL_P3)
#define HAL_UART_DMA 3
#else
#define HAL_UART_DMA 1
#endif
#define HAL_UART_PORT_3 0x03
修改文件:Components\hal\target\CC2530EB\_hal_uart_dma.c
#if (HAL_UART_DMA == 1)
#if defined ZTOOL_P1_ALT2
#define HAL_UART_PERCFG_BIT 0x01 // USART0 on P0, Alt-1; so clear this bit.
#define HAL_UART_Px_RX_TX 0x30 // Peripheral I/O Select for Rx/Tx.
#define HAL_UART_Px_RTS 0x08 // Peripheral I/O Select for RTS.
#define HAL_UART_Px_CTS 0x04 // Peripheral I/O Select for CTS.
#else
#define HAL_UART_PERCFG_BIT 0x01 // USART0 on P0, Alt-1; so clear this bit.
#define HAL_UART_Px_RX_TX 0x0C // Peripheral I/O Select for Rx/Tx.
#define HAL_UART_Px_RTS 0x20 // Peripheral I/O Select for RTS.
#define HAL_UART_Px_CTS 0x10 // Peripheral I/O Select for CTS.
#endif
#elif (HAL_UART_DMA == 2)
#define HAL_UART_PERCFG_BIT 0x02 // USART1 on P1, Alt-2; so set this bit.
#define HAL_UART_Px_RTS 0x20 // Peripheral I/O Select for RTS.
#define HAL_UART_Px_CTS 0x10 // Peripheral I/O Select for CTS.
#define HAL_UART_Px_RX_TX 0xC0 // Peripheral I/O Select for Rx/Tx.
#else
#define HAL_UART_PERCFG_BIT 0x02 // USART1 on P1, Alt-2; so set this bit.
#define HAL_UART_Px_RTS 0x20 // Peripheral I/O Select for RTS.
#define HAL_UART_Px_CTS 0x10 // Peripheral I/O Select for CTS.
#define HAL_UART_Px_RX_TX 0x30 // Peripheral I/O Select for Rx/Tx.
#endif
static void HalUARTInitDMA(void)
{
halDMADesc_t *ch;
P2DIR &= ~P2DIR_PRIPO;
P2DIR |= HAL_UART_PRIPO;
#if (HAL_UART_DMA == 1)
#if defined(ZTOOL_P1_ALT2)
PERCFG |= HAL_UART_PERCFG_BIT; // Set UART1 I/O to Alt. 2 location on P1.
#else
PERCFG &= ~HAL_UART_PERCFG_BIT; // Set UART0 I/O to Alt. 1 location on P0.
#endif
#elif (HAL_UART_DMA == 2)
PERCFG |= HAL_UART_PERCFG_BIT; // Set UART1 I/O to Alt. 2 location on P1.
#else
PERCFG &= ~HAL_UART_PERCFG_BIT; // Set UART1 I/O to Alt. 1 location on P1.
#endif
PxSEL |= HAL_UART_Px_RX_TX; // Enable Tx and Rx on P1.
ADCCFG &= ~HAL_UART_Px_RX_TX; // Make sure ADC doesnt use this.
UxCSR = CSR_MODE; // Mode is UART Mode.
UxUCR = UCR_FLUSH; // Flush it.
.......
.......
}
主要就是修改这里,剩下串口的用法就和使用串口0一样了。
此内容由EEWORLD论坛网友lemon0809原创,如需转载或用于商业用途需征得作者同意并注明出处