diff --git a/include/sta/hal/uart.hpp b/include/sta/hal/uart.hpp index b9dd65e..e8e5434 100644 --- a/include/sta/hal/uart.hpp +++ b/include/sta/hal/uart.hpp @@ -1,10 +1,10 @@ /** - * @brief Implementation for UART using HAL. + * @brief Implementation of UART using HAL. * - * Define STA_HAL_UART_ENABLE in to enable. + * Define **STA_HAL_UART_ENABLE** in `` to enable module. * - * To enable the global DebugSerial instance (example using UART1) define: - * #define STA_HAL_UART_DEBUG huart1 + * To use a HAL UART instance (e.g. UART1) for `` define: + * #define STA_HAL_UART_DEBUG_SERIAL huart1 */ #ifndef STA_HAL_UART_HPP #define STA_HAL_UART_HPP @@ -37,14 +37,6 @@ namespace sta private: UART_HandleTypeDef * handle_; /**< UART handle */ }; - - -#ifdef STA_HAL_UART_DEBUG - /** - * @brief Global UART instance for debug output. - */ - extern HalUART DebugSerial; -#endif // STA_HAL_UART_DEBUG } // namespace sta diff --git a/src/hal/uart.cpp b/src/hal/uart.cpp index 9413a28..7d3fcc6 100644 --- a/src/hal/uart.cpp +++ b/src/hal/uart.cpp @@ -17,16 +17,22 @@ namespace sta } // namespace sta -#ifdef STA_HAL_UART_DEBUG +#ifdef STA_HAL_UART_DEBUG_SERIAL + +// Get extern declaration for DebugSerial because const namespace level variables have internal linkage by default +#include #include namespace sta { - HalUART DebugSerial(&STA_HAL_UART_DEBUG); + HalUART gHalDebugSerial(&STA_HAL_UART_DEBUG_SERIAL); + + // Used by + UART * const DebugSerial = &gHalDebugSerial; } // namespace sta -#endif // STA_HAL_UART_DEBUG +#endif // STA_HAL_UART_DEBUG_SERIAL #endif // STA_HAL_UART_ENABLE