Remove debug serial logic from stm32/uart module

This commit is contained in:
Henrik Stickann 2023-01-20 02:24:00 +01:00
parent dd2983821e
commit c1edafa59e
4 changed files with 60 additions and 62 deletions

View File

@ -3,15 +3,10 @@
* @brief Debug output via UART. * @brief Debug output via UART.
* *
* Configuration: * Configuration:
* STA_DEBUG_SERIAL_ENABLE: Enable module * STA_DEBUG_SERIAL_UART: UART interface for output
* STA_DEBUG_SERIAL_FORCE: Ignore debug defines and always enable output * STA_DEBUG_SERIAL_FORCE: Ignore debug defines and always enable output
* DEBUG: Enables output when defined * DEBUG: Enables output when defined
* NDEBUG: Disables output when defined (overrides DEBUG) * NDEBUG: Disables output when defined (overrides DEBUG)
*
* The `sta::DebugSerial` instance must be provided.
* NOTE: Include this header before the definition because
* the default internal linkage of const namespace variables
* will cause undefined reference errors otherwise.
*/ */
#ifndef STA_CORE_DEBUG_SERIAL_HPP #ifndef STA_CORE_DEBUG_SERIAL_HPP
#define STA_CORE_DEBUG_SERIAL_HPP #define STA_CORE_DEBUG_SERIAL_HPP
@ -24,50 +19,51 @@
#ifdef DOXYGEN #ifdef DOXYGEN
/** /**
* @def STA_DEBUG_SERIAL_ENABLE * @def STA_DEBUG_SERIAL_UART
* @brief Enable module. * @brief UART interface for debug output.
*
* Automatically defined if DEBUG is defined.
* Automatically disabled if NDEBUG is defined.
* *
* @ingroup staCoreBuildConfig * @ingroup staCoreBuildConfig
*/ */
# define STA_DEBUG_SERIAL_ENABLE # define STA_DEBUG_SERIAL_UART
/** /**
* @def STA_DEBUG_SERIAL_DISABLE * @def STA_DEBUG_SERIAL_FORCE
* @brief Force disable module. * @brief Force enable module.
* *
* Overrides STA_DEBUG_SERIAL_ENABLE option. * Enables debug output even if NDEBUG is defined.
* *
* @ingroup staCoreBuildConfig * @ingroup staCoreBuildConfig
*/ */
# define STA_DEBUG_SERIAL_DISABLE # define STA_DEBUG_SERIAL_FORCE
#endif // DOXYGEN #endif // DOXYGEN
#include <sta/config.hpp> #include <sta/config.hpp>
#ifdef DEBUG // Determine if module should be enabled
# ifndef STA_DEBUG_SERIAL_ENABLE // Condition 1: STA_DEBUG_SERIAL_UART is defined
# define STA_DEBUG_SERIAL_ENABLE // Condition 2:
# endif // !STA_DEBUG_SERIAL_ENABLE // STA_DEBUG_SERIAL_FORCE is defined
#endif // DEBUG // or
// DEBUG is defined but not NDEBUG
#if defined(NDEBUG) || defined(STA_DEBUG_SERIAL_DISABLE) #ifdef STA_DEBUG_SERIAL_UART
# ifdef STA_DEBUG_SERIAL_ENABLE # ifdef STA_DEBUG_SERIAL_FORCE
# undef STA_DEBUG_SERIAL_ENABLE # define STA_DEBUG_SERIAL_ENABLED
# endif // STA_DEBUG_SERIAL_ENABLE # else // !STA_DEBUG_SERIAL_FORCE
#endif // NDEBUG || STA_DEBUG_SERIAL_DISABLE # if defined(DEBUG) && !defined(NDEBUG)
# define STA_DEBUG_SERIAL_ENABLED
# endif // DEBUG && !NDEBUG
# endif // !STA_DEBUG_SERIAL_FORCE
#endif // STA_DEBUG_SERIAL_UART
// Show enabled module in doxygen output // Show enabled module in doxygen output
#ifdef DOXYGEN #ifdef DOXYGEN
# define STA_DEBUG_SERIAL_ENABLE # define STA_DEBUG_SERIAL_ENABLED
#endif // DOXYGEN #endif // DOXYGEN
#ifdef STA_DEBUG_SERIAL_ENABLE #ifdef STA_DEBUG_SERIAL_ENABLED
#include <sta/printable_uart.hpp> #include <sta/printable_uart.hpp>
@ -99,10 +95,10 @@ namespace sta
* @ingroup staCoreDebug * @ingroup staCoreDebug
*/ */
# define STA_DEBUG_PRINTLN(...) sta::DebugSerial.println(__VA_ARGS__) # define STA_DEBUG_PRINTLN(...) sta::DebugSerial.println(__VA_ARGS__)
#else // !STA_DEBUG_SERIAL_ENABLE #else // !STA_DEBUG_SERIAL_ENABLED
# define STA_DEBUG_PRINT(...) ((void)0) # define STA_DEBUG_PRINT(...) ((void)0)
# define STA_DEBUG_PRINTLN(...) ((void)0) # define STA_DEBUG_PRINTLN(...) ((void)0)
#endif // !STA_DEBUG_SERIAL_ENABLE #endif // !STA_DEBUG_SERIAL_ENABLED
#endif // STA_CORE_DEBUG_SERIAL_HPP #endif // STA_CORE_DEBUG_SERIAL_HPP

View File

@ -11,16 +11,6 @@
* @brief STM32 UART module. * @brief STM32 UART module.
*/ */
#ifdef DOXYGEN
/**
* @def STA_STM32_UART_DEBUG_SERIAL
* @brief Create global sta::DebugSerial object using this HAL UART instance.
*
* @ingroup stm32BuildConfig
*/
# define STA_STM32_UART_DEBUG_SERIAL
#endif // DOXYGEN
// Only enable module on STM32 platform w/ HAL UART module enabled // Only enable module on STM32 platform w/ HAL UART module enabled
#include <sta/config.hpp> #include <sta/config.hpp>

30
src/debug_serial.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <sta/debug_serial.hpp>
#ifdef STA_DEBUG_SERIAL_ENABLED
#ifdef STA_PLATFORM_STM32
#include <sta/stm32/uart.hpp>
#include <usart.h>
// Set platform UART alias
using PlatformUART = sta::STM32UART;
#endif // STA_PLATFORM_STM32
namespace
{
// Create platform specific serial interface
PlatformUART platformDebugSerial(&STA_DEBUG_SERIAL_UART);
}
namespace sta
{
// Create debug serial object using platform specific serial interface
PrintableUART DebugSerial(&platformDebugSerial);
} // namespace sta
#endif // STA_DEBUG_SERIAL_ENABLED

View File

@ -22,22 +22,4 @@ namespace sta
} // namespace sta } // namespace sta
#ifdef STA_STM32_UART_DEBUG_SERIAL
// Get extern declaration for DebugSerial because const namespace level variables have internal linkage by default
#include <sta/debug_serial.hpp>
#include <usart.h>
namespace sta
{
STM32UART gStm32DebugSerial(&STA_STM32_UART_DEBUG_SERIAL);
// Used by <sta/debug.hpp>
PrintableUART DebugSerial(&gStm32DebugSerial);
} // namespace sta
#endif // STA_STM32_UART_DEBUG_SERIAL
#endif // STA_STM32_UART_ENABLED #endif // STA_STM32_UART_ENABLED