mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
Remove debug serial logic from stm32/uart module
This commit is contained in:
parent
dd2983821e
commit
c1edafa59e
@ -3,15 +3,10 @@
|
||||
* @brief Debug output via UART.
|
||||
*
|
||||
* Configuration:
|
||||
* STA_DEBUG_SERIAL_ENABLE: Enable module
|
||||
* STA_DEBUG_SERIAL_FORCE: Ignore debug defines and always enable output
|
||||
* DEBUG: Enables output when defined
|
||||
* 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.
|
||||
* STA_DEBUG_SERIAL_UART: UART interface for output
|
||||
* STA_DEBUG_SERIAL_FORCE: Ignore debug defines and always enable output
|
||||
* DEBUG: Enables output when defined
|
||||
* NDEBUG: Disables output when defined (overrides DEBUG)
|
||||
*/
|
||||
#ifndef STA_CORE_DEBUG_SERIAL_HPP
|
||||
#define STA_CORE_DEBUG_SERIAL_HPP
|
||||
@ -24,50 +19,51 @@
|
||||
|
||||
#ifdef DOXYGEN
|
||||
/**
|
||||
* @def STA_DEBUG_SERIAL_ENABLE
|
||||
* @brief Enable module.
|
||||
*
|
||||
* Automatically defined if DEBUG is defined.
|
||||
* Automatically disabled if NDEBUG is defined.
|
||||
* @def STA_DEBUG_SERIAL_UART
|
||||
* @brief UART interface for debug output.
|
||||
*
|
||||
* @ingroup staCoreBuildConfig
|
||||
*/
|
||||
# define STA_DEBUG_SERIAL_ENABLE
|
||||
# define STA_DEBUG_SERIAL_UART
|
||||
|
||||
/**
|
||||
* @def STA_DEBUG_SERIAL_DISABLE
|
||||
* @brief Force disable module.
|
||||
* @def STA_DEBUG_SERIAL_FORCE
|
||||
* @brief Force enable module.
|
||||
*
|
||||
* Overrides STA_DEBUG_SERIAL_ENABLE option.
|
||||
* Enables debug output even if NDEBUG is defined.
|
||||
*
|
||||
* @ingroup staCoreBuildConfig
|
||||
*/
|
||||
# define STA_DEBUG_SERIAL_DISABLE
|
||||
# define STA_DEBUG_SERIAL_FORCE
|
||||
#endif // DOXYGEN
|
||||
|
||||
|
||||
#include <sta/config.hpp>
|
||||
|
||||
#ifdef DEBUG
|
||||
# ifndef STA_DEBUG_SERIAL_ENABLE
|
||||
# define STA_DEBUG_SERIAL_ENABLE
|
||||
# endif // !STA_DEBUG_SERIAL_ENABLE
|
||||
#endif // DEBUG
|
||||
|
||||
#if defined(NDEBUG) || defined(STA_DEBUG_SERIAL_DISABLE)
|
||||
# ifdef STA_DEBUG_SERIAL_ENABLE
|
||||
# undef STA_DEBUG_SERIAL_ENABLE
|
||||
# endif // STA_DEBUG_SERIAL_ENABLE
|
||||
#endif // NDEBUG || STA_DEBUG_SERIAL_DISABLE
|
||||
// Determine if module should be enabled
|
||||
// Condition 1: STA_DEBUG_SERIAL_UART is defined
|
||||
// Condition 2:
|
||||
// STA_DEBUG_SERIAL_FORCE is defined
|
||||
// or
|
||||
// DEBUG is defined but not NDEBUG
|
||||
#ifdef STA_DEBUG_SERIAL_UART
|
||||
# ifdef STA_DEBUG_SERIAL_FORCE
|
||||
# define STA_DEBUG_SERIAL_ENABLED
|
||||
# else // !STA_DEBUG_SERIAL_FORCE
|
||||
# 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
|
||||
#ifdef DOXYGEN
|
||||
# define STA_DEBUG_SERIAL_ENABLE
|
||||
# define STA_DEBUG_SERIAL_ENABLED
|
||||
#endif // DOXYGEN
|
||||
|
||||
|
||||
#ifdef STA_DEBUG_SERIAL_ENABLE
|
||||
#ifdef STA_DEBUG_SERIAL_ENABLED
|
||||
|
||||
#include <sta/printable_uart.hpp>
|
||||
|
||||
@ -99,10 +95,10 @@ namespace sta
|
||||
* @ingroup staCoreDebug
|
||||
*/
|
||||
# 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_PRINTLN(...) ((void)0)
|
||||
#endif // !STA_DEBUG_SERIAL_ENABLE
|
||||
#endif // !STA_DEBUG_SERIAL_ENABLED
|
||||
|
||||
|
||||
#endif // STA_CORE_DEBUG_SERIAL_HPP
|
||||
|
@ -11,16 +11,6 @@
|
||||
* @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
|
||||
#include <sta/config.hpp>
|
||||
|
30
src/debug_serial.cpp
Normal file
30
src/debug_serial.cpp
Normal 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
|
@ -22,22 +22,4 @@ 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user