commit 1f94ac646e873806d02999dab3f1634b19707f0b
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Thu Feb 7 18:13:42 2019 +0100

    Enhanced the periphAL debug implementation to apply to tze new AMiRo-OS debug API

diff --git a/modules/DiWheelDrive_1-1/alldconf.h b/modules/DiWheelDrive_1-1/alldconf.h
index d6da5d0..bc3cf36 100644
--- a/modules/DiWheelDrive_1-1/alldconf.h
+++ b/modules/DiWheelDrive_1-1/alldconf.h
@@ -32,8 +32,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * compatibility guards
  */
 #define _AMIRO_LLD_CFG_
-#define AMIRO_LLD_CFG_VERSION_MAJOR         1
-#define AMIRO_LLD_CFG_VERSION_MINOR         0
+#define AMIRO_LLD_CFG_VERSION_MAJOR             1
+#define AMIRO_LLD_CFG_VERSION_MINOR             0
 
 /**
  * @brief   Width of the apalTime_t data type.
@@ -41,62 +41,62 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * @details Possible values are 8, 16, 32, and 64 bits.
  *          By definition time is represented at microsecond precision.
  */
-#define AMIROLLD_CFG_TIME_SIZE          32
+#define AMIROLLD_CFG_TIME_SIZE                  32
 
 /**
  * @brief   Enable flag for the A3906 motor driver.
  */
-#define AMIROLLD_CFG_A3906              1
+#define AMIROLLD_CFG_A3906                      1
 
 /**
  * @brief   Enable flag for the AT24C01BN-SH-B EEPROM.
  */
-#define AMIROLLD_CFG_AT24C01B           1
+#define AMIROLLD_CFG_AT24C01B                   1
 
 /**
  * @brief   Enable flag for the MHC5883L compass.
  */
-#define AMIROLLD_CFG_HMC5883L           1
+#define AMIROLLD_CFG_HMC5883L                   1
 
 /**
  * @brief   Enable flag for the INA219 power monitor.
  */
-#define AMIROLLD_CFG_INA219             1
+#define AMIROLLD_CFG_INA219                     1
 
 /**
  * @brief   Enable flag for the L3G4200D gyroscope.
  */
-#define AMIROLLD_CFG_L3G4200D           1
+#define AMIROLLD_CFG_L3G4200D                   1
 
 /**
  * @brief   Enable flag for the status LED.
  */
-#define AMIROLLD_CFG_LED                1
+#define AMIROLLD_CFG_LED                        1
 
 /**
  * @brief   Enable flag for the LIS331DLH accelerometer.
  */
-#define AMIROLLD_CFG_LIS331DLH          1
+#define AMIROLLD_CFG_LIS331DLH                  1
 
 /**
  * @brief   Enable flag for the LTC4412 power path controller.
  */
-#define AMIROLLD_CFG_LTC4412            1
+#define AMIROLLD_CFG_LTC4412                    1
 
 /**
  * @brief   Enable flag for the PCA9544A I2C multiplexer.
  */
-#define AMIROLLD_CFG_PCA9544A           1
+#define AMIROLLD_CFG_PCA9544A                   1
 
 /**
  * @brief   Enable flag for the TPS62113 step-down converter.
  */
-#define AMIROLLD_CFG_TPS6211x           1
+#define AMIROLLD_CFG_TPS6211x                   1
 
 /**
  * @brief   Enable flag for the VCNL4020 proximity sensor.
  */
-#define AMIROLLD_CFG_VCNL4020           1
+#define AMIROLLD_CFG_VCNL4020                   1
 
 #endif /* ALLDCONF_H */
 
diff --git a/modules/LightRing_1-0/alldconf.h b/modules/LightRing_1-0/alldconf.h
index f398463..29aaa5c 100644
--- a/modules/LightRing_1-0/alldconf.h
+++ b/modules/LightRing_1-0/alldconf.h
@@ -32,8 +32,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * compatibility guards
  */
 #define _AMIRO_LLD_CFG_
-#define AMIRO_LLD_CFG_VERSION_MAJOR         1
-#define AMIRO_LLD_CFG_VERSION_MINOR         0
+#define AMIRO_LLD_CFG_VERSION_MAJOR             1
+#define AMIRO_LLD_CFG_VERSION_MINOR             0
 
 /**
  * @brief   Width of the apalTime_t data type.
@@ -41,22 +41,22 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * @details Possible values are 8, 16, 32, and 64 bits.
  *          By definition time is represented at microsecond precision.
  */
-#define AMIROLLD_CFG_TIME_SIZE          32
+#define AMIROLLD_CFG_TIME_SIZE                  32
 
 /**
  * @brief   Enable flag for the AT24C01BN-SH-B EEPROM.
  */
-#define AMIROLLD_CFG_AT24C01B           1
+#define AMIROLLD_CFG_AT24C01B                   1
 
 /**
  * @brief   Enable flag for the TLC5947 LED driver.
  */
-#define AMIROLLD_CFG_TLC5947            1
+#define AMIROLLD_CFG_TLC5947                    1
 
 /**
  * @brief   Enable flag for the TPS2051BDBV power switch.
  */
-#define AMIROLLD_CFG_TPS20xxB           1
+#define AMIROLLD_CFG_TPS20xxB                   1
 
 #endif /* ALLDCONF_H */
 
diff --git a/modules/NUCLEO-F103RB/alldconf.h b/modules/NUCLEO-F103RB/alldconf.h
index b510d59..5e66fc3 100644
--- a/modules/NUCLEO-F103RB/alldconf.h
+++ b/modules/NUCLEO-F103RB/alldconf.h
@@ -32,8 +32,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * compatibility guards
  */
 #define _AMIRO_LLD_CFG_
-#define AMIRO_LLD_CFG_VERSION_MAJOR         1
-#define AMIRO_LLD_CFG_VERSION_MINOR         0
+#define AMIRO_LLD_CFG_VERSION_MAJOR             1
+#define AMIRO_LLD_CFG_VERSION_MINOR             0
 
 /**
  * @brief   Width of the apalTime_t data type.
@@ -41,7 +41,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * @details Possible values are 8, 16, 32, and 64 bits.
  *          By definition time is represented at microsecond precision.
  */
-#define AMIROLLD_CFG_TIME_SIZE          32
+#define AMIROLLD_CFG_TIME_SIZE                  32
 
 #endif /* ALLDCONF_H */
 
diff --git a/modules/NUCLEO-L476RG/alldconf.h b/modules/NUCLEO-L476RG/alldconf.h
index 73c5fd6..de110f8 100644
--- a/modules/NUCLEO-L476RG/alldconf.h
+++ b/modules/NUCLEO-L476RG/alldconf.h
@@ -32,8 +32,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * compatibility guards
  */
 #define _AMIRO_LLD_CFG_
-#define AMIRO_LLD_CFG_VERSION_MAJOR         1
-#define AMIRO_LLD_CFG_VERSION_MINOR         0
+#define AMIRO_LLD_CFG_VERSION_MAJOR             1
+#define AMIRO_LLD_CFG_VERSION_MINOR             0
 
 /**
  * @brief   Width of the apalTime_t data type.
@@ -41,7 +41,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * @details Possible values are 8, 16, 32, and 64 bits.
  *          By definition time is represented at microsecond precision.
  */
-#define AMIROLLD_CFG_TIME_SIZE          32
+#define AMIROLLD_CFG_TIME_SIZE                  32
 
 #endif /* ALLDCONF_H */
 
diff --git a/modules/PowerManagement_1-1/alldconf.h b/modules/PowerManagement_1-1/alldconf.h
index c6a8fc8..7f4dbb3 100644
--- a/modules/PowerManagement_1-1/alldconf.h
+++ b/modules/PowerManagement_1-1/alldconf.h
@@ -32,8 +32,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * compatibility guards
  */
 #define _AMIRO_LLD_CFG_
-#define AMIRO_LLD_CFG_VERSION_MAJOR         1
-#define AMIRO_LLD_CFG_VERSION_MINOR         0
+#define AMIRO_LLD_CFG_VERSION_MAJOR             1
+#define AMIRO_LLD_CFG_VERSION_MINOR             0
 
 /**
  * @brief   Width of the apalTime_t data type.
@@ -41,7 +41,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * @details Possible values are 8, 16, 32, and 64 bits.
  *          By definition time is represented at microsecond precision.
  */
-#define AMIROLLD_CFG_TIME_SIZE          32
+#define AMIROLLD_CFG_TIME_SIZE                  32
 
 // required to differentiate between various sensor rings
 #include <board.h>
@@ -49,62 +49,62 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /**
  * @brief   Enable flag for the AT24C01BN-SH-B EEPROM.
  */
-#define AMIROLLD_CFG_AT24C01B           1
+#define AMIROLLD_CFG_AT24C01B                   1
 
 /**
  * @brief   Enable flag for the BQ24103A charger.
  */
-#define AMIROLLD_CFG_BQ241xx            1
+#define AMIROLLD_CFG_BQ241xx                    1
 
 /**
  * @brief   Enable flag for the BQ27500 fuel gauge.
  */
-#define AMIROLLD_CFG_BQ27500            1
+#define AMIROLLD_CFG_BQ27500                    1
 
 /**
  * @brief   Enable flag for the INA219 power monitor.
  */
-#define AMIROLLD_CFG_INA219             1
+#define AMIROLLD_CFG_INA219                     1
 
 /**
  * @brief   Enable flag for the status LED.
  */
-#define AMIROLLD_CFG_LED                1
+#define AMIROLLD_CFG_LED                        1
 
 /**
  * @brief   Enable flag for the PKLCS1212E4001 buzzer.
  */
-#define AMIROLLD_CFG_PKxxxExxx          1
-#define PKxxxExxx_LLD_FREQUENCY_MIN     2000
-#define PKxxxExxx_LLD_FREQUENCY_SPEC    4000
-#define PKxxxExxx_LLD_FREQUENCY_MAX     6000
+#define AMIROLLD_CFG_PKxxxExxx                  1
+#define PKxxxExxx_LLD_FREQUENCY_MIN             2000
+#define PKxxxExxx_LLD_FREQUENCY_SPEC            4000
+#define PKxxxExxx_LLD_FREQUENCY_MAX             6000
 
 /**
  * @brief   Enable flag for the TPS2051BDBV power switch.
  */
-#define AMIROLLD_CFG_TPS20xxB           1
+#define AMIROLLD_CFG_TPS20xxB                   1
 
 /**
  * @brief   Enable flag for the TPS62113 step-down converter.
  */
-#define AMIROLLD_CFG_TPS6211x           1
+#define AMIROLLD_CFG_TPS6211x                   1
 
 #if (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) || defined(__DOXYGEN__)
 
 /**
  * @brief   Enable flag for the MPR121 touch sensor.
  */
-#define AMIROLLD_CFG_MPR121             1
+#define AMIROLLD_CFG_MPR121                     1
 
 /**
  * @brief   Enable flag for the PCA9544A I2C multiplexer.
  */
-#define AMIROLLD_CFG_PCA9544A           1
+#define AMIROLLD_CFG_PCA9544A                   1
 
 /**
  * @brief   Enable flag for the VCNL4020 proximity sensor.
  */
-#define AMIROLLD_CFG_VCNL4020           1
+#define AMIROLLD_CFG_VCNL4020                   1
 
 #endif /* BOARD_SENSORRING == BOARD_PROXIMITYSENSOR */
 
@@ -113,12 +113,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /**
  * @brief   Enable flag for the PCAL6524 GPIO extender
  */
-#define AMIROLLD_CFG_PCAL6524           1
+#define AMIROLLD_CFG_PCAL6524                   1
 
 /**
  * @brief   Enable flag for the AT42Q1050 touch sensor.
  */
-#define AMIROLLD_CFG_AT42QT1050         1
+#define AMIROLLD_CFG_AT42QT1050                 1
 
 #endif /* BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X */
 
@@ -127,12 +127,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /**
  * @brief   Enable flag for the PCAL6524 GPIO extender
  */
-#define AMIROLLD_CFG_PCAL6524           1
+#define AMIROLLD_CFG_PCAL6524                   1
 
 /**
  * @brief   Enable flag for the AT42Q1050 touch sensor.
  */
-#define AMIROLLD_CFG_AT42QT1050         1
+#define AMIROLLD_CFG_AT42QT1050                 1
 
 #endif /* BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X */
 
diff --git a/modules/STM32F407G-DISC1/alldconf.h b/modules/STM32F407G-DISC1/alldconf.h
index 83cc42f..41643df 100644
--- a/modules/STM32F407G-DISC1/alldconf.h
+++ b/modules/STM32F407G-DISC1/alldconf.h
@@ -32,8 +32,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * compatibility guards
  */
 #define _AMIRO_LLD_CFG_
-#define AMIRO_LLD_CFG_VERSION_MAJOR         1
-#define AMIRO_LLD_CFG_VERSION_MINOR         0
+#define AMIRO_LLD_CFG_VERSION_MAJOR             1
+#define AMIRO_LLD_CFG_VERSION_MINOR             0
 
 /**
  * @brief   Width of the apalTime_t data type.
@@ -41,7 +41,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * @details Possible values are 8, 16, 32, and 64 bits.
  *          By definition time is represented at microsecond precision.
  */
-#define AMIROLLD_CFG_TIME_SIZE          32
+#define AMIROLLD_CFG_TIME_SIZE                  32
 
 #endif /* ALLDCONF_H */
 
diff --git a/periphery-lld/periphAL.c b/periphery-lld/periphAL.c
new file mode 100644
index 0000000..536b22c
--- /dev/null
+++ b/periphery-lld/periphAL.c
@@ -0,0 +1,61 @@
+/*
+AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
+Copyright (C) 2016..2019  Thomas Schöpping et al.
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <amiro-lld.h>
+
+#if (AMIROOS_CFG_DBG == true) || defined(__DOXYGEN__)
+
+#include <amiroos.h>
+#include <chprintf.h>
+
+/**
+ * @brief Assert function to check a given condition and print a message string.
+ *
+ * @param[in] c     The condition to check.
+ * @param[in] fmt   Formatted message string to print.
+ */
+void _apalDbgAssertMsg(const bool c, const char* fmt, ...)
+{
+  if (!c) {
+    va_list ap;
+
+    va_start(ap, fmt);
+    chvprintf((BaseSequentialStream*)&aos.iostream, fmt, ap);
+    va_end(ap);
+    chThdExit(MSG_RESET);
+  }
+  return;
+}
+
+/**
+ * @brief Printf function for messages printed only in debug builds.
+ *
+ * @param[in] fmt   Formatted string to print.
+ */
+void apalDbgPrintf(const char* fmt, ...)
+{
+  va_list ap;
+
+  va_start(ap, fmt);
+  chvprintf((BaseSequentialStream*)&aos.iostream, fmt, ap);
+  va_end(ap);
+
+  return;
+}
+
+#endif /* AMIROOS_CFG_DBG == true */
diff --git a/periphery-lld/periphAL.h b/periphery-lld/periphAL.h
index ecd6f1d..8bc2316 100644
--- a/periphery-lld/periphAL.h
+++ b/periphery-lld/periphAL.h
@@ -41,9 +41,41 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /* DEPENDENCIES                                                               */
 /*============================================================================*/
 
+#include <aosconf.h>
 #include <hal.h>
 
 /*============================================================================*/
+/* DEBUG                                                                      */
+/*============================================================================*/
+
+#if (AMIROOS_CFG_DBG == true) || defined(__DOXYGEN__)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+  void _apalDbgAssertMsg(const bool c, const char* fmt, ...);
+  void apalDbgPrintf(const char* fmt, ...);
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @brief Assert function to check a given condition.
+ *
+ * @param[in] c     The condition to check.
+ */
+#define apalDbgAssert(c)                                                      \
+  _apalDbgAssertMsg(c, "%s(%u): apalDbgAssert failed", __FILE__, __LINE__);
+
+#else /* AMIROOS_CFG_DBG != true */
+
+#define apalDbgAssert(constition)
+#define apalDbgAssertMsg(condition, fmt, ...)
+#define apalDbgPrintf(fmt, ...)
+
+#endif /* AMIROOS_CFG_DBG */
+
+/*============================================================================*/
 /* GENERAL                                                                    */
 /*============================================================================*/
 
@@ -55,7 +87,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 static inline void usleep(apalTime_t us)
 {
   // check if the specified time can be represented by the system
-  chDbgCheck(us <= chTimeI2US(TIME_INFINITE));
+  apalDbgAssert(us <= chTimeI2US(TIME_INFINITE));
 
   const sysinterval_t interval = chTimeUS2I(us);
   // TIME_IMMEDIATE makes no sense and would even cause system halt
@@ -89,8 +121,8 @@ struct apalGpio_t {
  */
 static inline apalExitStatus_t apalGpioRead(apalGpio_t* gpio, apalGpioState_t* const val)
 {
-  chDbgCheck(gpio != NULL);
-  chDbgCheck(val != NULL);
+  apalDbgAssert(gpio != NULL);
+  apalDbgAssert(val != NULL);
 
   *val = (palReadPad(gpio->port, gpio->pad) == PAL_HIGH) ? APAL_GPIO_HIGH : APAL_GPIO_LOW;
   return APAL_STATUS_OK;
@@ -106,7 +138,7 @@ static inline apalExitStatus_t apalGpioRead(apalGpio_t* gpio, apalGpioState_t* c
  */
 static inline apalExitStatus_t apalGpioWrite(apalGpio_t* gpio, const apalGpioState_t val)
 {
-  chDbgCheck(gpio != NULL);
+  apalDbgAssert(gpio != NULL);
 
   // palWritePad() is not guaranteed to be atomic, thus the scheduler is locked.
   syssts_t sysstatus = chSysGetStatusAndLockX();
@@ -124,7 +156,7 @@ static inline apalExitStatus_t apalGpioWrite(apalGpio_t* gpio, const apalGpioSta
  */
 static inline apalExitStatus_t apalGpioToggle(apalGpio_t* gpio)
 {
-  chDbgCheck(gpio != NULL);
+  apalDbgAssert(gpio != NULL);
 
   // palWritePad() is not guaranteed to be atomic, thus the scheduler is locked.
   syssts_t sysstatus = chSysGetStatusAndLockX();
@@ -143,9 +175,9 @@ static inline apalExitStatus_t apalGpioToggle(apalGpio_t* gpio)
  */
 static inline apalExitStatus_t apalControlGpioGet(const apalControlGpio_t* const cgpio, apalControlGpioState_t* const val)
 {
-  chDbgCheck(cgpio != NULL);
-  chDbgCheck(cgpio->gpio != NULL);
-  chDbgCheck(val != NULL);
+  apalDbgAssert(cgpio != NULL);
+  apalDbgAssert(cgpio->gpio != NULL);
+  apalDbgAssert(val != NULL);
 
   *val = ((palReadPad(cgpio->gpio->port, cgpio->gpio->pad) == PAL_HIGH) ^ (cgpio->meta.active == APAL_GPIO_ACTIVE_HIGH)) ? APAL_GPIO_OFF : APAL_GPIO_ON;
   return APAL_STATUS_OK;
@@ -161,9 +193,9 @@ static inline apalExitStatus_t apalControlGpioGet(const apalControlGpio_t* const
  */
 static inline apalExitStatus_t apalControlGpioSet(const apalControlGpio_t* const cgpio, const apalControlGpioState_t val)
 {
-  chDbgCheck(cgpio != NULL);
-  chDbgCheck(cgpio->gpio != NULL);
-  chDbgCheck(cgpio->meta.direction == APAL_GPIO_DIRECTION_OUTPUT || cgpio->meta.direction == APAL_GPIO_DIRECTION_BIDIRECTIONAL);
+  apalDbgAssert(cgpio != NULL);
+  apalDbgAssert(cgpio->gpio != NULL);
+  apalDbgAssert(cgpio->meta.direction == APAL_GPIO_DIRECTION_OUTPUT || cgpio->meta.direction == APAL_GPIO_DIRECTION_BIDIRECTIONAL);
 
   // palWritePad() is not guaranteed to be atomic, thus the scheduler is locked.
   syssts_t sysstatus = chSysGetStatusAndLockX();
@@ -180,7 +212,7 @@ static inline apalExitStatus_t apalControlGpioSet(const apalControlGpio_t* const
     (edge == APAL_GPIO_EDGE_FALLING) ? PAL_EVENT_MODE_FALLING_EDGE :  \
      (edge == APAL_GPIO_EDGE_BOTH) ? PAL_EVENT_MODE_BOTH_EDGES : 0)
 
-#endif
+#endif /* HAL_USE_PAL */
 
 /*============================================================================*/
 /* PWM                                                                        */
@@ -204,7 +236,7 @@ typedef PWMDriver apalPWMDriver_t;
  */
 static inline apalExitStatus_t apalPWMSet(apalPWMDriver_t* pwm, const apalPWMchannel_t channel, const apalPWMwidth_t width)
 {
-  chDbgCheck(pwm != NULL);
+  apalDbgAssert(pwm != NULL);
 
   pwmEnableChannel(pwm, (pwmchannel_t)channel, pwm->period * ((float)width / (float)APAL_PWM_WIDTH_MAX) + 0.5f);
   return APAL_STATUS_OK;
@@ -220,8 +252,8 @@ static inline apalExitStatus_t apalPWMSet(apalPWMDriver_t* pwm, const apalPWMcha
  */
 static inline apalExitStatus_t apalPWMGetFrequency(apalPWMDriver_t* pwm, apalPWMfrequency_t* const frequency)
 {
-  chDbgCheck(pwm != NULL);
-  chDbgCheck(frequency != NULL);
+  apalDbgAssert(pwm != NULL);
+  apalDbgAssert(frequency != NULL);
 
   *frequency = pwm->config->frequency;
   return APAL_STATUS_OK;
@@ -237,14 +269,14 @@ static inline apalExitStatus_t apalPWMGetFrequency(apalPWMDriver_t* pwm, apalPWM
  */
 static inline apalExitStatus_t apalPWMGetPeriod(apalPWMDriver_t* pwm, apalPWMperiod_t* const period)
 {
-  chDbgCheck(pwm != NULL);
-  chDbgCheck(period != NULL);
+  apalDbgAssert(pwm != NULL);
+  apalDbgAssert(period != NULL);
 
   *period = pwm->period;
   return APAL_STATUS_OK;
 }
 
-#endif
+#endif /* HAL_USE_PWM */
 
 /*============================================================================*/
 /* QEI                                                                        */
@@ -267,8 +299,8 @@ typedef QEIDriver apalQEIDriver_t;
  */
 static inline apalExitStatus_t apalQEIGetDirection(apalQEIDriver_t* qei, apalQEIDirection_t* const direction)
 {
-  chDbgCheck(qei != NULL);
-  chDbgCheck(direction != NULL);
+  apalDbgAssert(qei != NULL);
+  apalDbgAssert(direction != NULL);
 
   *direction = (qei_lld_get_direction(qei)) ? APAL_QEI_DIRECTION_DOWN : APAL_QEI_DIRECTION_UP;
 
@@ -285,8 +317,8 @@ static inline apalExitStatus_t apalQEIGetDirection(apalQEIDriver_t* qei, apalQEI
  */
 static inline apalExitStatus_t apalQEIGetPosition(apalQEIDriver_t* qei, apalQEICount_t* const position)
 {
-  chDbgCheck(qei != NULL);
-  chDbgCheck(position != NULL);
+  apalDbgAssert(qei != NULL);
+  apalDbgAssert(position != NULL);
 
   *position = qei_lld_get_position(qei);
 
@@ -303,15 +335,15 @@ static inline apalExitStatus_t apalQEIGetPosition(apalQEIDriver_t* qei, apalQEIC
  */
 static inline apalExitStatus_t apalQEIGetRange(apalQEIDriver_t* qei, apalQEICount_t* const range)
 {
-  chDbgCheck(qei != NULL);
-  chDbgCheck(range != NULL);
+  apalDbgAssert(qei != NULL);
+  apalDbgAssert(range != NULL);
 
   *range = qei_lld_get_range(qei);
 
   return APAL_STATUS_OK;
 }
 
-#endif
+#endif /* HAL_USE_QEI */
 
 /*============================================================================*/
 /* I2C                                                                        */
@@ -339,7 +371,7 @@ typedef I2CDriver apalI2CDriver_t;
  */
 static inline apalExitStatus_t apalI2CMasterTransmit(apalI2CDriver_t* i2cd, const apalI2Caddr_t addr, const uint8_t* const txbuf, const size_t txbytes, uint8_t* const rxbuf, const size_t rxbytes, const apalTime_t timeout)
 {
-  chDbgCheck(i2cd != NULL);
+  apalDbgAssert(i2cd != NULL);
 
 #if (I2C_USE_MUTUAL_EXCLUSION == TRUE)
   // check whether the I2C driver was locked externally
@@ -401,7 +433,7 @@ static inline apalExitStatus_t apalI2CMasterTransmit(apalI2CDriver_t* i2cd, cons
  */
 static inline apalExitStatus_t apalI2CMasterReceive(apalI2CDriver_t* i2cd, const apalI2Caddr_t addr, uint8_t* const rxbuf, const size_t rxbytes, const apalTime_t timeout)
 {
-  chDbgCheck(i2cd != NULL);
+  apalDbgAssert(i2cd != NULL);
 
 #if (I2C_USE_MUTUAL_EXCLUSION == TRUE)
   // check whether the I2C driver was locked externally
@@ -450,7 +482,7 @@ static inline apalExitStatus_t apalI2CMasterReceive(apalI2CDriver_t* i2cd, const
   }
 }
 
-#endif
+#endif /* HAL_USE_I2C */
 
 /*============================================================================*/
 /* SPI                                                                        */
@@ -475,7 +507,7 @@ typedef SPIDriver apalSPIDriver_t;
  */
 static inline apalExitStatus_t apalSPIExchange(apalSPIDriver_t* spid, const uint8_t* const txData , uint8_t* const rxData, const size_t length)
 {
-  chDbgCheck(spid != NULL);
+  apalDbgAssert(spid != NULL);
 
 #if (SPI_USE_MUTUAL_EXCLUSION)
   // check whether the SPI driver was locked externally
@@ -509,7 +541,7 @@ static inline apalExitStatus_t apalSPIExchange(apalSPIDriver_t* spid, const uint
  */
 static inline apalExitStatus_t apalSPIReceive(apalSPIDriver_t* spid, uint8_t* const data, const size_t length)
 {
-  chDbgCheck(spid != NULL);
+  apalDbgAssert(spid != NULL);
 
 #if (SPI_USE_MUTUAL_EXCLUSION)
   // check whether the SPI driver was locked externally
@@ -543,7 +575,7 @@ static inline apalExitStatus_t apalSPIReceive(apalSPIDriver_t* spid, uint8_t* co
  */
 static inline apalExitStatus_t apalSPITransmit(apalSPIDriver_t* spid, const uint8_t* const data, const size_t length)
 {
-  chDbgCheck(spid != NULL);
+  apalDbgAssert(spid != NULL);
 
 #if (SPI_USE_MUTUAL_EXCLUSION)
   // check whether the SPI driver was locked externally
@@ -579,7 +611,7 @@ static inline apalExitStatus_t apalSPITransmit(apalSPIDriver_t* spid, const uint
  */
 static inline apalExitStatus_t apalSPITransmitAndReceive(apalSPIDriver_t* spid, const uint8_t* const txData , uint8_t* const rxData, const size_t txLength, const size_t rxLength)
 {
-  chDbgCheck(spid != NULL);
+  apalDbgAssert(spid != NULL);
 
 #if (SPI_USE_MUTUAL_EXCLUSION)
   // check whether the SPI driver was locked externally
@@ -603,31 +635,6 @@ static inline apalExitStatus_t apalSPITransmitAndReceive(apalSPIDriver_t* spid,
   return APAL_STATUS_OK;
 }
 
-#endif
-
-/*============================================================================*/
-/* DEBUG                                                                      */
-/*============================================================================*/
-
-/**
- * @brief Assert function to check a given condition.
- *
- * @param[in] c   The condition to check.
- */
-#define apalDbgAssert(c)              chDbgAssert(c, "")
-
-
-/**
- * @brief Printf function for messages printed only in debug builds.
- *
- * @param[in] fmt   Formatted string to print.
- */
-#if (AMIROOS_CFG_DBG == true) || defined(__DOXYGEN__)
-#define apalDbgPrintf(fmt, ...)       chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__)
-#else
-#define apalDbgPrintf(fmt, ...) {                         \
-  (void)(fmt);                                            \
-}
-#endif
+#endif /* HAL_USE_SPI */
 
 #endif /* AMIROOS_PERIPHAL_H */
diff --git a/periphery-lld/periphery-lld.mk b/periphery-lld/periphery-lld.mk
index b8c37eb..d0c0442 100644
--- a/periphery-lld/periphery-lld.mk
+++ b/periphery-lld/periphery-lld.mk
@@ -33,5 +33,6 @@ PERIPHERYLLDINC = $(AMIROLLD_INC) \
                   $(PERIPHERYLLD_DIR:/=)
 
 # C sources
-PERIPHERYLLDCSRC = $(AMIROLLD_CSRC)
+PERIPHERYLLDCSRC = $(AMIROLLD_CSRC) \
+                   $(PERIPHERYLLD_DIR)periphAL.c
 
