diff --git a/cpu/cortexm_common/vectors_cortexm.c b/cpu/cortexm_common/vectors_cortexm.c index 56eaae22ab61..c93db3ef5d4a 100644 --- a/cpu/cortexm_common/vectors_cortexm.c +++ b/cpu/cortexm_common/vectors_cortexm.c @@ -32,6 +32,10 @@ #include "panic.h" #include "vectors_cortexm.h" +#ifdef MODULE_PINDBG +#include "pindbg.h" +#endif + #ifndef SRAM_BASE #define SRAM_BASE 0 #endif @@ -113,6 +117,11 @@ void reset_handler_default(void) post_startup(); +#ifdef MODULE_PINDBG + /* initialize debug pins if configured */ + pindbg_init(); +#endif + /* initialize the board (which also initiates CPU initialization) */ board_init(); diff --git a/cpu/stm32_common/include/pindbg_cpu.h b/cpu/stm32_common/include/pindbg_cpu.h new file mode 100644 index 000000000000..a2f4f41c0bdf --- /dev/null +++ b/cpu/stm32_common/include/pindbg_cpu.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2017 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup cpu_stm32_common + * + * @{ + * @file + * @brief CPU specific handlers for direct control of debug pins + * + * @author Hauke Petersen + */ + +#ifndef PINDBG_CPU_H +#define PINDBG_CPU_H + +#include "cpu.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef PINDBG0 +#define PINDBG0_PORT ((GPIO_TypeDef *)(PINDBG0 & ~(0x0f))) +#define PINDBG0_MASK (1 << (PINDBG0 & 0xf)) +#define PINDBG0_SET (PINDBG0_PORT->BSRR = PINDBG0_MASK) +#define PINDBG0_CLR (PINDBG0_PORT->BSRR = (PINDBG0_MASK << 16)) +#define PINDBG0_TGL (PINDBG0_PORT->ODR ^= PINDBG0_MASK) +#endif + +#ifdef PINDBG1 +#define PINDBG1_PORT ((GPIO_TypeDef *)(PINDBG1 & ~(0x0f))) +#define PINDBG1_MASK (1 << (PINDBG1 & 0xf)) +#define PINDBG1_SET (PINDBG1_PORT->BSRR = PINDBG1_MASK) +#define PINDBG1_CLR (PINDBG1_PORT->BSRR = (PINDBG1_MASK << 16)) +#define PINDBG1_TGL (PINDBG1_PORT->ODR ^= PINDBG1_MASK) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* PINDBG_CPU_H */ +/** @} */ diff --git a/sys/include/pindbg.h b/sys/include/pindbg.h new file mode 100644 index 000000000000..f68def01da14 --- /dev/null +++ b/sys/include/pindbg.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2017 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_pindbg Direct pin control for debugging/profiling + * @ingroup sys + * + * This module gives the possibility to directly control a number of GPIO pins + * without the least possible overhead for debugging and profiling purposes. For + * this, the module provides a number of macros for setting, clearing, and + * toggling some defined pins: `PINDBG[\d]_[SET|CLR|TGL]`, for example + * `PINDBG0_SET` or `PINDBG1_TGL`. + * + * To use this module, you have to do two things: + * 1. the module has to be selected in your project: `USEMODULE += pindbg` + * 2. you have to define the pins you want to use for debugging, e.g.: + * `CFLAGS += -DPINDBG0=GPIO_PIN\(0,15\) -DPINDBG1=GPIO_PIN\(1,24\)` + * + * It is of course up to you to add these settings to your application Makefile + * for the duration of debugging/profiling or to set them through environment + * variables in your host systems shell. + * + * The initialization function is automatically called as early as possible + * during the system initialization so the debug pins can be used already during + * e.g. auto_init and so on. + * + * @{ + * @file + * @brief Module for direct pin control for debugging/profiling purposes + * + * @author Hauke Petersen + */ + +#ifndef PINDBG_H +#define PINDBG_H + +#include "pindbg_cpu.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Initialize all configured debug pins + */ +void pindbg_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* PINDBG_H */ +/** @} */ + diff --git a/sys/pindbg/Makefile b/sys/pindbg/Makefile new file mode 100644 index 000000000000..48422e909a47 --- /dev/null +++ b/sys/pindbg/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/sys/pindbg/pindbg.c b/sys/pindbg/pindbg.c new file mode 100644 index 000000000000..39d6c24a3a3a --- /dev/null +++ b/sys/pindbg/pindbg.c @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2017 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup sys_pindbg + * @{ + * + * @file + * @brief Initialization of configured direct controlled debug pins + * + * @author Hauke Petersen + * + * @} + */ + +#include "pindbg.h" +#include "periph/gpio.h" + +void pindbg_init(void) +{ +#ifdef PINDBG0 + gpio_init(PINDBG0, GPIO_OUT); +#endif +#ifdef PINDBG1 + gpio_init(PINDBG1, GPIO_OUT); +#endif +}