這裏所說的「配置」,是指告訴IAR:我要使用UART這個模塊了,請給我「初始化」。由於在main函數中調用了以下函數:web
/* Initialze the HAL driver */
HalDriverInit(); //各類驅動的初始化、如按鍵、lcd、adc、usb、uart等
而在函數HalDriverInit()中有這麼一句話:
svg
/* UART */
#if (defined HAL_UART) && (HAL_UART == TRUE)
HalUARTInit();
#endif
可見,只有在預編譯時#define HAL_UART,而且HAL_UART == TRUE,IAR纔會去調用HalUARTInit()函數,即UART的初始化函數。
而#define HAL_UART能夠在以下位置進行:
函數
————————————-+++———————————–spa
這個配置的實現是在《hal_board_cfg.h》文件中實現的,這個文件通常在這個地方:
代碼以下:
code
#if HAL_UART
// Always prefer to use DMA over ISR.
#if HAL_DMA
#ifndef HAL_UART_DMA
#if (defined ZAPP_P1) || (defined ZTOOL_P1)
#define HAL_UART_DMA 1
#elif (defined ZAPP_P2) || (defined ZTOOL_P2)
#define HAL_UART_DMA 2
#else
#define HAL_UART_DMA 1
#endif
#endif
#ifndef HAL_UART_ISR
#define HAL_UART_ISR 0
#endif
#else
#ifndef HAL_UART_ISR
#if (defined ZAPP_P1) || (defined ZTOOL_P1)
#define HAL_UART_ISR 1
#elif (defined ZAPP_P2) || (defined ZTOOL_P2)
#define HAL_UART_ISR 2
#else
#define HAL_UART_ISR 1
#endif
#endif
#ifndef HAL_UART_DMA
#define HAL_UART_DMA 0
#endif
#endif
// Used to set P2 priority - USART0 over USART1 if both are defined.
#if ((HAL_UART_DMA == 1) || (HAL_UART_ISR == 1))
#define HAL_UART_PRIPO 0x00
#else
#define HAL_UART_PRIPO 0x40
#endif
#else
#define HAL_UART_DMA 0
#define HAL_UART_ISR 0
#endif
這樣看起來,結構比較混亂,不容易從總體上把握一下這段代碼的意思,我接住Notepad++來分析:
注意:這裏使用的就是代碼左邊的「+」和「-」,來進行代碼的結構摺疊。註釋以下(行號會改變):
可見:UART是優先使用DMA的,而不是Interrupt。xml